Sub topic 6
Generating build provenance in a workflow
This chapter shows how to produce a signed provenance attestation from a GitHub Actions workflow. It assumes you can read a workflow file (jobs, steps, permissions), use the GitHub CLI, and build a binary or container image. It also assumes you know that a hash identifies file contents and that a signature proves who signed.
By the end you will be able to add actions/attest-build-provenance to a build job, explain each permission it needs, and find the resulting attestation.
What the action does
actions/attest-build-provenance runs inside your build job after the artifact exists. It performs four steps:
- It computes the SHA-256 digest of each subject you name. A subject is the artifact being described.
- It builds an in-toto statement. The statement lists the subjects and a SLSA provenance predicate. The predicate records the repository, commit, workflow file, trigger event, and runner details taken from the workflow run.
- It requests a short-lived signing certificate from Sigstore. It proves its identity with the OIDC token that GitHub issues to the running job.
- It signs the statement and stores the signed bundle with the repository. For public repositories the signature is also recorded in the public Sigstore transparency log.
You do not manage keys. The identity of the workflow is the signing identity. The earlier chapters on OIDC and Sigstore explain why this works, and this chapter focuses on using it.
A minimal workflow
The following workflow builds a file when a version tag is pushed 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 make build step is a placeholder. Replace it with your real build, as long as it writes the file named in subject-path.
The three permissions
The GITHUB_TOKEN is restricted by default in many repositories, so the job must ask for what it needs.
| Permission | Why the action needs it |
|---|---|
| `id-token: write` | Lets the job request an OIDC token. Sigstore uses this token to issue the signing certificate. |
| `attestations: write` | Lets the job store the signed attestation in the repository. |
| `contents: read` | Lets `actions/checkout` read the source. Setting any permission removes the defaults for the others, so you must list this one yourself. |
Grant these at the job level, not the workflow level. Then only the job that builds and attests holds id-token: write. Other jobs, such as a lint job that runs third-party code, cannot request a signing identity.
Private repositories
Attestation works for private repositories on plans that include the feature. The signing path differs. Public repositories use the public Sigstore instance and record entries in its public transparency log. Private repositories use a GitHub-operated Sigstore instance, so repository and workflow names are not published in a public log. Verification with the GitHub CLI works the same way in both cases.
Choosing the subject
The subject is the thing a consumer will later hash and look up. Choose it with care, because the attestation only covers what you name.
The action accepts three ways to name subjects:
subject-pathtakes a file path or a glob. Several files are allowed, one per line or matched by a pattern. Each file gets its own subject entry in a single statement.subject-checksumstakes a file insha256sumformat. Use it when a build step already produced checksums for many files.subject-nametogether withsubject-digestnames an artifact you do not have as a file, such as a pushed container image.
This example attests every file in dist/ that matches a glob.
- name: Attest release archives
uses: actions/attest-build-provenance@v2
with:
subject-path: 'dist/*.tar.gz'Quote the glob so YAML and the shell do not interpret it first. The action expands it. A pattern that matches nothing makes the step fail, which is the behavior you want. A silent pass would leave you with an unsigned release.
Attest the exact file you ship
The attestation records a digest. If a later step modifies, recompresses, or re-signs the file, the digest changes and verification fails for consumers. Order your steps like this:
- Build.
- Run every step that changes the file, such as stripping symbols, compressing, or code signing.
- Attest.
- Upload or publish the same file.
Do not rebuild after attesting. Rebuilds are often not byte-identical, because timestamps and file ordering can differ. Upload the file you attested.
Attesting a container image
For images the subject is the image name plus the digest of the manifest in the registry. A tag is not enough, because a tag can be moved to a different image. The following steps belong in a job that also has packages: write permission, in addition to the three above.
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }}
- name: Attest image provenance
uses: actions/attest-build-provenance@v2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: trueThree details matter here.
- The
id: pushon the build step makes its outputs available.steps.push.outputs.digestis thesha256:...digest of the image that was pushed. subject-namehas no tag. The digest identifies the image.push-to-registry: truealso stores the attestation in the registry next to the image, so tools that read registries can find it. The registry login in the earlier step must therefore be able to write.
Image names must be lowercase. If your repository name has capital letters, ${{ github.repository }} will produce an invalid name. Convert it in an earlier step and use that value in both the tags and subject-name fields.
The later chapter on container images covers verification and registry details. For now, remember the rule: attest by digest, and use the digest that the push step reports.
Making the build trustworthy enough to attest
The action reports facts about the run. It does not make the build safe. Several workflow choices decide how much the attestation is worth.
- Build in the attesting job. If one job builds, uploads an artifact, and a second job downloads and attests it, the attestation says only that the second job saw this file. The build steps are not covered by that claim. Build and attest in the same job when you can.
- Pin action versions. The examples use version tags for readability. For stricter control, pin third-party actions to a full commit SHA. A compromised action in the same job can alter the artifact before it is attested.
- Restrict triggers. Attest on tags or protected branches. An attestation from a workflow triggered by an untrusted pull request tells consumers little.
- Use ephemeral, GitHub-hosted runners. Self-hosted runners that persist between jobs can carry state from one run into the next. Their attestations are less reliable.
Finding and inspecting the attestation
After a successful run, the attestation appears in the repository's Actions area under attestations. The action also exposes outputs you can use in later steps:
bundle-pathis the path of the signed bundle file written to the runner.attestation-ididentifies the stored attestation.attestation-urllinks to it.
If you also publish release files, you can upload the bundle beside them so consumers can verify offline.
- name: Upload bundle with the release
uses: actions/upload-artifact@v4
with:
name: provenance-bundle
path: ${{ steps.attest.outputs.bundle-path }}This step assumes you gave the attest step id: attest. Without that id, the expression evaluates to an empty string and the upload fails.
Download the artifact and check it from your own machine with the GitHub CLI. The next chapter covers verification options.
gh attestation verify dist/app --repo OWNER/REPOA successful run prints the verified claims, including the repository and workflow that produced the file.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Step fails with a message about an OIDC token or `ACTIONS_ID_TOKEN_REQUEST_URL` | `id-token: write` is missing from the job | Add it under the job's `permissions` |
| Step fails when storing the attestation | `attestations: write` is missing, or the plan does not support the feature for a private repository | Add the permission, and check the repository's plan |
| Step fails with "no subjects found" | `subject-path` matched nothing, often because the path or glob is wrong | Print the directory in an earlier step and correct the path |
| Checkout fails after you added `permissions` | `contents: read` was removed along with the default permissions | List `contents: read` explicitly |
| Image attestation fails on the name | Uppercase letters in the image name | Lowercase the name before use |
| Verification later reports a digest mismatch | The file was changed or rebuilt after it was attested | Attest the last form of the file and publish that same file |
| Workflow from a fork cannot attest | Pull requests from forks do not receive `id-token: write` | Attest only in trusted triggers such as tags |
Summary of the pattern
A reliable attesting job has this shape: a trusted trigger, narrowly scoped permissions, a build, the final file, then the attest step on exactly that file or digest. The result is a signed statement that ties the artifact's hash to the repository, commit, and workflow that produced it.
Exercise
A workflow builds dist/app in one job and uploads it as a workflow artifact. A second job downloads it and runs actions/attest-build-provenance on it. A teammate says this is equivalent to attesting in the build job. Explain why it is not, and name one change that fixes it.
Show answer
The attestation is created by the second job, so its provenance describes that job's workflow run and identity, not the steps that produced the file. It shows only that the second job held a file with that digest. A consumer cannot tell from it how the file was built, and anything that altered the artifact between jobs would go unnoticed. The fix is to build and attest in the same job, giving that job id-token: write and attestations: write, and publish the file that was attested.
Exercise
You attest a container image with subject-name: ghcr.io/acme/web and subject-digest: ${{ steps.push.outputs.digest }}. The push step has no id. What happens, and why should you not substitute the tag latest for the digest?
Show answer
Without id: push, steps.push.outputs.digest is empty, so the action has no valid digest and the step fails. A tag such as latest is a movable pointer. It can later refer to a different image, so an attestation tied to a tag would not identify a fixed artifact. The digest is a hash of the image manifest and always identifies the same content.