Sub topic 11
Attaching and Verifying Attestations and SBOMs
This chapter assumes you can sign and verify an image with a Cosign key pair, and that you know images should be referenced by digest. A signature says "this signer vouches for this digest." An attestation says more: it is a signed statement about the image, such as "this image contains these packages" or "this image was built by this pipeline."
Signatures versus attestations
A plain signature has no content beyond the digest. An attestation wraps a predicate (the claim) and a subject (the image digest) in an in-toto statement, then signs the whole envelope. Anyone who verifies it learns who made the claim and which image it applies to.
Common predicate types include:
| Type flag | Meaning |
|---|---|
| `spdxjson` | An SBOM in SPDX JSON format |
| `cyclonedx` | An SBOM in CycloneDX format |
| `slsaprovenance` | Build provenance (how and where the image was built) |
| `vuln` | A vulnerability scan result |
| `custom` | Any JSON document you define |
An SBOM (software bill of materials) is an inventory of the packages inside an image. It helps you answer "are we affected?" when a new vulnerability is announced.
Generate an SBOM
Cosign does not create SBOMs. Use a scanner such as Syft, then attest the result.
IMAGE=registry.example.com/team/app@sha256:<digest>
# Generate an SPDX JSON SBOM for the image
syft "$IMAGE" -o spdx-json=sbom.spdx.jsonGenerate the SBOM from the digest reference so that the SBOM describes the exact content you will sign.
Attach and verify the attestation
Attest with the same key pair used for signing.
# Attach a signed SBOM attestation (SPDX JSON predicate)
cosign attest --key cosign.key --type spdxjson --predicate sbom.spdx.json "$IMAGE"
# Verify the attestation
cosign verify-attestation --key cosign.pub --type spdxjson "$IMAGE"Cosign stores the attestation in the registry next to the image, using the same mechanism as signatures. The --type flag on verification filters for that predicate type, so a verifier asking for spdxjson will not accept a slsaprovenance attestation by mistake.
Keyless attestation works the same way. Omit --key when attesting, and pin identity when verifying:
cosign verify-attestation \
--type spdxjson \
--certificate-identity [email protected] \
--certificate-oidc-issuer https://accounts.google.com \
"$IMAGE"Reading the attested content
verify-attestation prints the verified envelope, with the payload base64 encoded. To read the SBOM, decode the payload and extract the predicate.
cosign verify-attestation --key cosign.pub --type spdxjson "$IMAGE" \
| jq -r '.payload' | base64 -d | jq '.predicate' | head -n 20The output is only trustworthy because verification succeeded first. Never read an attestation with a tool that skips signature checks, and do not pipe the output of a failed verification into later steps.
Common errors
no matching attestations: The--typedoes not match what was attached, or the attestation was attached to a different digest. Re-check the digest and the type.- Signature verifies but attestation does not: A signature and an attestation are separate artifacts. Signing an image does not attest anything about it.
- Stale SBOM: Attestations are bound to one digest. If you rebuild, the digest changes, so you must generate and attest a new SBOM.
- Valid attestation, wrong claim: Verification proves who made the statement, not that the statement is true. An SBOM from an incomplete scanner is a correctly signed incomplete SBOM.
Exercise
You signed an image with cosign sign --key cosign.key "$IMAGE" and attached nothing else. A teammate runs cosign verify-attestation --key cosign.pub --type spdxjson "$IMAGE" and it fails with no matching attestations. Why, and what must you run to fix it?
Show answer
A signature and an attestation are separate artifacts, so signing the image did not create an SBOM attestation. Generate an SBOM (for example with syft "$IMAGE" -o spdx-json=sbom.spdx.json) and run cosign attest --key cosign.key --type spdxjson --predicate sbom.spdx.json "$IMAGE". Then the verify command succeeds.
Exercise
Why should a verifier pass --type spdxjson to cosign verify-attestation?
Show answer
It restricts verification to attestations with that predicate type, so an attestation of a different kind (such as build provenance) cannot be accepted in place of the SBOM.