Day 14: SBOM and signature – syft and cosign
Goal: You generate SBOMs in the common formats, sign notes-api in your registry with your own key and attach the SBOM as a signed attestation. · Duration: approx. 75 min · Prerequisite: Day 13
Briefing
- An SBOM (software bill of materials) is an image’s parts list: packages, versions, licenses, package URLs. syft generates it in SPDX, CycloneDX or its own syft JSON.
- cosign (Sigstore) signs images by digest and stores signature and attestations as OCI artifacts next to the image in the registry.
- In the lab you sign with a key pair and without a public transparency log – nothing leaves the VM except toward your own registry.
- An attestation is a signed statement about the image, here: “this is its SBOM” (in-toto statement with CycloneDX as the predicate).
notes-api@sha256:… ──syft──► api.cdx.json
│ │
├─cosign sign────────► signature ┐ in the registry as
└─cosign attest ─────► attestation┘ tag sha256-<digest> (referrers index)
cosign verify / verify-attestation with cosign.pub ──► ✔
Drill 1: syft – install it and generate the first SBOM
| Profile | syft |
|---|---|
| Task | Generate SBOMs from images, archives and folders |
| Special feature | Many formats in one run; the foundation of grype (Day 13) |
| Project | github.com/anchore/syft (Apache-2.0) |
| Version in this book | 1.55.0 |
source ~/ct-lab/setup/env.sh
mkdir -p ~/ct-lab/tag14 && cd ~/ct-lab/tag14
cp -R "$LAB/code/notes/." . && cp -R "$LAB/code/tag13/notes/." .
syft version | head -2
syft -q podman:docker.io/library/nginx:1.30.6-alpine | head -6Expected (shortened):
Application: syft
Version: 1.55.0
NAME VERSION TYPE
alpine-baselayout 3.7.2-r1 apk
alpine-baselayout-data 3.7.2-r1 apk
alpine-keys 2.6-r0 apk
alpine-release 3.24.3-r0 apk
aom-libs 3.14.1-r0 apk
Without a format, syft prints a table – 71 packages for nginx. As
with grype, you choose the source by prefix: podman: (via
the socket), registry:, docker-archive:,
oci-archive:, oci-dir:, dir: and
file:. Without a prefix, syft first tries the Docker API –
thanks to DOCKER_HOST from Day 4, that’s also the Podman
socket – and otherwise pulls from the registry.
Save your progress? Sign up for free
Drill 2: What syft finds
syft -q podman:localhost/notes-api:0.1.0Expected:
NAME VERSION TYPE
example.com/notes-api UNKNOWN go-module
github.com/google/uuid v1.6.0 go-module
github.com/jackc/pgpassfile v1.0.0 go-module
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 go-module
github.com/jackc/pgx/v5 v5.11.0 go-module
github.com/jackc/puddle/v2 v2.2.2 go-module
golang.org/x/sync v0.17.0 go-module
golang.org/x/text v0.29.0 go-module
stdlib go1.27.3 go-module
An image on scratch has no package database – syft reads
the build information that Go writes into every binary, including the Go
version (stdlib). The source folder can be cataloged too,
without any build at all:
syft -q dir:. | awk 'NR > 1 {print $NF}' | sort | uniq -c
syft -q dir:. -o purls | head -3Expected:
7 go-module
66 npm
8 python
pkg:npm/[email protected]
pkg:pypi/[email protected]
pkg:npm/[email protected]
Package URLs (pkg:type/name@version) are the common key
that scanners and databases use to match packages.
Save your progress? Sign up for free
Drill 3: Formats – SPDX, CycloneDX, syft JSON
-o can be repeated, format=file writes
straight to a file. One run, three formats, this time directly from your
registry:
syft -q "registry:$REG/notes/notes-api:0.1.0" -o syft-json=api.syft.json \
-o cyclonedx-json=api.cdx.json -o spdx-json=api.spdx.json
ls -l api.* | awk '{print $5, $9}'
jq -r '"\(.bomFormat) \(.specVersion): \(.components|length) Komponenten"' api.cdx.json
jq -r '"\(.spdxVersion): \(.packages | length) Pakete"' api.spdx.json
jq -r '"syft-json \(.schema.version): \(.artifacts | length) Artefakte"' api.syft.jsonExpected:
10364 api.cdx.json
14323 api.spdx.json
21589 api.syft.json
CycloneDX 1.7: 10 Komponenten
SPDX-2.3: 10 Pakete
syft-json 16.1.11: 9 Artefakte
| Format | Origin | Typical for |
|---|---|---|
SPDX (spdx-json, spdx-tag-value) |
Linux Foundation, ISO/IEC 5962 | License compliance, government agencies |
CycloneDX (cyclonedx-json, -xml) |
OWASP | Security, VEX, scanners |
syft JSON (syft-json) |
Anchore | Lossless storage, grype |
In SPDX and CycloneDX, the image itself counts as the tenth entry.
Older specifications are available via a suffix, such as
-o [email protected].
Save your progress? Sign up for free
Drill 4: Converting
syft convert api.syft.json -o cyclonedx-json=konvertiert.cdx.json
jq -r '.bomFormat, (.components | length)' konvertiert.cdx.json
syft convert api.cdx.json -o syft-table 2>/dev/null | head -3Expected:
[0000] WARN convert is an experimental feature, run `syft convert -h` for help
CycloneDX
10
NAME VERSION TYPE
example.com/notes-api UNKNOWN go-module
github.com/google/uuid v1.6.0 go-module
convert is marked as experimental: details get lost
between formats (github.com/anchore/syft/wiki/format-conversion). Only
the route out of syft JSON is lossless – which is why
it pays to always store the syft JSON as well.
Save your progress? Sign up for free
Drill 5: cosign – install it, key pair
| Profile | cosign |
|---|---|
| Task | Sign images and artifacts, verify signatures and attestations |
| Special feature | Signatures live as OCI artifacts in the same registry; key-based or keyless |
| Project | github.com/sigstore/cosign (Apache-2.0), docs at docs.sigstore.dev |
| Version in this book | v3.1.4 |
cosign version 2>&1 | grep -E 'GitVersion|Platform'
mkdir -p ~/ct-lab/keys && cd ~/ct-lab/keys
export COSIGN_PASSWORD=lab-cosign-pw-123
cosign generate-key-pair
ls -l | awk 'NR > 1 {print $1, $9}'
head -1 cosign.key
cd ~/ct-lab/tag14Expected:
GitVersion: v3.1.4
Platform: linux/arm64
Private key written to cosign.key
Public key written to cosign.pub
-rw------- cosign.key
-rw-r--r-- cosign.pub
-----BEGIN ENCRYPTED SIGSTORE PRIVATE KEY-----
The private key is encrypted with the password from
COSIGN_PASSWORD and readable only by you. It never belongs
in a repository – ~/ct-lab/keys deliberately lives outside
the project folder. The only thing you may hand out is
cosign.pub.
Save your progress? Sign up for free
Drill 6: Signing without a transparency log
You always sign the digest, never the tag – a tag
may point to a different image tomorrow. cosign logs in to the registry
with the login from ~/.docker/config.json (Day 7). The
obvious switch for “no public log” is deprecated in cosign v3:
img="$REG/notes/notes-api@$(crane digest "$REG/notes/notes-api:0.1.0")"
echo "$img"
cosign sign --key ~/ct-lab/keys/cosign.key --tlog-upload=false --yes "$img" 2>&1 \
| head -2 | cut -c1-88Expected:
registry.ct.lab:5000/notes/notes-api@sha256:5e37fbeda66793686142a853dc1a102de52b486723…
Flag --tlog-upload has been deprecated, prefer using a --signing-config file with no tra
Error: --tlog-upload=false is not supported with --signing-config or --use-signing-confi
Since v3, a signing config describes which Sigstore services (Fulcio, Rekor, timestamping) are used when signing. Without one, cosign fetches the public configuration. For the lab, you create an empty one – without any services:
cosign signing-config create --out lab-signing-config.json
cat lab-signing-config.json; echo
cosign sign --key ~/ct-lab/keys/cosign.key --signing-config lab-signing-config.json \
--yes "$img"Expected:
{"mediaType":"application/vnd.dev.sigstore.signingconfig.v0.2+json", "rekorTlogConfig":
{}, "tsaConfig":{}}
Signing artifact...
Pushing signature to: registry.ct.lab:5000/notes/notes-api
Security: In testing, signing ran with a blocked proxy (
HTTPS_PROXYpointing to a dead port,NO_PROXY=registry.ct.lab) – there wasn’t a single access outside your own registry. Without--signing-config, cosign would write the signature to the public Rekor log.
Where is the signature?
crane ls "$REG/notes/notes-api"
crane manifest "$REG/notes/notes-api:sha256-${img#*sha256:}" \
| jq -r '.mediaType, .manifests[0].artifactType'
curl -s -o /dev/null -w '%{http_code}\n' -u "$REG_USER:$REG_PASS" \
"https://$REG/v2/notes/notes-api/referrers/${img#*@}"Expected:
0.1.0
sha256-5e37fbeda66793686142a853dc1a102de52b486723834fcbd9b1764b4ddb5db2
application/vnd.oci.image.index.v1+json
application/vnd.dev.sigstore.bundle.v0.3+json
404
cosign v3 stores a Sigstore bundle as an OCI referrer. Registry 3.1.2
doesn’t support the Referrers API (404), so cosign uses the fallback
scheme from the OCI spec: an index under the tag
sha256-<digest>.
Save your progress? Sign up for free
Drill 7: Verifying
A plain cosign verify --key … additionally demands an
entry in the transparency log and loads the public Sigstore trust root
(TUF) for that. That entry deliberately doesn’t exist here – you tell
cosign so explicitly:
cosign verify --key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true "$img" \
2>verify.log | jq -c '.[0].critical'
cat verify.logExpected:
{"identity":{"docker-reference":"registry.ct.lab:5000/notes/notes-api@sha256:5e37fbe…"
},"image":{"docker-manifest-digest":"sha256:5e37fbe…"},"type":"https://sigstore.dev/co
sign/sign/v1"}
WARNING: Skipping tlog verification is an insecure practice that lacks transparency and
auditability verification for the signature.
Verification for registry.ct.lab:5000/notes/notes-api@sha256:5e37fbe… --
The following checks were performed on each of these signatures:
- The cosign claims were validated
- Existence of the claims in the transparency log was verified offline
- The signatures were verified against the specified public key
stdout has the verified payload (JSON), stderr the log. The line
about the transparency log is misleading – because of
--insecure-ignore-tlog, nothing of the kind was checked;
the warning above it is what applies. What matters is the last line: the
signature matches the public key. And an image without a signature?
podman push -q localhost/notes-api:0.2.0 "$REG/notes/notes-api:0.2.0"
cosign verify --key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true \
"$REG/notes/notes-api@$(crane digest "$REG/notes/notes-api:0.2.0")" 2>&1 | tail -1
echo "Exit: ${PIPESTATUS[0]}"Expected:
error during command execution: no signatures found
Exit: 10
Save your progress? Sign up for free
Drill 8: SBOM as an attestation
cosign attest --key ~/ct-lab/keys/cosign.key --signing-config lab-signing-config.json \
--yes --type cyclonedx --predicate api.cdx.json "$img"
cosign verify-attestation --key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true \
--type cyclonedx "$img" 2>/dev/null > att.json; echo "Exit: $?"
jq -r '.payload' att.json | base64 -d \
| jq -c '{_type, predicateType, n: (.predicate.components | length)}'Expected:
Using payload from: api.cdx.json
Signing artifact...
Exit: 0
{"_type":"https://in-toto.io/Statement/v0.1","predicateType":"https://cyclonedx.org/bom
","n":10}
--type cyclonedx sets the predicate type
(https://cyclonedx.org/bom); there are also
spdxjson, slsaprovenance, vuln or
a URI of your own. verify-attestation checks the signature
and the type and outputs the in-toto statement
Base64-encoded. That way a consumer gets the SBOM without access to your
build – and knows it comes from you.
Save your progress? Sign up for free
Drill 9: What’s attached to the image?
cosign tree and download
cosign tree "$img" 2>&1 | LC_ALL=C tr -cd '\12\40-\176' | cut -c1-80Expected (symbols and tree lines removed):
Supply Chain Security Related artifacts for an image: registry.ct.lab:5000/note
https://sigstore.dev/cosign/sign/v1 artifacts via OCI referrer: registry.ct.la
sha256:4fd43087f54817fe5caebbd1cb53be1107a43f0cd28bfb5e9c9fb2c7c7bb0af7
https://cyclonedx.org/bom artifacts via OCI referrer: registry.ct.lab:5000/not
sha256:5fc11d0a8b469def478ffbe6d21694387e32232bfd85515b56912a88e14cc7f8
cosign tree decorates its output with emojis;
tr leaves only ASCII. Two referrers are attached to the
image: the signature and the SBOM attestation, each as a Sigstore
bundle.
cosign download attestation "$img" 2>/dev/null \
| jq -r '.dsseEnvelope.payload' | base64 -d | jq -r '.predicateType'
cosign download attestation --predicate-type https://cyclonedx.org/bom "$img" \
2>/dev/null | jq -r '.dsseEnvelope.payload' | base64 -d \
| jq -r '.predicate.components[].name' | head -3Expected:
https://sigstore.dev/cosign/sign/v1
https://cyclonedx.org/bom
example.com/notes-api
github.com/google/uuid
github.com/jackc/pgpassfile
download verifies nothing – it only
fetches the Sigstore bundles. For decisions, always use
verify-attestation.
And your own CA? cosign is a Go program and trusts
the system certificate store, where you put your CA on Day 7. Without
it, TLS fails; --registry-cacert then passes the CA
directly:
SSL_CERT_FILE=/dev/null SSL_CERT_DIR=/dev/null cosign verify \
--key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true "$img" 2>&1 \
| tail -1 | cut -c1-88
SSL_CERT_FILE=/dev/null SSL_CERT_DIR=/dev/null cosign verify \
--key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true \
--registry-cacert "$LAB/registry/certs/ca.crt" "$img" >/dev/null 2>&1
echo "Exit: $?"Expected:
error during command execution: Get "https://registry.ct.lab:5000/v2/": tls: failed to v
Exit: 0
Save your progress? Sign up for free
Checkpoint
The key pair and the four files:
cd ~/ct-lab/tag14
source ~/ct-lab/setup/env.sh
ls ~/ct-lab/keys
ls api.cdx.json api.spdx.json api.syft.json lab-signing-config.jsonExpected:
cosign.key
cosign.pub
api.cdx.json
api.spdx.json
api.syft.json
lab-signing-config.json
Signature and SBOM attestation are valid:
img="$REG/notes/notes-api@$(crane digest "$REG/notes/notes-api:0.1.0")"
cosign verify --key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true "$img" \
>/dev/null 2>&1; echo "Exit: $?"
cosign verify-attestation --key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true \
--type cyclonedx "$img" >/dev/null 2>&1; echo "Exit: $?"Expected:
Exit: 0
Exit: 0
Challenge
Sign notes-api:0.2.0 in your registry with the
annotation version=0.2.0, attach an SPDX SBOM as an
attestation and verify both – the signature as valid only if the
annotation matches.
Hint: cosign sign -a key=value sets
annotations, cosign verify -a key=value requires them; the
SPDX type is called spdxjson.
Solution
img2="$REG/notes/notes-api@$(crane digest "$REG/notes/notes-api:0.2.0")"
syft -q "registry:$REG/notes/notes-api:0.2.0" -o spdx-json=api-020.spdx.json
cosign sign --key ~/ct-lab/keys/cosign.key --signing-config lab-signing-config.json \
--yes -a version=0.2.0 "$img2" 2>/dev/null
cosign attest --key ~/ct-lab/keys/cosign.key --signing-config lab-signing-config.json \
--yes --type spdxjson --predicate api-020.spdx.json "$img2" 2>/dev/null
cosign verify --key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true \
-a version=0.2.0 "$img2" >/dev/null 2>&1; echo "Exit: $?"
cosign verify --key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true \
-a version=0.1.0 "$img2" >/dev/null 2>&1; echo "Exit: $?"
cosign verify-attestation --key ~/ct-lab/keys/cosign.pub --insecure-ignore-tlog=true \
--type spdxjson "$img2" >/dev/null 2>&1; echo "Exit: $?"Expected:
Exit: 0
Exit: 1
Exit: 0
Save your progress? Sign up for free
Enterprise Note
- Keys belong in a KMS or HSM (
--key awskms://…,gcpkms://…,hashivault://…,k8s://…), not on developer laptops; the password comes from the pipeline’s secret store. - Keyless is the Sigstore default: the pipeline
authenticates via OIDC, Fulcio issues a short-lived certificate, Rekor
logs the signature publicly –
cosign verifythen checks identity and issuer instead of a key. For internal images there are self-hosted Fulcio/Rekor instances. - Signatures are only useful if someone verifies them: admission controllers (Sigstore policy-controller, Kyverno) admit only signed images with a valid SBOM attestation into the cluster.
- Choose a registry with a Referrers API (OCI 1.1) – or, when copying
between registries, take the
sha256-…tags along (regctl,oras, Day 8/9). - Keyless, provenance (SLSA), VEX and policies are covered in depth in “Secure supply chains hands-on”.