Sub topic 14
Guardrails: SCPs and Permissions Boundaries
This chapter assumes you know how a role's trust policy and a caller's identity policy combine to allow sts:AssumeRole, and that you can read IAM JSON policies. Here you will see two controls that can block cross-account access even when both of those policies allow it.
Guardrails do not grant access
A guardrail sets a maximum. It never gives permission by itself. Two guardrails matter for cross-account roles:
- A service control policy (SCP) applies to accounts in an AWS Organization. It limits what every principal in the account can do. It does not apply to the management account.
- A permissions boundary is a managed policy attached to one IAM user or role. It limits what that identity's own policies can grant.
Both work by intersection. An action is allowed only if the identity policy allows it and each guardrail also allows it.
Where each guardrail applies
The two accounts in a cross-account setup have different exposure.
- The caller's account may have an SCP that limits
sts:AssumeRole. It may also have a permissions boundary on the calling user or role. Either one can stop the call before it reaches the other account. - The role's account may have an SCP that limits what the role can do after it is assumed. A permissions boundary on the role also limits the role's session.
An SCP example
This SCP, applied to an organizational unit, denies role assumption into any account outside the organization. It fits the caller's side.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Deny",
"Action": "sts:AssumeRole",
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:ResourceOrgID": "o-exampleorgid"
}
}
}
]
}The aws:ResourceOrgID key holds the organization ID of the account that owns the resource, which here is the role. If you attach this SCP, a call to a role in an outside account fails with an explicit deny.
A permissions boundary example
This boundary limits a role to read-only actions on S3 and CloudTrail. Attach it to the role in the trusting account as its boundary. The role's permissions policy can then list broader actions, but only the overlap works.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"s3:List*",
"cloudtrail:LookupEvents"
],
"Resource": "*"
}
]
}Set it with the CLI:
aws iam put-role-permissions-boundary \
--role-name ReadOnlyAuditor \
--permissions-boundary arn:aws:iam::222222222222:policy/AuditorBoundaryIf the role's permissions policy allows s3:PutObject, the boundary still blocks it, because the boundary does not list it.
Common mistakes
- Expecting an SCP to grant access. An SCP only filters. You still need the trust policy and identity policy.
- Forgetting that the SCP in the role's account limits the assumed session, not only the caller.
- Applying a boundary to the caller and forgetting
sts:AssumeRolein it. The call is denied even though the identity policy allows it. - Looking for SCP effects on the management account. SCPs do not restrict it.
Exercise
Exercise
A role in account 222222222222 has a trust policy that allows account 111111111111, and the caller has an identity policy allowing sts:AssumeRole on that role. The call still fails. The caller's role has a permissions boundary that allows only s3:* actions. What is the cause, and how do you fix it?
Show answer
The boundary does not include sts:AssumeRole, so the intersection of the identity policy and boundary does not allow it. Add sts:AssumeRole (preferably scoped to the role ARN arn:aws:iam::222222222222:role/ReadOnlyAuditor) to the boundary policy, or use a different boundary.