STS has three operations for callers that already hold AWS credentials. AssumeRole returns credentials for a role, for up to the role’s maximum of 12 hours. GetSessionToken returns credentials for the same IAM user, usually to add MFA, for up to 36 hours. GetFederationToken, called with an IAM user’s long-term key, returns credentials for a federated user, also for up to 36 hours.
AssumeRoleWithWebIdentity and AssumeRoleWithSAML are called with no AWS credentials at all. The identity token from an OpenID Connect or SAML provider is the proof, the same idea chapter 04 uses for IAM Identity Center. GitHub Actions workflows and EKS service accounts reach AWS this way, and neither stores an access key.
Role chaining means using one role session to assume another role, and STS caps the second session at 1 hour whatever the role’s maximum says. Session policies and session tags passed to AssumeRole are packed into the token, which is one reason its size isn’t fixed.
STS has a global endpoint, sts.amazonaws.com, and regional ones such as sts.us-east-1.amazonaws.com. By default the global endpoint issues version 1 tokens, which don’t work in Regions you enabled by hand, such as Asia Pacific (Hong Kong). aws iam set-security-token-service-preferences --global-endpoint-token-version v2Token switches to version 2 tokens, which are longer and valid everywhere. AWS recommends the regional endpoints in any case.
Some services refuse a call with an encoded authorization message. aws sts decode-authorization-message turns it into readable JSON that names the policy and statement that refused, for a caller allowed sts:DecodeAuthorizationMessage.
ERRORS THIS CHAPTER EXPLAINS
ExpiredToken → the session passed its Expiration → get new credentials, or use a profile that renews them (chapter 03)InvalidClientTokenId with an ASIA key → the session token is missing or truncated → export all three values, not twoAccessDenied … is not authorized to perform: sts:AssumeRole → the trust policy refused, often because no MFA code was sent → pass --serial-number and --token-codeThe requested DurationSeconds exceeds the 1 hour session limit for roles assumed by role chaining → a role session asked for more than an hour → ask for 3,600 seconds or less