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.
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
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-12. 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 scopedCLOUDFLARE_API_TOKENsecret—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.ymlin this repo) needs zero cloud credentials at all; keeppermissions: 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
subclaim formats carefully so you don't accidentally widen access.
Gotchas
- Wildcard
subclaims (repo:my-org/*orrepo: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/mainor:environment:production. - Using
StringLikewhen you meantStringEquals: If there is no wildcard, use exactStringEqualsmatching. - Forgetting
id-token: write: Without it,configure-aws-credentialsfails 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: writeonly on the deploy job, not workflow-wide. - Cloud trust policy locks
audandsubto an exactrepo+environment(orrefs/heads/main). - GitHub
productionenvironment 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
Related Notes
Caching That Actually Works in CI/CD
Speed up GitHub Actions with pnpm store caching and Docker layer caching (cache-from/to gha), design stable cache keys, and know when caching hurts.
Deploy & Rollback Strategies
Compare rolling, blue-green, canary, feature flags, expand/contract DB migrations, and rollback vs roll-forward, using this site's planned Workers flow.