Repository navigation
Non-deterministic purl for Wolfi packages discovered via /var/lib/db/sbom (two apk components per SPDX document)
#11362
Replies: 3 comments 1 reply
|
Hello @xavier-calland It looks like both components describe the same package.
Every file in Trivy reads both apk components present in the document and ends up with two different purls for one package.
If it turns out the second component isn't needed, the best fix would be on the SBOM generator side. Regards, Dmitriy |
|
Thanks Dmitriy, that matches what we see. The nested component comes from a scan of the package's own contents: the package Wolfi already ran into the same effect in its own scanner: wolfi-dev/wolfictl#1409 ("expected exactly one APK package, found 2" when scanning the contents of an .apk). I've asked Chainguard the two questions here: wolfi-dev/os#78757. I'll post their answer in this thread. |
|
Hi @DmitriyLewen, Quick follow-up: no answer from Chainguard so far on wolfi-dev/os#78757 (opened on Oct 7, still untriaged, no comments). In the meantime, would you consider a fix on the Trivy side that does not depend on their answer?
Even (1) alone would fix the reproducibility problem for us. I'd be happy to open a PR for either, if you think it's an acceptable approach. I'll still report here if Chainguard answers. |
Uh oh!
There was an error while loading. Please reload this page.
Description
When the apk database (
/usr/lib/apk/db/installed) is absent or does not list a package (e.g. an image whose apkdatabase was overwritten by a later layer), Trivy discovers Wolfi/Chainguard packages from the per-package SPDX
documents in
/var/lib/db/sbom/*.spdx.json. Each of those documents contains two apk components with the samename and version but different purls, e.g.
libgcc-16.2.0-r1.spdx.json:SPDXRef-Package-apk-libgcc-16.2.0-r1(target ofSPDXRef-DOCUMENT DESCRIBES)pkg:apk/wolfi/libgcc@16.2.0-r1?arch=x86_64&distro=wolfiSPDXRef-Package-apk-libgcc-bc08e9c4c69fba15(nested)pkg:apk/wolfi/libgcc@16.2.0-r1?arch=x86_64&origin=gccTrivy keeps only one of them, and which one is random.
Analysis (v0.75.0):
pkg/sbom/io/decode.go:123iterates overfor id, c := range m.bom.Components(), a Go map: iteration order israndom;
pkg/fanal/applier/docker.go:301(lo.UniqByonID/FilePath) keeps whichever came first.Consequences: the generated SBOM is not reproducible, and downstream tools that match components by purl (e.g.
copying analysis decisions between Dependency-Track project versions) see the same package change identity from one
scan to the next.
Related, but not covering this case:
no apk database entry; the duplicate comes from inside a single SPDX document.
same root cause (map iteration order), different symptom.
Desired Behavior
The purl is chosen deterministically, preferably the one of the component targeted by
SPDXRef-DOCUMENT DESCRIBES(
?arch=x86_64&distro=wolfi), which is the package the document is about. Possible fixes:DESCRIBESwhen several components share the samename and version (or ignore apk components that the document does not describe);
Actual Behavior
Each run on the same files reports a different subset of packages with
origin=…instead ofdistro=wolfi.Five runs (19 apk packages each time), packages reported with
origin=:Reproduction Steps
Target
Container Image
Scanner
None
Output Format
CycloneDX
Mode
Standalone
Debug Output
Operating System
Ubuntu 26.04.1 LTS (x86_64), Docker 29.8.2, Trivy run from the
aquasec/trivy:0.75.0imageVersion
Checklist
trivy clean --allAll reactions