Sub topic 6
Enabling tokens with id-token: write
This chapter covers the permissions setting that lets a workflow request an OIDC token. It assumes you can read GitHub Actions workflow syntax, know what GITHUB_TOKEN is, and have a general idea of cloud IAM roles. Token claims and trust policies come in later chapters.
Why the permission exists
GitHub does not hand an OIDC token to every job. A job gets one only if the workflow grants id-token: write. This follows the same least-privilege idea as the rest of the permissions system: a job should hold only the access it needs.
The name is slightly misleading. The permission does not let the job write anything to your repository or to GitHub. It lets the job request a signed identity token from GitHub's OIDC provider. Without it, the runner does not set up the token request variables, and any attempt to fetch a token fails.
Setting the permission
You can set permissions at the workflow level, where it applies to every job, or at the job level, where it applies to one job. Prefer the job level so that only the job that talks to the cloud can request tokens.
name: deploy
on:
push:
branches: [main]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "This job cannot request an OIDC token"
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- run: echo "This job can request an OIDC token"Here the test job inherits only contents: read. The deploy job sets its own permissions block, which replaces the workflow-level one for that job.
What the runner provides
When a job has id-token: write, the runner adds two environment variables to the job:
| Variable | Purpose |
|---|---|
| `ACTIONS_ID_TOKEN_REQUEST_URL` | The GitHub endpoint that issues the token |
| `ACTIONS_ID_TOKEN_REQUEST_TOKEN` | A bearer credential that authorizes the request to that endpoint |
The request token is not the OIDC token. It only proves to GitHub that the call comes from a running job. GitHub's response to that call contains the real OIDC token. The next chapter shows how to make that request. Actions such as aws-actions/configure-aws-credentials make it for you.
Special cases
- Pull requests from forks. Workflows triggered by a fork's pull request run with a read-only token, and
id-token: writeis not granted. A deploy job should not run for fork pull requests anyway. - Reusable workflows. A called workflow can use the permission only if the caller allows it. The caller's
permissionsset the upper limit. - Organization and enterprise policy. Administrators can restrict the default token permissions. A workflow cannot raise its access above what policy allows.
Common errors
If a job lacks the permission, tools usually report that the OIDC request variables are missing. The configure-aws-credentials action, for example, fails with a message that it could not get the ID token, and it suggests adding id-token: write. Check the permissions block of the failing job first, then check whether a workflow-level block is replacing what you expected.
Exercise
A workflow sets permissions: { id-token: write } at the top level. A job in it runs actions/checkout@v4 on a private repository and fails. Why does it fail, and what is the fix?
Show answer
Listing any permission sets all unlisted permissions to none, so contents is now none and checkout cannot read the private repository. Add contents: read to the permissions block, preferably at the job level for the job that needs id-token: write.