Skip to content
Hands-on IT IT Drills

Day 10: Traceable and Verified

Goal: Every notes-api image carries version, commit and build time, builds bit-for-bit identically from the same commit, comes with SBOM and provenance, and fails a trivy gate if it contains known severe vulnerabilities. trivy config and ShellCheck check Dockerfiles and scripts. · Duration: approx. 105 min · Prerequisite: Day 9

Briefing

  • Labels answer “what is this, from which commit, when was it built?” – org.opencontainers.image.version, .revision, .created.
  • A tag is a movable name, the digest the checksum of the content.
  • Reproducible means: same commit, same digest. That’s what SOURCE_DATE_EPOCH and rewrite-timestamp=true take care of.
  • Attestations hang on the image index in the registry: SBOM (what’s inside) and provenance (how it was built). trivy checks the image or SBOM; --exit-code turns that into a gate.
  • Before the build: trivy config looks for misconfigurations in the Dockerfile (DS-…), ShellCheck for errors in shell scripts (SC…).
localhost:5001/notes-api:tag10 ──► image index sha256:…
                                    ├─ linux/arm64      image manifest (config, layers)
                                    └─ unknown/unknown  attestation manifest
                                         ├─ SBOM        (SPDX, from the final stage)
                                         └─ Provenance  (SLSA, build args, materials)

Drill 1: A commit as the source

source ~/docker-lab/setup/env.sh
mkdir -p ~/docker-lab/tag10 && cd ~/docker-lab/tag10
cp -R "$LAB/code/notes/." . && cp -R "$LAB/code/tag09/notes/." .

The second copy lays the state from the end of Day 9 on top – even if you skipped it. Metadata needs a source, so the folder becomes a Git repo. Only notes-api and the hadolint configuration go into the repository:

git init -q && git add notes-api .hadolint.yaml
git commit -qm "notes-api Stand Tag 10" && git tag v1.0.0
git log --oneline --decorate
git status --short

Expected (abbreviated, hash differs):

8d41e07 (HEAD -> main, tag: v1.0.0) notes-api Stand Tag 10
?? .dockerignore
?? .env
?? .env.example
?? README.md
?? notes-web/
?? notes-worker/

?? .env is a warning sign: one careless git add ., and the key is in the repo. You build the .gitignore against that on Day 12. If you’re missing a Git identity: git config user.name "Du" and git config user.email [email protected] in the repo.

Save your progress? Sign up for free

Drill 2: OCI labels from Git

In the final stage of notes-api/Dockerfile, replace the LABEL block with these lines (directly after the two COPY):

ARG VERSION=dev
ARG REVISION=unknown
ARG CREATED=unknown
LABEL org.opencontainers.image.title="notes-api" \
      org.opencontainers.image.description="Notiz-API aus dem Trainingslager" \
      org.opencontainers.image.source="https://example.com/docker-lab/notes" \
      org.opencontainers.image.version="${VERSION}" \
      org.opencontainers.image.revision="${REVISION}" \
      org.opencontainers.image.created="${CREATED}"
diff notes-api/Dockerfile ~/docker-lab/code/tag10/notes/notes-api/Dockerfile
git commit -qam "notes-api: OCI-Labels aus Build-Args" && git tag -f v1.0.0 >/dev/null

Expected: no output from diff; your Dockerfile matches the companion code.

Why the ARGs in the final stage? An ARG applies only in the stage where it appears (Day 2). A new commit then only changes the cheap label line, not the Go build. --build-arg NAME without a value takes the value from your environment. You get the values from Git: commit hash, tag, commit time as Unix time and as an RFC 3339 date in UTC:

export REVISION=$(git rev-parse HEAD)
export VERSION=$(git describe --tags --always --dirty)
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)
export CREATED=$(TZ=UTC git log -1 --date=format-local:%FT%TZ --format=%cd)
env | grep -E '^(VERSION|REVISION|CREATED|SOURCE_DATE_EPOCH)=' | sort
docker build -q -t notes-api:tag10 \
  --build-arg VERSION --build-arg REVISION --build-arg CREATED \
  --label org.opencontainers.image.vendor="IT-Trainingslager" notes-api
docker image inspect -f '{{json .Config.Labels}}' notes-api:tag10 | jq .
docker image inspect -f '{{.Created}}' notes-api:tag10

Expected (abbreviated, hash and times differ):

CREATED=2026-10-29T17:42:10Z
REVISION=3f9c2a1b7d4e…
SOURCE_DATE_EPOCH=1793295730
VERSION=v1.0.0
sha256:…
{
  "org.opencontainers.image.created": "2026-10-29T17:42:10Z",
  "org.opencontainers.image.description": "Notiz-API aus dem Trainingslager",
  "org.opencontainers.image.revision": "3f9c2a1b7d4e…",
  "org.opencontainers.image.source": "https://example.com/docker-lab/notes",
  "org.opencontainers.image.title": "notes-api",
  "org.opencontainers.image.vendor": "IT-Trainingslager",
  "org.opencontainers.image.version": "v1.0.0"
}
2026-10-29T17:42:10Z

--label adds labels from the outside without changing the Dockerfile. And .Created is the commit time, not the build time: buildx automatically passes SOURCE_DATE_EPOCH from your environment through as a build arg.

Tip: With BUILDX_GIT_LABELS=1, buildx sets org.opencontainers.image.revision and .source itself from the Git repo of the build context. Explicit build args are easier to trace in CI, though.

Save your progress? Sign up for free

Drill 3: Tag versus digest

The registry returns the digest of a tag in the Docker-Content-Digest header (Day 0):

docker tag notes-api:tag10 localhost:5001/notes-api:tag10
docker push -q localhost:5001/notes-api:tag10
curl -sI localhost:5001/v2/notes-api/manifests/tag10 | grep Digest

Expected (abbreviated, digests differ):

localhost:5001/notes-api:tag10
Docker-Content-Digest: sha256:eaaef8ebb3f2…

Now a new version under the same tag:

docker build -q -t localhost:5001/notes-api:tag10 --build-arg VERSION=v1.0.1 \
  --build-arg REVISION --build-arg CREATED notes-api
docker push -q localhost:5001/notes-api:tag10
curl -sI localhost:5001/v2/notes-api/manifests/tag10 | grep Digest

Expected (abbreviated, digests differ):

sha256:26021cdb79aa…
localhost:5001/notes-api:tag10
Docker-Content-Digest: sha256:26021cdb79aa…

The old state can still be fetched by its digest. Instead of <erster Digest>, insert the first digest from above (sha256:…):

docker pull -q localhost:5001/notes-api@<erster Digest>

Expected:

localhost:5001/notes-api@sha256:eaaef8ebb3f2…

The same tag now points to a different image; the old one stays reachable via its digest. Whoever deploys by tag gets whatever was pushed last. Whoever deploys by digest gets exactly the verified image – as with the base images on Day 8.

Save your progress? Sign up for free

Drill 4: Reproducible? Build twice

Two builds from the same commit, both without cache, via the builder docker-lab directly into the registry. Attestations are off here, because the provenance contains the start time and duration of the build and would never be identical:

docker buildx build --builder docker-lab -q --no-cache --provenance=false \
  --build-arg VERSION --build-arg REVISION --build-arg CREATED \
  -o type=image,name=localhost:5001/notes-api:repro-a,push=true,rewrite-timestamp=true \
  notes-api
docker buildx build --builder docker-lab -q --no-cache --provenance=false \
  --build-arg VERSION --build-arg REVISION --build-arg CREATED \
  -o type=image,name=localhost:5001/notes-api:repro-b,push=true,rewrite-timestamp=true \
  notes-api
docker buildx imagetools inspect localhost:5001/notes-api:repro-a | grep Digest
docker buildx imagetools inspect localhost:5001/notes-api:repro-b | grep Digest

Expected (abbreviated, digests differ):

sha256:71d09756b269…
sha256:71d09756b269…
Digest:    sha256:deb726c0f0b2890586933a543f6b25c68d79904a4285d3a5cd79d7a4f96e5db1
Digest:    sha256:deb726c0f0b2890586933a543f6b25c68d79904a4285d3a5cd79d7a4f96e5db1

The same counter-check without SOURCE_DATE_EPOCH and without rewrite-timestamp:

unset SOURCE_DATE_EPOCH
docker buildx build --builder docker-lab -q --no-cache --provenance=false \
  --build-arg VERSION --build-arg REVISION --build-arg CREATED \
  -o type=image,name=localhost:5001/notes-api:repro-c,push=true \
  notes-api
docker buildx build --builder docker-lab -q --no-cache --provenance=false \
  --build-arg VERSION --build-arg REVISION --build-arg CREATED \
  -o type=image,name=localhost:5001/notes-api:repro-d,push=true \
  notes-api
docker buildx imagetools inspect localhost:5001/notes-api:repro-c | grep Digest
docker buildx imagetools inspect localhost:5001/notes-api:repro-d | grep Digest
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)

Expected (abbreviated, digests differ):

sha256:2d37c63c11cc…
sha256:6208f5a115de…
Digest:    sha256:13a8bd2bdd592bc3bd59161fee24aa4c9512b039b4d6a78ab210df4037d6d39a
Digest:    sha256:c3071745caa6599751ea49507fd85fe441b5f1c87b24e6d26b412279d161248d

Without SOURCE_DATE_EPOCH, the image config created and the history contain the current time, and the files in the layer carry the build time as mtime. With SOURCE_DATE_EPOCH (from BuildKit 0.11 on), BuildKit sets both timestamps to the commit time; rewrite-timestamp=true (from BuildKit 0.13 on) additionally sets the file times. -trimpath and a Go build without CGO take care of the rest.

Warning: If the second build pulls a newer golang:1.27-alpine, the digest differs even though your code is the same. For real reproducibility, pin the base image by digest (Day 8).

Save your progress? Sign up for free

Drill 5: Attach SBOM and provenance

docker buildx build --builder docker-lab \
  --build-arg VERSION --build-arg REVISION --build-arg CREATED \
  --sbom=true --provenance=mode=max \
  -t localhost:5001/notes-api:tag10 --push notes-api
docker buildx imagetools inspect localhost:5001/notes-api:tag10

Expected (abbreviated, may vary by version):

Name:      localhost:5001/notes-api:tag10
MediaType: application/vnd.oci.image.index.v1+json
Digest:    sha256:91c0de…

Manifests:
  Name:        localhost:5001/notes-api:tag10@sha256:2be8a1…
  MediaType:   application/vnd.oci.image.manifest.v1+json
  Platform:    linux/arm64

  Name:        localhost:5001/notes-api:tag10@sha256:c47f05…
  MediaType:   application/vnd.oci.image.manifest.v1+json
  Platform:    unknown/unknown
  Annotations:
    vnd.docker.reference.digest: sha256:2be8a1…
    vnd.docker.reference.type:   attestation-manifest

The attestations hang in the index as a second manifest, unknown/unknown, so that no container ever starts them. Even without --provenance, BuildKit attaches a provenance with mode=min by default; that’s why Drill 4 had --provenance=false.

Save your progress? Sign up for free

Drill 6: Read attestations

imagetools inspect --format reads the attestations from the registry without pulling the image:

img=localhost:5001/notes-api:tag10
docker buildx imagetools inspect "$img" --format '{{ json .SBOM.SPDX }}' \
  > sbom.spdx.json
jq -r '.packages[].name' sbom.spdx.json
docker buildx imagetools inspect "$img" \
  --format '{{ json .Provenance.SLSA.materials }}' | jq -r '.[].uri'
docker buildx imagetools inspect "$img" \
  --format '{{ json .Provenance.SLSA.invocation.parameters.args }}' | jq .

Expected (abbreviated, may vary by version):

example.com/notes-api (devel)
github.com/google/uuid v1.6.0
stdlib go1.27.3
pkg:docker/docker/dockerfile@1
pkg:docker/[email protected]?platform=linux%2Farm64
{
  "build-arg:CREATED": "2026-10-29T17:42:10Z",
  "build-arg:REVISION": "3f9c2a1b7d4e…",
  "build-arg:SOURCE_DATE_EPOCH": "1793295730",
  "build-arg:VERSION": "v1.0.0",
  …
}

The SBOM finds the Go modules in the binary, even though the image consists of only one file. The provenance names the base images including digest (under .digest) and all build args.

Security: mode=max writes every --build-arg value readably into the provenance. An API key as a build arg thus ends up next to the image in the registry (Day 11). Secret mounts never appear there (Day 13).

Save your progress? Sign up for free

Drill 7: trivy on image and SBOM

trivy image -q --image-src remote localhost:5001/notes-api:tag10 | head -9
trivy sbom -q -f json -o sbom-scan.json sbom.spdx.json
f='.Results[].Vulnerabilities[]?
   | "\(.VulnerabilityID) \(.Severity) \(.PkgName) \(.InstalledVersion)'
f+=' -> \(.FixedVersion)"'
jq -r "$f" sbom-scan.json

Expected (abbreviated, depends on the Go patch level and the state of the trivy database):

Report Summary

┌───────────┬──────────┬─────────────────┐
│  Target   │   Type   │ Vulnerabilities │
├───────────┼──────────┼─────────────────┤
│ notes-api │ gobinary │        0        │
└───────────┴──────────┴─────────────────┘
…

No operating system, no OS packages: trivy only finds the Go binary and its standard library. With the current Go 1.27 there is nothing to report, and the jq line stays empty. That’s a snapshot: if a vulnerability in the standard library becomes known tomorrow, a line like CVE-… HIGH stdlib v1.27.3 -> 1.27.4 appears here. Image scan and SBOM scan should show the same; the SBOM scan needs neither registry access nor the image for that.

Save your progress? Sign up for free

Drill 8: Thresholds as a gate

--severity filters, --exit-code 1 turns every remaining finding into an error code. First on an SBOM with known legacy baggage (golang.org/x/text v0.3.5):

altlast=~/docker-lab/code/tag10/alt.cdx.json
trivy sbom -q --exit-code 1 --severity HIGH,CRITICAL -f json -o alt.json "$altlast"
echo "Exit-Code: $?"
jq -r "$f" alt.json
trivy sbom -q --exit-code 1 --severity CRITICAL "$altlast" >/dev/null
echo "Exit-Code nur CRITICAL: $?"

Expected (may vary depending on the state of the trivy database):

Exit-Code: 1
CVE-2021-38561 HIGH golang.org/x/text v0.3.5 -> 0.3.7
CVE-2022-32149 HIGH golang.org/x/text v0.3.5 -> 0.3.8
CVE-2026-56851 HIGH golang.org/x/text v0.3.5 -> 0.41.0
CVE-2026-56852 HIGH golang.org/x/text v0.3.5 -> 0.39.0
Exit-Code nur CRITICAL: 0

Now your own image: once as built with Go 1.27, once with the old Go 1.25, which no longer gets security fixes. The ARG GO_VERSION from Day 2 makes the switch a build arg:

trivy image -q --image-src remote --exit-code 1 --severity HIGH,CRITICAL \
  localhost:5001/notes-api:tag10 >/dev/null
echo "Go 1.27 – Exit-Code: $?"
docker buildx build --builder docker-lab -q --build-arg GO_VERSION=1.25 \
  --build-arg VERSION --build-arg REVISION --build-arg CREATED \
  --sbom=true --provenance=mode=max \
  -t localhost:5001/notes-api:tag10-go125 --push notes-api >/dev/null
trivy image -q --image-src remote --exit-code 1 --severity HIGH,CRITICAL \
  localhost:5001/notes-api:tag10-go125 >/dev/null
echo "Go 1.25 – Exit-Code: $?"
trivy image -q --image-src remote --severity HIGH,CRITICAL -f json \
  localhost:5001/notes-api:tag10-go125 | jq -r "$f"

Expected (may vary depending on the state of the trivy database):

Go 1.27 – Exit-Code: 0
Go 1.25 – Exit-Code: 1
CVE-2026-111943 HIGH stdlib v1.25.14 -> 1.26.10, 1.27.3
CVE-2026-78667 HIGH stdlib v1.25.14 -> 1.26.9, 1.27.2
CVE-2026-78669 HIGH stdlib v1.25.14 -> 1.26.9, 1.27.2
CVE-2026-97031 HIGH stdlib v1.25.14 -> 1.26.9, 1.27.2

Your code is the same; only the toolchain is older. According to the database, the fixes only exist in Go 1.26 and 1.27; no new patch for 1.25 will come. That Go 1.25 builds at all is due to go.mod: the line go 1.25 is a minimum version; the Dockerfile chooses the toolchain. Exactly this kind of forgotten pin is what a gate should catch. --ignore-unfixed leaves out findings without an available fix; deliberately accepted CVEs belong, with a justification, in a .trivyignore.

Save your progress? Sign up for free

Drill 9: trivy config – misconfiguration in the Dockerfile

trivy checks more than images. trivy config reads Dockerfiles (and Kubernetes YAML, Terraform, Helm) against built-in rules, without any build:

cd ~/docker-lab/tag10
trivy config -q notes-api/Dockerfile | sed -n '/Report Summary/,/└/p'
trivy config -q -f json . | jq -r '.Results[] | select(.Misconfigurations)
  | .Target as $t | .Misconfigurations[] | "\($t) \(.ID) \(.Severity) \(.Title)"'

Expected (abbreviated, may vary by version):

Report Summary

┌────────────┬────────────┬───────────────────┐
│   Target   │    Type    │ Misconfigurations │
├────────────┼────────────┼───────────────────┤
│ Dockerfile │ dockerfile │         0         │
└────────────┴────────────┴───────────────────┘
notes-api/Dockerfile.naiv DS-0002 HIGH Image user should not be 'root'
notes-api/Dockerfile.naiv DS-0026 LOW No HEALTHCHECK defined
notes-api/Dockerfile.naiv DS-0031 CRITICAL Secrets passed via `build-args` or envs or
copied secret files
notes-web/Dockerfile DS-0026 LOW No HEALTHCHECK defined
notes-worker/Dockerfile DS-0026 LOW No HEALTHCHECK defined

The notes-api Dockerfile is clean. The naive one fails with root (DS-0002), the key in ENV (DS-0031) and no HEALTHCHECK (DS-0026). Many rules overlap with hadolint (DL3002) and the build checks (SecretsUsedInArgOrEnv), but not all: only trivy reports the missing HEALTHCHECK of worker and web, at level LOW.

As a gate, again with --exit-code and --severity. The naive Dockerfile is a practice object, so you exclude it:

trivy config -q --exit-code 1 --severity HIGH,CRITICAL . >/dev/null
echo "mit Dockerfile.naiv – Exit-Code: $?"
trivy config -q --exit-code 1 --severity HIGH,CRITICAL \
  --skip-files '**/Dockerfile.naiv' . >/dev/null
echo "ohne Dockerfile.naiv – Exit-Code: $?"

Expected:

mit Dockerfile.naiv – Exit-Code: 1
ohne Dockerfile.naiv – Exit-Code: 0

Save your progress? Sign up for free

Drill 10: ShellCheck for the scripts

A build doesn’t consist of Dockerfiles alone: entrypoints and helper scripts are Bash. ShellCheck finds the typical errors there before they strike in the pipeline.

ShellCheck
Purpose statically check shell scripts (bash, sh, dash, ksh)
Special feature every message has a number SC… with an explanation in the wiki; also built into hadolint
Project github.com/koalaman/shellcheck (GPL-3.0)
Version in the book 0.11.0

A small script with three typical errors:

cat > push-tag.sh <<'EOF'
#!/usr/bin/env bash
# push-tag.sh – sets a tag in the local registry (deliberately buggy)
source ~/docker-lab/setup/env.sh
img=$1
cd $LAB/tag10
for t in $(docker images --format "{{.Tag}}" $img); do
  docker tag $img:$t $REGISTRY/$img:$t
done
echo "fertig: $img"
EOF
shellcheck -f gcc push-tag.sh

Expected:

push-tag.sh:3:8: warning: ShellCheck can't follow non-constant source. Use a directive
to specify location. [SC1090]
push-tag.sh:5:1: warning: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
[SC2164]
push-tag.sh:5:4: note: Double quote to prevent globbing and word splitting. [SC2086]
push-tag.sh:6:46: note: Double quote to prevent globbing and word splitting. [SC2086]
push-tag.sh:7:14: note: Double quote to prevent globbing and word splitting. [SC2086]
push-tag.sh:7:19: note: Double quote to prevent globbing and word splitting. [SC2086]
push-tag.sh:7:22: note: Double quote to prevent globbing and word splitting. [SC2086]
push-tag.sh:7:32: note: Double quote to prevent globbing and word splitting. [SC2086]
push-tag.sh:7:37: note: Double quote to prevent globbing and word splitting. [SC2086]

-f gcc prints one line per finding, good for editors and CI; without -f, ShellCheck shows each location with an arrow and a suggestion. The three classics: SC2086, a variable without quotes splits at spaces and becomes a glob; SC2164, if cd fails, the next commands run in the wrong folder; SC1090, ShellCheck can’t read along a file whose path is only known at runtime. The corrected version:

cat > push-tag.sh <<'EOF'
#!/usr/bin/env bash
# push-tag.sh <image> – copies all local tags of an image into the lab registry
set -euo pipefail
# shellcheck source=/dev/null
source "${LAB:-$HOME/docker-lab}/setup/env.sh"
img="${1:?Aufruf: push-tag.sh <image>}"
cd "$LAB/tag10" || exit 1
for t in $(docker images --format "{{.Tag}}" "$img"); do
  docker tag "$img:$t" "$REGISTRY/$img:$t"
done
echo "fertig: $img"
EOF
shellcheck push-tag.sh && echo "shellcheck: sauber"

Expected:

shellcheck: sauber

# shellcheck source=/dev/null is a directive: it tells ShellCheck not to look for the file. A directive applies to the next command; directly below the shebang line it applies to the whole file. With # shellcheck disable=SC2086 you turn off a rule selectively when a script deliberately relies on word splitting.

An exception without a justification is a trap for the next reader. In the pipeline, -S warning lets notes at the info and style levels through and only fails from warning on. And hadolint calls ShellCheck for every RUN itself:

printf 'FROM alpine:3.22\nRUN cd /tmp && echo $HOME > x\n' > Dockerfile.sc
hadolint --no-color Dockerfile.sc; rm Dockerfile.sc push-tag.sh

Expected:

Dockerfile.sc:2 DL3003 warning: Use WORKDIR to switch to a directory
Dockerfile.sc:2 SC2086 info: Double quote to prevent globbing and word splitting.

Five tools, five perspectives:

Tool checks typical findings Day
hadolint Dockerfile as text, RUN with ShellCheck DL3002 USER root, DL3026 registry 9
BuildKit build checks Dockerfile during the build SecretsUsedInArgOrEnv, JSONArgsRecommended 9
dockle finished image CIS-DI-0001 root, CIS-DI-0010 key in ENV 9
trivy Dockerfile, folder, image, SBOM DS-0002, secrets, CVEs 10, 11
ShellCheck shell scripts SC2086 quoting, SC2164 cd without check 10

Save your progress? Sign up for free

Checkpoint

The revision label is the current commit:

cd ~/docker-lab/tag10
git rev-parse HEAD
docker image inspect notes-api:tag10 \
  --format '{{index .Config.Labels "org.opencontainers.image.revision"}}'

Expected: the same hash twice.

e3c3a7b4b39e23f56fd3a38a4ef887f937f4927b
e3c3a7b4b39e23f56fd3a38a4ef887f937f4927b

Two builds, one digest (Drill 4):

docker buildx imagetools inspect localhost:5001/notes-api:repro-a | grep Digest
docker buildx imagetools inspect localhost:5001/notes-api:repro-b | grep Digest

Expected:

Digest:    sha256:deb726c0f0b2890586933a543f6b25c68d79904a4285d3a5cd79d7a4f96e5db1
Digest:    sha256:deb726c0f0b2890586933a543f6b25c68d79904a4285d3a5cd79d7a4f96e5db1

Attestations hang on the index:

docker buildx imagetools inspect localhost:5001/notes-api:tag10 | grep reference.type

Expected:

    vnd.docker.reference.type:   attestation-manifest

The SBOM knows google/uuid:

jq -r '.packages[].name' sbom.spdx.json | grep uuid

Expected:

github.com/google/uuid

The gate stops the legacy baggage:

trivy sbom -q --exit-code 1 --severity HIGH,CRITICAL \
  ~/docker-lab/code/tag10/alt.cdx.json >/dev/null; echo "Exit: $?"

Expected:

Exit: 1

No severe misconfiguration in the real Dockerfiles:

trivy config -q --exit-code 1 --severity HIGH,CRITICAL \
  --skip-files '**/Dockerfile.naiv' . >/dev/null; echo "Exit: $?"

Expected:

Exit: 0

Challenge

Release notes-api as v1.0.0, but only if the SBOM passes the gate: build a candidate localhost:5001/notes-api:v1.0.0-rc with SBOM and provenance, check the SBOM from the registry with trivy (HIGH, CRITICAL) and set the release tag to exactly the verified digest.

Hint: docker buildx imagetools create -t <new> <repo>@<digest> sets a tag in the registry without rebuilding.

Solution

The candidate and its digest:

cd ~/docker-lab/tag10
docker buildx build --builder docker-lab -q --sbom=true --provenance=mode=max \
  --build-arg VERSION --build-arg REVISION --build-arg CREATED \
  -t localhost:5001/notes-api:v1.0.0-rc --push notes-api
curl -sI localhost:5001/v2/notes-api/manifests/v1.0.0-rc | grep Digest

Expected (abbreviated, digests differ):

sha256:a6885c513474…
Docker-Content-Digest: sha256:a6885c513474…

Fetch the SBOM from the registry and send it through the gate:

docker buildx imagetools inspect localhost:5001/notes-api:v1.0.0-rc \
  --format '{{json .SBOM.SPDX}}' > rc.spdx.json
trivy sbom -q --exit-code 1 --severity HIGH,CRITICAL rc.spdx.json; echo "Exit: $?"

Expected (may vary depending on the state of the trivy database):

Report Summary
…
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)
Exit: 0

Exit 0: the gate passes. Only now the release tag, on the digest from above:

docker buildx imagetools create -t localhost:5001/notes-api:v1.0.0 \
  localhost:5001/notes-api@<Digest des Kandidaten>
curl -sI localhost:5001/v2/notes-api/manifests/v1.0.0 | grep Digest

Expected (abbreviated):

Docker-Content-Digest: sha256:a6885c513474…

The same digest as the candidate: the release tag points to exactly the image that trivy saw. With --build-arg GO_VERSION=1.25 (outdated Go) the gate would fail, exit 1, and there would be no release tag. Finally, clean up:

rm -f rc.spdx.json
docker ps -a --filter name=^notes- --format '{{.Names}}' | xargs -r docker rm -f
docker image ls --format '{{.Repository}}:{{.Tag}}' \
  | grep -E '^(notes-|localhost:5001/)' | xargs -r docker rmi
docker buildx prune --builder docker-lab --all --force

Tip: The cleanup leaves the registry standing. So the tags repro-*, tag10* and v1.0.0* remain retrievable until you delete its volume (Day 0, Drill 9).

Save your progress? Sign up for free

Enterprise Note

  • In CI, VERSION, REVISION and SOURCE_DATE_EPOCH come from the pipeline variables (e.g. CI_COMMIT_SHA in GitLab, github.sha in GitHub), never from manual input.
  • Attestations are only as good as their verification: sign image and attestations (e.g. cosign or Notation) and, before deployment, enforce signature, provenance and digest via a policy engine (Kyverno, OPA Gatekeeper).
  • Store SBOMs centrally (e.g. Dependency-Track) so that a new CVE immediately shows which running images are affected. Rescan running images regularly.
  • Define the gate rule in writing: for example, block HIGH/CRITICAL with an available fix, exceptions in .trivyignore only with a ticket and an expiry date.
  • In air-gapped networks, mirror the trivy database into your own registry (--db-repository), and build with mode=max only if no build arg contains a secret.