From eb7d7423ad9c9874cee15fc876a8f41e91a484ec Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:18:19 +0100 Subject: [PATCH 1/2] feat(yocto): a target's build output joins the scan (#150) A target takes a new artifact kind, build_output: a Yocto image's SPDX archive (.spdx.tar.zst), read with pipeline::yocto_spdx (#852). The scan joins what the build installed with the recipe inventory of the layer tree (pipeline::yocto_build): - by recipe name, since the tree's PV and the built version differ (busybox 1.35.0 in the layer, 1.36.1 built): the build's version, CPE, licence and InImageBasis::Built win, both evidence lines stay; - an image the SPDX covers is authoritative: a recipe declared in it but not installed loses that marking; declarations for other images stay; - recipes only the build lists are added; - NVD is asked with the built version and CPE, one query per recipe; - a CVE the build's patches fixed (create-spdx "CVEs fixed") is stated fixed; otherwise the recipe's CVE_STATUS applies, joined by name. An archive that cannot be read, and packages listed without their documents, are noted on the run (build_spdx; new informational SkipCode::BuildPackagesUnresolved). The classifier takes an image SPDX archive as Yocto evidence. The SBOM page's in-image tooltip now says how the marking is known (declared in the recipes, or installed by the build). Co-Authored-By: Claude Opus 5.5 --- compliance-agent/src/classify/language.rs | 7 + compliance-agent/src/ingest/mod.rs | 5 +- compliance-agent/src/pipeline/mod.rs | 1 + compliance-agent/src/pipeline/orchestrator.rs | 111 ++++- compliance-agent/src/pipeline/repo_view.rs | 4 + compliance-agent/src/pipeline/yocto_build.rs | 424 ++++++++++++++++++ .../src/pipeline/yocto_inventory.rs | 4 +- compliance-agent/src/pipeline/yocto_spdx.rs | 3 + compliance-agent/src/targets.rs | 2 + compliance-core/src/models/onboarding.rs | 10 + compliance-core/src/models/scan.rs | 4 + compliance-dashboard/src/i18n/texts.rs | 15 + compliance-dashboard/src/pages/sbom.rs | 8 +- 13 files changed, 589 insertions(+), 9 deletions(-) create mode 100644 compliance-agent/src/pipeline/yocto_build.rs diff --git a/compliance-agent/src/classify/language.rs b/compliance-agent/src/classify/language.rs index 7e80242..f8d4d3a 100644 --- a/compliance-agent/src/classify/language.rs +++ b/compliance-agent/src/classify/language.rs @@ -390,6 +390,13 @@ impl HeuristicClassifier { ArtifactKind::SourceArchive if lower.ends_with(".projectarchive") => out.push( verdict(TargetType::PlcSps, 0.85, "CODESYS project archive", vec![]), ), + // A Yocto image's SPDX archive is Yocto by itself. + ArtifactKind::BuildOutput if lower.ends_with(".spdx.tar.zst") => out.push(verdict( + TargetType::EmbeddedLinuxYocto, + 0.7, + "Yocto image SPDX archive", + vec![], + )), ArtifactKind::LiveUrl if input.artifacts.len() == 1 => { out.push(verdict(TargetType::WebApp, 0.3, "live URL only", vec![])) } diff --git a/compliance-agent/src/ingest/mod.rs b/compliance-agent/src/ingest/mod.rs index 989ed08..adc4378 100644 --- a/compliance-agent/src/ingest/mod.rs +++ b/compliance-agent/src/ingest/mod.rs @@ -189,7 +189,10 @@ pub fn ingest_artifact( ArtifactKind::SourceArchive | ArtifactKind::MobilePackage | ArtifactKind::PlcProject => { ingest_blob(artifact, ctx, true) } - ArtifactKind::FirmwareImage => ingest_blob(artifact, ctx, false), + // Stored as uploaded: the SPDX reader opens the archive itself. + ArtifactKind::FirmwareImage | ArtifactKind::BuildOutput => { + ingest_blob(artifact, ctx, false) + } ArtifactKind::ContainerImage => Ok(metadata_only( artifact, DetectedFact::new("container_ref", artifact.source_ref.as_str(), "ingest"), diff --git a/compliance-agent/src/pipeline/mod.rs b/compliance-agent/src/pipeline/mod.rs index ce14e23..a26e553 100644 --- a/compliance-agent/src/pipeline/mod.rs +++ b/compliance-agent/src/pipeline/mod.rs @@ -54,6 +54,7 @@ pub(crate) mod unity_settings; pub mod variants; pub mod vendor; pub mod vex_lifecycle; +pub mod yocto_build; pub mod yocto_inventory; pub mod yocto_pins; pub mod yocto_spdx; diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index 3983bba..8f8d413 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -557,7 +557,15 @@ impl PipelineOrchestrator { ) .await; } - let yocto_entries = yocto_inventory::entries(&yocto.recipes, &declarations, &repo_id); + // What the build installed, from its image SPDX: joined with the + // inventory by recipe name, the build's version and image marking win. + let built_images = self.read_build_outputs(repo, &repo_id, scan_run_id).await; + let built = crate::pipeline::yocto_build::Built::new(&built_images); + let yocto_entries = built.merge(yocto_inventory::entries( + &yocto.recipes, + &declarations, + &repo_id, + )); let yocto_recipes = yocto.recipes; for entry in embedded.into_iter().chain(codesys).chain(yocto_entries) { let known = sbom_entries @@ -688,8 +696,10 @@ impl PipelineOrchestrator { // A Yocto recipe inventory's components: NVD by CPE, within a budget // of their own (a layer tree can name hundreds of products). - if !yocto_recipes.is_empty() { - let (queries, unversioned) = yocto_inventory::nvd_queries(&yocto_recipes); + if !yocto_recipes.is_empty() || !built.is_empty() { + let (inventory_queries, mut unversioned) = yocto_inventory::nvd_queries(&yocto_recipes); + let (queries, built_unversioned) = built.nvd_queries(inventory_queries); + unversioned.extend(built_unversioned); let lookup = cve_scanner .scan_yocto( &repo_id, @@ -1021,7 +1031,7 @@ impl PipelineOrchestrator { // stated again after the alerts were stored, never over a person's, // and before the notifications, which a `not_affected` or `fixed` // suppresses. - let statements = yocto_inventory::vex_statements(&yocto_recipes, &cve_alerts); + let statements = built.statements(&yocto_recipes, &cve_alerts); if !statements.is_empty() { match crate::pipeline::vex_lifecycle::apply_scan_statements( &self.db, @@ -1345,6 +1355,7 @@ impl PipelineOrchestrator { } let mut repo = RepoView::from_target(target, code, &self.secrets); repo.yocto_layers = yocto_layers; + repo.build_outputs = build_output_paths(target, &working_paths); let n = self.run_pipeline(&repo, scan_run_id, trigger).await?; self.finalize_target(target, &repo, n).await?; new_count += n; @@ -1360,6 +1371,7 @@ impl PipelineOrchestrator { Some(tree) => { let mut repo = RepoView::from_target(target, code, &self.secrets); repo.yocto_layers = yocto_layers; + repo.build_outputs = build_output_paths(target, &working_paths); let upload = crate::pipeline::plc::sbom::uploaded_archive(code); let n = self.scan_tree(tree, upload, &repo, scan_run_id).await?; self.finalize_target(target, &repo, n).await?; @@ -2617,6 +2629,78 @@ 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. + /// The images the target's build outputs describe + /// ([`crate::pipeline::yocto_spdx`]). One that cannot be read is noted on + /// the run (and skipped), and so are packages the archive lists in an + /// image without their documents. + async fn read_build_outputs( + &self, + repo: &RepoView, + repo_id: &str, + scan_run_id: &str, + ) -> Vec { + let mut images = Vec::new(); + for path in &repo.build_outputs { + let name = path + .file_name() + .map(|n| n.to_string_lossy().into_owned()) + .unwrap_or_default(); + let file = path.clone(); + let id = repo_id.to_string(); + let read = tokio::task::spawn_blocking(move || { + crate::pipeline::yocto_spdx::read_archive( + &file, + &id, + crate::pipeline::yocto_spdx::ReadLimits::default(), + ) + }) + .await; + match read { + Ok(Ok(read)) => images.extend(read), + Ok(Err(e)) => { + tracing::warn!(scan_run_id, file = %name, error = %e, "build output not read"); + self.skip_stage( + scan_run_id, + SkippedStage::new( + crate::pipeline::yocto_spdx::STAGE, + SkipCode::ArtifactNotIngested, + format!( + "{name} was not read as a Yocto image SPDX archive \ + (.spdx.tar.zst): {e}" + ), + ) + .about(name), + ) + .await; + } + Err(e) => tracing::warn!(scan_run_id, error = %e, "build output read failed"), + } + } + let unresolved: Vec = images + .iter() + .flat_map(|i| i.unresolved.iter().cloned()) + .collect::>() + .into_iter() + .collect(); + if !unresolved.is_empty() { + let list = component_list(&unresolved); + self.skip_stage( + scan_run_id, + SkippedStage::new( + crate::pipeline::yocto_spdx::STAGE, + SkipCode::BuildPackagesUnresolved, + format!( + "the image SPDX lists these packages in the image without their \ + documents, so their recipes are not known: {list}" + ), + ) + .about(list), + ) + .await; + } + images + } + async fn yocto_recipes(&self, tree: &std::path::Path, scan_run_id: &str) -> Inventory { match yocto_inventory::read(tree).await { Ok(inventory) if inventory.recipes.is_empty() && inventory.errors.is_empty() => { @@ -2998,3 +3082,22 @@ mod tests { assert_eq!(repo.checkout, code.id); } } + +/// The ingested files of `target`'s build outputs (Yocto image SPDX +/// archives), or the stored upload where ingest recorded no working path. +fn build_output_paths( + target: &OnboardedTarget, + working_paths: &std::collections::HashMap, +) -> Vec { + target + .artifacts + .iter() + .filter(|a| a.kind == ArtifactKind::BuildOutput) + .filter_map(|a| { + working_paths + .get(&a.id) + .cloned() + .or_else(|| a.stored_path.as_deref().map(std::path::PathBuf::from)) + }) + .collect() +} diff --git a/compliance-agent/src/pipeline/repo_view.rs b/compliance-agent/src/pipeline/repo_view.rs index cc4594a..e7bcbea 100644 --- a/compliance-agent/src/pipeline/repo_view.rs +++ b/compliance-agent/src/pipeline/repo_view.rs @@ -52,6 +52,9 @@ pub struct RepoView { /// Directories and files the target's settings leave out of every scan /// stage (`scan_config.exclude_paths`). pub exclude_paths: Vec, + /// The target's uploaded build outputs (Yocto image SPDX archives), as + /// ingested. Set by the caller; empty from [`Self::from_target`]. + pub build_outputs: Vec, } impl RepoView { @@ -83,6 +86,7 @@ impl RepoView { uploads_allow_skip: crate::pipeline::change::uploads_allow_git_skip(target), yocto_layers: false, exclude_paths: target.scan_config.exclude_paths.clone(), + build_outputs: Vec::new(), }; if let Some(git) = &code.git { view.default_branch = git.default_branch.clone(); diff --git a/compliance-agent/src/pipeline/yocto_build.rs b/compliance-agent/src/pipeline/yocto_build.rs new file mode 100644 index 0000000..38fec21 --- /dev/null +++ b/compliance-agent/src/pipeline/yocto_build.rs @@ -0,0 +1,424 @@ +//! A Yocto build's own evidence (its image SPDX, [`crate::pipeline::yocto_spdx`]) +//! combined with the recipe inventory of the layer tree +//! ([`crate::pipeline::yocto_inventory`]). +//! +//! The two name the same recipes differently: the inventory reads PV as +//! written (`linux-yocto 6.6`), the build records what it built +//! (`6.6.151+git`). So they are joined by recipe name, and for a recipe in +//! both the build wins: its version, CPE and licence, and its image marking +//! ([`InImageBasis::Built`]). An image the build's SPDX covers is +//! authoritative: a recipe the inventory declares in it but the build did not +//! install loses that marking; images the SPDX does not cover keep theirs. +//! +//! The build also says which CVEs its patches fixed; those become `fixed` +//! VEX statements on the matching alerts, ahead of what the recipes state. + +use std::collections::{BTreeMap, BTreeSet, HashMap}; + +use compliance_core::models::{ + CveAlert, InImage, InImageBasis, SbomEntry, VexAssessment, VexStatus, YOCTO_RECIPE_MANAGER, +}; + +use crate::pipeline::yocto_inventory::{self, CpeProduct, NvdQuery, Recipe}; +use crate::pipeline::yocto_spdx::BuiltImage; + +/// What the build installed, across its images, by recipe name. +#[derive(Debug, Default)] +pub struct Built<'a> { + /// One component per recipe (the first image's, with every image named). + components: BTreeMap, + /// The images the SPDX covers (`core-image-minimal`). + images: BTreeSet, + /// The CVEs fixed per recipe name. + fixed: HashMap>, +} + +impl<'a> Built<'a> { + /// Gather `images` (from one or more build-output archives). + pub fn new(images: &'a [BuiltImage]) -> Self { + let mut built = Self::default(); + for image in images { + built.images.insert(image.image.clone()); + for entry in &image.entries { + match built.components.get_mut(&entry.name) { + Some(known) => add_image(known, &image.image), + None => { + built.components.insert(entry.name.clone(), entry.clone()); + } + } + } + for fixed in &image.fixed { + built + .fixed + .entry(fixed.component.clone()) + .or_default() + .insert(fixed.cve.as_str()); + } + } + built + } + + /// Whether the build listed nothing. + pub fn is_empty(&self) -> bool { + self.components.is_empty() + } + + /// The SBOM components: `inventory` (the recipe inventory's) joined with + /// what the build installed, by recipe name. See the module docs. + pub fn merge(&self, inventory: Vec) -> Vec { + let mut out = Vec::with_capacity(inventory.len() + self.components.len()); + let mut joined = BTreeSet::new(); + for mut entry in inventory { + if entry.package_manager != YOCTO_RECIPE_MANAGER { + out.push(entry); + continue; + } + match self.components.get(&entry.name) { + Some(built) => { + joined.insert(entry.name.clone()); + out.push(self.joined(entry, built)); + } + None => { + self.uncover(&mut entry); + out.push(entry); + } + } + } + out.extend( + self.components + .values() + .filter(|c| !joined.contains(&c.name)) + .cloned(), + ); + out + } + + /// `inventory`'s component with what the build says about it. + fn joined(&self, inventory: SbomEntry, built: &SbomEntry) -> SbomEntry { + let mut entry = built.clone(); + // The inventory knows where the recipe is and what it fetches. + entry.download_url = built.download_url.clone().or(inventory.download_url); + entry.license = built.license.clone().or(inventory.license); + entry.cpe = built.cpe.clone().or(inventory.cpe); + let declared_elsewhere: Vec = inventory + .in_image + .as_ref() + .filter(|i| i.basis == InImageBasis::Declared) + .map(|i| { + i.images + .iter() + .filter(|image| !self.images.contains(*image)) + .cloned() + .collect() + }) + .unwrap_or_default(); + let mut evidence: Vec = inventory + .evidence + .into_iter() + .filter(|line| !line.starts_with(InImageBasis::Declared.describe())) + .collect(); + if !declared_elsewhere.is_empty() { + evidence.push( + InImage { + basis: InImageBasis::Declared, + images: declared_elsewhere, + } + .describe(), + ); + } + for line in built.evidence.iter() { + if !evidence.contains(line) { + evidence.push(line.clone()); + } + } + entry.evidence = evidence; + entry + } + + /// Take the images the build covers out of `entry`'s declared marking: + /// the build installed it there, or it is not there. + fn uncover(&self, entry: &mut SbomEntry) { + let Some(in_image) = entry + .in_image + .as_mut() + .filter(|i| i.basis == InImageBasis::Declared) + else { + return; + }; + let before = in_image.describe(); + in_image.images.retain(|image| !self.images.contains(image)); + let after = (!in_image.images.is_empty()).then(|| in_image.describe()); + if after.is_none() { + entry.in_image = None; + } + entry.evidence.retain(|line| *line != before); + entry.evidence.extend(after); + } + + /// What to ask NVD: the inventory's `queries`, with the build's version + /// and CPE for a recipe the build installed, and a query for each built + /// recipe the inventory does not have. Returns the queries and the + /// components that cannot be asked about (no release version). + pub fn nvd_queries(&self, queries: Vec) -> (Vec, Vec) { + let mut out: Vec = queries + .into_iter() + .filter(|q| !self.components.contains_key(&q.name)) + .collect(); + let mut unversioned = Vec::new(); + for component in self.components.values() { + let products: Vec = + component.cpe.iter().filter_map(|c| product(c)).collect(); + if products.is_empty() { + continue; + } + match yocto_inventory::release_of(&component.version) { + Some(cve_version) => out.push(NvdQuery { + name: component.name.clone(), + version: component.version.clone(), + cve_version, + products, + }), + None => unversioned.push(format!("{} (no release version)", component.name)), + } + } + (out, unversioned) + } + + /// The VEX statements on `alerts`: `fixed` for a CVE the build's patches + /// fixed in the component, else what its recipe in the tree states + /// (joined by name, whatever version either side names), else what + /// [`yocto_inventory::vex_statements`] finds. + pub fn statements( + &self, + recipes: &[Recipe], + alerts: &[CveAlert], + ) -> Vec<(String, VexAssessment)> { + let (built_alerts, other): (Vec<&CveAlert>, Vec<&CveAlert>) = alerts + .iter() + .partition(|a| self.components.contains_key(&a.affected_package)); + let mut out: Vec<(String, VexAssessment)> = built_alerts + .iter() + .filter_map(|alert| { + let fixed = self + .fixed + .get(&alert.affected_package) + .is_some_and(|cves| cves.contains(alert.cve_id.as_str())); + let statement = if fixed { + Some(yocto_inventory::scan_statement( + VexStatus::Fixed, + None, + format!( + "Fixed by a patch the build applied to {} (Yocto create-spdx: CVEs \ + fixed)", + alert.affected_package + ), + )) + } else { + recipes + .iter() + .find(|r| r.bpn == alert.affected_package) + .and_then(|r| yocto_inventory::recipe_statement(r, &alert.cve_id)) + }; + statement.map(|vex| (alert.cve_id.clone(), vex)) + }) + .collect(); + let rest: Vec = other.into_iter().cloned().collect(); + out.extend(yocto_inventory::vex_statements(recipes, &rest)); + out + } +} + +/// Add `image` to `entry`'s built marking and its evidence line. +fn add_image(entry: &mut SbomEntry, image: &str) { + let Some(in_image) = entry.in_image.as_mut() else { + return; + }; + if in_image.images.iter().any(|i| i == image) { + return; + } + let before = in_image.describe(); + in_image.images.push(image.to_string()); + let after = in_image.describe(); + for line in entry.evidence.iter_mut() { + if *line == before { + line.clone_from(&after); + } + } +} + +/// The product a CPE 2.3 name names (`cpe:2.3:*:openssl:openssl:3.5.9:…` → +/// vendor `openssl`, product `openssl`; a `*` vendor is any vendor). +fn product(cpe: &str) -> Option { + let mut parts = cpe.split(':'); + if parts.next()? != "cpe" || parts.next()? != "2.3" { + return None; + } + let _part = parts.next()?; + let vendor = parts.next()?; + let product = parts.next()?; + if product.is_empty() || product == "*" { + return None; + } + Some(CpeProduct { + vendor: (vendor != "*" && !vendor.is_empty()).then(|| vendor.replace('\\', "")), + product: product.replace('\\', ""), + }) +} + +#[cfg(test)] +#[allow(clippy::expect_used, clippy::unwrap_used)] +mod tests { + use super::*; + use crate::pipeline::yocto_spdx::{read_dir, ReadLimits}; + + fn built_images() -> Vec { + let dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../fixtures/yocto/spdx-scarthgap"); + read_dir(&dir, "t", ReadLimits::default()).unwrap() + } + + /// An inventory component as the recipe inventory makes it. + fn inventory(name: &str, version: &str, declared: &[&str]) -> SbomEntry { + let mut e = SbomEntry::new( + "t".into(), + name.into(), + version.into(), + YOCTO_RECIPE_MANAGER.into(), + ); + e.evidence.push(format!( + "Yocto recipe inventory: recipes-core/{name}/{name}.bb" + )); + if !declared.is_empty() { + let in_image = InImage { + basis: InImageBasis::Declared, + images: declared.iter().map(|s| s.to_string()).collect(), + }; + e.evidence.push(in_image.describe()); + e.in_image = Some(in_image); + } + e + } + + #[test] + fn the_build_wins_by_recipe_name_whatever_version_the_tree_names() { + let images = built_images(); + let built = Built::new(&images); + let merged = built.merge(vec![ + // PV in the tree differs from what the build recorded. + inventory("busybox", "1.36", &["core-image-minimal", "rescue-image"]), + inventory("dropbear", "2024.85", &["core-image-minimal"]), + inventory("tool", "1.0", &["rescue-image"]), + SbomEntry::new("t".into(), "serde".into(), "1.0".into(), "cargo".into()), + ]); + let by_name = |n: &str| merged.iter().find(|e| e.name == n).unwrap(); + + let busybox = by_name("busybox"); + assert_eq!(busybox.version, "1.36.1"); + assert_eq!( + busybox.in_image.as_ref().map(|i| i.basis), + Some(InImageBasis::Built) + ); + assert!(busybox.evidence[0].starts_with("Yocto recipe inventory")); + // The image the SPDX does not cover keeps its declaration as evidence. + assert!(busybox.evidence.iter().any( + |l| l.starts_with(InImageBasis::Declared.describe()) && l.ends_with("rescue-image") + )); + // The built image's declaration is gone: the build says where it is. + assert!(!busybox + .evidence + .iter() + .any(|l| l.starts_with(InImageBasis::Declared.describe()) + && l.contains("core-image-minimal"))); + + // Declared in the built image but not installed by the build: unmarked. + assert!(by_name("dropbear").in_image.is_none()); + assert_eq!(by_name("dropbear").evidence.len(), 1); + // Another image's declaration is left alone. + assert_eq!( + by_name("tool").in_image.as_ref().map(|i| i.images.clone()), + Some(vec!["rescue-image".to_string()]) + ); + // Built only: added. Not a recipe component: untouched. + assert!(merged + .iter() + .any(|e| e.name == "openssl" && e.version == "3.5.9")); + assert_eq!(by_name("serde").package_manager, "cargo"); + assert_eq!(merged.iter().filter(|e| e.name == "busybox").count(), 1); + } + + #[test] + fn nvd_is_asked_with_the_built_version_and_cpe() { + let images = built_images(); + let built = Built::new(&images); + let stale = NvdQuery { + name: "busybox".into(), + version: "1.36".into(), + cve_version: "1.36".into(), + products: vec![], + }; + let other = NvdQuery { + name: "zlib".into(), + version: "1.3".into(), + cve_version: "1.3".into(), + products: vec![], + }; + let (queries, unversioned) = built.nvd_queries(vec![stale, other]); + let names: Vec<(&str, &str)> = queries + .iter() + .map(|q| (q.name.as_str(), q.version.as_str())) + .collect(); + assert!(names.contains(&("zlib", "1.3")), "{names:?}"); + assert!(names.contains(&("busybox", "1.36.1")), "{names:?}"); + assert!(!names.contains(&("busybox", "1.36"))); + let openssl = queries.iter().find(|q| q.name == "openssl").unwrap(); + assert_eq!( + openssl.products, + [CpeProduct { + vendor: Some("openssl".into()), + product: "openssl".into() + }] + ); + // The package group has no CPE: nothing to ask, nothing missing. + assert!(!queries.iter().any(|q| q.name == "packagegroup-core-boot")); + assert!(unversioned.is_empty()); + } + + #[test] + fn a_cve_the_build_patched_is_stated_fixed() { + let images = built_images(); + let built = Built::new(&images); + let alert = |package: &str, cve: &str| { + CveAlert::new( + cve.into(), + "t".into(), + package.into(), + "1.36.1".into(), + compliance_core::models::CveSource::Nvd, + ) + }; + let statements = built.statements( + &[], + &[ + alert("busybox", "CVE-2022-48174"), + alert("busybox", "CVE-2099-0001"), + ], + ); + assert_eq!(statements.len(), 1); + assert_eq!(statements[0].0, "CVE-2022-48174"); + assert_eq!(statements[0].1.status, VexStatus::Fixed); + assert!(statements[0].1.by_scan); + } + + #[test] + fn cpe_products_are_read_from_cpe_names() { + assert_eq!( + product("cpe:2.3:*:*:busybox:1.36.1:*:*:*:*:*:*:*"), + Some(CpeProduct { + vendor: None, + product: "busybox".into() + }) + ); + assert_eq!(product("cpe:2.3:a:*:*:1:*"), None); + assert_eq!(product("cpe:/a:x:y"), None); + } +} diff --git a/compliance-agent/src/pipeline/yocto_inventory.rs b/compliance-agent/src/pipeline/yocto_inventory.rs index 20e8fbe..55d9cb3 100644 --- a/compliance-agent/src/pipeline/yocto_inventory.rs +++ b/compliance-agent/src/pipeline/yocto_inventory.rs @@ -323,7 +323,7 @@ impl RecipeVersion { /// The release part of a PV: what precedes a git or SCM suffix or a variable /// the tree does not define (`1.0+git${SRCPV}` → `1.0`). `None` when nothing /// is left (`git`, `+git`). -fn release_of(pv: &str) -> Option { +pub(crate) fn release_of(pv: &str) -> Option { let end = ["${", "+git", "AUTOINC", "+svn", "+hg", "+cvs"] .iter() .filter_map(|marker| pv.find(marker)) @@ -842,7 +842,7 @@ fn status_statement(status: &str) -> Option<(VexStatus, Option } /// A statement the scan makes, saying where it comes from. -fn scan_statement( +pub(crate) fn scan_statement( status: VexStatus, justification: Option, because: String, diff --git a/compliance-agent/src/pipeline/yocto_spdx.rs b/compliance-agent/src/pipeline/yocto_spdx.rs index fba4a83..d7acb42 100644 --- a/compliance-agent/src/pipeline/yocto_spdx.rs +++ b/compliance-agent/src/pipeline/yocto_spdx.rs @@ -29,6 +29,9 @@ use compliance_core::purl::encode; /// Where a component read from the build's SPDX comes from, on its evidence. pub const SOURCE: &str = "Yocto build SPDX"; +/// The scan run's stage id for the build's image SPDX. +pub const STAGE: &str = "build_spdx"; + /// Limits on an uploaded archive: it is untrusted input. #[derive(Debug, Clone, Copy)] pub struct ReadLimits { diff --git a/compliance-agent/src/targets.rs b/compliance-agent/src/targets.rs index 6b1673b..2dc8fd8 100644 --- a/compliance-agent/src/targets.rs +++ b/compliance-agent/src/targets.rs @@ -101,6 +101,7 @@ pub fn uploaded_artifact( ArtifactKind::FirmwareImage => Artifact::firmware_image(filename), ArtifactKind::SourceArchive => Artifact::source_archive(filename), ArtifactKind::MobilePackage => Artifact::mobile_package(filename), + ArtifactKind::BuildOutput => Artifact::build_output(filename), _ => return None, }; artifact.stored_path = Some(stored_path.to_string_lossy().to_string()); @@ -131,6 +132,7 @@ pub fn reference_artifact( Artifact::plc_project(source_ref, plc_format.unwrap_or(PlcFormat::PlcopenXml)) } ArtifactKind::PlaintextDescription => Artifact::plaintext(source_ref), + ArtifactKind::BuildOutput => Artifact::build_output(source_ref), } } diff --git a/compliance-core/src/models/onboarding.rs b/compliance-core/src/models/onboarding.rs index 22c2fe3..bc2ad46 100644 --- a/compliance-core/src/models/onboarding.rs +++ b/compliance-core/src/models/onboarding.rs @@ -84,6 +84,9 @@ pub enum ArtifactKind { PlcProject, /// Free-form plaintext describing the target (feeds classification only). PlaintextDescription, + /// What a build wrote about its image: a Yocto image's SPDX archive + /// (`.spdx.tar.zst`). + BuildOutput, } impl std::fmt::Display for ArtifactKind { @@ -97,6 +100,7 @@ impl std::fmt::Display for ArtifactKind { Self::LiveUrl => write!(f, "live_url"), Self::PlcProject => write!(f, "plc_project"), Self::PlaintextDescription => write!(f, "plaintext_description"), + Self::BuildOutput => write!(f, "build_output"), } } } @@ -328,6 +332,11 @@ impl Artifact { Self::bare(ArtifactKind::MobilePackage, source_ref) } + /// A build-output artifact (a Yocto image's SPDX archive) by file name. + pub fn build_output(source_ref: impl Into) -> Self { + Self::bare(ArtifactKind::BuildOutput, source_ref) + } + /// A container-image artifact referenced by OCI ref. pub fn container_image(source_ref: impl Into) -> Self { Self::bare(ArtifactKind::ContainerImage, source_ref) @@ -802,6 +811,7 @@ mod tests { assert_eq!(TargetType::PlcSps.to_string(), "plc_sps"); assert_eq!(ArtifactKind::PlcProject.to_string(), "plc_project"); assert_eq!(ArtifactKind::MobilePackage.to_string(), "mobile_package"); + assert_eq!(ArtifactKind::BuildOutput.to_string(), "build_output"); } #[test] diff --git a/compliance-core/src/models/scan.rs b/compliance-core/src/models/scan.rs index ca587aa..6f57e06 100644 --- a/compliance-core/src/models/scan.rs +++ b/compliance-core/src/models/scan.rs @@ -202,6 +202,9 @@ pub enum SkipCode { /// Vendor and third-party directories left out of SAST; `subject` lists /// them. VendorCode, + /// Packages a build's image SPDX lists in the image without their + /// documents, so their recipes are not known; `subject` lists them. + BuildPackagesUnresolved, /// Test-data directories (`fixtures/`, `testdata/`) left out of the whole /// scan: code findings, SBOM and CVE match; `subject` lists them. TestData, @@ -278,6 +281,7 @@ impl SkipCode { match self { Self::VendorCode | Self::TestData + | Self::BuildPackagesUnresolved | Self::ExcludedPaths | Self::SuppressedInSource | Self::NotInTree => true, diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 39ee5ef..78fe538 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -487,6 +487,10 @@ pub mod scans { de: "Ausgenommene Pfade", en: "Excluded paths", }, + "build_spdx" => Text { + de: "Build-SPDX (Yocto-Image)", + en: "Build SPDX (Yocto image)", + }, "test_data" => Text { de: "Testdaten (fixtures, testdata)", en: "Test data (fixtures, testdata)", @@ -600,6 +604,12 @@ pub mod scans { (SkipCode::VendorCode, Lang::En) => format!( "Vendor and third-party code, left out of code analysis but in the SBOM: {subject}" ), + (SkipCode::BuildPackagesUnresolved, Lang::De) => format!( + "Im Image-SPDX des Builds ohne eigenes Dokument, Rezept daher unbekannt: {subject}" + ), + (SkipCode::BuildPackagesUnresolved, Lang::En) => format!( + "In the build's image SPDX without their own document, so their recipe is not known: {subject}" + ), (SkipCode::TestData, Lang::De) => format!( "Testdaten, von der ganzen Prüfung ausgenommen (Codeanalyse, Stückliste, CVEs): {subject}" ), @@ -2289,6 +2299,11 @@ pub mod sbom { de: "Aus den Rezepten gelesen (IMAGE_INSTALL, Paketgruppen eine Ebene tief, IMAGE_FEATURES), nicht von BitBake aufgelöst: Overrides, PACKAGECONFIG und von DISTRO_FEATURES abhängige Pakete sind nicht berücksichtigt.", en: "Read from the recipes (IMAGE_INSTALL, package groups one level deep, IMAGE_FEATURES), not resolved by bitbake: overrides, PACKAGECONFIG and packages that depend on DISTRO_FEATURES are not taken into account.", }; + /// The in-image badge's tooltip for a component the build installed. + pub const IN_IMAGE_BUILT_HINT: Text = Text { + de: "Vom Build installiert, laut dessen Image-SPDX (Yocto create-spdx): Overrides, PACKAGECONFIG und Maschine sind berücksichtigt.", + en: "Installed by the build, according to its image SPDX (Yocto create-spdx): overrides, PACKAGECONFIG and the machine are taken into account.", + }; /// The in-image filter's other choice. pub const ALL_COMPONENTS: Text = Text { de: "Alle Komponenten", diff --git a/compliance-dashboard/src/pages/sbom.rs b/compliance-dashboard/src/pages/sbom.rs index 677531f..69bc280 100644 --- a/compliance-dashboard/src/pages/sbom.rs +++ b/compliance-dashboard/src/pages/sbom.rs @@ -354,9 +354,13 @@ pub fn SbomPage(target: String) -> Element { let edit_target = target.clone(); let edit_existing = entry.concluded.clone(); let row_key_click = row_key.clone(); - // Which images declare it, on the badge's tooltip. + // Which images hold it, and how that is known, on the badge's tooltip. let in_image_title = entry.in_image.as_ref().map(|i| { - format!("{} (Images: {})", tx::IN_IMAGE_HINT.get(lang), i.images.join(", ")) + let hint = match i.basis { + compliance_core::models::InImageBasis::Declared => tx::IN_IMAGE_HINT, + compliance_core::models::InImageBasis::Built => tx::IN_IMAGE_BUILT_HINT, + }; + format!("{} (Images: {})", hint.get(lang), i.images.join(", ")) }); rsx! { tr { -- 2.54.1 From 1f0d9c17fd318d3add928d60fa5fc37dd19241b7 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:25:53 +0100 Subject: [PATCH 2/2] fix: build_output_paths before the test module (clippy) Co-Authored-By: Claude Opus 5.5 --- compliance-agent/src/pipeline/orchestrator.rs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index 8f8d413..cb135e7 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -2980,6 +2980,25 @@ pub(super) fn extract_base_url(git_url: &str) -> Option { } } +/// The ingested files of `target`'s build outputs (Yocto image SPDX +/// archives), or the stored upload where ingest recorded no working path. +fn build_output_paths( + target: &OnboardedTarget, + working_paths: &std::collections::HashMap, +) -> Vec { + target + .artifacts + .iter() + .filter(|a| a.kind == ArtifactKind::BuildOutput) + .filter_map(|a| { + working_paths + .get(&a.id) + .cloned() + .or_else(|| a.stored_path.as_deref().map(std::path::PathBuf::from)) + }) + .collect() +} + #[cfg(test)] #[allow(clippy::expect_used, clippy::unwrap_used)] mod tests { @@ -3082,22 +3101,3 @@ mod tests { assert_eq!(repo.checkout, code.id); } } - -/// The ingested files of `target`'s build outputs (Yocto image SPDX -/// archives), or the stored upload where ingest recorded no working path. -fn build_output_paths( - target: &OnboardedTarget, - working_paths: &std::collections::HashMap, -) -> Vec { - target - .artifacts - .iter() - .filter(|a| a.kind == ArtifactKind::BuildOutput) - .filter_map(|a| { - working_paths - .get(&a.id) - .cloned() - .or_else(|| a.stored_path.as_deref().map(std::path::PathBuf::from)) - }) - .collect() -} -- 2.54.1