Lesson 6 of 6 AWS IAM

Federating Identities to Obtain Temporary AWS Credentials

This lesson explains how federation lets people and workloads use an identity they already have, from a corporate directory, a social provider or a CI/CD system, to obtain temporary AWS credentials without IAM users.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose a federation option for each kind of user.
  • Use session attributes for access control and auditing.
  • Identify how workloads obtain temporary credentials on each compute service.

Federation options

Federation lets people and systems use an existing identity to access AWS, instead of creating IAM users. The right mechanism depends on who needs access.

Employees who work in many accounts sign in through IAM Identity Center, connected to the corporate identity provider, such as Microsoft Entra ID or Okta. They get single sign-on to every assigned account and application, and access is managed centrally with permission sets. For a single account or an older setup, an IAM SAML 2.0 or OIDC identity provider in the account lets users assume roles directly.

Customers of an application sign in through Cognito user pools, often with social or enterprise identity providers, and Cognito identity pools exchange their tokens for limited AWS credentials when the application calls AWS directly. CI/CD systems, such as GitHub Actions, use an IAM OIDC identity provider: each job receives a token and exchanges it for short-lived role credentials, so no access keys are stored in the pipeline. The following table summarises the options.

WhoFederation throughResult
Employees across many accountsIAM Identity Center with the corporate IdPSingle sign-on to accounts and applications
Users of one account, legacy setupsAn IAM SAML 2.0 or OIDC identity providerAssumeRoleWithSAML or AssumeRoleWithWebIdentity
Customers of an applicationCognito user pools and identity poolsApplication sign-in and scoped AWS credentials
CI/CD systems such as GitHub ActionsAn IAM OIDC identity providerShort-lived role credentials per job, no stored keys

The following diagram shows the CI/CD case from the table: a GitHub Actions job exchanging an OIDC token for role credentials.

Deploying from GitHub Actions without stored keys. Each job requests a short-lived OIDC token from GitHub and calls AssumeRoleWithWebIdentity. AWS STS checks the token against the IAM OIDC identity provider and the role's trust policy, which allows only the repository's main branch, and returns role credentials valid for about an hour. A job from another branch or repository is refused.
The trust policy's conditions on the token's claims, such as the repository and branch, decide which jobs may assume the role.
Sort into groups

Which federation route?

Exam skills 1.1.6 · 1.2.3

Choose the federation route for each kind of user or system.

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

Session attributes

Federated sessions can carry additional attributes that support access control and auditing. The following list describes these attributes and the related trust policy conditions.

  • Session tags passed from the IdP, such as department or project, feed ABAC policies.
  • A source identity persists through role chaining, so CloudTrail shows the original person behind every action.
  • Trust policies for OIDC providers should restrict the audience and subject claims, such as a specific GitHub repository and branch.
"Condition": {
  "StringEquals": {"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"},
  "StringLike": {"token.actions.githubusercontent.com:sub": "repo:acme/payments:ref:refs/heads/main"}
}

Instance and workload credentials

Workloads obtain temporary credentials in different ways depending on where they run. On Amazon EC2, an instance profile delivers role credentials through the instance metadata service. Instances should require IMDSv2, which needs a session token obtained with a PUT request; this protects the credentials against server-side request forgery (SSRF) attacks, which can usually make only GET requests.

Workloads outside AWS, such as on-premises servers or another cloud, can obtain temporary credentials with IAM Roles Anywhere, which authenticates them with X.509 certificates from a trusted certificate authority. This removes the need to store long-term access keys on those servers.

Scenario questions

Workload credentials

Exam skills 1.1.3 · 1.1.1

Choose how each workload should get temporary credentials.

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

Deploying from GitHub Actions without keys

A team stores IAM access keys as GitHub secrets so its workflows can deploy to AWS. The keys are long-lived and shared by every workflow in the repository.

StepAction
1Create an IAM OIDC identity provider for token.actions.githubusercontent.com
2Create a deployment role whose trust policy allows AssumeRoleWithWebIdentity only for the repository's main branch
3The workflow requests a short-lived token from GitHub and exchanges it for role credentials
4Delete the stored access keys

Each run now receives credentials valid for about an hour, and a workflow on any other branch or repository is refused by the trust policy's conditions.

Check yourself

Employees sign in with the company's existing identity provider. Which service gives them access to many AWS accounts from one portal?

Show answer

IAM Identity Center, connected to the identity provider through SAML 2.0 and SCIM, with permission sets that define what users can do in each account.

Exam Tips

Remember for the exam

  • For CI/CD from GitHub Actions without stored keys, use an OIDC provider with AssumeRoleWithWebIdentity.
  • For employee access to many accounts with corporate credentials, use IAM Identity Center.
  • To pass department attributes from the identity provider for ABAC, use session tags.
  • Require IMDSv2 on EC2 to protect instance credentials.
  • For on-premises servers that need temporary AWS credentials without access keys, use IAM Roles Anywhere.