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 scratchcontaining 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-debian12Multi-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;hadolintflags an explicit finalUSER root(DL3002) — a Dockerfile with noUSERline at all passes silently, which is the miss that actually ships.COPY . .drags.git,.env, and test fixtures into the image unless.dockerignoresays otherwise.--mount=type=secret,id=npmrcfor build-time secrets;ARGvalues persist in image history forever, readable by anyone who can pull.hadolint Dockerfilelints 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,librarysplits 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 historyon a shipped image is a five-second audit forARGleaks and stray tooling.grype sbom:sbom.jsonscans the SBOM instead of the image — same answer, no registry pull, useful when the image is heavy.- Minimal-image builders —
kofor Go, Jib for Java,apkofor anything — produce near-empty filesystems by construction, which is the whole problem solved upstream of the scanner.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Buying Time: Package Managers Are Adding Delay as a Security Control
Composer 2.11 shipped a cooldown that refuses to install a version until it has aged. vlt now holds npm publishes until their dependencies actually exist, because 22% of new npm versions land broken. And Ruby Central's reviewers threw out 90% of what an AI scanner flagged.
Your npm Install Just Ran Someone Else's Code: Why Dependency Security Has to Start Before CI
A pull request checkout, a poisoned GitHub Actions cache, and an OIDC token pulled straight out of runner memory. That's how 84 malicious versions of TanStack's packages hit npm in six minutes.
CVE-2025-62718: Critical Axios SSRF Vulnerability Explained
A critical SSRF flaw in Axios was used in a North Korean supply chain attack. Here's what it does and how to patch it today.
What is Supply Chain Security? Dependencies, SBOMs, and the Attack That Hit 2.6 Billion npm Downloads
Your application is only as secure as every package it depends on. In September 2025, attackers compromised 27 npm packages with 2.6 billion weekly downloads by phishing one maintainer.