Day 14: The supply chain – scan, describe, sign
Goal: Check images for vulnerabilities and stop the build on critical findings, generate a bill of materials (SBOM), sign images with cosign and admit only signed images from your own registry into the cluster – and build all of this into the pipeline from Day 6 · Duration: approx. 90 min · Prerequisite: Day 13
Briefing
- What runs in the cluster arrives via a supply chain: base image, dependencies, build, registry, deployment. Every station can be tampered with or be outdated. Three tools:
| Question | Tool | Result |
|---|---|---|
| Which known vulnerabilities does the image have? | Trivy | Vulnerability report, exit code as a gate |
| What’s inside? | syft | SBOM (SPDX or CycloneDX) |
| Is it the image our CI built? | cosign | Signature in the registry |
- A tag such as
:79aa3e8can be re-pointed, a digest (@sha256:…) cannot. Signatures apply to digests – that is why the digest ends up in Git at the end. - By default, cosign also writes signatures to the public transparency log Rekor. For an internal lab with private addresses you don’t want that: you sign with your own key and without a public log.
Drill 1: Tools
# on cp1
mkdir -p ~/cnpe/tag14 && cd /tmp
ARCH=$(dpkg --print-architecture)
# Trivy: archive with a fixed architecture name (64bit = amd64; arm64: ARM64)
curl -sSfLO https://github.com/aquasecurity/trivy/releases/download/v0.76.2/trivy_0.76.2_Linux-64bit.tar.gz
tar xzf trivy_0.76.2_Linux-64bit.tar.gz trivy && sudo install -m 755 trivy /usr/local/bin/
# cosign: a single binary
sudo curl -sSfL -o /usr/local/bin/cosign https://github.com/sigstore/cosign/releases/download/v3.1.6/cosign-linux-$ARCH
sudo chmod 755 /usr/local/bin/cosign
# syft
curl -sSfLO https://github.com/anchore/syft/releases/download/v1.57.2/syft_1.57.2_linux_$ARCH.tar.gz
tar xzf syft_1.57.2_linux_$ARCH.tar.gz syft && sudo install -m 755 syft /usr/local/bin/
cd ~/cnpe/tag14
trivy --version | head -1; cosign version | grep GitVersion; syft version | grep ^VersionExpected:
Version: 0.76.2
GitVersion: v3.1.6
Version: 1.57.2
Save your progress? Sign up for free
Drill 2: How old is shop?
# on cp1
IMG=172.16.0.126:30300/platform/shop:820f70f
# --insecure registry speaks HTTP
# --severity only high and critical findings
# --format json machine-readable, evaluated with jq
trivy image --insecure --severity HIGH,CRITICAL --quiet --format json $IMG > shop-scan.json
jq -r '.Metadata.OS | "\(.Family) \(.Name)"' shop-scan.json
jq -r '[.Results[].Vulnerabilities[]?] | group_by(.Severity) | map("\(.[0].Severity): \(length)") | .[]' shop-scan.json
# how many of them already have a fixed version?
jq -r '[.Results[].Vulnerabilities[]? | select(.FixedVersion != null and .FixedVersion != "")] | length' shop-scan.jsonExpected (the numbers change with every new vulnerability database):
alpine 3.23.4
CRITICAL: 1
HIGH: 57
58
All 58 findings are fixed – just not in this image. The base image
nginx:1.29-alpine is outdated; the current series is
1.31:
# on cp1
for i in nginx:1.29-alpine nginx:1.31-alpine; do
echo "$i: $(trivy image --severity HIGH,CRITICAL --quiet --format json $i \
| jq -r '(.Metadata.OS.Name) + " " + ([.Results[].Vulnerabilities[]?] | group_by(.Severity) | map("\(.[0].Severity)=\(length)") | join(" "))')"
doneExpected:
nginx:1.29-alpine: 3.23.4 CRITICAL=1 HIGH=57
nginx:1.31-alpine: 3.24.4 HIGH=6
Trivy as a gate: with --exit-code 1 the
command exits with an error as soon as something is found – a pipeline
then aborts.
# on cp1
trivy image --insecure --severity CRITICAL --exit-code 1 --quiet --format json $IMG > /dev/null; echo "exit=$?"Expected:
exit=1
New base image, built with the pipeline from Day 6:
# on cp1
cd ~/cnpe/tag06/shop-app && git pull -q
sed -i 's/nginx:1.29-alpine/nginx:1.31-alpine/' Dockerfile
git commit -qam 'Basis-Image nginx 1.31' && git push -q
cd .. && k create -f lauf.yaml
tkn pipelinerun logs -n ci --last -f | grep -E 'klonen|commit-push'
cd ~/cnpe/tag14Expected (your hashes will differ):
pipelinerun.tekton.dev/shop-fp4qb created
[klonen : clone] 79aa3e8
[ausrollen : commit-push] db95b1e staging: shop auf 79aa3e8 (Pipeline)
Save your progress? Sign up for free
Drill 3: The bill of materials
# on cp1
IMG=172.16.0.126:30300/platform/shop:79aa3e8
# registry:<image> read directly from the registry, no local Docker needed
# -o spdx-json=<datei> SPDX format as JSON into a file
syft scan registry:$IMG -o spdx-json=shop-sbom.spdx.json -q
jq -r '.packages | length' shop-sbom.spdx.json
jq -r '.packages[] | select(.name=="nginx" or .name=="musl") | "\(.name) \(.versionInfo)"' shop-sbom.spdx.json | sort -uExpected:
73
musl 1.2.6-r3
nginx 1.31.10-r1
73 packages. If a vulnerability in musl becomes known
tomorrow, the SBOM immediately answers whether shop is
affected – without scanning the image again.
Save your progress? Sign up for free
Drill 4: Signing without a public log
# on cp1
# Key pair; the password protects the private key
export COSIGN_PASSWORD=lab-signatur-123
cosign generate-key-pair
# Signing config without transparency log and timestamp service: nothing leaves the lab
cosign signing-config create --out signing-config.json
cat signing-config.json; echo
# log in to the registry (writes ~/.docker/config.json)
cosign login 172.16.0.126:30300 -u platform -p platform-lab-123
# --allow-insecure-registry --allow-http-registry registry without TLS
# --yes no confirmation prompt
cosign sign --key cosign.key --signing-config signing-config.json \
--allow-insecure-registry --allow-http-registry --yes $IMGExpected (abridged):
Private key written to cosign.key
Public key written to cosign.pub
{"mediaType":"application/vnd.dev.sigstore.signingconfig.v0.2+json", "rekorTlogConfig":{}, "tsaConfig":{}}
logged in via /home/ubuntu/.docker/config.json
Signing artifact...
Pushing signature to: 172.16.0.126:30300/platform/shop
The first attempt with the formerly common
--tlog-upload=false fails with cosign 3 with not
supported with –signing-config – the signing config is the new way.
Verify:
# on cp1
# --insecure-ignore-tlog there is no log that could be checked
cosign verify --key cosign.pub --allow-insecure-registry --allow-http-registry --insecure-ignore-tlog=true $IMG 2>&1 \
| grep -v '^WARNING' | head -4
cosign verify --key cosign.pub --allow-insecure-registry --allow-http-registry --insecure-ignore-tlog=true \
172.16.0.126:30300/platform/shop:820f70f 2>&1 | tail -1Expected:
Verification for 172.16.0.126:30300/platform/shop:79aa3e8 --
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
error during command execution: no signatures found
cosign.key belongs in a vault (OpenBao, KMS), never in
Git. cosign.pub may be seen by anyone.
Save your progress? Sign up for free
Drill 5: Only signed images into the cluster
An ImageValidatingPolicy checks images from the platform registry against the public key:
# on cp1
{
cat <<'EOF'
apiVersion: policies.kyverno.io/v1
kind: ImageValidatingPolicy
metadata:
name: signierte-images
spec:
validationActions: [Deny]
matchConstraints:
resourceRules:
- apiGroups: [""]
apiVersions: [v1]
operations: [CREATE, UPDATE]
resources: [pods]
namespaceSelector:
matchLabels:
tier: tenant
matchImageReferences: # only images from our own registry
- glob: "172.16.0.126:30300/platform/*"
attestors:
- name: plattform
cosign:
key:
data: |
EOF
# insert the public key, indented
sed 's/^/ /' cosign.pub
cat <<'EOF'
ctlog:
insecureIgnoreTlog: true # we sign without a transparency log
validations:
- expression: >-
images.containers.map(image, verifyImageSignatures(image, [attestors.plattform])).all(e, e > 0)
message: Images aus der Plattform-Registry muessen mit dem Plattform-Schluessel signiert sein
EOF
} > signierte-images.yaml
k apply -f signierte-images.yaml
sleep 10
k -n team-gelb run signiert --image=172.16.0.126:30300/platform/shop:79aa3e8
k -n team-gelb run unsigniert --image=172.16.0.126:30300/platform/shop:820f70f
k -n team-gelb get pod signiert -o jsonpath='{.spec.containers[0].image}{"\n"}'
k -n team-gelb delete pod signiert --nowExpected:
imagevalidatingpolicy.policies.kyverno.io/signierte-images created
pod/signiert created
Error from server: admission webhook "ivpol.validate.kyverno.svc-fail" denied the request: Policy signierte-images failed: Images aus der Plattform-Registry muessen mit dem Plattform-Schluessel signiert sein; verification details: image "172.16.0.126:30300/platform/shop:820f70f@sha256:6de37ffb…", attestor "plattform": failed to verify cosign signatures: no signatures found
172.16.0.126:30300/platform/shop:79aa3e8@sha256:476d876b000430fe0630ee10921f209ed80a6c1da29f40ae793433b8a173863c
pod "signiert" deleted from team-gelb namespace
Kyverno has added the digest to the image in the pod: exactly this image was verified, and exactly this one runs – re-pointing the tag later changes nothing.
Save your progress? Sign up for free
Drill 6: Kyverno versus Argo CD
What does this addition do to team-green-shop-staging,
which Argo CD manages from Git?
# on cp1
argocd app get team-green-shop-staging --refresh | grep -E 'Sync Status|Deployment'
argocd app diff team-green-shop-staging | grep imageExpected:
Sync Status: OutOfSync from main (db95b1e)
apps Deployment team-green-staging shop OutOfSync Healthy
< - image: 172.16.0.126:30300/platform/shop:79aa3e8@sha256:476d876b000430fe0630ee10921f209ed80a6c1da29f40ae793433b8a173863c
> - image: 172.16.0.126:30300/platform/shop:79aa3e8
Git says tag, the cluster says tag plus digest – Argo CD sees a drift
it can never eliminate, because Kyverno adds the digest again on every
sync. Switching the addition off
(validationConfigurations.mutateDigest: false) doesn’t
help: then the policy rejects images without a digest
(verifyDigest is the default) – image … does not have a
digest. The right solution: the digest is in Git.
Kustomize can do that:
# on cp1
cd ~/cnpe/plattform && git pull -q
K=apps/team-green/shop/overlays/staging/kustomization.yaml
yq -i '.images[0].digest = "sha256:476d876b000430fe0630ee10921f209ed80a6c1da29f40ae793433b8a173863c"' $K
tail -5 $K
k kustomize apps/team-green/shop/overlays/staging | grep image:
git commit -qam 'staging: shop per Digest' && git push -q
argocd app get team-green-shop-staging --refresh >/dev/null
sleep 30
argocd app get team-green-shop-staging | grep -E 'Sync Status|Health Status'
cd ~/cnpe/tag14Expected:
images:
- name: nginx
newTag: "79aa3e8"
newName: 172.16.0.126:30300/platform/shop
digest: sha256:476d876b000430fe0630ee10921f209ed80a6c1da29f40ae793433b8a173863c
- image: 172.16.0.126:30300/platform/shop:79aa3e8@sha256:476d876b000430fe0630ee10921f209ed80a6c1da29f40ae793433b8a173863c
Sync Status: Synced to main (9d2ad9d)
Health Status: Healthy
If a sync was stuck beforehand (waiting for healthy state),
you end it as on Day 4 with
argocd app terminate-op team-green-shop-staging.
Save your progress? Sign up for free
Drill 7: The supply chain in the pipeline
The pipeline from Day 6 only sets the tag – the old digest in Git
would win. It gets three changes: bauen returns the digest,
pruefen stops on critical findings, signieren
signs, ausrollen writes tag and
digest.
# on cp1
# Key and signing config as Kubernetes objects for the pipeline
k -n ci create secret generic cosign-schluessel --from-file=cosign.key --from-literal=password=lab-signatur-123
k -n ci create configmap cosign-signing-config --from-file=signing-config.json
cat > lieferkette-tasks.yaml <<'EOF'
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: bauen
namespace: ci
spec:
params:
- name: image
- name: tag
workspaces:
- name: quelle
results:
- name: digest # new: digest of the pushed image
steps:
- name: build-push
image: quay.io/buildah/stable:v1.46.1
workingDir: $(workspaces.quelle.path)
securityContext:
privileged: true
script: |
set -e
buildah --storage-driver=vfs bud -q -t $(params.image):$(params.tag) .
buildah --storage-driver=vfs push --tls-verify=false --digestfile /tmp/digest $(params.image):$(params.tag)
tr -d "\n" < /tmp/digest | tee $(results.digest.path)
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: pruefen
namespace: ci
spec:
params:
- name: image
steps:
- name: trivy
image: aquasec/trivy:0.76.2
script: |
trivy image --insecure --quiet --severity HIGH,CRITICAL --format table $(params.image)
# Gate: critical findings end the task with an error
trivy image --insecure --quiet --severity CRITICAL --exit-code 1 --format json $(params.image) > /dev/null
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: signieren
namespace: ci
spec:
params:
- name: image
volumes:
- name: schluessel
secret: {secretName: cosign-schluessel}
- name: config
configMap: {name: cosign-signing-config}
steps:
- name: cosign
image: ghcr.io/sigstore/cosign/cosign:v3.1.6 # no shell: args instead of script
env:
- name: COSIGN_PASSWORD
valueFrom: {secretKeyRef: {name: cosign-schluessel, key: password}}
volumeMounts:
- {name: schluessel, mountPath: /schluessel}
- {name: config, mountPath: /config}
args: [sign, --key, /schluessel/cosign.key, --signing-config, /config/signing-config.json,
--allow-insecure-registry, --allow-http-registry, --yes, $(params.image)]
---
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: ausrollen
namespace: ci
spec:
params:
- name: repo
- name: datei
- name: image
- name: tag
- name: digest
workspaces:
- name: plattform
steps:
- name: clone
image: alpine/git:2.54.1
workingDir: $(workspaces.plattform.path)
script: |
git clone -q --depth 1 $(params.repo) .
- name: tag-setzen
image: mikefarah/yq:4.54.3
workingDir: $(workspaces.plattform.path)
securityContext:
runAsUser: 0
script: |
yq -i ".images[0].newName = \"$(params.image)\" | .images[0].newTag = \"$(params.tag)\" | .images[0].digest = \"$(params.digest)\"" $(params.datei)
tail -5 $(params.datei)
- name: commit-push
image: alpine/git:2.54.1
workingDir: $(workspaces.plattform.path)
script: |
set -e
git config user.name "Tekton"
git config user.email [email protected]
git commit -qam "staging: shop auf $(params.tag) (Pipeline, signiert)"
git push -q origin HEAD:main
git log --oneline -1
EOF
k apply -f lieferkette-tasks.yaml
cat > pipeline.yaml <<'EOF'
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: shop
namespace: ci
spec:
params:
- name: image
default: 172.16.0.126:30300/platform/shop
workspaces:
- name: arbeit
tasks:
- name: klonen
taskRef: {name: klonen}
params:
- {name: url, value: http://172.16.0.126:30300/platform/shop-app.git}
workspaces:
- {name: quelle, workspace: arbeit, subPath: quelle}
- name: bauen
runAfter: [klonen]
taskRef: {name: bauen}
params:
- {name: image, value: $(params.image)}
- {name: tag, value: $(tasks.klonen.results.commit)}
workspaces:
- {name: quelle, workspace: arbeit, subPath: quelle}
- name: pruefen # always scans and signs the digest, never the tag
runAfter: [bauen]
taskRef: {name: pruefen}
params:
- {name: image, value: "$(params.image)@$(tasks.bauen.results.digest)"}
- name: signieren
runAfter: [pruefen]
taskRef: {name: signieren}
params:
- {name: image, value: "$(params.image)@$(tasks.bauen.results.digest)"}
- name: ausrollen
runAfter: [signieren]
taskRef: {name: ausrollen}
params:
- {name: repo, value: http://172.16.0.126:30300/platform/plattform.git}
- {name: datei, value: apps/team-green/shop/overlays/staging/kustomization.yaml}
- {name: image, value: $(params.image)}
- {name: tag, value: $(tasks.klonen.results.commit)}
- {name: digest, value: $(tasks.bauen.results.digest)}
workspaces:
- {name: plattform, workspace: arbeit, subPath: plattform}
EOF
k apply -f pipeline.yaml
# Build version 3 of the page
cd ~/cnpe/tag06/shop-app && git pull -q
sed -i 's/Version 2/Version 3/' index.html && git commit -qam 'Shop Version 3' && git push -q
k create -f ~/cnpe/tag06/lauf.yaml
tkn pipelinerun logs -n ci --last -f | grep -E 'sha256:|Total:|signature|digest:|commit-push'
tkn pipelinerun list -n ci --limit 1Expected (abridged, your hashes will differ):
pipelinerun.tekton.dev/shop-mqnjd created
[bauen : build-push] sha256:d0cb59fbc4e675a5b6c2e1fa49af6ff4e9c0691906053ab3948e040400355082
[pruefen : trivy] Total: 6 (HIGH: 6, CRITICAL: 0)
[signieren : cosign] Pushing signature to: 172.16.0.126:30300/platform/shop
[ausrollen : tag-setzen] digest: sha256:d0cb59fbc4e675a5b6c2e1fa49af6ff4e9c0691906053ab3948e040400355082
[ausrollen : commit-push] 02b9cfe staging: shop auf b2d2679 (Pipeline, signiert)
NAME STARTED DURATION STATUS
shop-mqnjd 2 minutes ago 2m29s Succeeded
# on cp1
argocd app get team-green-shop-staging --refresh >/dev/null
sleep 40
argocd app get team-green-shop-staging | grep -E 'Sync Status|Health Status'
k -n team-green-staging run probe --rm -i --restart=Never --image=curlimages/curl:8.17.0 \
--command -- curl -s -m 5 http://shop/ 2>/dev/null | head -1Expected:
Sync Status: Synced to main (02b9cfe)
Health Status: Healthy
<h1>Shop von Team Green – Version 3</h1>
Save your progress? Sign up for free
Exercise: Find the signature
Time limit: 5 minutes. Where is the image’s signature stored in the
registry? List the packages of platform.
Solution
# on cp1
curl -s -u platform:platform-lab-123 'http://172.16.0.126:30300/api/v1/packages/platform?type=container' \
| jq -r '.[] | "\(.name) \(.version)"' | sortExpected (abridged):
shop 32ee6c8
shop 79aa3e8
shop 820f70f
shop b2d2679
shop sha256-476d876b000430fe0630ee10921f209ed80a6c1da29f40ae793433b8a173863c
...
Next to the tags of the builds there are entries named after digests:
these are the signatures (and references to them) as separate artifacts
in the same repository. Whoever copies the image must copy the signature
along with it (cosign copy).
Save your progress? Sign up for free
Challenge
Time limit: 10 minutes. An attacker with write access to the registry
builds their own image and pushes it under the tag b2d2679.
What happens in staging, and what could have happened without the digest
in Git?
Solution
In staging: nothing. Git points to the digest
sha256:d0cb…; the re-pointed tag refers to a different
digest that nobody requests. Without the digest in Git, the next pod
restart would have pulled the new image – Kyverno’s signature check
would then have rejected it (unsigned), but the service would no longer
have started. Digest in Git and signature verification
complement each other: one prevents the swap, the other detects it.
Save your progress? Sign up for free
Checkpoint
# on cp1
# Pipeline with five tasks
k -n ci get pipeline shop -o jsonpath='{range .spec.tasks[*]}{.name} {end}{"\n"}'
# staging runs with a digest
k -n team-green-staging get deploy shop -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}' | grep -c '@sha256:'
# policy active
k get imagevalidatingpolicy signierte-images -o jsonpath='{.spec.validationActions}{"\n"}'
# key not in the Git repo
git -C ~/cnpe/plattform ls-files | grep -c cosign.keyExpected:
klonen bauen pruefen signieren ausrollen
1
["Deny"]
0
Interview Note
- Why sign when the registry is internal? The signature proves the image originates from the CI – even against someone with access to the registry. Without verification in the cluster it is worthless.
- Tag or digest in the Deployment? Digest; the tag may stand
next to it for humans (
name:tag@sha256:…). - Why an SBOM when there are scanners? The scanner answers “which vulnerabilities today”, the SBOM “what’s inside” – for new vulnerabilities, licences and evidence towards customers (Cyber Resilience Act).
Enterprise Note
- Keys in a KMS or in OpenBao (cosign supports
--key hashivault://…), or keyless with the CI’s OIDC and your own Sigstore (Fulcio, Rekor) in the data centre. - Store the SBOM as a signed attestation on the image
(
cosign attest --type spdxjson) and require it with Kyverno. - Update base images automatically (Renovate) – the outdated
nginx:1.29was the biggest vulnerability, not your own code. - SLSA provenance (Tekton Chains) shows how the image was built.