layerblame reads an OCI image layout, merges its layers in memory with OCI whiteout rules, and attributes every vulnerable Debian package to the layer and Dockerfile step that put it there. It then predicts which findings a base-image rebuild clears by replaying the application layers' package changes on top of the new base, instead of stacking status-file snapshots. It is defensive tooling: it reads images and advisory feeds and never runs or extracts anything. The images and advisories in the demo are synthetic: package names are real Debian names, versions and advisory ids are invented.
A platform team maintains about 40 service images built FROM two shared Debian base images. The scanner reports 150-300 findings per image and does not say where each came from. Service teams ignore findings they believe are inherited from the base, and the platform team cannot say which findings a base refresh would clear.
Two common mistakes make the picture worse. Tools that read a lower layer's package database, or that ignore whiteouts, also report packages that a later layer purged. And a naive rebase prediction that stacks the application's last dpkg status file on the new base brings the old base versions back, because an application layer that touched the package database carries a full copy of it.
flowchart LR
A["OCI layout<br/>index.json, blobs"] --> B["Verify digests<br/>blob sha256 and diff_ids"]
B --> C["Merge layers in order<br/>whiteouts, opaque dirs"]
C --> D["dpkg status after<br/>each layer"]
D --> E["Per-layer deltas<br/>added, upgraded, removed"]
F["Advisory feed<br/>release, source package"] --> G["Match in dpkg<br/>version order"]
E --> G
G --> H["Attribution table<br/>layer, Dockerfile step, origin"]
E --> I["Replay app-layer deltas<br/>on the new base"]
G --> I
I --> J["Rebase prediction<br/>cleared, still-in-base,<br/>app-layer, introduced"]
layerblame.ociselects a manifest by itsorg.opencontainers.image.ref.nameannotation and checks every blob against its descriptor and every uncompressed layer againstconfig.rootfs.diff_ids. Onlytarandtar+gziplayers are supported.layerblame.vfsindexes each layer's tar members into a path table (path, layer, type, size, sha256) without extracting anything..wh.<name>removes the name and everything below it from lower layers;.wh..wh..opqhides every lower entry of its directory but keeps the same layer's entries. Absolute paths and..components are rejected before any content is read, and a per-layer size limit is checked from the tar headers.layerblame.dpkgparsesvar/lib/dpkg/statusafter each layer (onlyStatus: install ok installed) and compares versions with a from-scratch implementation of dpkg's ordering.layerblame.deltasdiffs consecutive databases. A package is blamed on the last layer that added it or changed its version; a layer that rewrites the status file without changing a version has an empty delta.layerblame.advisoriesmatches the source package version against the feed.layerblame.rebasereplays the application layers' deltas on the new base's final database.
python3 -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"
layerblame demo --out .tmp/demo
layerblame layers .tmp/demo/image --ref orders-api:1.4
layerblame scan .tmp/demo/image --ref orders-api:1.4 --feed .tmp/demo/feed.json --json .tmp/findings.json
layerblame rebase .tmp/demo/image --ref orders-api:1.4 \
--old-base base:2026.09 --new-base base:2026.11 --feed .tmp/demo/feed.json
layerblame rebase .tmp/demo/image --ref orders-api:1.4 \
--old-base base:2026.09 --new-base base:2026.11 --feed .tmp/demo/feed.json --mode snapshotCommands:
| Command | Purpose |
|---|---|
demo --out DIR |
Write the synthetic OCI layout (DIR/image) and advisory feed (DIR/feed.json). |
layers OCI_DIR --ref REF [--all] |
Per-layer digest, history step, package delta and whiteout count. |
scan OCI_DIR --ref REF --feed FEED [--json OUT] [--base-ref REF] [--release NAME] |
One row per finding, with layer, step and origin (base or app). |
rebase OCI_DIR --ref REF --old-base REF --new-base REF --feed FEED [--mode delta|snapshot] |
Classify each finding after a base rebuild. |
Origin comes from the manifest's org.opencontainers.image.base.digest annotation when the base manifest is in the layout, otherwise from --base-ref; with neither it is unknown. Errors print error: <Type>: <message> and exit with code 2.
The demo has two base images and one application image, all synthetic. base:2026.09 has two layers; orders-api:1.4 adds four layers (install, purge, copy, a status-file copy) and has 11 history entries, 5 of them empty. Output below is pasted from a real run; layers lists at most eight package changes per layer unless --all is given.
$ layerblame demo --out .tmp/demo
wrote OCI layout: .tmp/demo/image
wrote advisory feed: .tmp/demo/feed.json
images: base:2026.09, base:2026.11, orders-api:1.4 (synthetic)
$ layerblame layers .tmp/demo/image --ref orders-api:1.4
orders-api:1.4 sha256:bdfc600f6427
6 layers, 11 history entries (5 empty)
layer 0 sha256:f3c5b70ee7ef ADD rootfs.tar.gz /
delta: +48 added, ^0 upgraded, v0 downgraded, -0 removed; whiteouts: 0
+ base-files
+ base-passwd
+ bash
+ bsdutils
+ coreutils
+ dash
+ debconf
+ debian-archive-keyring
... 40 more (use --all)
layer 1 sha256:9373ed9719f6 RUN apt-get update && apt-get upgrade -y
delta: +0 added, ^3 upgraded, v0 downgraded, -0 removed; whiteouts: 0
^ libc-bin 2.36-9+deb12u7 -> 2.36-9+deb12u8
^ libc6 2.36-9+deb12u7 -> 2.36-9+deb12u8
^ libgnutls30 3.7.9-2+deb12u3 -> 3.7.9-2+deb12u4
layer 2 sha256:a10a35b6f933 RUN apt-get install libxml2 curl
delta: +2 added, ^2 upgraded, v0 downgraded, -0 removed; whiteouts: 0
+ curl
+ libxml2
^ libcurl4 7.88.1-10+deb12u5 -> 7.88.1-10+deb12u8
^ libnghttp2-14 1.52.0-1+deb12u1 -> 1.52.0-1+deb12u2
layer 3 sha256:9a0bfa68447a RUN apt-get purge wget && rm -rf /usr/share/doc/*
delta: +0 added, ^0 upgraded, v0 downgraded, -1 removed; whiteouts: 52
- wget
layer 4 sha256:2925b74970af COPY app/ /srv/app/
delta: +0 added, ^0 upgraded, v0 downgraded, -0 removed; whiteouts: 1
layer 5 sha256:9e6251bfa75b COPY --from=sbom /var/lib/dpkg/status /var/lib/dpkg/status
delta: +0 added, ^0 upgraded, v0 downgraded, -0 removed; whiteouts: 0
Layer 3 purges wget and whites out /usr/share/doc/*; layer 5 copies a full status file but changes no version.
$ layerblame scan .tmp/demo/image --ref orders-api:1.4 --feed .tmp/demo/feed.json
package installed source advisory severity fixed-in layer step origin
------------- ----------------------- ----------- -------------- -------- ----------------------- ----- ---------------------------------------- ------
libgnutls30 3.7.9-2+deb12u4 gnutls28 DEMO-2026-0007 critical 3.7.9-2+deb12u6 1 RUN apt-get update && apt-get upgrade -y base
libssl3 3.0.15-1~deb12u1 openssl DEMO-2026-0001 high 3.0.16-1~deb12u1 0 ADD rootfs.tar.gz / base
libgcrypt20 1.10.1-3 libgcrypt20 DEMO-2026-0003 high 1.10.1-3+deb12u1 0 ADD rootfs.tar.gz / base
libxml2 2.9.14+dfsg-1.3~deb12u1 libxml2 DEMO-2026-0008 high 2.9.14+dfsg-1.3~deb12u3 2 RUN apt-get install libxml2 curl app
zlib1g 1:1.2.13.dfsg-1 zlib DEMO-2026-0002 medium 1:1.2.13.dfsg-2 0 ADD rootfs.tar.gz / base
libsystemd0 252.26-1~deb12u2 systemd DEMO-2026-0004 medium 252.30-1~deb12u1 0 ADD rootfs.tar.gz / base
libnghttp2-14 1.52.0-1+deb12u2 nghttp2 DEMO-2026-0009 medium 1.52.0-1+deb12u3 2 RUN apt-get install libxml2 curl app
libpam0g 1.5.2-6+deb12u1 pam DEMO-2026-0005 low 1.5.2-6+deb12u2 0 ADD rootfs.tar.gz / base
tar 1.34+dfsg-1.2+deb12u1 tar DEMO-2026-0006 low (none) 0 ADD rootfs.tar.gz / base
9 findings (layer 0: 6, layer 1: 1, layer 2: 2)
libssl3 matches the advisory for source package openssl. libgnutls30 is blamed on layer 1 (the base's apt-get upgrade), and libnghttp2-14 on layer 2, which upgraded it. The advisories for wget (purged in layer 3) and for curl (libcurl4 was upgraded past the fix in layer 2) produce no rows, as do the negative controls for glibc and util-linux.
$ layerblame rebase .tmp/demo/image --ref orders-api:1.4 --old-base base:2026.09 --new-base base:2026.11 --feed .tmp/demo/feed.json
rebase base:2026.09 -> base:2026.11 (mode: delta)
package advisory severity installed after rebase class
------------- -------------- -------- ----------------------- ----------------------- --------------------
libgnutls30 DEMO-2026-0007 critical 3.7.9-2+deb12u4 3.7.9-2+deb12u5 still-in-base
libssl3 DEMO-2026-0001 high 3.0.15-1~deb12u1 3.0.16-1~deb12u1 cleared-by-rebase
libgcrypt20 DEMO-2026-0003 high 1.10.1-3 1.10.1-3+deb12u1 cleared-by-rebase
libxml2 DEMO-2026-0008 high 2.9.14+dfsg-1.3~deb12u1 2.9.14+dfsg-1.3~deb12u1 app-layer (layer 2)
zlib1g DEMO-2026-0002 medium 1:1.2.13.dfsg-1 1:1.2.13.dfsg-2 cleared-by-rebase
libsystemd0 DEMO-2026-0004 medium 252.26-1~deb12u2 252.30-1~deb12u1 cleared-by-rebase
libnghttp2-14 DEMO-2026-0009 medium 1.52.0-1+deb12u2 1.52.0-1+deb12u2 app-layer (layer 2)
libexpat1 DEMO-2026-0011 medium - 2.5.0-1+deb12u1 introduced-by-rebase
libpam0g DEMO-2026-0005 low 1.5.2-6+deb12u1 1.5.2-6+deb12u2 cleared-by-rebase
tar DEMO-2026-0006 low 1.34+dfsg-1.2+deb12u1 1.34+dfsg-1.2+deb12u1 still-in-base
cleared-by-rebase: 5
still-in-base: 2
app-layer: 2
introduced-by-rebase: 1
Stacking the application's last status file instead of replaying deltas:
$ layerblame rebase ... --mode snapshot
...
cleared-by-rebase: 0
still-in-base: 7
app-layer: 2
introduced-by-rebase: 0
stale snapshot: 5 finding(s) that a delta replay clears are still reported
- Deltas over a merged view, not per-layer database reads. The package database is read from the status file as the merged view shows it after each layer, so whiteouts and replaced files are honoured. The cost is that each layer is read twice, once to verify its digest and diff_id and once to index it (a rebase also reads the new base's layers); images are indexed in memory and nothing is extracted.
- Blame the last layer that changed a version. A layer that rewrites the status file (the application's
COPY --fromlayer 5) is not blamed for packages it merely carries. The trade-off is that a downgrade followed by an upgrade back to the same version is attributed to the later layer. - Replay deltas on rebase. Application additions and upgrades keep their version unless the new base already has the same or a higher one (apt does not downgrade); removals remove; explicit downgrades are applied.
--mode snapshotkeeps the naive method available so the difference stays visible. Snapshot mode does not consult the new base for its findings: it re-labels the old image's findings, and the new base only decides which of them are reported as stale (those a delta replay clears). It does not model package dependencies or conflicts, so a prediction is only as good as the delta of each layer. - Match on the source version. Advisories are keyed by distro release and source package, and the installed binary's source version (from
Source: name (version),Source: name, or the binary version when the field is absent) is compared withfixed_version. A binNMU suffix such as+b2on the binary does not hide a vulnerable source version. - Verify before trusting, reject before reading. Blob digests and diff_ids are checked before any layer is parsed; unsafe member names fail up front;
--max-layer-mibis checked against tar headers before member content is read. Symlinks are recorded and never followed. - Reproducible fixtures. Tar members are sorted with mtime 0 and uid/gid 0, and gzip layers are written as stored deflate blocks, so digests do not depend on the zlib build. Limits: Debian-style
dpkgonly, single-arch images only, no zstd layers.
GITHUB_ACTIONS=true CI=true COLUMNS=80 pytest
ruff check . && ruff format --check .124 tests pass offline. They cover a table of dpkg orderings plus hypothesis checks (300 examples each) that the comparator is antisymmetric and transitive; digest and diff_id corruption; history mapping; whiteout and opaque-directory cases including a hand-built three-layer image; unsafe members and the size limit (with a check that no member content is read, and the --max-layer-mib flag through layers, scan and rebase); malformed manifests, configs and feeds ending in error: ... with exit code 2; hardlinked status files; the nine scan findings and their layers; the rebase classification counts in both modes; idempotence of a rebase onto the same base; and byte-identical demo and scan --json output.
src/layerblame/
oci.py layout reading, digest and diff_id verification, history mapping
vfs.py in-memory merged view, whiteouts, safety checks
dpkg.py status parsing and version comparison
deltas.py per-layer package deltas and attribution
advisories.py feed loading and matching
analysis.py image -> per-layer databases, deltas, owners
scan.py findings with layer, step and origin
rebase.py delta replay and classification
report.py text tables
ocibuild.py deterministic OCI layout writer
fixtures.py synthetic demo images and advisories
cli.py Typer commands
tests/ pytest and hypothesis suites
.github/workflows/ci.yml
MIT. See LICENSE.
