GitHub Actions: OIDC — Secrets Without Storing Secrets
OIDC is a way for GitHub to prove a workflow run to a cloud service, so the run gets short lived credentials. No long lived cloud key is stored in GitHub at all.
Ask GitHub for the identity token
The id-token write permission lets the job request the OIDC token.
permissions:
id-token: write
contents: readTrade the token for cloud credentials
This step hands the token to AWS and asks for short lived credentials for the named role.
- uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::123456789012:role/github-actions-demo
aws-region: eu-west-1Use the credentials like any login
Later steps can now run cloud commands. The credentials expire on their own.
- run: aws sts get-caller-identityExample
name: OIDC demo
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::123456789012:role/github-actions-demo
aws-region: eu-west-1
- run: aws sts get-caller-identityKey points
- Use OIDC when a workflow needs to reach a cloud service, like AWS.
- OIDC stands for OpenID Connect, a standard way to prove identity.
- GitHub issues a short lived token for the run, and the cloud trusts it.
- The cloud gives back credentials that expire in minutes.
- The workflow needs the id-token write permission to ask for the token.
- A role is a named set of cloud permissions, like a job title for a program.
- This lesson was not run live in the demo repo, because it needs a cloud account.
In this example, the deploy job asks GitHub for an OIDC identity token, using the id-token write permission. The configure step trades that token for short lived AWS credentials for the named role. The last step shows which identity AWS now sees. This workflow was not run live in the demo repo, because it needs a real AWS account and a real role. A successful run shows the role name in the identity output, and no cloud key is stored in GitHub.
Note
The role address below is a placeholder. Replace the account number and the role name with your own values.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What is the main benefit of OIDC over storing a long lived cloud key in GitHub?