Sub topic 2
Enabling OIDC Tokens in GitHub Actions
Assume you know basic workflow syntax, repository secrets, and cloud IAM roles. This chapter focuses on the permission and trust steps that connect a workflow to a cloud provider.
Enable the token permission
GitHub Actions does not automatically let every job request an OIDC token. Grant the id-token: write permission at workflow or job level. This permission allows token requests; it does not give access to your cloud account by itself.
name: deploy
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-deploy
aws-region: us-east-1
- run: aws sts get-caller-identityYou can place the permission only on the deployment job when other jobs do not need cloud access.
Request a token and choose its audience
A workflow step requests an ID token from GitHub’s OIDC provider. The aud claim, or audience, identifies the service that should accept the token. AWS uses sts.amazonaws.com. The AWS credentials action requests this token and exchanges it for temporary credentials.
A step can request a token directly through GitHub’s request endpoint:
curl -sS \
-H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=sts.amazonaws.com" \
| jq -r '.value'Do not print the returned JWT in logs. It is a bearer credential until it expires.
Validate the token and apply trust conditions
The provider validates the JWT’s signature using GitHub’s published keys. It also checks the issuer (iss), audience (aud), and expiry. After validation, it compares claims such as sub with the role’s trust policy.
A trust policy should restrict both the audience and the subject. For example, this policy accepts only the main branch of one repository:
{
"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:octo-org/octo-repo:ref:refs/heads/main"
}
}
}A mismatched audience or subject causes the role assumption to fail.
Exercise
What does id-token: write permit, and what does it not decide?
Show answer
It permits the job to request an OIDC token. The cloud provider's trust policy still decides whether that token can assume a role.