Sub topic 15
Troubleshooting AccessDenied and Auditing with CloudTrail
This chapter assumes you know IAM roles, trust policies, and the AWS CLI. You have seen how a cross-account role needs permission on both sides. Here you will learn to find which side is failing and to confirm what happened afterward.
Which side is denying you
An AssumeRole call is allowed only when the role's trust policy and the caller's identity policy both permit it. Guardrails such as service control policies (SCPs) and permissions boundaries can also block it. Start with the error text.
aws sts assume-role \
--role-arn arn:aws:iam::222222222222:role/ReadOnlyAuditor \
--role-session-name audit-sessionA failure looks like this:
An error occurred (AccessDenied) when calling the AssumeRole operation:
User: arn:aws:iam::111111111111:user/dana is not authorized to perform:
sts:AssumeRole on resource: arn:aws:iam::222222222222:role/ReadOnlyAuditorRead the message for the principal, the action, and the resource. Then work through the checks below.
Checklist by symptom
| Symptom | Likely cause | Fix |
|---|---|---|
| "is not authorized to perform: sts:AssumeRole" and the message names no policy type | The caller has no identity policy allowing `sts:AssumeRole` on that role ARN, or the trust policy does not trust the caller | Check both policies |
| "...because no identity-based policy allows the sts:AssumeRole action" | The caller's identity policy is missing or names the wrong role ARN | Fix the `Resource` in the caller's policy |
| "...with an explicit deny in a service control policy" | An SCP in the caller's organization blocks the action | Ask the organization administrator to change the SCP |
| "...with an explicit deny in a permissions boundary" | The caller's permissions boundary does not include `sts:AssumeRole` | Update the boundary |
| Denied only without MFA, or without the right external ID | A trust policy condition is not met | Pass the missing value, such as `--external-id` |
| "Not authorized to perform sts:AssumeRole" after a wrong account ID | The role ARN has a typo, or the role does not exist | Compare the ARN character by character |
Newer AWS error messages often name the policy type that caused the denial. Use that detail before you guess.
Check each side in order
- Confirm who you are. Run
aws sts get-caller-identity. Profiles and environment variables can silently change your identity. - Check the role's trust policy in account 222222222222. The
Principalmust name the caller's account or the caller itself, and theActionmust bests:AssumeRole. - Check the caller's identity policy in account 111111111111. It must allow
sts:AssumeRoleon the exact role ARN. - Check conditions. Look for
sts:ExternalId,aws:PrincipalOrgID, or MFA conditions in the trust policy. - Check guardrails. Look for SCPs and permissions boundaries that apply to the caller.
Auditing with CloudTrail
AWS CloudTrail records every AssumeRole call. The event appears in the account that owns the role, because AWS STS processes the request there. Look for the event name AssumeRole.
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=AssumeRole \
--max-results 5 \
--region us-east-1Each event shows the caller's identity, the role ARN, the session name, and the source IP address. Failed calls include an errorCode and errorMessage. Actions taken later with the temporary credentials show the role session name in userIdentity. A clear --role-session-name therefore lets you trace actions back to a person or tool.
Exercise
A developer in account 111111111111 gets AccessDenied on sts:AssumeRole for a role in account 222222222222. The role's trust policy trusts account 111111111111, and get-caller-identity shows the expected user. Name two further places to check and one place to find the failed event.
Show answer
Check the user's identity policy for an sts:AssumeRole allow on the exact role ARN, and check for conditions, SCPs, or permissions boundaries that deny the call. Find the failed event in CloudTrail in account 222222222222, where the AssumeRole event shows the errorCode and errorMessage.