Sub topic 5
Allowing callers to assume the role from their own account
This chapter covers the caller side of cross-account access. It assumes you can read IAM JSON policies, know what an ARN is, and have used the AWS CLI. The role's trust policy, which lives in the other account, is covered in the previous chapter. Here the focus is the identity policy in the account that makes the call.
Why the caller needs its own permission
A cross-account request is checked in two accounts. The account that owns the role (the trusting account) checks its trust policy. The account that makes the call (the trusted account) checks whether its own principal is allowed to ask.
For sts:AssumeRole across accounts, both checks must allow the request. This is different from same-account access. In a single account, a trust policy that names a specific role or user ARN can be enough by itself. When the trust policy names the account root, as in arn:aws:iam::111111111111:root, the trust policy only says "this account may delegate". Each principal in that account then needs an identity policy that grants sts:AssumeRole.
That second step is what lets the account administrator of 111111111111 decide which of their own users and roles may use the delegation. The administrator of 222222222222 cannot control that, and does not need to.
The identity policy
The policy below goes on the IAM user or role in account 111111111111 that needs access. It allows one action on one resource.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::222222222222:role/ReadOnlyAuditor"
}
]
}Three parts matter:
- Action.
sts:AssumeRoleis the API action that returns temporary credentials for a role. Other STS actions, such assts:AssumeRoleWithWebIdentity, are separate permissions. - Resource. The resource is the ARN of the role in the other account. It must include the other account's ID. If you write only a role name or an ARN with your own account ID, the policy matches a different role and the call is denied.
- Effect. An explicit
Allowis required. There is no default permission to assume roles in other accounts.
Choosing how wide the Resource should be
You can scope the resource at several levels. Narrower is safer.
| Resource value | What it allows |
|---|---|
| `arn:aws:iam::222222222222:role/ReadOnlyAuditor` | One named role. Recommended default. |
| `arn:aws:iam::222222222222:role/audit/*` | Any role under the `/audit/` path in that account. |
| `arn:aws:iam::*:role/ReadOnlyAuditor` | A role with that name in any account. Use only with a condition. |
| `*` | Any role in any account. Avoid. |
A wildcard in the account field lets the caller assume a same-named role in an account you do not control. Anyone who creates such a role and trusts your principals could receive requests from you. If you need to cover many accounts, pair the wildcard with a condition such as aws:ResourceOrgID, which limits the resource to accounts in your organization.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::*:role/ReadOnlyAuditor",
"Condition": {
"StringEquals": { "aws:ResourceOrgID": "o-exampleorgid" }
}
}
]
}Where to attach the policy
Attach the policy to the identity that will call AssumeRole. You have three common options.
- An IAM user. Simple, but it ties access to a long-lived identity. Prefer roles or federated identities for people where you can.
- An IAM role. For example, an EC2 instance role or a Lambda execution role. The workload calls
AssumeRoleusing the credentials it already has. - An IAM group. Attach the policy to a group such as
Auditors, and add users to it. This is easy to manage and audit, because membership is the only thing that changes.
Account 111111111111 controls who gets the permission. Account 222222222222 only controls which accounts, and optionally which principals, are trusted.
How the two policies combine
The trust policy's Principal determines how much the caller-side policy matters. Two cases behave differently.
| Trust policy principal | Caller needs an identity policy? | Notes |
|---|---|---|
| Account root, such as `arn:aws:iam::111111111111:root` | Yes | The whole account is trusted, but each principal must be granted `sts:AssumeRole` explicitly. |
| A specific user or role ARN | Not always | An allow in the trust policy can be enough for that exact principal, but a missing identity policy is still a common cause of surprise. Add the identity policy anyway. |
The reliable rule for cross-account setups is to write both policies. Doing so gives you a clear record on each side, and it works the same way for all principals.
An explicit Deny in either account always wins. That includes a deny in the identity policy, the trust policy, a permissions boundary, a service control policy (SCP), or a session policy. If both policies look correct and the call still fails, look for a deny elsewhere.
Testing the setup
After attaching the identity policy, request credentials from a principal in account 111111111111.
aws sts assume-role \
--role-arn arn:aws:iam::222222222222:role/ReadOnlyAuditor \
--role-session-name audit-sessionA successful call returns a Credentials object with AccessKeyId, SecretAccessKey, SessionToken, and Expiration. The --role-session-name value appears in logs and in the assumed-role ARN, so choose a name that identifies the person or job. The next chapter covers the call and the credentials in detail.
If you prefer to check the policy before calling the API, use the IAM policy simulator or the CLI:
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::111111111111:user/alice \
--action-names sts:AssumeRole \
--resource-arns arn:aws:iam::222222222222:role/ReadOnlyAuditorThe simulator evaluates only the identity side. It does not evaluate the trust policy in the other account, so an allowed result does not prove the whole call will succeed.
Common caller-side errors
The error message from STS usually names the principal and the action. Read it before changing anything.
An error occurred (AccessDenied) when calling the AssumeRole operation:
User: arn:aws:iam::111111111111:user/alice is not authorized to perform:
sts:AssumeRole on resource: arn:aws:iam::222222222222:role/ReadOnlyAuditorThis message means no policy in the caller's account allowed the action on that resource. It does not tell you whether the trust policy is correct. Check these causes in order.
- No identity policy. The user or role has no
sts:AssumeRoleallow at all. Attach the policy. - Wrong resource ARN. A typo in the account ID, the role name, or the path. A role with a path, such as
role/audit/ReadOnlyAuditor, must be written with the path in the ARN. - Policy attached to the wrong identity. You attached it to a group the user is not in, or to a different role than the one your workload runs as. Run
aws sts get-caller-identityto see which identity is actually calling. - An explicit deny. An SCP, a permissions boundary, or another statement denies
sts:AssumeRole. A boundary on the caller must also allow the action. - The trust policy rejects the caller. The message looks similar, but the cause is in the other account. If the identity policy is correct, ask the owner of the role to review the trust policy and its conditions.
Summary of the caller side
- The caller's account must explicitly allow
sts:AssumeRolefor the target role ARN. - The Resource must contain the role's own account ID, not the caller's.
- Scope it to one role, or use a wildcard only with an organization condition.
- Write both policies, and remember that a deny anywhere overrides allows.
Exercise
A user in account 111111111111 runs aws sts assume-role for arn:aws:iam::222222222222:role/ReadOnlyAuditor and gets AccessDenied. The role's trust policy names arn:aws:iam::111111111111:root with sts:AssumeRole. The user's only attached policy allows sts:AssumeRole on arn:aws:iam::111111111111:role/ReadOnlyAuditor. What is wrong, and how do you fix it?
Show answer
The identity policy's Resource uses the caller's own account ID (111111111111), so it matches a different role than the target. Because the trust policy names the account root, the user needs an explicit allow for the actual target. Change the Resource to arn:aws:iam::222222222222:role/ReadOnlyAuditor, then retry the call.
Exercise
You want a group of auditors to assume a role named ReadOnlyAuditor in any account of your AWS Organization, but not in accounts outside it. Which statement elements do you use in the group's identity policy?
Show answer
Allow sts:AssumeRole with Resource arn:aws:iam::*:role/ReadOnlyAuditor and a Condition of StringEquals on aws:ResourceOrgID set to your organization ID, such as o-exampleorgid.