#150, PR 1 of the plan: the reader. The upload path and the scan come in PR 2. Tracker #167.
Why
The recipe inventory (yocto_inventory) reads a layer tree as written. It sees every recipe, and an image's content only as its recipes declare it. A build knows what it actually installed, and Yocto's create-spdx (the default; scarthgap writes SPDX 2.2) records exactly that in <image>.spdx.tar.zst next to the image.
What
pipeline::yocto_spdx has three entry points:
read_archive(<image>.spdx.tar.zst, …) reads the archive;
read_dir(extracted, …) reads the extracted documents;
both return Vec<BuiltImage>, one per image document.
How it resolves the image:
The image package (SPDXRef-Image-…) CONTAINS the installed packages. Each package is GENERATED_FROM its recipe (SPDXRef-Recipe-…), and both links are followed through externalDocumentRefs by documentNamespace.
There is one SbomEntry per recipe that has packages in the image (util-linux's 11 packages make one component):
manager yocto-recipe, the same as the inventory, so PR 2 can reconcile the two;
the recipe's versionInfo and pkg:generic/<name>@<version>;
the declared licence, with DocumentRef-…: prefixes dropped and NOASSERTION read as none;
the CPE (cpe23Type) and the homepage;
evidence listing the packages;
in_image with the new InImageBasis::Built ("In the image (installed by the build, from its SPDX)").
fixed: the CVEs each recipe's patches fix. create-spdx writes them as sourceInfo: "CVEs fixed: …", and they become VEX fixed in PR 2.
unresolved: contained packages whose document or recipe is not in the archive. They are listed, not guessed.
Limits: the archive is untrusted input, so document count, size per document (read through take, whatever the tar header says) and total size are capped.
New direct dependency zstd = "0.14". It was already in the tree via zip, so Cargo.lock gains only the edge.
Fixture
fixtures/yocto/ holds a trimmed copy of a real scarthgap 5.0.21core-image-minimal for qemuarm64 from the ferrite build, as extracted documents plus the same files as a 2.9 KB .spdx.tar.zst. It contains:
busybox (3 packages, CPE, 15 fixed CVEs);
openssl (3 packages, vendor CPE);
base-files;
packagegroup-core-boot (no CPE);
one dangling CONTAINS reference.
File lists, per-file relationships and descriptions are stripped. There are no local paths or personal data.
Tests
Unit tests:
the extracted and the archived form give the same result;
components, versions, licence, CPE, Built, the package grouping, and the fixed CVEs are sorted and complete;
#150, PR 1 of the plan: the reader. The upload path and the scan come in PR 2. Tracker #167.
## Why
The recipe inventory (`yocto_inventory`) reads a layer tree as written. It sees every recipe, and an image's content only as its recipes *declare* it. A build knows what it actually installed, and Yocto's `create-spdx` (the default; scarthgap writes SPDX 2.2) records exactly that in `<image>.spdx.tar.zst` next to the image.
## What
`pipeline::yocto_spdx` has three entry points:
- `read_archive(<image>.spdx.tar.zst, …)` reads the archive;
- `read_dir(extracted, …)` reads the extracted documents;
- both return `Vec<BuiltImage>`, one per image document.
How it resolves the image:
- The image package (`SPDXRef-Image-…`) `CONTAINS` the installed packages. Each package is `GENERATED_FROM` its recipe (`SPDXRef-Recipe-…`), and both links are followed through `externalDocumentRefs` by `documentNamespace`.
- There is one `SbomEntry` per recipe that has packages in the image (util-linux's 11 packages make one component):
- manager `yocto-recipe`, the same as the inventory, so PR 2 can reconcile the two;
- the recipe's `versionInfo` and `pkg:generic/<name>@<version>`;
- the declared licence, with `DocumentRef-…:` prefixes dropped and NOASSERTION read as none;
- the CPE (`cpe23Type`) and the homepage;
- evidence listing the packages;
- `in_image` with the new **`InImageBasis::Built`** ("In the image (installed by the build, from its SPDX)").
- `fixed`: the CVEs each recipe's patches fix. create-spdx writes them as `sourceInfo: "CVEs fixed: …"`, and they become VEX `fixed` in PR 2.
- `unresolved`: contained packages whose document or recipe is not in the archive. They are listed, not guessed.
Limits: the archive is untrusted input, so document count, size per document (read through `take`, whatever the tar header says) and total size are capped.
New direct dependency `zstd = "0.14"`. It was already in the tree via `zip`, so `Cargo.lock` gains only the edge.
## Fixture
`fixtures/yocto/` holds a trimmed copy of a real **scarthgap 5.0.21** `core-image-minimal` for qemuarm64 from the ferrite build, as extracted documents plus the same files as a 2.9 KB `.spdx.tar.zst`. It contains:
- busybox (3 packages, CPE, 15 fixed CVEs);
- openssl (3 packages, vendor CPE);
- base-files;
- packagegroup-core-boot (no CPE);
- one dangling `CONTAINS` reference.
File lists, per-file relationships and descriptions are stripped. There are no local paths or personal data.
## Tests
Unit tests:
- the extracted and the archived form give the same result;
- components, versions, licence, CPE, `Built`, the package grouping, and the fixed CVEs are sorted and complete;
- the dangling reference is reported;
- limits on count and size;
- no image document, or broken JSON;
- licence cleaning.
CI only.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
The recipe inventory reads a layer tree as written: every recipe, and an
image's content as its recipes declare it. A build knows more, and
Yocto's create-spdx class already writes it down: one SPDX 2.2 document
per image, package and recipe, archived as <image>.spdx.tar.zst.
pipeline::yocto_spdx reads that archive (or the extracted documents):
the image CONTAINS its installed packages, each GENERATED_FROM a recipe,
resolved through externalDocumentRefs by namespace. Per recipe with
packages in the image it returns one SBOM component (yocto-recipe, the
recipe version, the declared licence without document prefixes, the
CPEs, the homepage), marked InImageBasis::Built, plus the CVEs the
recipe's patches fix ("CVEs fixed:" in sourceInfo) for fixed VEX
statements, and the references it could not resolve. The archive is
untrusted input: document count, document size and total size are
capped while it is read.
Reader only; the upload and the scan follow in the next PR. The fixture
is a trimmed copy of a real scarthgap 5.0.21 core-image-minimal for
qemuarm64 (four recipes, one dangling reference).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang
merged commit 2ca87d1920 into main2026-11-04 21:47:01 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
#150, PR 1 of the plan: the reader. The upload path and the scan come in PR 2. Tracker #167.
Why
The recipe inventory (
yocto_inventory) reads a layer tree as written. It sees every recipe, and an image's content only as its recipes declare it. A build knows what it actually installed, and Yocto'screate-spdx(the default; scarthgap writes SPDX 2.2) records exactly that in<image>.spdx.tar.zstnext to the image.What
pipeline::yocto_spdxhas three entry points:read_archive(<image>.spdx.tar.zst, …)reads the archive;read_dir(extracted, …)reads the extracted documents;Vec<BuiltImage>, one per image document.How it resolves the image:
SPDXRef-Image-…)CONTAINSthe installed packages. Each package isGENERATED_FROMits recipe (SPDXRef-Recipe-…), and both links are followed throughexternalDocumentRefsbydocumentNamespace.SbomEntryper recipe that has packages in the image (util-linux's 11 packages make one component):yocto-recipe, the same as the inventory, so PR 2 can reconcile the two;versionInfoandpkg:generic/<name>@<version>;DocumentRef-…:prefixes dropped and NOASSERTION read as none;cpe23Type) and the homepage;in_imagewith the newInImageBasis::Built("In the image (installed by the build, from its SPDX)").fixed: the CVEs each recipe's patches fix. create-spdx writes them assourceInfo: "CVEs fixed: …", and they become VEXfixedin PR 2.unresolved: contained packages whose document or recipe is not in the archive. They are listed, not guessed.Limits: the archive is untrusted input, so document count, size per document (read through
take, whatever the tar header says) and total size are capped.New direct dependency
zstd = "0.14". It was already in the tree viazip, soCargo.lockgains only the edge.Fixture
fixtures/yocto/holds a trimmed copy of a real scarthgap 5.0.21core-image-minimalfor qemuarm64 from the ferrite build, as extracted documents plus the same files as a 2.9 KB.spdx.tar.zst. It contains:CONTAINSreference.File lists, per-file relationships and descriptions are stripped. There are no local paths or personal data.
Tests
Unit tests:
Built, the package grouping, and the fixed CVEs are sorted and complete;CI only.
🤖 Generated with Claude Code
The recipe inventory reads a layer tree as written: every recipe, and an image's content as its recipes declare it. A build knows more, and Yocto's create-spdx class already writes it down: one SPDX 2.2 document per image, package and recipe, archived as <image>.spdx.tar.zst. pipeline::yocto_spdx reads that archive (or the extracted documents): the image CONTAINS its installed packages, each GENERATED_FROM a recipe, resolved through externalDocumentRefs by namespace. Per recipe with packages in the image it returns one SBOM component (yocto-recipe, the recipe version, the declared licence without document prefixes, the CPEs, the homepage), marked InImageBasis::Built, plus the CVEs the recipe's patches fix ("CVEs fixed:" in sourceInfo) for fixed VEX statements, and the references it could not resolve. The archive is untrusted input: document count, document size and total size are capped while it is read. Reader only; the upload and the scan follow in the next PR. The fixture is a trimmed copy of a real scarthgap 5.0.21 core-image-minimal for qemuarm64 (four recipes, one dangling reference). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>