Sooner or later, a second AWS account, a contractor or a CI system needs to work inside one of your AWS accounts. Handing them permanent access keys is risky, and AssumeRole lets them borrow access for a short time instead. You create an IAM role in the target account, which is a set of permissions with no password or keys of its own. AWS STS (Security Token Service) then gives the caller temporary credentials for that role, valid for one hour by default.
Two policies must agree before this works. The role’s trust policy says which accounts or identities may assume it, and an identity policy in the source account allows the caller to run sts:AssumeRole on that role. If either half is missing, you get the same “not authorized to perform: sts:AssumeRole” error. For vendors, add an external ID too: a shared value they must send, so their access cannot be turned against you on another customer’s behalf. Below you will check both halves, test the assumption, and set up a CLI profile so nobody handles raw session tokens.
What’s happening
A role is a set of permissions with no credentials of its own and two policies that matter. The trust policy (visible in the console as the role’s “Trust relationships” tab) is a resource-based policy answering one question: which principals may call sts:AssumeRole on me? For cross-account use, the standard pattern trusts the other account’s root ARN — arn:aws:iam::111122223333:root — which does not mean the root user; it delegates the decision to account 111122223333’s own IAM, so admins there choose which of their principals get sts:AssumeRole in an identity policy. Both sides must therefore allow the assumption: the target trusts the source account, and the source grants its principal the action. This double opt-in is the design, not a redundancy.
When AssumeRole succeeds, STS returns an access key, secret key, and session token valid for one hour by default, extendable up to the role’s MaxSessionDuration (as high as 12 hours) via --duration-seconds. One caveat that surprises people: role chaining — using assumed-role credentials to assume another role — caps the second session at one hour regardless of settings. For third parties assuming into your account, add an ExternalId condition to the trust policy; it defends against the confused-deputy problem where a vendor is tricked into using their access on the wrong customer’s behalf. The full parameter list is in the IAM documentation under the STS API reference.
What to check first
- Both halves exist. Read the trust policy on the target role and the identity policy on the source principal; nine of ten failures are a missing half.
- The exact role ARN. Account ID typos and role-name case mismatches produce the same denied error as a real permission gap.
- Conditions in the trust policy.
ExternalId,aws:PrincipalOrgID, or MFA conditions silently fail assumptions that do not supply them. - Session duration requests. Asking for
--duration-seconds 14400against a role whose maximum is still the 3600 default fails with a validation error, not an access error.
How to verify
# Read the trust policy on the target role (run in the target account)
aws iam get-role --role-name CrossAccountOps \
--query 'Role.AssumeRolePolicyDocument'
# Attempt the assumption (run as the source principal)
aws sts assume-role \
--role-arn arn:aws:iam::222222222222:role/CrossAccountOps \
--role-session-name horia-ops-check
# Confirm which identity you now hold
aws sts get-caller-identity
A successful assume-role returns Credentials and an AssumedRoleUser.Arn like arn:aws:sts::222222222222:assumed-role/CrossAccountOps/horia-ops-check. In the target account’s CloudTrail, the assumption appears as an AssumeRole event under CloudTrail > Event history, and every subsequent action carries the session name — which is why session names should identify the human or system, not be session1.
The runbook
- Create the role in the target account with a scoped trust policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::111122223333:root"},
"Action": "sts:AssumeRole",
"Condition": {"StringEquals": {"sts:ExternalId": "acme-7f3b2c"}}
}
]
}
Attach the permissions the session should have — and nothing more — as the role’s identity policies. Drop the Condition block for internal cross-account use; keep it mandatory for third parties.
- Grant the assumption in the source account. On the calling role, group, or user:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::222222222222:role/CrossAccountOps"
}
]
}
- Wire the CLI profile so nobody handles raw session tokens. In
~/.aws/config:
[profile prod-ops]
role_arn = arn:aws:iam::222222222222:role/CrossAccountOps
source_profile = default
role_session_name = horia
external_id = acme-7f3b2c
Then aws s3 ls --profile prod-ops assumes, caches, and refreshes credentials automatically.
- Tighten the trust policy from account root to specific principals once the pattern works — name the exact source role ARN instead of
:rootwhen only one caller should exist. - Raise MaxSessionDuration only where the workflow demands it. Long interactive maintenance sessions may justify 4 hours; automation almost never should exceed the 1-hour default.
When this is the wrong move
If you are wiring dozens of human-to-account paths, hand-built AssumeRole plumbing recreates what IAM Identity Center already does with permission sets — use the managed version, as covered in our Identity Center migration guide. And for granting one service in another account access to a single bucket or queue, a resource policy on the bucket or queue is often simpler than a role round-trip.
Common mistakes
- Writing the trust policy but forgetting the source-side
sts:AssumeRolegrant — the double opt-in bites everyone once. - Trusting
:rootpermanently when a single named role should be the only caller. - Omitting
ExternalIdfor vendor access, leaving the confused-deputy door open. - Generic session names like
cli-session, which make the target account’s CloudTrail unattributable.
Prevention
- Keep every trust policy in infrastructure-as-code; trust edits are the highest-blast-radius IAM change there is.
- Alert on
UpdateAssumeRolePolicyevents — a modified trust policy is either a planned change or an incident. - Audit trust policies quarterly for unknown account IDs and
Principal: "*"(which should never appear). - Add
aws:PrincipalOrgIDconditions on internal cross-account roles so a typo in an account ID cannot trust a stranger.
Cross-account AssumeRole is a two-key lock, and almost every problem with it is one key missing or one key cut too wide. If nobody on your team truly owns the AWS environment end to end, that is the root of most of these problems — Stack Harbor runs AWS accounts daily under AWS Operations, and you can book an AWS review.