CCyberwiki

Short-lived credentials and OIDC federation

Short-lived credentials and OIDC federation
TypeAuthentication method for programs
Also known asWorkload identity federation (WIF), keyless authentication
Built onOpenID Connect ID tokens
ReplacesLong-lived cloud access keys and service account keys stored as secrets
Token issuersGitHub Actions, Vercel
Accepted byAWS, Google Cloud, Microsoft Azure, Vercel
RelatedSecrets management, Secret exposure in CI/CD workflows

A deploy job that copies files into cloud storage has to prove to the cloud provider who it is. The older arrangement is an access key created in the cloud account and pasted into the CI/CD system as a secret, which the job sends on every run.1 Such a key works for anyone who holds a copy until someone notices and rotates it.2 OIDC federation removes the stored key. The platform that runs the job signs a short token stating which job it is; the cloud provider checks the signature and the token's details against a rule the account owner wrote, and hands back a short-lived credential that stops working on its own.1

The exchange

The token is a JSON Web Token in the format OpenID Connect defines for ID tokens. Its claims include iss, the issuer's HTTPS address; sub, the subject, an identifier the issuer never reassigns; aud, the audience the token is meant for; and exp, the time after which the receiver must refuse it.3 GitHub writes a fresh token for each job. A job deploying from the prod environment of octo-org/octo-repo carries the subject repo:octo-org/octo-repo:environment:prod, with further claims for the branch, commit, workflow file and the person who started the run.1

AWS fetches GitHub's signing keys from the published address https://token.actions.githubusercontent.com/.well-known/jwks and uses them to verify each token.4 It then compares the claims with the conditions in the trust policy of the cloud role the job asks for.1 The AWS call that performs the swap, AssumeRoleWithWebIdentity, needs no AWS credentials. The credentials it returns last one hour by default; the caller may ask for anything from 15 minutes up to the role's maximum, which is set between 1 and 12 hours.5 After that AWS refuses them, with no revocation needed.6 The GitHub token itself lives less than five minutes and cannot be used once its job has ended.4

Google Cloud follows the OAuth 2.0 token exchange specification: its Security Token Service verifies the outside token and returns a federated token in its place.7 Vercel issues such tokens to builds and Functions, so a function can reach AWS, Google Cloud, Azure or a private API with no key in its environment variables. It also accepts GitHub Actions tokens in place of a Vercel access token.2

Servers

Code running on Amazon EC2 or Lambda receives the temporary credentials of its role from the platform, and the AWS SDKs discover them, so no long-lived key needs to be copied onto the machine. A server outside AWS can get temporary credentials through IAM Roles Anywhere, which accepts an X.509 certificate from the owner's own certificate authority.8 See also Service accounts and Cloud instance metadata service.

GitHub Actions and AWS

In AWS, the account owner adds an identity provider with the URL https://token.actions.githubusercontent.com and the audience sts.amazonaws.com, then creates a role whose trust policy names the repository and the branch or environment allowed to use it:9

"Condition": {
  "StringEquals": {
    "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
    "token.actions.githubusercontent.com:sub": "repo:octo-org/octo-repo:environment:prod"
  }
}

The workflow asks for the token with the id-token: write permission and passes it to the official AWS action. The permission allows requesting a token and grants no write access to any resource.9

permissions:
  id-token: write
  contents: read
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
        with:
          role-to-assume: arn:aws:iam::123456123456:role/example-role
          role-session-name: deploy
          aws-region: eu-west-1

Repositories created after 15 July 2026, and older ones that opt in, send a subject that also contains fixed owner and repository IDs, such as repo:octo-org@123456/octo-repo@456789:ref:refs/heads/main, and the trust policy has to use the format the repository sends. When a policy names an environment, GitHub advises adding protection rules to it so that only chosen branches and tags can deploy.9 The action is pinned to a full commit hash (see Pinning to commit hashes).

The subject check

Every repository on GitHub gets tokens from the same issuer, so a valid signature proves only that some GitHub job made the request. The sub condition is what limits the role to one repository. Without it, a workflow in any GitHub repository can take on the role and receive its credentials.4 On Google Cloud the same job falls to an attribute condition, an expression that rejects tokens from identities the owner did not choose.7

In 2023 Datadog searched public workflow files for AWS role names, found more than 500 roles in over 275 accounts, and was able to assume a number of them from its own repository. The researchers traced the flaw to unofficial guides with insecure examples and to owners not knowing that both the audience and the subject must be checked. Roles used by build pipelines also tend to carry broad permissions. Since June 2025 AWS refuses to create a role with such a trust policy, but roles made earlier can still have the flaw.4

UK Government Digital Service, 2023

One of the roles belonged to the UK Government Digital Service. A workflow in alphagov/govuk-infrastructure used it to mirror the organisation's GitHub repositories into private repositories on AWS CodeCommit, Amazon's Git hosting service, and it could pull from and push to every CodeCommit repository in the account. The role was written in Terraform, a tool that builds cloud settings from code. The source did include a subject check, but Terraform keeps only the last of two identical keys in a map, and a second StringEquals key holding the audience check overwrote it. Datadog read private mirrored repositories with the role. GDS said the mirror served as a backup, so a restore from it during a GitHub outage could have deployed tampered code. The flaw was reported on 9 May 2023 and fixed within 26 hours.4

Detection

CloudTrail, the AWS log of account activity, records each AssumeRoleWithWebIdentity call with the token's subject.5 A query for calls on a GitHub-trusting role whose user name does not start with repo: followed by the owner's organisation finds use from outside repositories.4 In the newer subject format the organisation name is followed by @ and its ID, so the pattern has to allow for that.9 Reading each such role's trust policy for a missing sub condition finds the exposure before anyone uses it. The policy to read is the one AWS stores, because the GDS source code looked correct.4

Prompt for a coding agent

Find every CI workflow and server configuration in this project that uses a stored cloud access key or service account key, such as AWS_ACCESS_KEY_ID in GitHub secrets or a JSON key file. For each one, propose an OpenID Connect federation setup instead: the identity provider to add in the cloud account, a role with a trust policy that checks both the audience and the subject (exact repository plus branch or environment), the minimum permissions the job needs, and the workflow change (permissions: id-token: write and the provider's official login action pinned to a commit). Do not delete any existing key. List each file, the key it uses and the trust policy you suggest.

In SecFlash

A credential written into a workflow file, left in the checkout for a later step, or printed past GitHub's log masking shows as SF-SEC-805 on the Security page.

See also

References

  1. a b c d GitHub (2026). "OpenID Connect". GitHub Docs.
  2. a b Vercel. "OpenID Connect (OIDC) Federation". Vercel Docs.
  3. back OpenID Foundation. "OpenID Connect Core 1.0". OpenID specifications.
  4. a b c d e f g Tafani-Dereeper, Christophe (27 July 2023, updated 18 June 2025). "No keys attached: Exploring GitHub-to-AWS keyless authentication flaws". Datadog Security Labs.
  5. a b Amazon Web Services. "AssumeRoleWithWebIdentity". AWS Security Token Service API Reference.
  6. back Amazon Web Services. "Temporary security credentials in IAM". AWS Identity and Access Management User Guide.
  7. a b Google Cloud. "Workload Identity Federation". Google Cloud IAM documentation.
  8. back Amazon Web Services. "Security best practices in IAM". AWS Identity and Access Management User Guide.
  9. a b c d GitHub (2026). "Configuring OpenID Connect in Amazon Web Services". GitHub Docs.