Skip to content

Lesson 8 of 12 · 22m

Container Scanning: Images Are Frozen Filesystems

Every package in the image ships to prod and stays that vulnerable until you rebuild — base-image hygiene, digest pinning, and Trivy flags that keep the gate honest.

A container image is a frozen filesystem. Every package in it — the Debian userland, the Python wheels, the debugging tool someone apt installed six months ago — ships to production and stays exactly that vulnerable until you rebuild. The scan itself is easy. The interesting part is realizing your node:20 base pulled last March is carrying a year of unpatched OpenSSL and a curl nobody asked for.

What the scanner sees

Trivy and Grype unpack image layers and inventory two things — OS packages (the dpkg/apk/rpm databases) and language packages (node_modules, site-packages, gems, JARs) — then match that inventory against CVE feeds. Two consequences follow:

  • It reports what's installed, not what's exploited. Same reachability caveat as dependency scanning, one filesystem down.
  • It can't flag what isn't there. An image FROM scratch containing one static binary has almost nothing to report — which is the entire point of distroless.
trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 \
  registry.internal/app@sha256:4b2f…

--ignore-unfixed is doing heavy lifting: it drops findings with no released patch, which on a Debian base is a firehose of "yes, we know, there's no fix." Gating on unfixable CVEs is how you teach a team to ignore the gate. Add --scanners vuln,secret and the same run catches the .env someone baked into a layer.

Most findings are base-image debt

Before fixing anything, check what fraction lives in the OS layer — usually most of it. The leverage moves:

# fat: full OS — shell, package manager, hundreds of packages
FROM node:20
# lean: distroless — no shell, no package manager, near-zero OS surface
FROM gcr.io/distroless/nodejs22-debian12

Multi-stage builds aren't only about size: the build stage carries compiler and toolchain CVEs, and the final stage shouldn't. Alpine is not automatically better — musl versus glibc breaks things subtly, and Alpine's package set still ships CVEs; distroless or vendor slim variants are usually the quieter win.

Pin the base by digest, not tag: node:20 today is not node:20 in six weeks. image@sha256:… makes builds reproducible and makes the scan report describe what you actually ran. Then rebuild on a schedule even when code doesn't change — images rot sitting still.

The Dockerfile is a security boundary

  • USER node — or a created UID. "Root inside the container" turns a container escape into a host escape; hadolint flags an explicit final USER root (DL3002) — a Dockerfile with no USER line at all passes silently, which is the miss that actually ships.
  • COPY . . drags .git, .env, and test fixtures into the image unless .dockerignore says otherwise.
  • --mount=type=secret,id=npmrc for build-time secrets; ARG values persist in image history forever, readable by anyone who can pull.
  • hadolint Dockerfile lints all of this next to the image scan — it's the cheapest control in this lesson.

Where to scan

Twice. In CI before push — gate on it — and in the registry on a schedule, to monitor what's deployed. An image clean at build time has new CVEs by Friday; the registry rescan (ECR enhanced scanning, Harbor's embedded Trivy, a cron trivy image over your :prod tags) is how you notice. Scan the image you actually deploy — by digest — not the :latest you happened to test.

Field notes

  • --pkg-types os,library splits the report so you can see OS debt versus your lockfiles separately.
  • A "zero findings" image is a small image, not a lucky one — cut the surface, then the scan takes care of itself.
  • docker history on a shipped image is a five-second audit for ARG leaks and stray tooling.
  • grype sbom:sbom.json scans the SBOM instead of the image — same answer, no registry pull, useful when the image is heavy.
  • Minimal-image builders — ko for Go, Jib for Java, apko for anything — produce near-empty filesystems by construction, which is the whole problem solved upstream of the scanner.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.