Sub topic 7
Verifying an artifact with gh attestation verify
This chapter assumes you can run the GitHub CLI (gh), that you know what a SHA-256 digest is, and that you have a workflow that already produces attestations with actions/attest-build-provenance. Here you play the consumer: you hold a downloaded file and want proof of where it came from.
What the command checks
gh attestation verify takes an artifact and looks for attestations whose subject digest matches it. For each candidate it performs these checks:
- It computes the SHA-256 digest of the local file.
- It fetches attestations for that digest from GitHub's attestation store.
- It validates the signature and the signing certificate chain against the trusted root.
- It checks that the certificate identity matches the repository or owner you asked about.
- It checks that the signature was recorded in the transparency log.
The artifact is trusted only if the bytes you hold hash to the digest in a signed statement. Changing one byte of the file makes the check fail.
Basic verification
You must always say who you expect to have built the artifact. Pass --repo for a single repository or --owner for a user or organization.
# Verify a downloaded file against the repository that built it
gh attestation verify dist/app --repo OWNER/REPOOn success the command prints the matching attestation and exits with status 0. On failure it prints the reason and exits non-zero, so you can use it directly in scripts and CI steps.
Narrowing the check
A repository check accepts any workflow in that repository. Often you want to accept only one. The --signer-workflow flag pins the workflow that signed the attestation.
# Require a specific signing workflow
gh attestation verify dist/app --repo OWNER/REPO \
--signer-workflow OWNER/REPO/.github/workflows/build.ymlThis matters when a repository has several workflows with different trust levels. A workflow that runs on pull requests should not be able to produce an attestation that you accept as a release.
Verifying container images
For images, prefix the reference with oci://. The CLI resolves the tag to a digest and then looks up attestations for that digest. The --format json flag prints the verified attestation details so a script can read them.
# Verify a container image and print the verified attestation details as JSON
gh attestation verify oci://ghcr.io/OWNER/IMAGE:TAG --owner OWNER --format jsonThe JSON output includes the signed statement and the certificate fields. You can pipe it to jq to inspect the build, for example to read the commit that was built.
Reading the result
A successful run shows which claims were verified. Look at these fields:
| Field | What it tells you |
|---|---|
| Subject digest | The hash the signature covers. It must match your file. |
| Source repository | The repository that ran the workflow. |
| Signer workflow | The workflow file that requested the signing certificate. |
| Source ref and commit | The tag or branch and the commit SHA that were built. |
| Predicate type | The kind of claim, such as SLSA provenance. |
Common errors
- No attestations found. The file may have been rebuilt, repackaged or re-compressed after signing. Verify the exact bytes that were attested. A different file means a different digest.
- Repository or owner mismatch. The artifact was built somewhere other than the place you named. Treat this as a real signal, not as a flag to loosen.
- Signer workflow mismatch. The attestation exists but a different workflow signed it. Check the path in
--signer-workflow, including theOWNER/REPO/prefix. - Authentication error. The CLI needs to reach GitHub. Run
gh auth login, or setGH_TOKENin CI. - Wrong image reference. Container image names must be lowercase. An uppercase repository name fails to resolve.
Try it
Pick a release from a project that publishes attestations, download one binary, and run the repository check. Then append a byte to the file and run it again to watch the digest check fail.
Exercise
You verify a binary with gh attestation verify app --repo acme/tool and it passes. A teammate says this does not guarantee the binary came from the release workflow. What flag closes the gap, and why?
Show answer
Add --signer-workflow acme/tool/.github/workflows/<release-file>.yml. The --repo check passes for an attestation signed by any workflow in the repository, including one triggered by a pull request or a less trusted job. Pinning the signer workflow limits acceptance to the workflow you trust for releases.
Exercise
A release asset fails verification with "no attestations found", though the build job succeeded and attested dist/app. Name one likely cause and how to confirm it.
Show answer
The file you downloaded is not the file that was attested, for example because a later step compressed, renamed-and-rewrapped or re-signed it. Compare sha256sum of the downloaded file with the digest of dist/app in the build logs. If they differ, attest the final published bytes instead.