Sub topic 13
When a resource-based policy is enough
This chapter assumes you know how a role's trust policy and a caller's sts:AssumeRole permission work together, as covered in earlier chapters. It also assumes you can read IAM JSON policies and S3 ARNs.
The alternative to assuming a role
Assuming a role is not the only way to cross an account boundary. Some services let you attach a resource-based policy directly to the resource, and that policy can name a principal from another account. Examples include S3 buckets, SQS queues, SNS topics, KMS keys, and Lambda functions. The caller then uses its own identity and never calls STS.
Both sides still need permission
For cross-account access, AWS requires an Allow in both accounts:
- The resource's account must allow the outside principal, through the resource-based policy.
- The caller's account must allow the action, through an identity policy on the user or role.
This is the same two-sided rule as for role assumption. The difference is that the resource policy replaces the trust policy and the role's permissions policy.
Example: sharing a bucket
Account 222222222222 owns the bucket example-shared-reports. This bucket policy lets one role from account 111111111111 read its objects:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111111111111:role/ReportReader" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-shared-reports/*"
}
]
}The ReportReader role in account 111111111111 needs its own identity policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::example-shared-reports/*"
}
]
}With both policies in place, the caller runs an ordinary command with its own credentials:
aws s3 cp s3://example-shared-reports/q3.csv .Resource policy or assumed role
| Question | Resource-based policy | Assumed role |
|---|---|---|
| Does the caller keep its own identity? | Yes. | No. It acts as the role. |
| Can it use its own account's resources and the shared one in one session? | Yes. | Not at once. The session holds only the role's permissions. |
| Which services does it work with? | Only services that support resource policies. | Any service the role can reach. |
| Where is access managed? | On each resource. | In one role, covering many resources. |
| What does CloudTrail record? | The caller's own identity. | The assumed-role session name. |
Use a resource policy when you share one or a few resources and the service supports it. A common case is copying an object from one account's bucket to another's in a single call. Use a role when the caller needs broad access across many services, or when the service has no resource policies, such as many EC2 and IAM actions.
Gotchas
- Principal scope: naming
arn:aws:iam::111111111111:rootin a resource policy delegates to the whole account. Each identity in that account still needs its own policy. Naming a specific role ARN is narrower. - Deleted principals: an ARN in a policy resolves to an internal ID when you save it. If you delete and recreate the role, the old policy entry no longer matches.
- KMS: a key policy must allow the outside account, or encrypted objects stay unreadable even when the bucket policy allows the read.
- Object ownership: S3 objects written by another account may still belong to that account. Bucket owner enforced ownership avoids this.
- Same account: within one account, a resource policy that names the principal is enough without an identity policy. Across accounts, it never is.
Exercise
A role in account 111111111111 is named in a bucket policy in account 222222222222, but its own account has no identity policy for s3:GetObject. Does the cross-account read succeed? What would you add?
Show answer
It fails with AccessDenied. Cross-account access needs an Allow on both sides, and the caller's account has none. Add an identity policy to the role in account 111111111111 that allows s3:GetObject on arn:aws:s3:::example-shared-reports/*.