Skip to content

Lesson 6 of 9 · 22m

Scanning, SBOMs, and Image Supply Chain

You ship every CVE in your base image. Scan what's actually in the image, pin what you depend on, and sign what you build.

Your image is a frozen slice of the internet: a base OS snapshot, a language runtime, transitive dependencies nobody chose on purpose. Vulnerability scanners exist because nobody can hold that bill of materials in their head — and the findings surprise everyone the first time. The base image alone usually carries more CVEs than your application code introduces.

Scan the artifact, not the intent

# Trivy — the pragmatic default
trivy image --severity HIGH,CRITICAL myapp:1.4.2

# Grype/Syft — same job, different engine, good cross-check
grype myapp:1.4.2 --fail-on high

The output splits into three buckets, and treating them differently is the whole skill:

  1. OS packages (deb/rpm/apk from the base image) — fix by rebuilding on a fresher base. You don't patch these; you re-pull. This is why "set and forget" images rot: the image is frozen, the CVE list is not.
  2. Language dependencies (npm/pip/gem) — fix in the lockfile, rebuild. Scanners match these against package-specific databases and they're usually the actionable majority.
  3. False positives and wontfix noise — every scanner has them. A .trivyignore with a comment and an expiry date is legitimate; ignoring everything is not.

Pin by digest, not tag

# a tag is a mutable pointer — today's nginx:1.27 ≠ last month's
FROM nginx:1.27
# a digest is content-addressed — this exact bitstream forever
FROM nginx:1.27@sha256:fb197595ebe76b9c0c3ab68159fd036c11bd0b6a025c2f5b19f05a50b6a5f4c5

Tags move. Every reproducibility incident — "worked in CI Tuesday, broken Wednesday, no code changes" — is a moved tag until proven otherwise. Pin digests in Dockerfiles and let Dependabot/Renovate bump them deliberately with PRs you can read.

SBOMs and signing: prove what you ship

# generate a software bill of materials
syft myapp:1.4.2 -o spdx-json > sbom.spdx.json

# attest and sign with cosign (keyless, via OIDC)
cosign sign --yes registry.example.com/myapp@sha256:<digest>
cosign verify registry.example.com/myapp@sha256:<digest>   --certificate-identity-regexp 'https://github.com/yourorg/*'   --certificate-oidc-issuer https://token.actions.githubusercontent.com

An SBOM answers "are we affected?" in minutes instead of an incident-long archaeology dig — when the next log4shell drops, you grep SBOMs, not memories. Signing answers "is this artifact the one CI built?" — admission control in Kubernetes (Kyverno, Sigstore policy-controller) can refuse unsigned images entirely.

Field notes

  • Scan in CI and rescan what's already deployed — new CVEs are published against old images daily. A weekly rescan of running digests catches exposure that CI can't.
  • scratch and distroless bases eliminate most OS-package CVEs by having no packages. The best scan result is a small attack surface.
  • Severity scores lie by omission: a CRITICAL in a CLI tool that never runs in your container is noise; a MEDIUM in a network-facing parser is real. Triage with context.
  • Cache the scanner's vulnerability DB in CI or you'll rate-limit yourself out of your own pipeline on a bad day.

Was this lesson helpful?

Sign in to rate