feat(yocto): a target with only its build output is scanned (#150)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 3m27s
CI / Check (pull_request) Failing after 13m15s

A Yocto target whose only input is its build output (the image SPDX
archive, the cve-check report), without the layers in git or an
archive, was not scanned: run_target's no-code branch only tries DAST.
That is the likely shape of a customer who ships a device, not layers.

- run_target: such a target runs scan_tree over an empty working
  directory under the agent's work dir, with the build outputs attached,
  so the SBOM, NVD, cve-check, VEX, issues and finalisation are the same
  as for a layer tree. The run lists source_code under "Nicht
  ausgeführt" (code analysis, recipe inventory and lint need the layers).
- scan_matrix: the Yocto image SBOM and CVE rules are on, with a new
  ArtifactRequirement::BuildOutput, instead of "planned"; without a
  build output they read "no build_output artifact provided", which the
  dashboard words as "needs the image's build output".
- guide/yocto: what runs, and "Without the layers".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-05 00:41:13 +01:00
1 parent 919cac01e9
commit fd7f084ad8
4 files changed
+121 -44

No files matched your search

@@ -1406,6 +1406,14 @@ impl PipelineOrchestrator {
}
}
}
// Only what a build wrote about its image (an image SPDX archive,
// a cve-check report): the same stages run over an empty tree, so
// the SBOM, CVEs and VEX come from the build output alone.
None if target.has(ArtifactKind::BuildOutput) => {
new_count += self
.scan_build_output_only(target, &target_id, &working_paths, scan_run_id)
.await?;
}
None => {
// No code to scan. DAST is attempted for a target the matrix
// plans it for, and for a migrated DAST target, which carries no
@@ -2645,6 +2653,63 @@ impl PipelineOrchestrator {
/// The recipes, images and package groups of a Yocto layer tree. A parser
/// that failed, a tree with no layer, or recipes the parser could not read
/// are recorded on the run.
/// Scan a target whose only code-like input is its build output: the
/// stages run over an empty working directory (nothing to find there),
/// with the build outputs read as for a layer tree. The run says that
/// there was no source code.
///
/// # Returns
///
/// How many findings were new.
///
/// # Errors
///
/// The working directory cannot be made, or a stage fails as in
/// [`Self::scan_tree`].
async fn scan_build_output_only(
&self,
target: &OnboardedTarget,
target_id: &str,
working_paths: &std::collections::HashMap<String, std::path::PathBuf>,
scan_run_id: &str,
) -> Result<u32, AgentError> {
let Some(first) = target
.artifacts
.iter()
.find(|a| a.kind == ArtifactKind::BuildOutput)
else {
return Ok(0);
};
self.skip_stage(
scan_run_id,
SkippedStage::new(
"source_code",
SkipCode::NotAnalysedYet,
"the target has no source code (a git repository or a source archive): only \
its build output is read; code analysis, the recipe inventory and the recipe \
lint need the layer tree",
),
)
.await;
// Under the agent's own work directory, so it is never a tree the
// scan may not touch, and empty on every run.
let tree = crate::ingest::blob::work_dir(
std::path::Path::new(&self.config.artifact_store_base_path),
target_id,
"build-output-only",
);
let _ = std::fs::remove_dir_all(&tree);
std::fs::create_dir_all(&tree)
.map_err(|e| AgentError::Other(format!("build-output work directory: {e}")))?;
let mut repo = RepoView::from_target(target, first, &self.secrets);
repo.build_outputs = build_output_paths(target, working_paths);
let scanned = self.scan_tree(&tree, None, &repo, scan_run_id).await;
let _ = std::fs::remove_dir_all(&tree);
let n = scanned?;
self.finalize_target(target, &repo, n).await?;
Ok(n)
}
/// What the target's build outputs say: the images their SPDX archives
/// describe ([`crate::pipeline::yocto_spdx`]) and their cve-check reports
/// ([`crate::pipeline::yocto_cve_check`]), told apart by content. One
+39 -29
View File
@@ -29,9 +29,6 @@ const CONTAINER_IMAGES: &str =
"container images are not scanned yet: only the sources that build them are";
/// Why a Yocto image has no SBOM or CVE match yet: that needs the build's
/// artefacts (tier 2), not the layer tree.
const YOCTO_IMAGE_SBOM: &str = "a Yocto image SBOM needs build artefacts (SPDX/manifest), planned";
const YOCTO_IMAGE_CVE: &str =
"CVE matching for a Yocto image needs build artefacts (SPDX/manifest), planned";
/// Why the firmware SBOM stage passes over a Yocto layer tree: Firmwerk forms
/// no build plan from BitBake recipes. The agent records it with this text.
pub const YOCTO_BUILD_PLANNED: &str =
@@ -62,6 +59,9 @@ pub enum ArtifactRequirement {
Mobile,
/// A container image.
Container,
/// What a build wrote about its image: a Yocto image SPDX archive or its
/// cve-check report.
BuildOutput,
/// No specific artifact required.
Any,
}
@@ -231,7 +231,7 @@ pub fn rules_for(target_type: TargetType) -> Vec<ScanRule> {
/// The rules specific to a target type (see [`rules_for`], which adds the rules
/// that apply to every target).
fn target_rules(target_type: TargetType) -> Vec<ScanRule> {
use ArtifactRequirement::{Code, Firmware, HttpUrl, Mobile, Plc, RunningUrl};
use ArtifactRequirement::{BuildOutput, Code, Firmware, HttpUrl, Mobile, Plc, RunningUrl};
match target_type {
TargetType::WebApp | TargetType::BackendService => {
let mut r = sast_umbrella();
@@ -304,17 +304,18 @@ fn target_rules(target_type: TargetType) -> Vec<ScanRule> {
Firmware,
UNPACKING_IMAGES,
));
r.push(ScanRule::unavailable(
// Tier 2: what the build wrote about its image (#150).
r.push(ScanRule::new(
ScanType::Sbom,
"SBOM from the image's build artefacts",
Firmware,
YOCTO_IMAGE_SBOM,
true,
"SBOM of the image from the build's own SPDX (create-spdx)",
BuildOutput,
));
r.push(ScanRule::unavailable(
r.push(ScanRule::new(
ScanType::Cve,
"Match image components against known CVEs",
Firmware,
YOCTO_IMAGE_CVE,
true,
"Image components against known CVEs, with Yocto's cve-check verdicts",
BuildOutput,
));
r.push(ScanRule::new(
ScanType::Dast,
@@ -409,6 +410,7 @@ fn representative_kind(req: ArtifactRequirement) -> Option<ArtifactKind> {
ArtifactRequirement::Plc => Some(ArtifactKind::PlcProject),
ArtifactRequirement::Mobile => Some(ArtifactKind::MobilePackage),
ArtifactRequirement::Container => Some(ArtifactKind::ContainerImage),
ArtifactRequirement::BuildOutput => Some(ArtifactKind::BuildOutput),
ArtifactRequirement::Any => None,
}
}
@@ -438,6 +440,7 @@ fn requirement_satisfied(req: ArtifactRequirement, target: &OnboardedTarget) ->
}
ArtifactRequirement::Mobile => target.has(ArtifactKind::MobilePackage),
ArtifactRequirement::Container => target.has(ArtifactKind::ContainerImage),
ArtifactRequirement::BuildOutput => target.has(ArtifactKind::BuildOutput),
ArtifactRequirement::Any => true,
}
}
@@ -734,34 +737,41 @@ mod tests {
}
#[test]
fn a_yocto_image_has_no_sbom_until_build_artefacts_can_be_imported() {
let t = target_with(
fn a_yocto_image_sbom_comes_from_the_build_output() {
let without = target_with(
TargetType::EmbeddedLinuxYocto,
vec![
Artifact::firmware_image("core-image.wic"),
Artifact::live_url("https://device.local"),
],
);
let opts = applicable_scans(&t);
let image_option = |scan: ScanType| {
opts.iter().find(|o| {
o.scan == scan && o.required_artifact == Some(ArtifactKind::FirmwareImage)
})
};
for (scan, reason) in [
(ScanType::Sbom, YOCTO_IMAGE_SBOM),
(ScanType::Cve, YOCTO_IMAGE_CVE),
] {
let opt = image_option(scan).expect("image rule listed");
assert!(!opt.default_on);
assert_eq!(opt.unavailable_with_artifact(), Some(reason));
assert!(reason.contains("build artefacts (SPDX/manifest), planned"));
let opts = applicable_scans(&without);
for scan in [ScanType::Sbom, ScanType::Cve] {
let opt = option(&opts, scan).expect("image rule listed");
assert_eq!(opt.required_artifact, Some(ArtifactKind::BuildOutput));
assert_eq!(
opt.blocked_reason.as_deref(),
Some("no build_output artifact provided")
);
}
// With a web address DAST is unblocked but still opt-in; no pentest
// until an image boots in an emulation sandbox.
let dast = option(&opts, ScanType::Dast).expect("dast listed");
assert!(dast.blocked_reason.is_none() && !dast.default_on);
assert!(!supports_pentest(t.target_type));
assert!(!supports_pentest(without.target_type));
// The image's SPDX archive, without a layer tree, turns both on.
let with = target_with(
TargetType::EmbeddedLinuxYocto,
vec![Artifact::build_output(
"core-image-minimal.rootfs.spdx.tar.zst",
)],
);
let opts = applicable_scans(&with);
for scan in [ScanType::Sbom, ScanType::Cve] {
let opt = option(&opts, scan).expect("image rule listed");
assert!(opt.default_on && opt.blocked_reason.is_none(), "{scan:?}");
}
}
#[test]
+7 -11
View File
@@ -3577,9 +3577,9 @@ pub mod coverage {
de: "App-Pakete werden noch nicht analysiert",
en: "app packages are not analysed yet",
};
pub const YOCTO_BUILD_ARTEFACTS: Text = Text {
de: "braucht die Build-Artefakte des Images (SPDX/Manifest), geplant",
en: "needs the image's build artefacts (SPDX/manifest), planned",
pub const NEEDS_BUILD_OUTPUT: Text = Text {
de: "braucht die Build-Ergebnisse des Images (Image-SPDX, cve-check)",
en: "needs the image's build output (image SPDX, cve-check)",
};
pub const YOCTO_BUILD_PLANNED: Text = Text {
de: "Die Analyse von Yocto-Builds ist geplant (Stufe 2); ein Layer-Baum ist kein \
@@ -3609,8 +3609,8 @@ pub mod coverage {
// Yocto first: its image reasons also name firmware images.
let text = if r.contains("yocto build analysis") {
YOCTO_BUILD_PLANNED
} else if r.contains("build artefacts") {
YOCTO_BUILD_ARTEFACTS
} else if r.contains("build_output") {
NEEDS_BUILD_OUTPUT
} else if r.contains("recipe inventory") {
RECIPE_INVENTORY_PLANNED
} else if r.contains("recipe lint") {
@@ -3687,12 +3687,8 @@ mod coverage_tests {
coverage::MOBILE_NOT_ANALYSED,
),
(
"a Yocto image SBOM needs build artefacts (SPDX/manifest), planned",
coverage::YOCTO_BUILD_ARTEFACTS,
),
(
"CVE matching for a Yocto image needs build artefacts (SPDX/manifest), planned",
coverage::YOCTO_BUILD_ARTEFACTS,
"no build_output artifact provided",
coverage::NEEDS_BUILD_OUTPUT,
),
(
"Yocto build analysis is planned (tier 2): a layer tree is not a firmware build",
+10 -4
View File
@@ -40,7 +40,7 @@ searched.
| Layer pins and Yocto release | runs: kas files, `repo` manifests and submodules, and a finding when the release is end of life; see [Layer pins and the Yocto release](#layer-pins-and-the-yocto-release) |
| Recipe inventory | runs: SBOM components and NVD CVEs from the recipes, `CVE_STATUS` and `CVE:` patches as VEX; see [Recipe inventory](#recipe-inventory) |
| In the image (declared) | runs: the recipes your image recipes install are marked; see [Im Image (deklariert)](#im-image-deklariert) |
| Image SBOM / CVE | needs build artefacts (SPDX / manifest), planned (tier 2) |
| Image SBOM / CVE | runs with the build output (image SPDX, cve-check); see [Im Image (gebaut)](#im-image-gebaut-the-build-s-own-output) |
| DAST | opt-in, with an http(s) address of the running device |
| Penetration test | not offered until an image can be booted in an emulation sandbox |
@@ -346,13 +346,19 @@ open.
**On the run.** A file that is neither an image SPDX archive nor a cve-check
report is listed under **Build-SPDX (Yocto-Image)** and skipped. So is a package
the image lists without its document in the archive. A new upload starts a new
scan. A target needs the layer tree (git or archive) next to the build output
for now.
scan.
**Without the layers.** A target can carry the build output alone, without a
git repository or source archive of the layers: the SBOM, the CVEs and the VEX
statements then come from the build output only, and the run lists
**source_code** under **Nicht ausgeführt** (code analysis, the recipe inventory
and the recipe lint need the layer tree). With the layers as well, both are
joined as described above.
## What is planned
| Tier | Input | Analysis |
| --- | --- | --- |
| **1: layer tree** (in progress) | the layers in git, no build | **Recipe inventory**: every recipe's name, version, `SRC_URI`, `CVE_PRODUCT` and `CVE_STATUS`, matched against NVD; labelled as a recipe inventory, not the image's SBOM; the recipes an image recipe installs marked as declared. **Recipe lint**: done, see above |
| **2: build artefacts** (in progress) | the image `.spdx.tar.zst` (SPDX 2.2), the cve-check `.json`; later SPDX 3.0, `*.vex.json`, the kernel `.config` | **Done:** the image SPDX joins the SBOM (installed by the build), the cve-check verdicts become VEX, see *Im Image (gebaut)*. **Planned:** SPDX 3.0 (Styhead and later), kernel CVEs filtered by the configuration, a target with build output only |
| **2: build artefacts** (in progress) | the image `.spdx.tar.zst` (SPDX 2.2), the cve-check `.json`; later SPDX 3.0, `*.vex.json`, the kernel `.config` | **Done:** the image SPDX joins the SBOM (installed by the build), the cve-check verdicts become VEX, see *Im Image (gebaut)*. **Planned:** SPDX 3.0 (Styhead and later), kernel CVEs filtered by the configuration |
| **3: image / rootfs** | `.wic`, tar, ext4, squashfs | unpacking, ELF hardening of every binary, secrets and default credentials in the root filesystem; DAST and pentest only for a qemu build in an isolated sandbox |