Sub topic 6
Generating build provenance in a workflow
This chapter assumes you can write a GitHub Actions workflow with jobs, steps and permissions. It also assumes you know what a hash and a digital signature are. Here you will add one step that produces a signed provenance attestation for a build output.
What the action does
The actions/attest-build-provenance action does four things during a run:
- It computes the SHA-256 digest of each file you name as a subject.
- It builds an in-toto statement. The statement records the subject digests and a SLSA provenance predicate with the repository, the commit, the workflow file, the trigger and the runner.
- It requests an OIDC token from GitHub and uses it to get a short-lived Sigstore certificate.
- It signs the statement, records the signature in a transparency log, and stores the resulting bundle with the repository, where
gh attestation verifycan find it.
You do not manage any signing keys. The signing identity is the workflow itself.
A minimal workflow
The following workflow builds a file on a version tag and attests it.
name: build
on:
push:
tags: ['v*']
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write
steps:
- uses: actions/checkout@v4
- name: Build
run: make build # assumed to write dist/app
- name: Attest build provenance
uses: actions/attest-build-provenance@v2
with:
subject-path: dist/appThe permissions
The job needs three permissions. Each one has a specific purpose.
| Permission | Why the action needs it |
|---|---|
| `id-token: write` | Lets the job request an OIDC token, which proves the workflow's identity to Sigstore. |
| `attestations: write` | Lets the job store the signed attestation for the repository. |
| `contents: read` | Lets `actions/checkout` read the repository. |
Setting permissions on a job removes every default permission that you do not list. If you leave out contents: read, checkout fails on a private repository.
Choosing the subject
The subject is the artifact that the attestation describes. Use subject-path to name it. The value can be a path, a glob such as dist/*, or a comma-separated list. The action hashes every matching file and puts one subject entry per file in the statement.
Attest the exact bytes that you publish. If you build a file, attest it, and then compress or modify it before upload, the published file has a different digest. Verification of that file will then fail.
Where the attestation runs
Attest in the same job that builds the artifact. Then the provenance describes the real build, and no other job can swap the file between the build and the signing step. If you build in one job and attest in another, you pass the file through an artifact upload and download. Anyone who can alter that handoff can change the file before it is signed.
Common errors
Unable to get ACTIONS_ID_TOKEN_REQUEST_URL: the job lacksid-token: write. Add it to the job'spermissions.- Resource not accessible by integration: the job lacks
attestations: write. - No subject matched:
subject-pathpoints to a file that does not exist when the step runs. Check the working directory and the build output path. - Attestation step skipped on pull requests: forks get a read-only token, so signing cannot work there. Attest on tags or on pushes to the main branch.
- Private repositories: attestations require a plan that supports them. Check your account type if the step is rejected.
Check that the attestation exists
After the run finishes, download app from where you published it. Then check it from the command line:
gh attestation verify dist/app --repo OWNER/REPOThe next chapter covers verification options in detail. For now, a successful result confirms that the signature, certificate identity and digest all matched.
Exercise
A teammate's workflow attests dist/app, but a later step runs gzip dist/app and publishes dist/app.gz. Why does verification of the published file fail, and how would you fix it?
Show answer
The attestation records the SHA-256 digest of the uncompressed dist/app. The published app.gz has different bytes and so a different digest, and no attestation matches it. Fix it by compressing first and then attesting the file you publish, with subject-path: dist/app.gz.
Exercise
The attest step fails with an error about ACTIONS_ID_TOKEN_REQUEST_URL. Which permission is missing, and why is it needed?
Show answer
id-token: write. It lets the job request an OIDC token from GitHub. Sigstore uses that token to issue a short-lived signing certificate tied to the workflow's identity.