Sub topic 7
Verifying an artifact with gh attestation verify
Prerequisites and scope
This chapter assumes you know what a SLSA provenance attestation is, which the earlier chapters covered. It also assumes you can run the GitHub CLI (gh) and have signed in with gh auth login. The command reads attestations from the GitHub API, so it needs a token even for public repositories.
By the end you should be able to verify a downloaded file, choose flags that match your trust decision, read the output, and diagnose the usual failures.
What the command checks
gh attestation verify answers one question: did the workflow I expect produce these exact bytes? It does this in several steps.
Each step matters for a different reason:
- The digest lookup ties the attestation to the file contents. A renamed file still verifies. A file with one changed byte does not.
- The signature and certificate checks prove that Sigstore's certificate authority issued a short-lived certificate for a GitHub Actions workflow identity. They also prove that this identity signed the statement.
- The identity comparison is where your policy applies. A valid signature from the wrong repository is still a failure for you.
Basic verification
You must give either --repo or --owner. The command refuses to run without one, because a signature alone says nothing about who signed.
# Verify a downloaded file against the repository that built it
gh attestation verify dist/app --repo OWNER/REPO
# Require a specific signing workflow
gh attestation verify dist/app --repo OWNER/REPO \
--signer-workflow OWNER/REPO/.github/workflows/build.yml
# Verify a container image and print the verified attestation details as JSON
gh attestation verify oci://ghcr.io/OWNER/IMAGE:TAG --owner OWNER --format jsonA successful run prints an abbreviated report like this one. The exact wording varies by gh version.
Loaded digest sha256:3f1c...e9 for file://dist/app
Loaded 1 attestation from GitHub API
The following policy criteria will be enforced:
- Predicate type must match:................ https://slsa.dev/provenance/v1
- Source Repository Owner URI must match:... https://github.com/OWNER
- Source Repository URI must match:......... https://github.com/OWNER/REPO
- Subject Alternative Name must match regex: (?i)^https://github.com/OWNER/REPO/
- OIDC Issuer must match:................... https://token.actions.githubusercontent.com
✓ Verification succeeded!The "policy criteria" block is the most useful part. It lists what the command enforced. If a criterion you care about is missing, add a flag for it.
The exit status is the machine-readable result. It is 0 on success and non-zero on any failure, so you can use the command directly in if statements and CI steps.
Choosing flags that match your trust decision
The default policy is "some workflow in this repository (or owner) signed a SLSA v1 provenance statement for this digest". Often that is too loose. The flags below narrow it.
| Flag | What it constrains | Use it when |
|---|---|---|
| `--repo OWNER/REPO` | The source repository recorded in the signing certificate | You trust one repository |
| `--owner OWNER` | The organization or user that owns the source repository | You trust everything an organization builds |
| `--signer-workflow OWNER/REPO/path.yml` | The workflow file that ran the signing step | Several workflows can attest, but only one is the release pipeline |
| `--signer-repo OWNER/REPO` | The repository that holds the signing (reusable) workflow | You use a shared reusable workflow |
| `--predicate-type URI` | The attestation type to check | You verify SBOMs or custom attestations |
| `--deny-self-hosted-runners` | Rejects builds on self-hosted runners | You only trust GitHub-hosted runners |
| `--cert-identity` / `--cert-identity-regex` | The exact or pattern-matched certificate identity | You need a tighter match than the workflow flags give |
| `--source-ref` and `--source-digest` | The Git ref or commit that triggered the build | You want to accept only release tags or a known commit |
Check gh attestation verify --help for the flags your installed version supports. The two source flags appear only in newer releases.
Repository, owner, and signer workflow are different checks
--repo checks the repository that triggered the build. --signer-workflow checks which workflow file did the signing. These are different questions, and they diverge when you use reusable workflows (see the chapter on Build Level 3). In that setup the triggering repository is the application repository. The signing workflow lives in a separate, centrally controlled repository.
For that case, use both flags together:
gh attestation verify dist/app \
--repo OWNER/APP \
--signer-workflow OWNER/shared-workflows/.github/workflows/build.ymlThis reads as: "built from the app repository, using the trusted shared build workflow". Neither flag alone says that.
A tag or branch on the signer workflow does not change the check, because --signer-workflow takes a path without a ref. If you must pin the exact version of the workflow, use the signer-digest style flags where your gh version provides them.
Verifying other predicate types
The default predicate type is https://slsa.dev/provenance/v1. An SBOM attestation uses a different predicate type, so the default check will not find it, even though the same file has a valid attestation of that kind. Pass the type explicitly:
gh attestation verify dist/app \
--repo OWNER/REPO \
--predicate-type https://spdx.dev/Document/v2.3If you attest both provenance and an SBOM for one file, you need two separate verify commands, one per predicate type. A policy that only checks provenance says nothing about the SBOM.
Using the result in scripts
For gates in CI or install scripts, rely on the exit status and keep the failure visible:
#!/usr/bin/env bash
set -euo pipefail
artifact="$1"
repo="OWNER/REPO"
workflow="OWNER/REPO/.github/workflows/build.yml"
if ! gh attestation verify "$artifact" \
--repo "$repo" \
--signer-workflow "$workflow" >/dev/null; then
echo "Refusing to install $artifact: attestation check failed" >&2
exit 1
fi
echo "Verified $artifact"With --format json the command prints the verified results as a JSON array. Each element contains the attestation bundle and a verificationResult object with the parsed certificate fields. Use --jq to pull values out:
gh attestation verify dist/app --repo OWNER/REPO --format json \
--jq '.[].verificationResult.signature.certificate.sourceRepositoryDigest'This prints the commit SHA that the build ran against. You can record it in an audit log, or compare it to the commit you expect a release to come from. Print the full JSON once and read it before you build a script around specific field names.
Verifying offline
By default the command contacts GitHub twice: once to fetch attestations, and once to refresh the Sigstore trusted root. In an air-gapped environment, split the steps. First, on a connected machine:
gh attestation download dist/app --owner OWNER
gh attestation trusted-root > trusted_root.jsonlThe first command writes a file named after the digest, such as sha256:3f1c...e9.jsonl. This is the attestation bundle. Move the artifact, the bundle, and the trusted root to the isolated machine, then run:
gh attestation verify dist/app \
--bundle 'sha256:3f1c...e9.jsonl' \
--custom-trusted-root trusted_root.jsonl \
--owner OWNERThe cryptographic checks still run. The trusted root is a snapshot, so rotate it on a schedule. An old copy will miss newly rotated Sigstore keys and certificate authorities.
Verifying container images
For images, give the command an oci:// reference. The CLI resolves the tag to a digest and verifies against that digest, not the tag itself. A later push to the same tag does not invalidate the earlier attestation, but it changes which digest the tag points at. Pin deployments to the digest:
gh attestation verify oci://ghcr.io/OWNER/IMAGE@sha256:3f1c...e9 --repo OWNER/REPOThe CLI needs access to the registry to resolve and pull image metadata. Make sure Docker has credentials for private registries.
Common errors
No attestations found. The lookup is by digest and owner. Common causes:
- The file was rebuilt, repackaged, or re-compressed after attestation. Any change gives a new digest.
- The attestation was created by a different organization than the one in
--owner. - The workflow attested a file other than the one you downloaded, for example a build output instead of the zip that was uploaded.
- You are not authenticated, or your token cannot see the repository's attestations.
Verification failed: certificate identity or repository mismatch. A real attestation exists, but its certificate does not match your policy. Read the "policy criteria" block, then inspect the actual identity with --format json. This is also the expected result when someone gives you an artifact built by a fork.
Predicate type mismatch. You asked for the default provenance type, but the artifact only has an SBOM attestation, or the reverse. Pass --predicate-type.
Self-hosted runner rejected. You passed --deny-self-hosted-runners, and the build ran on one. If you control the runners, decide deliberately whether to drop the flag.
Trusted root or certificate validity errors offline. The bundle was signed after your snapshot of the trusted root was taken, or your system clock is wrong. Refresh the root and check the clock.
Exercises
Exercise
You run gh attestation verify app.tar.gz --owner acme and it succeeds. A teammate says that is not enough to ship. Name two flags you would add and say what each one rules out.
Show answer
Add --repo acme/app to rule out artifacts built by other repositories in the acme organization. Add --signer-workflow acme/app/.github/workflows/release.yml to rule out artifacts signed by other workflows in that repository, such as a test or experiment workflow. --deny-self-hosted-runners is also a valid answer; it rules out builds on runners you do not control.
Exercise
A release file verifies fine when downloaded directly. After you unzip it, add a file, and zip it again, gh attestation verify reports that no attestations were found. Why, and what should you verify instead?
Show answer
Attestations are looked up by the SHA-256 digest of the file's bytes. Re-zipping produces different bytes and so a different digest, and no attestation exists for it. Verify the original downloaded file. If you must distribute a modified file, your pipeline needs to attest the new file.
Exercise
Your organization builds all applications with a shared reusable workflow in acme/shared-workflows. Write a verify command that accepts only builds of acme/payments made through build.yml in that shared repository.
Show answer
gh attestation verify dist/app --repo acme/payments --signer-workflow acme/shared-workflows/.github/workflows/build.yml