Sub topic 10
Attaching SBOM and custom predicates
This chapter assumes you can already generate and verify build provenance with actions/attest-build-provenance and gh attestation verify. It also assumes you know the parts of an in-toto statement (subject, predicate type, predicate). Here you will reuse the same signing machinery to attach other claims to an artifact: a software bill of materials (SBOM) and predicates you define yourself.
Provenance is one predicate among many
An attestation is a signed in-toto statement with three parts:
- The subject is the artifact, identified by name and digest.
- The predicate type is a URI that says what kind of claim follows.
- The predicate is the claim itself, as a JSON object.
Build provenance uses the predicate type https://slsa.dev/provenance/v1. Nothing in the signing process depends on that type. The same OIDC token, Fulcio certificate and transparency log entry can sign any predicate, so you can bind other facts to the same digest. Common examples are the list of components inside the artifact, test results, or a vulnerability scan summary.
Two actions cover this:
| Action | Use it for | Predicate type |
|---|---|---|
| `actions/attest-sbom` | An SBOM file you already generated | Chosen from the SBOM format (SPDX or CycloneDX) |
| `actions/attest` | Any JSON predicate | The URI you pass in `predicate-type` |
Both need the same permissions as provenance: id-token: write and attestations: write, plus contents: read. Add packages: write when you push the attestation to a container registry.
What an SBOM attestation adds
An SBOM lists the components in an artifact, such as libraries, versions and licenses. A plain sbom.spdx.json file sitting next to a release has a weakness: nothing ties it to the binary. A consumer cannot tell whether it was produced from the build they downloaded, or edited afterwards.
An SBOM attestation fixes this by signing the SBOM as the predicate and the artifact digest as the subject. A verifier can then check three things:
- The signature is valid and was made by the expected workflow identity.
- The subject digest matches the file in hand.
- The SBOM content is exactly what the workflow produced.
This does not make the SBOM correct. It proves who produced it and that it was not altered. If your generator misses a dependency, the signed SBOM misses it too.
Generating the SBOM
The attest action does not create an SBOM. It signs one you provide, so generate it earlier in the job from the same source tree and build output. Generate it after the build, so it describes what was built. This job uses the Anchore SBOM action, which runs Syft:
name: release
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: Generate SBOM
uses: anchore/sbom-action@v0
with:
path: .
format: spdx-json
output-file: sbom.spdx.json
upload-artifact: false
- name: Attest build provenance
uses: actions/attest-build-provenance@v2
with:
subject-path: dist/app
- name: Attest SBOM
uses: actions/attest-sbom@v2
with:
subject-path: dist/app
sbom-path: sbom.spdx.jsonBoth attest steps point at the same subject-path. They create two separate attestations for one digest, and a consumer can ask for either.
For a container image, use subject-name and subject-digest as in the image provenance step from the previous chapter. Add push-to-registry: true to store the SBOM attestation next to the image in the registry.
- name: Attest image SBOM
uses: actions/attest-sbom@v2
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.push.outputs.digest }}
sbom-path: sbom.spdx.json
push-to-registry: trueThe subject-digest must come from the push step's output. If you pass a digest of a different build, the attestation will still sign successfully and will describe the wrong thing.
Predicate types you will see
attest-sbom picks the predicate type from the SBOM content:
| SBOM format | Predicate type |
|---|---|
| SPDX (JSON) | `https://spdx.dev/Document/v2.3` |
| CycloneDX (JSON) | `https://cyclonedx.org/bom` |
The SBOM must be valid JSON in one of these two formats. The action rejects other formats, and it limits SBOM size, so check the action's README if you have a very large SBOM. If you attach SPDX XML or tag-value, convert it first.
Verifying an SBOM attestation
gh attestation verify checks for SLSA provenance by default. To check a different predicate you must name its type with --predicate-type:
# Verify the SBOM attestation and print it as JSON
gh attestation verify dist/app \
--repo OWNER/REPO \
--predicate-type https://spdx.dev/Document/v2.3 \
--format json
# Pull only the SBOM out of the verified result
gh attestation verify dist/app \
--repo OWNER/REPO \
--predicate-type https://spdx.dev/Document/v2.3 \
--format json \
--jq '.[].verificationResult.statement.predicate.packages[].name'Verification happens before the output is printed, so the --jq filter only sees data that passed the signature, identity and digest checks. If you read the SBOM straight from a release page instead, you skip those checks.
Two common errors:
- No attestations found. You asked for the default provenance type but only an SBOM attestation exists, or the reverse. Match
--predicate-typeto what you attached. - Digest mismatch. The artifact in hand is not the file that was attested. Rebuilds are the usual cause: a second build of the same source may differ by timestamps, so a newly built file has a new digest and no attestation.
Custom predicates with actions/attest
When the claim is not an SBOM, use actions/attest. You supply the predicate type and the predicate JSON. Here is a small test-results predicate.
- name: Run tests and record results
run: |
make test
cat > test-results.json <<EOF
{
"suite": "unit",
"passed": true,
"commit": "${GITHUB_SHA}",
"runId": "${GITHUB_RUN_ID}"
}
EOF
- name: Attest test results
uses: actions/attest@v1
with:
subject-path: dist/app
predicate-type: https://example.com/test-results/v1
predicate-path: test-results.jsonPin the action to the major version that is current when you read this. Inputs have stayed stable, but check the README.
You can also pass the predicate inline with the predicate input instead of predicate-path. A file is easier to inspect and to reuse between steps.
The consumer verifies it the same way:
gh attestation verify dist/app \
--repo OWNER/REPO \
--predicate-type https://example.com/test-results/v1 \
--format json \
--jq '.[].verificationResult.statement.predicate'Designing a predicate type
The predicate type URI is a contract between the producer and everyone who verifies. Keep these rules in mind:
- Choose a URI you control, and put a version at the end (
/v1). Changing the shape of the JSON later means publishing/v2. - Document the fields. A verifier needs to know what
passed: truemeans, such as which tests and which environment. - Prefer an established type when one exists, for example SLSA provenance, SPDX, CycloneDX or the in-toto test result and vulnerability predicates. Existing tools already understand them.
- Keep the predicate small and factual. Put large reports in a file and store its digest in the predicate.
Trust and what a consumer should require
Every attestation signed by your workflow carries the same signing identity. A consumer who only checks "some valid attestation exists" has not checked much. Narrow the check:
- Use
--repoor--ownerso attestations from other repositories are rejected. - Use
--signer-workflowto require a specific workflow file, which matters when several workflows in the repository can sign. - Use
--predicate-typeto require the exact claim you rely on. - For an SBOM, require both the provenance attestation and the SBOM attestation. That way you know who built the artifact and what the build says it contains.
Because any step in an authorized workflow can create an attestation, a compromised or careless step can sign arbitrary predicates. Limit which workflows hold attestations: write, and keep attest steps in workflows that run only on protected tags or branches. The reusable-workflow approach from the previous chapter helps here, because the signer identity then names the trusted workflow rather than the caller.
Limits to remember
- An SBOM attestation does not detect vulnerabilities. It supplies the component list that scanners use. Run a scanner against the verified SBOM, and rerun it over time because new advisories appear after release.
- Attestations are about one subject digest. If you repackage the artifact, such as zipping the binary, the new file needs its own attestation or a verified link back to the original.
- Public repositories write signatures to the public Sigstore transparency log, so predicate contents are visible to anyone. Do not put secrets or internal hostnames in a custom predicate. Private repositories use GitHub's own Sigstore instance, but treat the predicate as content you may need to share.
- Self-reported predicates, such as test results and scan summaries, are only as trustworthy as the workflow that generates them.
Exercise
Your release workflow attests build provenance for dist/app and also an SPDX SBOM. A consumer runs gh attestation verify dist/app --repo OWNER/REPO --format json --jq '.[].verificationResult.statement.predicate.packages' and gets no package list. What is the likely cause, and what change fixes it?
Show answer
Without --predicate-type, the command verifies the default SLSA provenance attestation, whose predicate has no packages field, so the filter returns nothing. Add --predicate-type https://spdx.dev/Document/v2.3 so the command selects and verifies the SBOM attestation instead.
Exercise
A teammate proposes a custom predicate type https://example.com/scan with a free-form JSON body, and adds the attest step before the scanner runs so the signature is ready early. Name two problems and a fix for each.
Show answer
First, the type has no version, so any later change to the JSON shape breaks existing verifiers. Fix it by using a versioned URI such as https://example.com/scan/v1 and documenting the fields. Second, attesting before the scan runs means the predicate cannot contain real scan output, and the signature would vouch for a claim nobody checked. Fix it by running the scanner first, writing its actual output to the predicate file, and attesting only after the scan step succeeds.