Design a Container Security Scanner

Hard45 min
1 / 30
System design answer

Design a Container Security Scanner

Hard45 min30 sections
understanding•10 min read

Problem Statement: A Trust Engine for Every Image

Frames the scanner as a content-addressed analysis platform, not a cron job that runs a CLI tool.

Problem statement

Design a container security scanner: a platform that examines every container image an organization builds or pulls, unpacks its layers, extracts an inventory of installed packages, matches that inventory against vulnerability databases (CVEs and vendor advisories), scores the results, and turns them into decisions — developer notifications, merge gates, deployment blocks, dashboards, and audit evidence.

An OCI image is a manifest that references a config blob and a list of layer blobs, each a compressed tar archive identified by a sha256 digest. Layers are content-addressed and shared: two images built from the same base reuse identical base layers byte-for-byte. That single fact drives the entire architecture. A serious scanner never re-analyzes a layer digest it has already unpacked; it caches the extracted package inventory per layer digest and recombines cached inventories when a new image reuses old layers. Scanning then splits into two very different workloads: inventory extraction (expensive, CPU- and IO-bound, cacheable forever per digest) and vulnerability matching (cheap, data-bound, must rerun whenever the CVE feeds change).

Why the problem is distinctive

A naive design — "run an open-source scanner on every push and store the JSON" — collapses under four realities:

  1. The vulnerability database moves under you. Roughly 30,000 new CVEs are published per year, and vendor advisories from Debian, Ubuntu, Red Hat, Alpine, and language ecosystems update continuously. An image scanned clean on Monday can be critically vulnerable on Tuesday without changing a single byte. The platform must re-evaluate historical inventories against fresh data in minutes, not re-scan the world.
  2. Scale is dominated by layers, not images. Public ecosystem reporting puts Docker Hub alone at more than 15 million hosted images, and industry surveys such as Datadog's State of Cloud Security reports have consistently found roughly half of image tags carry at least one high or critical vulnerability. An internal registry with 250,000 images can still contain only a few million unique layers, and a push-time scan of a typical 14-layer image should touch only the one or two layers the build actually changed.
  3. The input is hostile. Layers are untrusted tar archives. A malicious or corrupted layer can attempt path traversal, symlink escapes, decompression bombs, or billions of tiny entries. The scanner must unpack defensively inside an isolated worker, because the scanner itself is an attack surface.
  4. Decisions must be reproducible and defensible. When a gate blocks a release, engineering leadership will ask why. The answer must be a pinned tuple: image digest, SBOM digest, feed version, policy version, and scanner version. Without immutability, every finding is hearsay.

The four architectural planes

  1. Ingestion plane: registry webhooks and polling, CI hooks, manifest fetching, layer dedup resolution, scan job creation.
  2. Analysis plane: sandboxed workers that unpack layers, extract package inventories (SBOM), and match inventories against versioned vulnerability feeds.
  3. Decision plane: policy evaluation, severity thresholds, allowlists, gating verdicts for merges and deployments, notifications.
  4. Data and learning plane: findings store, trend analytics, fix-time metrics, feed health, audit trail.

A strong answer keeps these planes separate: feed ingestion failure must not corrupt scans, a slow registry must not starve workers, and a policy change must never rewrite historical findings — it produces a new evaluation over immutable facts.

Key Highlights

  • •Images are manifests over content-addressed layers; scanning caches inventory per layer digest and never unpacks the same blob twice.
  • •Inventory extraction is expensive and cacheable; vulnerability matching is cheap and must rerun whenever CVE feeds change.
  • •Roughly 30,000 CVEs are published per year, so yesterday's clean scan can be today's critical finding without any image change.
  • •Layers are untrusted input: the scanner must unpack defensively in isolated workers or it becomes its own attack surface.
  • •Every verdict is reproducible from the tuple (image digest, SBOM digest, feed version, policy version, scanner version).
Lead With Content Addressing
State in the first two minutes that layers are content-addressed and shared, so the platform caches extraction per layer digest. This instantly separates a real scanner design from a shell script around a CLI.
Do Not Treat Scans as Static Truth
A scan result is only valid against the feed version it used. If your design has no re-matching story for new CVEs, findings rot within days.

Section Rescue Kit

Buzzwords to use:

Content-Addressed LayerSBOM

Safe statements:

  • "I will separate expensive inventory extraction from cheap vulnerability matching, because they fail and scale differently."
  • "Before choosing stores, let me define which artifacts are immutable facts and which are recomputable projections."
Design a Container Security Scanner - System Design | WinJob | WinJob