Sub topic 11
Attaching and verifying attestations and SBOMs
This chapter assumes you can sign and verify an image with a Cosign key pair or keyless identity, and that you know why signatures reference digests. It also assumes you have used a registry and can read JSON on the command line. Here you will sign claims about an image, such as its SBOM, and check those claims before trusting them.
Signatures versus attestations
A plain Cosign signature says one thing: "this signer vouches for this digest." It carries no detail about what the image contains or how it was built.
An attestation is a signed statement about an image. It has two parts:
- Subject: the image digest the statement is about.
- Predicate: the claim itself, such as a list of packages, a build provenance record, or a vulnerability scan result.
The statement follows the in-toto format. In-toto is a specification for describing software supply chain steps. The statement is wrapped in a DSSE envelope (Dead Simple Signing Envelope), which holds the payload and one or more signatures over it. Cosign signs the envelope with the same key or keyless certificate you use for image signatures.
| Row | Signature | Attestation |
|---|---|---|
| Command | `cosign sign` | `cosign attest` |
| Content | Reference to the image digest only | Digest plus a typed JSON predicate |
| Verify with | `cosign verify` | `cosign verify-attestation` |
| Answers | "Who approved this image?" | "Who made this claim about this image, and what is the claim?" |
Predicate types
The --type flag tells Cosign what kind of predicate you are attaching. It sets the predicate type URI inside the statement, and verification filters on it.
| `--type` value | Meaning |
|---|---|
| `spdxjson` | SPDX SBOM in JSON |
| `cyclonedx` | CycloneDX SBOM |
| `slsaprovenance` | SLSA build provenance |
| `vuln` | Vulnerability scan result |
| `openvex` | OpenVEX statement about exploitability |
| a URI such as `https://example.com/build-checks/v1` | Custom predicate |
An SBOM (software bill of materials) is a list of the components inside an image, with versions and licenses. You generate it with a separate tool. This chapter uses Syft, but any tool that emits SPDX or CycloneDX JSON works.
Workflow overview
Creating an SBOM attestation with a key
Start from a digest reference, as in earlier chapters, and generate the SBOM from that exact reference:
# IMAGE must be a digest reference
IMAGE=registry.example.com/team/app@sha256:<digest>
# Generate an SPDX JSON SBOM for exactly that image
syft "$IMAGE" -o spdx-json=sbom.spdx.json
# 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 attest builds an in-toto statement whose subject is the digest in $IMAGE. It then signs the statement and uploads it to the registry. Cosign asks for the private key password unless you set COSIGN_PASSWORD.
cosign verify-attestation checks three things:
- The signature on the envelope is valid for the given public key.
- The envelope's predicate type matches
--type. - The statement's subject matches the digest you passed.
If you pass a tag instead of a digest, Cosign resolves the tag first, but you lose the guarantee that you are looking at the same content later. Use digests.
Reading the verified result
On success, verify-attestation prints the verified envelopes as JSON, one per line. The payload field is base64-encoded. Decode it to see the statement:
cosign verify-attestation --key cosign.pub --type spdxjson "$IMAGE" \
| jq -r '.payload' \
| base64 -d \
| jq '.predicate.packages | length'The decoded statement has a subject (with the digest), a predicateType, and a predicate. The last command prints how many packages the SBOM lists.
Read the decoded data only after verification succeeds. If you use cosign download attestation instead, you get the stored envelopes with no checks at all, which is fine for debugging and wrong for decisions.
Keyless attestations
Attestations use the same signing methods as images, so keyless works too. In CI, add an attest step after the sign step. The job's OIDC token (from id-token: write) produces a short-lived certificate, and the signing event goes to the Rekor log.
- name: Generate SBOM
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
syft ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }} -o spdx-json=sbom.spdx.json
- name: Attest the SBOM
run: |
cosign attest --yes --type spdxjson --predicate sbom.spdx.json \
ghcr.io/${{ github.repository }}@${{ steps.build.outputs.digest }}This continues the build-and-sign workflow from the CI chapter, so it needs the same permissions block (id-token: write, packages: write) and the cosign-installer step. The --yes flag skips the interactive confirmation that Cosign shows before it records the signing event in the public log.
Verify a keyless attestation the same way you verify a keyless signature, by pinning the identity and issuer:
cosign verify-attestation \
--type spdxjson \
--certificate-identity https://github.com/OWNER/REPO/.github/workflows/build.yml@refs/heads/main \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
ghcr.io/OWNER/REPO@sha256:<digest>Where attestations are stored
Like signatures, attestations are OCI artifacts in the registry, stored next to the image. In the classic layout, Cosign pushes them to a tag derived from the image digest, with an .att suffix (sha256-<digest>.att). A signature uses the .sig suffix. Newer Cosign versions can store the same data using OCI referrers and signing bundles, depending on version and flags. In every layout, three consequences follow:
- The registry account that pushes the image must also be allowed to push these extra artifacts.
- Copying an image to another registry does not copy its attestations unless you copy them too.
cosign copyhandles this, and so do tools that copy the signature and attestation artifacts. cosign tree "$IMAGE"lists the signatures and attestations attached to a digest, which helps when a verify command finds nothing.
Checking the content, not just the signature
A valid signature proves who made the claim. It does not prove the claim is true. An SBOM generated by a poor scanner is still a validly signed SBOM. Trust has two layers: trust the signer's identity, and trust that the signer's process generates accurate data.
Cosign can evaluate a policy against the predicate during verification. The --policy flag accepts a CUE or Rego file, and verification fails if the predicate does not satisfy it. Typical rules include "no package with a banned license" and "the vulnerability report contains no critical findings." Use this for simple gates in scripts. For cluster-wide enforcement, the admission policies in the next chapters apply the same idea at deploy time.
Common errors
no matching attestations: the--typedoes not match what was attached, or the attestation was made against a different digest. Checkcosign treeand confirm the digest.- Verifying with the wrong method: an attestation made with a key cannot be verified with
--certificate-identity, and a keyless one cannot be verified with--key. - SBOM generated from a tag: if the tag moved between SBOM generation and attestation, the SBOM describes different content. Generate from the digest.
- Rebuilt image, old attestation: a rebuild produces a new digest. Attestations do not carry over, so attest every build.
- Image verified, attestation not: a successful
cosign verifysays nothing about attestations. Run both commands, or enforce both in policy. - Large SBOMs: very large predicates can hit registry size limits. Check your registry's limits if the push fails.
Exercise
You run cosign verify-attestation --key cosign.pub --type cyclonedx "$IMAGE" and get "no matching attestations", but cosign verify --key cosign.pub "$IMAGE" succeeds. What are the two most likely causes, and how do you investigate?
Show answer
Either no CycloneDX attestation was attached to this digest (the SBOM may have been attested as spdxjson, or attached to a different digest), or the attestation was signed with a different key. A passing cosign verify only proves the image signature. Run cosign tree "$IMAGE" to list the attestations attached to this digest, and check which predicate type they carry. Then re-run verification with the matching --type and the correct key.
Exercise
A teammate verifies a keyless SBOM attestation with cosign verify-attestation --type spdxjson "$IMAGE" plus --certificate-identity-regexp '.*' and --certificate-oidc-issuer-regexp '.*'. Why is this unsafe, and what should they use instead?
Show answer
The wildcard regexes accept a certificate for any identity from any issuer, so anyone who can get a Fulcio certificate can produce an attestation that passes. They should pin the exact expected identity and issuer, for example --certificate-identity https://github.com/OWNER/REPO/.github/workflows/build.yml@refs/heads/main and --certificate-oidc-issuer https://token.actions.githubusercontent.com.