Sub topic 16
Guardrails: permissions boundaries and SCPs
This chapter assumes you can read IAM policy JSON, know the difference between identity-based and resource-based policies, and understand the allow, explicit deny, and implicit deny outcomes from policy evaluation. It also assumes you know what an AWS Organizations account hierarchy is.
Guardrails limit permissions and never grant them
Most policies you have written so far grant access. A guardrail does the opposite. It sets a ceiling on what other policies can grant. IAM has two main guardrails:
- A permissions boundary is a managed policy attached to one IAM user or role. It limits what that single identity can do.
- A service control policy (SCP) is a policy in AWS Organizations. It limits what the IAM users and roles in a set of accounts can do.
Neither guardrail gives permission to anyone. If a boundary allows s3:* but the identity has no policy allowing S3 actions, the identity cannot use S3. The effective permissions are the intersection of every layer.
The diagram is simplified. The full evaluation logic also covers resource-based policies and session policies, which the exceptions section below touches on.
Permissions boundaries
You can set a boundary on a user or a role, but not on a group. The boundary must be a managed policy, either AWS managed or customer managed. Here is a boundary that confines an identity to three services:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowedServicesOnly",
"Effect": "Allow",
"Action": [
"s3:*",
"dynamodb:*",
"cloudwatch:*"
],
"Resource": "*"
}
]
}Save it as a customer managed policy named DevBoundary. You then attach it when you create the user:
aws iam create-user \
--user-name dev-user \
--permissions-boundary arn:aws:iam::111122223333:policy/DevBoundarySuppose you also attach the AWS managed AdministratorAccess policy to dev-user. The user can still use only S3, DynamoDB, and CloudWatch. A call to ec2:RunInstances fails, because the boundary has no statement that allows it. This is an implicit deny.
For an existing identity, use aws iam put-user-permissions-boundary or aws iam put-role-permissions-boundary.
Delegating administration safely
Boundaries are most useful when you let developers create their own roles. If a developer could create a role with AdministratorAccess, they could assume it and escape their limits. To prevent this, give the developer a policy that allows iam:CreateRole only when the new role carries your boundary:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CreateRolesOnlyWithBoundary",
"Effect": "Allow",
"Action": [
"iam:CreateRole",
"iam:AttachRolePolicy",
"iam:PutRolePolicy"
],
"Resource": "arn:aws:iam::111122223333:role/app-*",
"Condition": {
"StringEquals": {
"iam:PermissionsBoundary": "arn:aws:iam::111122223333:policy/DevBoundary"
}
}
}
]
}Every role the developer creates is now capped by DevBoundary, so it can never hold more than the developer is allowed to delegate. You would also deny iam:DeleteRolePermissionsBoundary and iam:PutRolePermissionsBoundary, so the developer cannot remove or swap the boundary afterward.
How boundaries interact with other policies
- Identity-based policies: both the boundary and an identity policy must allow the action.
- Explicit deny: a Deny in the boundary or in an identity policy wins, as it does everywhere.
- Resource-based policies: in the same account, a resource-based policy that names the user's ARN directly can grant access even when the boundary does not allow the action. The boundary does not limit that grant. Check this case before you rely on a boundary as a hard stop.
- Roles: the boundary applies to the role's permissions policies. It does not change the trust policy, so it does not control who may assume the role.
Service control policies
SCPs belong to AWS Organizations. You attach one to the organization root, an organizational unit (OU), or a single account. The policy affects every account beneath that point.
What SCPs cover
- They apply to IAM users, roles, and the root user in member accounts.
- They do not apply to the management account. Keep workloads out of it for that reason.
- They do not apply to service-linked roles.
- They do not grant anything. An account still needs identity-based or resource-based policies to give people access.
- They limit only principals inside the affected accounts. A principal from outside your organization that reaches a resource in a member account through a resource-based policy is not restricted by your SCP.
The hierarchy rule
An action must be allowed at every level between the root and the account. If an OU's SCP does not allow ec2:*, no account under that OU can use EC2, even if the account's own SCP allows it. New organizations start with the AWS managed FullAWSAccess SCP attached at each level, which allows everything.
You can use SCPs in two styles:
| Style | How it works | Trade-off |
|---|---|---|
| Deny list | Keep `FullAWSAccess` and add statements that Deny specific actions. | Easy to adopt. You must name each risky action. |
| Allow list | Remove `FullAWSAccess` and allow only the services you approve. | Stricter. New services stay blocked until you add them, and each level needs its own allows. |
Most teams start with a deny list. Here is an example:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ProtectAuditTrail",
"Effect": "Deny",
"Action": [
"cloudtrail:StopLogging",
"cloudtrail:DeleteTrail"
],
"Resource": "*"
},
{
"Sid": "StayInOrganization",
"Effect": "Deny",
"Action": "organizations:LeaveOrganization",
"Resource": "*"
}
]
}Because the SCP applies to the account's root user, it stops even the root user from stopping the trail. You can use this to protect actions that no one in the account should take.
Boundaries and SCPs compared
| Feature | Permissions boundary | SCP |
|---|---|---|
| Scope | One user or role | An account, an OU, or the whole organization |
| Managed in | IAM | AWS Organizations |
| Grants permissions | No | No |
| Affects the root user | No | Yes, in member accounts |
| Typical use | Cap what delegated admins can create | Enforce rules across accounts |
Common mistakes
- Expecting a boundary to grant access. If an action is not in the identity's own policies, the boundary does not add it.
- Attaching
Denywith a condition key that may be missing. Use theIfExistscondition operators when a missing key should count as a match. - Testing an SCP only in one account. Check the policies on every OU above it.
- Detaching
FullAWSAccessbefore you attach your allow list. This blocks all actions in the affected accounts.
Exercise
A user has the AdministratorAccess managed policy and a permissions boundary that allows only s3: and dynamodb:. The user calls ec2:DescribeInstances. What is the result, and why?
Show answer
The request is denied. The boundary has no statement that allows ec2 actions, so the effective permissions (the intersection of the boundary and the identity policy) exclude it. The result is an implicit deny, even though AdministratorAccess alone would allow it.
Exercise
An OU has an SCP that denies cloudtrail:StopLogging. An administrator in a member account under that OU has an IAM policy allowing cloudtrail:*. Can the administrator stop a trail? Can the root user of that account?
Show answer
Neither can. The SCP's explicit Deny overrides the Allow in the IAM policy. SCPs also apply to the root user of member accounts, so the root user is blocked as well.
Exercise
Why does a developer-delegation policy include the condition iam:PermissionsBoundary on iam:CreateRole?
Show answer
It forces every role the developer creates to carry the approved boundary. Without it, the developer could create a role with broader permissions than they hold and then assume it to escape their own limits.