Sub topic 2
Allowing Callers to Assume a Cross-Account Role
Assume you know AWS accounts, IAM users and roles, JSON policies, the AWS CLI, and Amazon Resource Names (ARNs). In this chapter, account 111111111111 contains the caller. Account 222222222222 owns the role.
Allowing Callers to Assume the Role from Their Own Account
The role's trust policy in account 222222222222 must trust account 111111111111. The caller also needs an identity policy in its own account. This policy grants permission to call AWS Security Token Service (STS) for one role ARN.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::222222222222:role/ReadOnlyAuditor"
}
]
}The role's permissions policy separately defines what the assumed role can do. Both policies matter: the caller policy permits the request, and the trust policy accepts the caller.
Assuming the Role with AWS STS
Call AssumeRole with the role ARN and a session name. STS returns credentials for a temporary session.
aws sts assume-role \
--role-arn arn:aws:iam::222222222222:role/ReadOnlyAuditor \
--role-session-name audit-sessionWorking with Temporary Credentials and Session Duration
The response contains an access key ID, secret access key, session token, and expiration time. These credentials identify the role session, not the original caller, when they access resources.
| Value | Purpose |
|---|---|
| Access key ID | Identifies the temporary credential |
| Secret access key | Signs AWS requests |
| Session token | Required for temporary credentials |
| Expiration | Marks when the session ends |
The role's maximum session duration limits how long credentials can last. A role assumed by another role is subject to role chaining, which limits the session to one hour.
Assuming Roles Automatically with CLI Profiles
A CLI profile can use a source profile to call STS automatically.
[profile auditor]
role_arn = arn:aws:iam::222222222222:role/ReadOnlyAuditor
source_profile = default
region = us-east-1Verify the resulting identity:
aws sts get-caller-identity --profile auditorThe returned ARN should contain assumed-role/ReadOnlyAuditor/audit-session or a generated session name.
Exercise
The caller has sts:AssumeRole permission, but the command returns AccessDenied. What should you inspect first?
Show answer
Inspect the target role's trust policy, then confirm the caller policy targets the exact role ARN and that no SCP or permissions boundary denies the action.