Skip to Content
Mengty Learns
CI/CD

OIDC in CI Instead of Long-Lived Keys

Use GitHub Actions OpenID Connect (OIDC) to mint short-lived cloud credentials on AWS, GCP, and Azure instead of storing static IAM keys in secrets.

how-tointermediateTested with github-actions docs (2026-11)Updated Nov 26, 2026

TL;DR

Stop pasting static cloud access keys into GitHub Secrets. Grant your workflow permissions: id-token: write, configure your cloud provider (AWS IAM, GCP Workload Identity, or Azure Entra) to trust https://token.actions.githubusercontent.com, and lock the sub claim to an exact repo, branch, or environment.

Why it exists

Static IAM keys (AWS_SECRET_ACCESS_KEY, GCP JSON service-account keys) never expire on their own. If a secret leaks via a compromised dependency or misconfigured PR workflow, attackers can use it months later—and rotating keys across dozens of repos is painful.

Mental model

With OIDC, GitHub acts as an Identity Provider (IdP) and signs a short-lived JSON Web Token (JWT) for each job run. Your cloud provider verifies GitHub's signature, checks the claims (aud, sub), and hands back temporary credentials that expire automatically.

▶ Flow: watch it work

GitHub Actions OIDC Credential Exchange

Overview of GitHub Actions OIDC Credential Exchange. 4 steps.
Overview4 steps in this flow

Press Start or tap any step dot to trace the path.

▸All steps (4)

Do it

1. Workflow side (GitHub Actions)

Declare id-token: write and pin the auth action to a full commit SHA:

# .github/workflows/deploy.yml (not run)
permissions:
  id-token: write
  contents: read

steps:
  - name: Configure AWS credentials via OIDC
    uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c265591464d6b8ed75 # v4.1.0
    with:
      role-to-assume: arn:aws:iam::123456789012:role/deploy-prod
      aws-region: ap-southeast-1

2. Cloud trust policy shape (AWS / GCP / Azure)

Every provider checks the same core fields—issuer, audience, and subject (sub):

{
  "Effect": "Allow",
  "Principal": {
    "Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
  },
  "Action": "sts:AssumeRoleWithWebIdentity",
  "Condition": {
    "StringEquals": {
      "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
      "token.actions.githubusercontent.com:sub": "repo:my-org/my-repo:environment:production"
    }
  }
}

When you DON'T need this

  • Providers without OIDC support: Not every host supports GitHub OIDC yet. For example, this site's planned Cloudflare Workers deploy (docs/deploy/CLOUDFLARE-WORKERS-PLAN.md) still uses a scoped CLOUDFLARE_API_TOKEN secret—in that case, narrow the token's permissions to one account/zone and rotate it periodically.
  • Public CI with no cloud deploys: A lint/test-only workflow (like .github/workflows/ci.yml in this repo) needs zero cloud credentials at all; keep permissions: contents: read.
  • Cost / complexity trade-off: OIDC is free on GitHub, AWS, GCP, and Azure, and removes key-rotation toil. The initial setup takes ~15 minutes of Terraform/OpenTofu or console config, and you must test sub claim formats carefully so you don't accidentally widen access.

Gotchas

  • Wildcard sub claims (repo:my-org/* or repo:my-org/my-repo:*): Using * lets any branch, tag, or another repo in the org assume your production role. Always pin to :ref:refs/heads/main or :environment:production.
  • Using StringLike when you meant StringEquals: If there is no wildcard, use exact StringEquals matching.
  • Forgetting id-token: write: Without it, configure-aws-credentials fails immediately because GitHub refuses to mint a JWT.

Production checklist

  • Zero long-lived AWS/GCP/Azure static keys remain in GitHub repository secrets.
  • Workflow grants id-token: write only on the deploy job, not workflow-wide.
  • Cloud trust policy locks aud and sub to an exact repo + environment (or refs/heads/main).
  • GitHub production environment requires manual approval or branch protection before the OIDC job runs.

Check yourself

Check Yourself

1. Why is setting sub: 'repo:my-org/my-repo:*' in an AWS OIDC trust policy dangerous?

2. Which GitHub Actions permission allows a job to request an OIDC JWT?

Sources