Sub topic 8
Same-account and cross-account requests
This chapter assumes you know the default-deny rule, that an explicit deny beats any allow, and how identity-based and resource-based policies are written. Here you will see how the account boundary changes how those policies combine.
The account of the principal versus the account of the resource
AWS compares two accounts for each request: the account that owns the principal and the account that owns the resource. The comparison decides whether one allow is enough or two are needed.
| Situation | What must allow the request |
|---|---|
| Same account | An identity-based policy or a resource-based policy |
| Different accounts | An identity-based policy and a resource-based policy |
In both cases an explicit deny in any applicable policy ends the evaluation with a deny.
Same account: either policy can grant
When the principal and the resource are in the same account, AWS takes the union of the grants. Suppose a role has no S3 permissions in its identity policy, but the bucket policy names that role as an allowed principal. The request succeeds, because the resource-based policy supplies the allow.
The reverse also works. The role's identity policy allows s3:GetObject on the bucket, and the bucket policy says nothing about the role. The request still succeeds.
Limiting policies still apply. A permission boundary on the role or an SCP covering the account can remove an allow that would otherwise work. One exception: a same-account resource policy that names an IAM user or role ARN directly is not limited by that principal's permission boundary.
Cross-account: both sides must say yes
A principal in one account has no automatic standing in another account. The resource account must trust the principal, and the principal's own account must let it make the call. This gives two checks:
- The resource-based policy in the resource's account allows the principal.
- The identity-based policy in the principal's account allows the action on that resource.
The bucket policy below lives in account 111122223333 and names a role from account 222233334444.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowReportReaderRoleFromOtherAccount",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::222233334444:role/ReportReader" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-reports-bucket/*"
}
]
}This policy alone is not enough. The ReportReader role in account 222233334444 also needs an identity policy like this one:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadReports",
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-reports-bucket/*"
}
]
}The identity policy has no Principal element, because the principal is whoever it is attached to. The bucket policy has no way to grant permissions that the role's own account has withheld. Each account controls what its own principals may do.
Common errors
- Only one side configured. A cross-account bucket policy with no matching identity policy returns
AccessDenied. This is the most common mistake. The fix is to add the missing allow in the principal's account. - Trusting the whole account when you meant one role. A
Principalofarn:aws:iam::222233334444:rootdelegates to account 222233334444. That account's administrators then decide which of their principals get access. - Forgetting resources that need their own grant. Some resources have special rules. An IAM role's trust policy must name the caller before anyone can assume it, and an AWS KMS key policy must allow the account or principal explicitly.
- Ignoring limits on the other account. An SCP in the principal's organization can block a call that both policies allow.
Exercise
A role in account 222233334444 has an identity policy that allows s3:PutObject on a bucket in account 111122223333. The bucket has no bucket policy. Does the PutObject call succeed? What changes if the role and the bucket are in the same account?
Show answer
The call fails. It is cross-account, so the bucket's account must also allow the role, and with no bucket policy there is only an implicit deny. If the role and bucket are in the same account, the identity policy alone is enough, provided no explicit deny, permission boundary, or SCP blocks it.