AssumeRole and Trust Policies
What you'll learn: How IAM roles enable cross-account access through AssumeRole API and configuring trust relationships between accounts.
The Core Mechanism
When you need to grant one AWS account (or service) permission to access resources in another account, you use IAM roles with trust policies. The AssumeRole API is the handshake mechanism that makes this work.
Think of it like a hotel key card system: The trust policy determines who can request a key card (which accounts or principals are trusted). When someone passes that check, AssumeRole issues them temporary credentials—like handing over the key card—that grant specific permissions defined by the role's permission policies.
How It Works
-
Trust Policy: Attached to the IAM role in the target account (where resources live). This policy specifies which principals can assume the role using the
sts:AssumeRoleaction. -
AssumeRole Call: A user or service in the source account calls the AWS STS
AssumeRoleAPI, requesting to take on that role. -
Temporary Credentials: If the trust policy allows it, STS returns temporary security credentials (access key, secret key, session token) valid for a limited time.
-
Access Resources: The caller uses these temporary credentials to access resources as if they were that role.
Trust Policy Example Structure
The trust policy lives in the target account's role and looks like this conceptually:
"Who (Principal) can perform AssumeRole on this role, under what Conditions?"
The trust policy answers: Which external account ID or service is allowed to assume this role? The role's permission policies then determine what that assumed identity can actually do.
Key Takeaway: AssumeRole enables secure cross-account access by combining trust policies (who can assume) with temporary credentials (time-limited access tokens), eliminating the need to share long-term credentials across account boundaries.