Sub topic 13
When a resource-based policy is enough
This chapter assumes you have read the earlier chapters on trust policies, caller policies, and sts:AssumeRole. You should know how IAM evaluates an identity policy and what a principal is. Here you will see a second way to cross an account boundary that needs no role and no temporary credentials.
Two ways to cross an account boundary
So far, cross-account access has meant assuming a role. The caller asks STS for temporary credentials. It then acts as the role, and its original permissions no longer apply.
Some AWS services let you attach a policy to the resource itself. This is a resource-based policy. Examples are an S3 bucket policy, an SQS queue policy, an SNS topic policy, a Lambda function policy, a Secrets Manager secret policy, and a KMS key policy. A resource-based policy has a Principal element, and that element can name a principal in another account. The caller then reaches the resource directly, using its own identity.
| Row | Assume a role | Resource-based policy |
|---|---|---|
| Caller identity during the call | The role session | The caller's own user or role |
| Credentials | New temporary credentials from STS | The caller's existing credentials |
| Permissions the caller keeps | Only those of the role | Its own, plus what the resource grants |
| Where access is defined | Trust policy plus role permissions policy | One policy on the resource |
| Works for | Any service the role can reach | Only services that support resource policies |
| CloudTrail shows | The assumed-role session | The original caller |
What changes in the evaluation
For a cross-account request, both accounts must allow it. This rule is the same as in the role model. With a resource-based policy, the two sides are these:
- The resource policy in the resource's account allows the caller's principal.
- An identity policy in the caller's account allows the action on that resource.
If either side is missing, the request is denied. An explicit Deny in any applicable policy still wins.
Inside a single account, the rule is looser. A resource policy that names a specific IAM user or role in the same account is enough on its own. Across accounts that shortcut does not apply, so the caller's own account must always grant the permission too.
Worked example: sharing a bucket
Account 222222222222 owns a bucket named example-shared-reports. A role called ReportReader in account 111111111111 needs to read it. You will grant this with a bucket policy instead of a role in account 222222222222.
Step 1: the resource policy in the bucket's account
Attach this bucket policy in account 222222222222:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowReportReaderFromAccount111",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:role/ReportReader"
},
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": [
"arn:aws:s3:::example-shared-reports",
"arn:aws:s3:::example-shared-reports/*"
]
}
]
}s3:ListBucket applies to the bucket ARN. s3:GetObject applies to the object ARN, which ends in /*. Listing both resources covers both actions. The policy names one role, not the whole account, so only that role is granted.
Step 2: the identity policy in the caller's account
Attach this policy to the ReportReader role in account 111111111111:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": [
"arn:aws:s3:::example-shared-reports",
"arn:aws:s3:::example-shared-reports/*"
]
}
]
}Step 3: call the service directly
Run the following from a session that uses the ReportReader role:
aws s3 ls s3://example-shared-reports/
aws s3 cp s3://example-shared-reports/2026/summary.csv .No sts assume-role call and no role_arn profile is involved. The caller keeps its own credentials. Run aws sts get-caller-identity and you will see the ReportReader identity from account 111111111111, not an identity in account 222222222222.
Choosing the principal in the resource policy
The Principal value changes what the policy delegates.
- A specific role or user ARN, as in the example. Only that identity is granted on the resource side. This is the narrowest form.
- The account root ARN, such as
arn:aws:iam::111111111111:root. This trusts the whole account. Any identity in account 111111111111 whose identity policy allows the action can then use the resource. Account 111111111111's administrators decide who that is. - A specific assumed-role session ARN. This matches only that named session, and it stops matching when the session ends. Prefer the role ARN.
A role ARN in the Principal element matches sessions of that role, so callers who assumed ReportReader in their own account match. Avoid "Principal": "*" without a condition such as aws:PrincipalOrgID. Without one, the resource is open to everyone.
If you delete and recreate a role, the new role has a different internal ID. A resource policy that referenced the old role may then show a raw ID like AROA... in place of the ARN, and it no longer grants anything. Re-save the policy with the ARN after recreating the role.
When this is the better choice
A resource-based policy is enough when these hold:
- The service supports resource policies, and the access is to that one resource or a small set of them.
- The caller needs to keep its own permissions during the call. A common case is copying objects from a bucket in one account to a bucket in its own account. An assumed role would give up the caller's access to the source side of the copy.
- You want a single place that lists who can use the resource.
- You want CloudTrail to record the original caller without having to correlate a role session back to a person.
A role is the better choice in these cases:
- The service has no resource policies. EC2 is an example.
- The caller needs broad access across many services in the other account.
- The other account's administrators want to bundle the permissions into one named role that they control and can revoke in one step.
- You need session-level controls: an external ID, MFA conditions, session tags, or a session duration limit. These live in the role's trust policy, which a resource policy does not have.
Gotchas
Some services need more than the resource policy. KMS is the main case. A key policy in the key's account must allow the principal, and the caller's identity policy must allow actions such as kms:Decrypt. If the bucket objects are encrypted with a customer managed key, S3 access alone is not enough. The caller also needs access to the key. The caller's account is not allowed to use the key by default.
Object ownership in S3. New buckets use the BucketOwnerEnforced setting, which disables ACLs and makes the bucket owner own every object. If an older bucket still has ACLs enabled, an object written by another account can belong to the writer, and the bucket owner may not be able to read it. Check the bucket's Object Ownership setting before debugging policies.
Condition keys differ per service. Confused deputy protection for services acting on your behalf uses aws:SourceArn and aws:SourceAccount in the resource policy. This is the resource-policy counterpart of the external ID. Use it when a service such as SNS or S3 writes into your resource.
Guardrails still apply. An SCP in the caller's organization or a permissions boundary on the caller can block the call even when both policies allow it. A resource policy cannot override those.
Diagnosing AccessDenied
When a cross-account resource call fails, check in this order:
- Does the resource policy name the right principal ARN, with the right account ID and role name?
- Do the
ActionandResourceentries match the call? For S3, check bucket versus object ARNs. - Does the caller's identity policy allow the same action on the same resource?
- Is there an explicit
Deny, an SCP, a permissions boundary, or a session policy in the way? - For encrypted data, does the key policy and the caller's policy allow the KMS actions?
- Are S3 block public access settings or Object Ownership relevant?
CloudTrail records the denied call in the resource owner's account for data events if you have enabled them. In the caller's account, it records the call from the caller's side. The error message names the action and, often, the denying policy type.
Exercise
Account 111111111111 has a role Uploader whose identity policy allows sqs:SendMessage on a queue ARN in account 222222222222. The queue's policy in 222222222222 has no statement naming account 111111111111. Does the send succeed, and what is the smallest fix?
Show answer
It fails with AccessDenied. A cross-account request needs both sides to allow it, and the queue policy has no statement for the caller. The smallest fix is to add a statement to the queue policy that allows sqs:SendMessage for the principal arn:aws:iam::111111111111:role/Uploader on the queue. No role in account 222222222222 is needed.
Exercise
Why might you choose an IAM role over a bucket policy for a vendor who needs access to your bucket and also needs to be protected from the confused deputy problem?
Show answer
A role's trust policy can require an sts:ExternalId condition, which a bucket policy cannot enforce on the vendor's calls. It also gives you one named role to revoke, and it can cover other services besides S3.