cosign attest: Attach an SBOM Attestation
cosign attest signs an attestation (such as an SBOM or build provenance) and attaches it to a container image.
A signature says who built an image; an attestation says what is inside it or how it was made. cosign attest binds a signed predicate, often an SBOM, to the image digest.
What it does
cosign attest wraps a predicate file (an SBOM, SLSA provenance, or custom JSON) in an in-toto attestation, signs it (key-based or keyless), and stores it next to the image. cosign verify-attestation later checks the signature and the predicate type, optionally evaluating a policy against the predicate.
Common usage
# attach a CycloneDX SBOM attestation, keyless
syft ghcr.io/org/app@${DIGEST} -o cyclonedx-json=sbom.cdx.json
cosign attest --yes --type cyclonedx \
--predicate sbom.cdx.json ghcr.io/org/app@${DIGEST}
# verify the attestation by identity
cosign verify-attestation --type cyclonedx \
--certificate-identity-regexp 'https://github.com/org/.+' \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
ghcr.io/org/app@${DIGEST}Options
| Flag | What it does |
|---|---|
| --predicate <file> | The predicate JSON (SBOM, provenance, custom) |
| --type <type> | Predicate type: cyclonedx, spdxjson, slsaprovenance, custom |
| --key <ref> | Signing key (omit for keyless) |
| --yes | Skip the confirmation prompt |
| --policy <file> | CUE/Rego policy for verify-attestation |
In CI
Generate the SBOM with syft or trivy, then cosign attest --type cyclonedx (or spdxjson) keylessly so the SBOM is signed and stored with the image. Verify it in the deploy gate with cosign verify-attestation, pinning the same identity and issuer used at build time.
Common errors in CI
"invalid predicate type" means --type does not match the predicate format; use cyclonedx for CycloneDX and spdxjson for SPDX. "no matching attestations" on verify means the type filter differs from what was attached, or you verified a moved tag. EOF on the password prompt means COSIGN_PASSWORD is unset for a key-based attest.