Lesson 3 of 4 Identity Federation and Temporary Credentials

Issuing and Revoking Temporary Credentials with AWS STS

This lesson explains the AWS Security Token Service (AWS STS) APIs and session limits, which issue the temporary credentials behind federation, cross-account access and workload identity.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose the STS API that matches where an identity comes from.
  • Identify other temporary access mechanisms, such as presigned URLs.
  • Revoke a role's sessions with an aws:TokenIssueTime condition.

STS APIs

AWS Security Token Service (STS) issues temporary credentials, and the API depends on where the identity comes from. AssumeRole is used by principals that already have AWS credentials to assume a role in the same or another account. It accepts an external ID, MFA details, session tags, session policies and a sourceIdentity that stays attached through role chaining for auditing. AssumeRoleWithSAML is used for enterprise federation from a SAML identity provider. AssumeRoleWithWebIdentity exchanges an OIDC token, such as one from GitHub Actions or an EKS service account, for role credentials, with no stored keys.

GetSessionToken gives an IAM user temporary credentials after MFA, so that MFA-protected API actions can be called. GetFederationToken creates sessions for federated users from a custom identity broker. The following table summarises the APIs.

APIUse
AssumeRoleSame or cross-account; optional external ID, MFA, session tags, session policies, sourceIdentity
AssumeRoleWithSAMLEnterprise federation
AssumeRoleWithWebIdentityOIDC tokens, for example GitHub Actions or EKS IRSA
GetSessionTokenMFA-protected API access for IAM users
GetFederationTokenFederated user sessions

Sessions are capped by the role's maximum session duration (1 to 12 hours); role chaining limits them to 1 hour. Regional STS endpoints should be used.

Match the pairs

STS APIs

Exam skills 4.1.2

Match each STS API with its use.

Log in to try this activity Interactive activities are free with an account.

Other temporary access

AWS also provides other mechanisms for granting temporary access. The following list describes them.

  • S3 presigned URLs give time-limited access to one object with the signer's credentials; they stop working at expiry or when those credentials expire, and can be restricted with s3:signatureAge.
  • IAM Roles Anywhere lets workloads outside AWS exchange X.509 certificates for temporary credentials.
Fill in the number

Session limits

Exam skills 4.1.2

Work out session durations from the STS limits in the lesson.

Log in to try this activity Interactive activities are free with an account.

Revoking and troubleshooting sessions

Temporary credentials cannot be deleted, but a role's sessions can be revoked: an inline deny policy with an aws:TokenIssueTime condition denies all sessions issued before a chosen time. CloudTrail records AssumeRole* and ConsoleLogin calls with error codes; trust policies, external IDs, SAML attributes, certificate expiry and clock skew are the usual causes of failures.

The following diagram follows the response when a deployment role's credentials are printed in a public build log.

Responding to deployment-role credentials printed in a public build log. They stay valid until they expire, so an inline deny on aws:TokenIssueTime earlier than 14:05 revokes every older session; pipelines that assume the role again get new credentials, and CloudTrail shows what the leaked session did first.
The scenario is illustrative.
Select all that apply

Why AssumeRole fails

Exam skills 4.1.3

Pick the usual causes of failed AssumeRole calls.

Log in to try this activity Interactive activities are free with an account.
Worked example

Revoking sessions after a credential leak

Temporary credentials for a deployment role were printed in a public build log. They remain valid until they expire, so the team revokes every session issued before now with an inline deny on the role:

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Deny",
    "Action": "*",
    "Resource": "*",
    "Condition": { "DateLessThan": { "aws:TokenIssueTime": "2026-10-11T14:05:00Z" } }
  }]
}

The console's "Revoke active sessions" action adds the same policy. Pipelines that assume the role afterwards receive new credentials and keep working, while the leaked ones are denied. CloudTrail is then searched for any calls made with the leaked session before the revocation.

Check yourself

How can a CI/CD system deploy to AWS without stored access keys?

Show answer

With an OIDC identity provider and AssumeRoleWithWebIdentity.

Exam Tips

Remember for the exam

  • For CI/CD without stored keys, use an OIDC provider with AssumeRoleWithWebIdentity.
  • Role chaining limits sessions to one hour.
  • For time-limited access to one private object, use an S3 presigned URL.
  • To revoke active role sessions, deny with an aws:TokenIssueTime condition.
  • Set sourceIdentity so actions through shared roles are attributed to a person.