Prevents manual creation of IAM users and policy attachments through the console, ensuring these actions are only performed through approved automation.
The recommended solution using multiple policy layers
To effectively restrict console administrative actions while allowing automation, we implement a two-layer approach:
This SCP restricts sensitive IAM operations to specific automation roles by focusing on the principal's ARN rather than trying to detect the console source:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "RestrictSensitiveIAMOperations",
"Effect": "Deny",
"Action": [
"iam:CreateUser",
"iam:AttachUserPolicy",
"iam:CreatePolicy",
"iam:PutUserPolicy"
],
"Resource": "*",
"Condition": {
"ArnNotLike": {
"aws:PrincipalARN": [
"arn:aws:iam::*:role/AutomationRole*",
"arn:aws:iam::*:role/ServiceRole*"
]
}
}
}
]
}A complementary IAM permission boundary or policy that specifically controls console access:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyConsoleAccessForIAMAdmin",
"Effect": "Deny",
"Action": [
"iam:CreateUser",
"iam:AttachUserPolicy",
"iam:CreatePolicy",
"iam:PutUserPolicy"
],
"Resource": "*",
"Condition": {
"Bool": {
"aws:ViaAWSService": "false"
},
"StringNotLike": {
"aws:UserAgent": "*AWS-CloudFormation*"
}
}
}
]
}How to test this combined approach works
To validate this solution, test both automated and manual operations:
The combination of SCP and IAM policies ensures that sensitive IAM operations can only be performed through approved automation channels, while effectively blocking console and direct API access.
An example of what not to do
The following approach demonstrates common mistakes when trying to restrict console access:
❌ Do Not Use This Approach:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Action": [
"iam:CreateUser",
"iam:AttachUserPolicy"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:ViaAWSService": "false",
"aws:RequestedVia": "console" // Not a valid condition key
}
}
}
]
}