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 attestation structure: a signed statement with a subject, a predicate type, and a predicate.
Same envelope, different predicate
A provenance attestation is one kind of in-toto statement. The statement names a subject (the artifact digest) and carries a predicate whose meaning is set by its predicate type, a URI. Provenance uses https://slsa.dev/provenance/v1. Other predicate types let you bind other claims to the same artifact with the same signing and verification machinery.
Two cases are common:
- An SBOM (software bill of materials) lists the components inside the artifact.
- A custom predicate is any JSON document you define, such as test results or a vulnerability scan summary.
Attesting an SBOM
The actions/attest-sbom action does not generate an SBOM. You produce the SBOM first, in SPDX or CycloneDX JSON, and the action signs it and binds it to the artifact. The permissions are the same as for provenance.
- name: Generate SBOM
uses: anchore/sbom-action@v0
with:
path: dist/
format: spdx-json
output-file: sbom.spdx.json
- name: Attest SBOM
uses: actions/attest-sbom@v2
with:
subject-path: dist/app
sbom-path: sbom.spdx.jsonFor a container image, use subject-name and subject-digest instead of subject-path, and set push-to-registry: true. The job then also needs packages: write.
The action reads the SBOM and sets the predicate type from its format, for example https://spdx.dev/Spdx/v2.3 for SPDX 2.3 or https://cyclonedx.org/bom for CycloneDX.
Attesting a custom predicate
actions/attest is the generic action that the provenance and SBOM actions are built on. You choose the predicate type and supply the predicate JSON.
- name: Run tests and write a summary
run: |
cat > test-results.json <<'EOF'
{"passed": 212, "failed": 0, "suite": "unit"}
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.jsonThe predicate type URI identifies the schema. Choose a URI you control and version it, so consumers can tell which shape of JSON to expect.
Verifying by predicate type
gh attestation verify checks provenance by default. Pass --predicate-type to select a different attestation. Add --format json to read the predicate itself.
# Verify the SBOM attestation and print it
gh attestation verify dist/app --repo OWNER/REPO \
--predicate-type https://spdx.dev/Spdx/v2.3 \
--format json
# Verify the custom test-results attestation
gh attestation verify dist/app --repo OWNER/REPO \
--predicate-type https://example.com/test-results/v1 \
--format json \
--jq '.[].verificationResult.statement.predicate'Verification still checks the signature, the certificate identity and the artifact digest. It does not evaluate what the predicate says.
Common errors
- Wrong predicate type on verify. If the type you pass does not match, the command reports no matching attestations. Check the exact URI, including the SPDX version.
- Treating the SBOM as proof of contents. The signature shows that your workflow vouched for the SBOM file. It does not show that the SBOM is complete or accurate. An SBOM generated from the source tree can miss what the build pulled in.
- Attesting a file that is not the shipped artifact. The subject must be the exact bytes consumers download. If you repackage after attesting, the digest no longer matches.
- Missing permissions.
id-token: writeandattestations: writeare required. Registry pushes also needpackages: write. - Trusting custom claims blindly. Anyone running a workflow in the repository can sign any predicate. A verified test-results attestation tells you which workflow made the claim. Whether the claim is true depends on that workflow.
Exercise
A consumer runs gh attestation verify dist/app --repo OWNER/REPO and succeeds, but wants to read the SBOM attached to the same file. Which flag do they add, and why does a successful provenance check not already cover the SBOM?
Show answer
They add --predicate-type with the SBOM's type URI, for example https://spdx.dev/Spdx/v2.3, and usually --format json to read it. Each attestation has its own predicate type, and verification without the flag selects provenance attestations only. A successful provenance check says nothing about whether an SBOM attestation exists or is valid.
Exercise
You attest a custom test-results predicate for dist/app. A reviewer says "the signature proves the tests passed." What is wrong with that statement?
Show answer
The signature proves that a specific workflow identity signed a statement about that exact artifact digest. It does not prove the statement is true. The tests passed only if the workflow ran them honestly and recorded the real results. The consumer must decide whether to trust that workflow, for example by requiring --signer-workflow.