← All posts IAM

AWS STS AssumeRole: trust policies and role chaining

Summary

  • sts:AssumeRole hands a principal temporary credentials for an IAM role. The role's trust policy must name the caller as trusted, and for cross-account access the caller also needs an identity policy that allows the call.
  • The trust policy is a resource policy on the role. A narrow Principal is a specific role or user. A broad one, such as an entire account, trusts every principal in that account that also holds the identity permission.
  • Conditions such as sts:ExternalId, aws:SourceArn and aws:PrincipalOrgID narrow who can assume a role. The external ID exists to prevent the confused deputy problem.
  • Role chaining, assuming one role then using it to assume another, is how lateral movement and cross-account escalation happen. Each trust edge is a hop, and Pathbreak validates which chains resolve and gives the one change that breaks the most.

Almost everything in AWS gets its permissions by assuming a role. A CI job, a Lambda function, an engineer switching accounts, a third-party SaaS integration: each one calls sts:AssumeRole and receives temporary credentials for a role. Because role assumption is so central, the policies that govern it are where a large share of cloud risk sits, and the trust policy in particular is easy to get subtly wrong.

How AssumeRole works

When a principal calls sts:AssumeRole on a role, the Security Token Service returns a temporary access key, secret key and session token. For the life of that session the caller acts as the role and holds the role's permissions. A session lasts between 15 minutes and the role's maximum session duration, which an administrator sets between 1 and 12 hours. Two things gate the call:

  • The role's trust policy must name the caller, or an account or service the caller belongs to, as a trusted principal.
  • For cross-account access, the caller also needs an identity policy that allows sts:AssumeRole on the target role. In the same account a trust policy that names the caller directly is enough on its own, though delegating to the account root still requires that identity-policy allow.

There are two federated variants, AssumeRoleWithSAML and AssumeRoleWithWebIdentity, which trade an external identity assertion for role credentials, and they are gated by the same trust policy.

The trust policy is a resource policy

A role's trust policy is the resource-based policy attached to the role. It allows sts:AssumeRole, names trusted principals in a Principal element, and can add conditions. The Principal is where scope is won or lost.

Trust policy PrincipalWhat it allowsWhat to watch
A specific role or user ARNOnly that principal can assume the role.The tightest option. Pair it with a condition when the caller is outside your account.
An account root, arn:aws:iam::ACCOUNT:rootAny principal in that account that also has sts:AssumeRole in its identity policy can assume the role.Trust is delegated to the other account's IAM. Scope the identity side there, or name specific principals instead.
A service, such as lambda.amazonaws.comThe named AWS service can assume the role on your behalf.Add aws:SourceArn or aws:SourceAccount so only your resource triggers the assume.
A federated provider (SAML or OIDC)Identities from that identity provider can assume the role.Constrain the audience and subject claims so only the intended identities match.
"*" with no conditionAny AWS principal, in any account, can attempt the assume.Avoid. If it must be open, gate it with a strong condition such as aws:PrincipalOrgID.

ExternalId and the confused deputy

When you let a third-party service assume a role in your account, the service is a deputy acting for many customers. Without a shared secret, an attacker who is also a customer of that service could get it to act against your account instead of theirs. This is the confused deputy problem. The external ID solves it: the service gives you a unique value, and your trust policy requires it with a StringEquals condition on sts:ExternalId, so only requests that carry it succeed. You take the external ID from the provider rather than inventing your own, and a provider should issue a different one per customer.

Role chaining

Role chaining is using the credentials from one assumed role to assume another, and then another. A session reached this way through the CLI or API is capped at one hour, and that limit cannot be raised. Chaining is ordinary in a well-run account, and it is also the shape most cross-account attacks take. Each role whose trust policy admits the previous hop is one more edge an attacker can follow, and a chain of permissive trust policies can lead from a low-value foothold to an administrative role in another account.

When a trust edge becomes an attack path

A single trust policy reads as routine in a review. The risk shows up when you follow the edges. A role that trusts a whole account, whose own identity policy can then reach iam:PassRole and lambda:CreateFunction, is one hop away from running code as a privileged role. Each grant and each trust relationship looks defensible on its own. The chain across them is what reaches administrator.

AssumeRoleAssumeRoletrusts caller01Attacker02Role A03Role B04Administrator
A principal that can reach a privileged role creates a function, passes the role, and runs as it. Every trust relationship is a hop a principal can take. One trust policy reads as routine; the chain of them is what reaches administrator.

Working out which of those chains resolve is what Pathbreak does. It reads your AWS configuration with a read-only role, builds a graph of principals, roles, trust edges and resources, then an agent chains control-plane moves, including role assumptions, into candidate attack paths. It validates each path end to end against the authorization that applies, including identity and resource policies, permission boundaries, service control policies and the trust policies on every role in the chain, so the list is the paths that resolve rather than every path that might. Paths are ranked by how many of them each fix breaks, and each one comes with the single change that removes the most risk and the command to apply it. A rescan confirms the path is gone. Nothing is executed in your account.

Pathbreak does not replace IAM or your review process. It answers the question a trust policy cannot answer on its own: which assume-role chains, across your accounts, reach administrator or data.

How to tighten role assumption on AWS today

  1. Inventory every role's trust policy and list which principals, accounts and services each role trusts. The roles that trust a whole account or a federated provider deserve the first look.
  2. Narrow each Principal to the specific role, user or service that needs it, and add a condition: sts:ExternalId for third parties, aws:SourceArn for service roles, aws:PrincipalOrgID for org-internal trust.
  3. Run pathbreak-audit, a free read-only CLI, to list the principals in one account that hold abusable permissions and toxic combinations. Install it with pip install pathbreak-audit.
  4. Validate the chains with Pathbreak on one account to see which assume-role paths reach admin or data, ranked by blast radius, with the one change that breaks the most.

For a reference of the specific AWS permissions attackers chain, including sts:AssumeRole, and the change that breaks each one, see the AWS privilege escalation map.

Frequently asked questions

What is sts:AssumeRole?

sts:AssumeRole is the AWS Security Token Service call that returns temporary credentials for an IAM role. A principal that is allowed to call it, and that the role's trust policy names as trusted, receives an access key, a secret key and a session token, and for the life of that session it acts as the role with the role's permissions. It is the mechanism behind cross-account access, federation and service roles.

What is a trust policy in AWS?

A trust policy is the resource-based policy attached to an IAM role that says who may assume it. It names trusted principals in a Principal element, allows sts:AssumeRole, and can add conditions such as sts:ExternalId or aws:SourceArn. For cross-account access, both the trust policy and the caller's own identity policy must allow the action; in the same account a trust policy that names the caller directly is enough. A broad Principal, such as an entire account, trusts every principal in it that also holds the identity permission.

What is role chaining and why is it capped at one hour?

Role chaining is using the credentials from one assumed role to assume another, and then another. AWS caps a session reached through role chaining at one hour through the CLI or API, and that limit cannot be raised. Each hop is a trust edge, which is why chaining is how lateral movement and cross-account escalation happen in AWS.

What is the sts:ExternalId for?

The external ID addresses the confused deputy problem, where a third party gets a trusted role to act on the wrong customer's account. The service you integrate with gives you a unique external ID, and your role's trust policy requires it with a StringEquals condition on sts:ExternalId, so only requests carrying that value can assume the role. You do not invent it yourself; the third party supplies it.

How do I find risky cross-account trust in AWS?

Inventory every role's trust policy and look for broad principals and missing conditions, then run pathbreak-audit, a free read-only CLI, to list the principals that hold abusable permissions in one account. Pathbreak then validates which assume-role chains resolve against the real trust and identity policies, and ranks the single change that breaks the most paths.

Related posts

See which over-permissioned identities in your AWS accounts reach admin or data, and the one change that closes each path.

Request a demo Watch the demo