Skip to Content
Asterrr's Handbook
4 · Identity and access management

STS, roles and cross-account access

Choosing the right STS API, cross-account role assumption, external ID, session tags, source identity, role chaining, IAM Roles Anywhere and revoking sessions.

Exam tasks: 4.1 (Skills 4.1.2 mechanisms that issue temporary credentials, 4.1.3 troubleshooting authentication with CloudTrail), 4.2 (Skills 4.2.1 role trust policies and IAM Roles Anywhere, 4.2.3 session policies)

The decision: who (or what) is asking for credentials, what have they already proved, and which STS call turns that proof into the shortest-lived, narrowest session that works?

AWS STS issues temporary credentials (access key, secret key, session token). It is API-only, with a global endpoint and Regional endpoints. Calls are logged in CloudTrail. Roles are the main way to delegate access across accounts, to services and to federated identities.

Account AAccount BAssumeRoletemp credentialsDev userRole in BAWS STS
Two halves must agree. The trust policy in the target account names the caller, and the caller needs sts:AssumeRole in its own account.
15 min
Minimum session length for any STS credential.
12 h
Highest maximum session duration you can set on a role.
1 h
Cap for chained role sessions, and for root GetSessionToken.
36 h
Longest GetSessionToken or GetFederationToken session for an IAM user.
2
Access keys per IAM user.
4 h
How often you can generate a fresh credential report.

Cross-account role assumption

After assuming, the caller gives up its own permissions and acts with the role permissions. Services with resource-based policies offer an alternative that needs no role switch, but then both accounts must allow the request.

Which STS API

IAM user or rolecredentialsact as another role,maybe in another accountprove MFA for an IAMuser's API callscustom broker hands outscoped creds (legacy)SAML assertionOIDC JWT (CI, Cognito,Kubernetes)X.509 cert, workloadoutside AWSOrg admin needs aroot-only task in amember accountCaller needs AWScredentialsWhat does the calleralready hold?Goal?AssumeRoleGetSessionTokenGetFederationTokenAssumeRoleWithSAMLAssumeRoleWithWebIdentityIAM RolesAnywhereCreateSessionAssumeRoot
Decision tree for which sts api
APICaller signs withLifetime (default / max)MFA in callSession policyWatch out for
AssumeRoleUser or role creds1 h / role max (up to 12 h)YesYesRole chaining caps at 1 hour
AssumeRoleWithSAMLNothing (assertion)1 h / role maxNo, done by IdPYesTrust policy checks SAML:aud
AssumeRoleWithWebIdentityNothing (JWT)1 h / role maxNo, done by IdPYesTrust policy must pin aud and sub
GetSessionTokenIAM user (or root)12 h / 36 h (root 1 h)YesNoCan't call IAM without MFA, can only call AssumeRole in STS
GetFederationTokenIAM user (or root)12 h / 36 h (root 1 h)NoYes, required to get any permissionCan't call IAM or STS through the API
AssumeRootManagement or delegated admin principal15 min maxn/aTask policy (fixed list)Regional endpoint only
  • Every session is at least 15 minutes. Set the role's maximum session duration from 1 to 12 hours.
  • sts:GetCallerIdentity needs no permission and cannot be denied. It's the first call when debugging "who am I?"
  • sts:DecodeAuthorizationMessage needs explicit permission. It decodes the reason behind an access denied.
  • Credentials already issued stay valid until they expire, even if you change the role. See revoking sessions.

Restrictions on the results:

  • AssumeRole, SAML and web identity credentials cannot call GetFederationToken or GetSessionToken.
  • GetFederationToken credentials cannot call IAM through CLI or API, and cannot call STS except GetCallerIdentity.
  • GetSessionToken credentials cannot call IAM APIs unless MFA is included, and cannot call STS except AssumeRole and GetCallerIdentity. They cannot be used for console single sign-on.
  • Passkeys and security keys cannot be passed to STS MFA parameters. aws login supplies CLI credentials instead.

Exam trap

Role chaining (a role session assuming another role) caps the new session at 1 hour, whatever the role maximum is. Asking for a longer DurationSeconds in a chain makes the call fail.

Exam signal

"CI system (GitHub Actions, GitLab) must deploy without stored keys" means an IAM OIDC provider and AssumeRoleWithWebIdentity, with a trust policy that pins the repository in the sub claim. "Servers in our data centre with certificates from our PKI" means IAM Roles Anywhere.

Trust policies and the confused deputy

A role has two policies: the trust policy (who may assume it) and the permissions policies (what the session may do). Both must be right.

  • Third party assumes your role: require an sts:ExternalId the vendor generates per customer. Without it, another customer of the same vendor could trick the vendor into using your role. That's the confused deputy.
  • AWS service acts on your resource: in resource policies, condition on aws:SourceArn or aws:SourceAccount so the service only acts for your resource, not someone else's. aws:SourceOrgID and aws:SourceOrgPaths work too, and an RCP can enforce them.
  • OIDC: never trust a provider without conditions on aud and sub. A GitHub trust with no sub condition lets any repository on GitHub assume the role.
{
  "Effect": "Allow",
  "Principal": { "AWS": "arn:aws:iam::210987654321:root" },
  "Action": "sts:AssumeRole",
  "Condition": { "StringEquals": { "sts:ExternalId": "fernhill-7Q2K9" } }
}

External ID as a secret

The external ID isn't a password, and you shouldn't generate it yourself. It stops the vendor being confused between customers. Protection against someone stealing the vendor's credentials comes from the vendor's own security, not the external ID.

Shaping a session

FeaturePassed asWhat it does
Session policyPolicy (inline) and up to 10 PolicyArnsCaps the session to the intersection with the role's policies
Session tagsTags, or SAML/OIDC attributesBecome aws:PrincipalTag/... for ABAC. Need sts:TagSession in the trust policy
Transitive tagsTransitiveTagKeysSurvive role chaining
Source identitySourceIdentitySet once, can't be changed down the chain, logged in CloudTrail. Needs sts:SetSourceIdentity
Session nameRoleSessionNameAppears in the session ARN and CloudTrail. Condition on sts:RoleSessionName to force a username
  • Session tags can't be passed in the console switch-role. Role tags can't be made transitive.
  • aws:PrincipalTag holds IAM tags plus session tags. Session tags override same-key role tags.
  • sts:SetSourceIdentity must be allowed in the caller policy and the trust policy (both, for cross-account). Source identity persists through chaining and appears as aws:SourceIdentity.

Exam signal

"Know which human used a shared role in CloudTrail" is source identity. "Pass department from the IdP for ABAC" is session tags. "Third party SaaS with access to our account" is a role with an external ID.

Session limits

ItemValue
Role maximum session duration1 to 12 hours, default 1 hour
Session policyOne JSON doc or up to 10 managed ARNs, 2,048 characters combined
Session tagsUp to 50. Key 128, value 256 characters
Role session name64 characters
ExternalId2 to 1,224 characters
SourceIdentity2 to 256 characters, cannot start with aws:
STS request quota600 per second per account per Region, shared by AssumeRole, GetCallerIdentity, GetFederationToken, GetSessionToken and others

IAM Roles Anywhere

  • For workloads outside AWS (on-prem servers, other clouds, edge devices) that hold an X.509 certificate.
  • Trust anchor: your CA, either AWS Private CA or an uploaded external CA bundle. Profile: which roles can be assumed and an optional session policy. Role: trusts rolesanywhere.amazonaws.com, ideally with aws:SourceArn pinned to the trust anchor and conditions on certificate attributes.
  • The credential helper signs CreateSession with the private key and returns standard temporary credentials.
  • Import a CRL to revoke certificates. Protect the private key, ideally in a TPM or HSM.
  • It is Regional and per account. The alternatives for workloads outside AWS are IAM user access keys (last resort, rotate and scope) and OIDC federation, see federation.

Presigned URLs

  • S3 presigned URLs let someone without AWS credentials GET or PUT one object until expiry.
  • The URL carries the signer's permissions. If those credentials are temporary, the URL dies when they expire, whatever expiry you set. Maximum 7 days with SigV4 and long-term keys.
  • Restrict their use with bucket policy conditions such as s3:signatureAge or aws:SourceIp.

Revoking sessions

  • Revoke active role sessions: "Revoke active sessions" on the role adds an inline deny with aws:TokenIssueTime earlier than now. Fixing the policy alone doesn't end sessions already issued. See compromised credentials.

Scenarios

Scenario
A monitoring vendor needs read-only access to 30 customer accounts, including yours. The vendor's platform assumes a role in each customer's account from its own AWS account. What should your role's trust policy contain to prevent the confused deputy problem?
Scenario
An analytics job assumes role A, then from that session assumes role B in another account. Role B has a maximum session duration of 8 hours, and the job requests 4 hours. The call fails. Why?

Further reading

On this page