Sub topic 14
Guardrails: SCPs and Permissions Boundaries
This chapter assumes you can read IAM JSON policies and know the trust policy, role permissions policy, and caller identity policy covered in earlier chapters. It also assumes you have used aws sts assume-role. Here you will learn the two guardrail mechanisms that cap what a cross-account role can do, even when the trust policy and the permissions policy both look correct.
Why guardrails matter for cross-account roles
A trust policy and a permissions policy grant access. Neither one can take away access that another layer has denied. Guardrails are policies that set a maximum. They never grant anything on their own. They only limit what other policies are allowed to grant.
Two guardrails matter most for cross-account work:
- Service control policies (SCPs) are set in AWS Organizations and limit every principal in the affected accounts.
- Permissions boundaries are set on one IAM user or role and limit that single identity.
The effective permission of a principal is the overlap of everything that applies to it. If any layer is missing the action, or has an explicit deny for it, the request fails.
Service control policies
An SCP is a policy you attach to an organization root, an organizational unit (OU), or a single member account. It applies to all IAM users and roles in the account, including roles that people assume from other accounts. It does not apply to the organization's management account, and it does not apply to service-linked roles.
An SCP does not grant permissions. An action is possible only if the SCP allows it and an identity policy also allows it.
How SCPs affect AssumeRole
SCPs apply to the account where the principal lives, so both sides of a cross-account call can be affected:
- An SCP on the caller's account can block
sts:AssumeRole, so the call never leaves the account. - An SCP on the role's account limits what the assumed role can do after the call succeeds. The role's session is a principal in that account, so that account's SCPs apply to it.
This is a common surprise. The role in account 222222222222 might have s3:* in its permissions policy, but an SCP on that account can deny s3:DeleteBucket. The session then cannot delete a bucket.
An example SCP
This SCP denies a set of dangerous actions for every principal in the account unless the caller is a specific administrative role. It is a typical "deny with an exception" pattern.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyLeavingOrganization",
"Effect": "Deny",
"Action": "organizations:LeaveOrganization",
"Resource": "*"
},
{
"Sid": "DenyDisablingCloudTrail",
"Effect": "Deny",
"Action": [
"cloudtrail:StopLogging",
"cloudtrail:DeleteTrail"
],
"Resource": "*",
"Condition": {
"ArnNotLike": {
"aws:PrincipalArn": "arn:aws:iam::*:role/SecurityAdmin"
}
}
}
]
}A role such as ReadOnlyAuditor cannot stop CloudTrail from this account, even if someone later adds cloudtrail:* to its permissions policy.
Two common SCP strategies
| Strategy | How it works | Trade-off |
|---|---|---|
| Deny list | Keep the default `FullAWSAccess` SCP and add explicit Deny statements. | Easy to start with. You must remember to deny every risky action. |
| Allow list | Remove `FullAWSAccess` and allow only named services. | Strong control. Any service you forget to allow stops working. |
Most teams start with a deny list and move to an allow list only for tightly regulated accounts.
Permissions boundaries
A permissions boundary is a managed policy that you attach to an IAM user or role as its boundary. It sets the maximum permissions that identity-based policies can give that identity. Like an SCP, it grants nothing by itself.
For a role, the effective permissions from identity policies are the intersection of the permissions policy and the boundary.
Because that diagram form is not available in plain text here, use the following table to see the intersection.
| Action | In permissions policy | In boundary | Allowed |
|---|---|---|---|
| `s3:GetObject` | Yes | Yes | Yes |
| `s3:PutObject` | Yes | No | No |
| `ec2:DescribeInstances` | No | Yes | No |
An example boundary
This boundary caps a role to read-only access in S3 and EC2 listing calls.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"s3:List*",
"ec2:Describe*"
],
"Resource": "*"
}
]
}You attach it to the role with the CLI. The command below runs in the role's account and uses a placeholder policy ARN.
aws iam put-role-permissions-boundary \
--role-name ReadOnlyAuditor \
--permissions-boundary arn:aws:iam::222222222222:policy/AuditorBoundaryBoundaries and the trust policy
A permissions boundary on a role does not restrict who can assume it. The trust policy controls that. The boundary only limits what the session can do after assumption. This distinction matters when you troubleshoot. A failure at AssumeRole is not caused by a boundary on the target role. A failure after a successful AssumeRole can be.
Boundaries for delegated administration
Boundaries are most useful when you let someone else create roles. Suppose a team lead in account 222222222222 may create roles for their applications. You grant iam:CreateRole only if the request includes your boundary:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:CreateRole",
"iam:PutRolePolicy",
"iam:AttachRolePolicy"
],
"Resource": "arn:aws:iam::222222222222:role/app-*",
"Condition": {
"StringEquals": {
"iam:PermissionsBoundary": "arn:aws:iam::222222222222:policy/AuditorBoundary"
}
}
}
]
}New roles cannot be created without the boundary, so a delegated administrator cannot create a role more powerful than the boundary allows. In practice you should also deny iam:DeleteRolePermissionsBoundary so the boundary cannot be removed later.
How all the layers combine
For a cross-account call, a request passes through several checks. The role's session must be allowed by every layer that applies.
| Layer | Where it lives | What it controls |
|---|---|---|
| Caller SCP | Caller's account | Whether the caller can call `sts:AssumeRole` |
| Caller identity policy | Caller's account | Permission to assume the specific role |
| Role trust policy | Role's account | Who may assume the role |
| Role SCP | Role's account | The ceiling for all principals there |
| Permissions boundary | The role | The ceiling for that role |
| Permissions policy | The role | What the role is granted |
An explicit Deny in any of these overrides every Allow.
A short rule helps when reasoning about a failure: the trust policy and the caller policy decide whether you get a session, and the SCP, boundary, and permissions policy decide what the session can do.
Seeing guardrails in action
Assume the role and try an action that the guardrails block. First get a session using the profile from an earlier chapter:
aws sts get-caller-identity --profile auditorA successful result shows an assumed-role ARN in account 222222222222. Then try an action outside the boundary:
aws s3api put-object \
--bucket example-audit-bucket \
--key test.txt \
--body test.txt \
--profile auditorIf the boundary does not include s3:PutObject, the call fails with a message like this:
An error occurred (AccessDenied) when calling the PutObject operation:
User: arn:aws:sts::222222222222:assumed-role/ReadOnlyAuditor/audit-session
is not authorized to perform: s3:PutObject on resource:
"arn:aws:s3:::example-audit-bucket/test.txt"
because no permissions boundary allows the s3:PutObject actionThe message names the layer that blocked the request. For an SCP it reads "with an explicit deny in a service control policy" or "no service control policy allows". Read the final clause first, because it tells you which guardrail to inspect.
Common errors and gotchas
- Editing the permissions policy to fix a guardrail failure. Adding an action to the role does nothing if an SCP or boundary blocks it. Check the error text for the layer.
- Forgetting the management account is exempt from SCPs. SCPs do not limit principals in the management account. Do not rely on them to protect it.
- Assuming a boundary limits who can assume. It does not. Use the trust policy and conditions for that.
- Resource-based policies and boundaries. A resource-based policy that names the role's ARN directly as principal can allow access without the boundary applying. A boundary does not limit grants from a resource policy to a role ARN. Check this if a role seems to exceed its boundary.
- Role chaining and SCPs. Each hop is evaluated against the SCPs of the account where that role lives.
Choosing between them
- Use an SCP when a rule must hold for a whole account or OU, such as blocking unapproved regions or protecting CloudTrail.
- Use a permissions boundary when you delegate role creation or want to cap one role regardless of which policies are attached later.
- Use both when you need a company-wide ceiling and a per-role ceiling.
Exercise
A role ReadOnlyAuditor in account 222222222222 has a permissions policy allowing s3:*. A user in account 111111111111 assumes it successfully, but s3:DeleteBucket fails with AccessDenied. The error says "with an explicit deny in a service control policy". Which account's configuration should you inspect, and does editing the role's permissions policy fix it?
Show answer
Inspect the SCPs that apply to account 222222222222 (its OU, the root, and the account itself), because the assumed-role session is a principal in that account. Editing the role's permissions policy does not help, since an explicit deny in an SCP overrides any Allow. Remove or adjust the deny statement in the SCP, or use an exception condition for the role.
Exercise
You attach a permissions boundary that allows only s3:Get and s3:List to a role whose trust policy allows account 111111111111. Can a user in that account still assume the role? Can the session call s3:PutObject?
Show answer
Yes, the user can still assume the role, because a boundary does not affect the trust policy or who can assume. No, the session cannot call s3:PutObject, because the effective permissions are the intersection of the permissions policy and the boundary, and the boundary does not include that action.