Only run images you built, without known holes
Scan. trivy image lists known vulnerabilities (CVEs) in an image's packages, with the version that fixes each. First a summary, one row per target: the OS packages, then every jar (0 = clean, - = that scanner did not run); then a section for each target with findings:
Report Summary
┌────────────────────────────────────────────────┬────────┬─────────────────┬─────────┐
│ Target │ Type │ Vulnerabilities │ Secrets │
├────────────────────────────────────────────────┼────────┼─────────────────┼─────────┤
│ registry.lab/shop/legacy-api:1.0 (debian 12.1) │ debian │ 2 │ - │
├────────────────────────────────────────────────┼────────┼─────────────────┼─────────┤
│ app/legacy-api.jar │ jar │ 0 │ - │
└────────────────────────────────────────────────┴────────┴─────────────────┴─────────┘
...
registry.lab/shop/legacy-api:1.0 (debian 12.1)
==============================================
Total: 2 (HIGH: 1, CRITICAL: 1)
│ Library │ Vulnerability │ Severity │ Status │ Installed Version │ Fixed Version │ ...
│ libc6 │ CVE-2023-4911 │ HIGH │ fixed │ 2.36-9+deb12u1 │ 2.36-9+deb12u3 │ ...
│ libcurl4 │ CVE-2023-38545 │ CRITICAL │ │ 7.88.1-10+deb12u1 │ 7.88.1-10+deb12u4 │ ...
A cell equal to the one above it is left blank (Status: both fixed). In CI, trivy image --exit-code 1 --severity HIGH,CRITICAL <image> fails the pipeline: the gate. (simulator) the lab uses a small vulnerability database; the two CVEs are real Debian 12 advisories (glibc "Looking Glass", curl SOCKS5), with the severity trivy shows (NVD's: the Debian tracker rates neither).
Inside the app too. trivy also reads the libraries packed in the image's jars (catalog.jar is a fat jar, with them inside under BOOT-INF/lib/): one summary row per jar, and in its section a library shows as org.apache.logging.log4j:log4j-core (catalog.jar). A jar with log4j-core 2.14.1 is Log4Shell (CVE-2021-44228, CRITICAL, fixed in 2.15.0; 2.17.1 fixes the whole family). A new base image clears the OS rows, never these: only a rebuild with the fixed library does.
Inventory. An SBOM (software bill of materials) lists every package in an image. syft <image> prints it; syft <image> -o spdx-json > sbom.json writes a standard SPDX document you keep with the release, so when the next big CVE lands you can answer "which images contain it?" without rescanning.
Sign. A scan says "no known holes"; a signature says "this is the image we built". cosign (v3):
cosign generate-key-pair # cosign.key (private) + cosign.pub
cosign sign --key cosign.key -y registry.lab/shop/api:2.3
cosign verify --key cosign.pub registry.lab/shop/api:2.3
cosign v3 packs the signature, and what is needed to check it, into a Sigstore bundle that it attaches to the image in the registry, and it records the signature in Rekor, Sigstore's public transparency log. So sign first prints the Sigstore privacy statement and asks Are you sure you would like to continue? [y/N]; -y answers yes. verify checks the log entry, then the signature:
Verification for registry.lab/shop/api:2.3 --
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
An image nobody signed: Error: no signatures found, exit code 10. Signed, but with another key: the log entry names that key (transparency log certificate does not match), exit code 1. Older guides add --tlog-upload=false; cosign v3 refuses it while it uses Sigstore's signing config (the default).
Sign by digest (image@sha256:...) in real use: a tag can be moved to another image after you signed it (cosign warns when you sign a tag, and says signing by tag will go away).
Enforce. Nobody runs cosign verify by hand before every deploy. An admission policy does it on every Pod. With Kyverno 1.19 that is an ImageValidatingPolicy: it picks the images to check (matchImageReferences), names who may sign them (attestors), and a CEL validation calls verifyImageSignatures, which returns how many attestors verified the image.
apiVersion: policies.kyverno.io/v1
kind: ImageValidatingPolicy
metadata:
name: verify-shop-images
spec:
validationActions: [Deny] # Audit = only report
matchConstraints:
resourceRules:
- apiGroups: ['']
apiVersions: ['v1']
operations: ['CREATE', 'UPDATE']
resources: ['pods']
matchImageReferences:
- glob: "registry.lab/shop/*"
attestors:
- name: cosign
cosign:
key:
data: |
-----BEGIN PUBLIC KEY-----
...
validations:
- expression: >-
images.containers.map(image, verifyImageSignatures(image, [attestors.cosign])).all(e, e > 0)
message: failed the image Signature verification
An unsigned image is refused by Kyverno's image webhook, which names the policy:
Error from server: admission webhook "ivpol.validate.kyverno.svc-fail" denied the request: Policy
verify-shop-images failed: failed the image Signature verification
(A policy with matchConditions gets a webhook of its own: ivpol.validate.kyverno.svc-fail-finegrained-<policy>.)
Digests by default. spec.validationConfigurations has three switches, all on unless you turn them off: mutateDigest rewrites every matched image to <image>:<tag>@sha256:... at admission (in Audit too), verifyDigest fails an image that has no digest, and required fails an image no policy verified. So the pod that gets in runs registry.lab/shop/api:2.3@sha256:...: the build that was checked, not whatever the tag points at tomorrow. A signature belongs to that digest, so a new tag on a hand-built image has none. Autogen applies the same policy to Deployments, StatefulSets, DaemonSets, Jobs and CronJobs: kubectl set image deployment/... is checked itself, not only its pods.
Older clusters use the same check as a verifyImages rule in a kyverno.io/v1 ClusterPolicy (imageReferences, attestors[].entries[].keys.publicKeys). Kyverno 1.19 (August 2026) deprecates ClusterPolicy and plans to remove it in 1.20; a cluster that still has them prints a deprecation warning on every apply. Write new policies with the policies.kyverno.io types.
In an interview: "scanning, signing and admission are three different controls: known vulnerabilities, provenance, enforcement".
On the exam: domain "Supply chain security" - scan with trivy, find the image with a given CVE, write an admission policy.