Sub topic 4
Workflow identity through GitHub Actions OIDC tokens
This chapter assumes you can read a GitHub Actions workflow with jobs, steps and permissions. It also assumes you know that a digital signature proves who signed something, and that a hash identifies file contents. You do not need to know OpenID Connect (OIDC) in advance.
The problem: who is signing?
A signature is only useful if the verifier knows who made it. Traditional signing uses a long-lived private key. You store the key as a secret, and anyone who steals it can sign as you. For build provenance, the signer should be the workflow run itself, not a person or a stored key.
GitHub Actions solves this by acting as an identity provider. A running job can ask GitHub for a short-lived, signed token that states facts about that run. Other systems can check the token and trust those facts without any shared secret.
What an OIDC token is
OIDC (OpenID Connect) is a standard for proving identity with a signed token. The token is a JSON Web Token (JWT). It has three parts: a header, a set of claims, and a signature. The claims are name and value pairs describing the run.
GitHub signs each token with its own key and publishes the matching public keys. A verifier fetches those keys and checks the signature. If the signature is valid, the claims were issued by GitHub for that specific run.
Useful claims in a GitHub Actions token include:
| Claim | Meaning | Example |
|---|---|---|
| `iss` | Issuer of the token | `https://token.actions.githubusercontent.com` |
| `sub` | Subject, built from repository and ref | `repo:octo-org/octo-repo:ref:refs/tags/v1.0.0` |
| `repository` | Repository that ran the workflow | `octo-org/octo-repo` |
| `ref` | Git ref that triggered the run | `refs/tags/v1.0.0` |
| `sha` | Commit the run used | a 40-character commit hash |
| `workflow_ref` | Path of the workflow file and its ref | `octo-org/octo-repo/.github/workflows/build.yml@refs/tags/v1.0.0` |
| `job_workflow_ref` | The workflow file that contains the running job. This differs from `workflow_ref` when a reusable workflow is called. | `octo-org/shared/.github/workflows/build.yml@refs/heads/main` |
| `runner_environment` | Whether the runner is GitHub-hosted or self-hosted | `github-hosted` |
| `aud` | Audience the token is meant for | a URL chosen by the requester |
The aud (audience) claim limits where a token is accepted. A service should reject tokens whose audience is not its own. This stops one service from replaying a token it received to impersonate the job elsewhere.
Requesting a token: the `id-token` permission
A job cannot get a token by default. It must opt in with the id-token: write permission. This is the permission you saw in the first workflow example of this tutorial.
permissions:
contents: read
id-token: writeThe name is misleading. The permission does not let the job write anything to your repository. It only lets the job request an OIDC token for its own run. When you set permissions, every permission you leave out is set to none, so list the ones you need.
When the permission is granted, the runner exposes two environment variables: ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN. A step can send a request to that URL with the request token and an audience parameter. GitHub returns the signed JWT. Actions such as actions/attest-build-provenance do this for you, so you rarely write the request yourself.
Why this identity suits attestations
The token ties a signature to a specific, checkable context:
- The
repositoryandshaclaims say which source was built. - The
job_workflow_refclaim says which workflow file ran the job. A consumer can require a particular workflow, not just a particular repository. - The token lives for only a few minutes, so there is no long-lived key to leak.
- Only a job that GitHub itself started can obtain a token. A person cannot mint one by hand for an arbitrary repository.
In the next chapter, a certificate authority turns these claims into a signing certificate. The consumer's checks in gh attestation verify, such as --repo and --signer-workflow, compare against the identity claims recorded there.
Common errors
- Missing
id-token: write. The step fails with an error about being unable to get theACTIONS_ID_TOKEN_REQUEST_URLvariable. Add the permission to the job that needs it. - Permission set only at the wrong level. A job-level
permissionsblock replaces the workflow-level one. Set it where the attesting job is. - Pull requests from forks. Workflows triggered by fork pull requests get a read-only token and no OIDC access. Do not attest from those runs.
- Trusting the token too broadly. A token proves where a run came from, not that the code is safe. Anyone who can push to an allowed branch or tag can produce a valid token for that ref.
- Wrong audience. A service that checks
audrejects tokens requested for a different audience.
Exercise
A job sets permissions: contents: read and calls actions/attest-build-provenance. The step fails because it cannot obtain an OIDC token. What is wrong, and what should you add?
Show answer
The job does not have the id-token: write permission, and setting permissions made every unlisted permission none. Add id-token: write to the job's permissions. The attest action also needs attestations: write.
Exercise
Which claim lets a consumer require that a build ran in a specific workflow file, even when that file is a reusable workflow called from another repository?
Show answer
The job_workflow_ref claim. It names the workflow file that contains the running job, while workflow_ref names the calling workflow.