Sub topic 4
Workflow identity through GitHub Actions OIDC tokens
This chapter assumes you can write a GitHub Actions workflow with jobs, steps and permissions. It also assumes you know what a JSON Web Token (JWT) looks like and what a digital signature proves. The previous chapter described the parts of a provenance attestation. This one covers where the signer's identity comes from, because a signature only helps if the verifier knows who signed.
The problem: signing without a stored key
A build that signs its output needs a key. A long-lived key stored as a repository secret can be copied by anyone who can run code in the workflow, and it says nothing about which workflow used it. Attestations avoid this by signing with a short-lived key and proving the identity of the workflow that holds it. That proof is an OpenID Connect (OIDC) token issued by GitHub for a specific job run.
OIDC is a standard for one party (the identity provider) to vouch for who someone is. Here, GitHub is the identity provider, and the "someone" is a running workflow job. The vouching takes the form of a JWT, a signed JSON document, that other systems can verify without sharing any secret with GitHub.
What the token is
Every job can ask the Actions runtime for an OIDC token. The token is a JWT with three dot-separated parts: a header, a payload of claims, and a signature. A claim is a name and value pair that states a fact about the job. GitHub signs the token with a private key. Anyone can check that signature using GitHub's public keys, which are published at a well-known address under https://token.actions.githubusercontent.com.
The token has these properties:
- It is issued per job run, not per repository or per user.
- It is short-lived, so a leaked token expires quickly.
- It carries an
aud(audience) claim that names the service the token is meant for. A service should reject tokens whose audience is not its own. - Its claims are set by GitHub, not by workflow code. A step cannot change
repositoryorjob_workflow_ref.
The claims that matter for attestations
| Claim | Example value | What it states |
|---|---|---|
| `iss` | `https://token.actions.githubusercontent.com` | Who issued the token. |
| `sub` | `repo:octo-org/octo-repo:ref:refs/tags/v1.2.0` | The subject, built from the repository and the trigger context. |
| `aud` | `sigstore` | Who the token is intended for. |
| `repository` | `octo-org/octo-repo` | The repository running the job. |
| `repository_owner` | `octo-org` | The owning user or organization. |
| `ref` | `refs/tags/v1.2.0` | The Git ref that triggered the run. |
| `sha` | `a1b2c3...` | The commit the run is for. |
| `workflow_ref` | `octo-org/octo-repo/.github/workflows/build.yml@refs/tags/v1.2.0` | The top-level workflow file and ref. |
| `job_workflow_ref` | `octo-org/shared/.github/workflows/build.yml@refs/heads/main` | The workflow file that contains the running job. |
| `event_name` | `push` | The event that started the run. |
| `runner_environment` | `github-hosted` | Whether the job ran on a GitHub-hosted or a self-hosted runner. |
Two of these claims are easy to confuse. workflow_ref names the workflow that started the run, which is the caller. job_workflow_ref names the workflow file that holds the job being executed. In an ordinary workflow they are the same. When a workflow calls a reusable workflow, job_workflow_ref points at the reusable one. Chapter 9 uses this difference to separate the build definition from the repository that calls it, which is how you reach SLSA Build Level 3.
The sub claim follows a fixed format that depends on how the run started. A push to a branch gives repo:OWNER/REPO:ref:refs/heads/main. A pull request gives repo:OWNER/REPO:pull_request. A job that targets a deployment environment gives repo:OWNER/REPO:environment:production. Systems that trust these tokens often match on sub, so the form matters.
How a job gets a token
The job needs permission to request a token. Without it, the runtime does not provide the request variables at all.
permissions:
id-token: write
contents: readThe id-token: write permission does not let the job write to anything in your repository. It only allows the job to request an OIDC token for itself. Chapter 6 uses it together with attestations: write.
With the permission set, the runner exposes two environment variables: ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN. A step sends a request to the URL, authenticating with the request token, and can add an audience query parameter. The response is a JSON object whose value field is the JWT.
The attestation action does all of this for you. Running it by hand once is still worth doing, because it shows what the signing service will see.
name: show-oidc-claims
on: workflow_dispatch
permissions:
id-token: write
contents: read
jobs:
claims:
runs-on: ubuntu-latest
steps:
- name: Request a token and print selected claims
run: |
TOKEN=$(curl -fsS \
-H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=demo-audience" | jq -r .value)
echo "::add-mask::$TOKEN"
export TOKEN
python3 - <<'PY'
import base64, json, os
payload = os.environ["TOKEN"].split(".")[1]
payload += "=" * (-len(payload) % 4)
claims = json.loads(base64.urlsafe_b64decode(payload))
for key in ("iss", "sub", "aud", "repository", "ref",
"job_workflow_ref", "event_name", "runner_environment"):
print(key, "=", claims.get(key))
PYRun it from the Actions tab with "Run workflow". The log shows the claims for that run, with aud set to demo-audience.
The ::add-mask:: line tells the runner to hide the token value in logs. The script prints only claims, never the token itself. Treat a token as a credential until it expires. Anyone holding it can present it to a service that trusts GitHub, as long as the audience matches.
From token to signing certificate
The OIDC token proves who the job is, but nobody downstream wants to verify a JWT from GitHub every time they download a file. Instead, the identity is converted into a certificate that is stored with the attestation. The next chapter covers this in detail. In outline:
- The job creates a fresh key pair that exists only for this signing event.
- The job sends its OIDC token and the public key to Fulcio, the certificate authority in the Sigstore project.
- Fulcio fetches GitHub's public keys, checks the token's signature, issuer, audience and expiry, and then issues a short-lived certificate for the public key.
- The certificate records the workflow identity: the signing workflow appears in the certificate as the identity (the Subject Alternative Name, a field that names who the certificate is for), and the repository, ref, commit and trigger appear in extensions.
- The job signs the attestation with the private key and discards the key.
The certificate outlives the token and the key. After signing, the verifier needs neither. It reads the workflow identity from the certificate and checks it against what the consumer expects. This is why gh attestation verify can say "this file was built by workflow X in repository Y" without contacting the original workflow.
What a verifier can conclude
The certificate's identity fields come from the token's claims, so verification options map directly onto them:
--repo OWNER/REPOand--owner OWNERcheck the repository and owner in the certificate.--signer-workflow OWNER/REPO/.github/workflows/build.ymlchecks the workflow that signed. The claim behind this isjob_workflow_ref.- Other flags can narrow on the ref or the trigger, if you need that.
A token does not say the build was safe. It says which workflow, at which commit, on what kind of runner, produced the signature. If an attacker can change the workflow file at a ref you trust, they can build anything under that identity. The identity is only as trustworthy as the controls on the repository, such as branch protection, tag protection and required reviews.
Common errors
- Missing
id-token: write. The step that requests a token fails because the request variables are not set, or the attestation action reports that it cannot get a token. Add the permission at the job or workflow level. - Permissions set at the wrong level. Once a
permissions:block lists any permission, every permission not listed becomesnone. A job-level block replaces the workflow-level block entirely. Includecontents: readyourself if the job checks out code. - Pull requests from forks. Runs triggered by a fork's pull request receive a read-only token and do not get an OIDC token. Do not attest from such runs. Attest from a push, a tag or a release in your own repository.
- Matching on too little of
sub. A service that accepts anyrepo:OWNER/*subject trusts every repository in the organization, including new and forked-then-transferred ones. Pin the full repository, and where it matters, the ref or environment. - Wrong audience. A token requested for audience
sigstoreis rejected by a service expecting a different audience. The attestation action sets the audience for you. When you request tokens by hand, set it explicitly. - Trusting a mutable ref.
refs/heads/mainmoves with every merge, and tags can be deleted and recreated unless protected. Theshaclaim pins the exact commit, so prefer it when you need to know precisely what ran. - Self-hosted runners. The token states that the job ran on a self-hosted runner through
runner_environment, but it cannot show that the runner's machine was clean. A compromised self-hosted runner can build with a valid identity. This limit returns in chapter 12.
Exercise
A repository's build.yml workflow has permissions: contents: read at the top and a job that uses actions/attest-build-provenance. The job fails because it cannot obtain an OIDC token. What is the minimal change, and which claim in the certificate will later let a consumer require that the file was signed by build.yml specifically?
Show answer
Add id-token: write (and attestations: write, which the action also needs) to the job's permissions. Because the top-level block lists only contents, every other permission is none, so the token request is denied. A consumer can require the signing workflow with gh attestation verify --signer-workflow OWNER/REPO/.github/workflows/build.yml. This check rests on the job_workflow_ref claim that GitHub put in the token and Fulcio copied into the certificate.