From b1d317e3e16f8ae43e984196a37d2f5336921a40 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Wed, 18 Nov 2026 14:05:43 +0100 Subject: [PATCH] feat(sbom): the stripped SBOM a supplier workspace releases (#1028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first Prüfwerk piece of phase 4: `sbom_docs::released_cyclonedx`, the CycloneDX 1.6 document a supplier workspace releases to a connected customer workspace. - `metadata.component` is the released target with the published version and the supplier workspace's name as its `supplier`. - Each component keeps only what identifies it, its licences and its hashes, by a list of kept keys: no properties (where it was found, the images it is in, the licence review), copyright, references or manufacturer, and a custom licence keeps its name but not its text. - No `vulnerabilities`: the customer's own scan finds them. Tests: nothing else crosses (vulnerability, download URL, image, contract); valid against the CycloneDX 1.6 schema; read back by the supplier SBOM reader with every component and purl, as the customer will receive it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- .../src/pipeline/sbom/supplied.rs | 41 ++++++ compliance-core/src/sbom_docs.rs | 131 +++++++++++++++++- compliance-core/tests/released_sbom.rs | 37 +++++ 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 compliance-core/tests/released_sbom.rs diff --git a/compliance-agent/src/pipeline/sbom/supplied.rs b/compliance-agent/src/pipeline/sbom/supplied.rs index 4deb972..0e58df1 100644 --- a/compliance-agent/src/pipeline/sbom/supplied.rs +++ b/compliance-agent/src/pipeline/sbom/supplied.rs @@ -650,6 +650,47 @@ mod tests { parse_with_statements(bytes, repo_id, label).map(|sbom| sbom.entries) } + #[test] + fn a_released_sbom_is_read_back_as_a_supplier_sbom() { + // What a supplier workspace releases (#1028) reaches the customer + // through this reader: every component, with its purl, and the + // product itself left out. + let entries: Vec = (0..3) + .map(|i| { + let mut e = SbomEntry::new( + "supplier-target".into(), + format!("pkg{i}"), + "1.0.0".into(), + "npm".into(), + ); + e.purl = Some(format!("pkg:npm/pkg{i}@1.0.0")); + e + }) + .collect(); + let product = compliance_core::sbom_docs::ReleasedProduct { + name: "DR-4 Firmware", + version: "1.4.0", + supplier: "Test Antriebstechnik", + }; + let doc = compliance_core::sbom_docs::released_cyclonedx(&entries, &product); + let bytes = serde_json::to_vec(&doc).expect("json"); + + let read = parse_with_statements(&bytes, "customer-target", "").expect("readable"); + + assert_eq!(read.format, "CycloneDX 1.6"); + assert!(read.statements.is_empty()); + let purls: Vec> = read.entries.iter().map(|e| e.purl.as_deref()).collect(); + assert_eq!( + purls, + [ + Some("pkg:npm/pkg0@1.0.0"), + Some("pkg:npm/pkg1@1.0.0"), + Some("pkg:npm/pkg2@1.0.0") + ] + ); + assert!(read.entries.iter().all(|e| e.repo_id == "customer-target")); + } + const CDX_JSON: &str = r#"{ "bomFormat": "CycloneDX", "specVersion": "1.5", diff --git a/compliance-core/src/sbom_docs.rs b/compliance-core/src/sbom_docs.rs index 0025f43..e91f050 100644 --- a/compliance-core/src/sbom_docs.rs +++ b/compliance-core/src/sbom_docs.rs @@ -415,6 +415,75 @@ pub fn cyclonedx(entries: &[SbomEntry], subject: &str) -> serde_json::Value { doc } +/// The product a released SBOM describes (#1028): the target a supplier +/// workspace releases, the version it publishes, and the workspace's name as +/// its supplier. +#[derive(Debug, Clone, Copy)] +pub struct ReleasedProduct<'a> { + /// The target's name. + pub name: &'a str, + /// The version the supplier publishes, such as `1.4.0`. + pub version: &'a str, + /// The supplier: the releasing workspace's display name. + pub supplier: &'a str, +} + +/// The keys of a component that a released SBOM keeps: what identifies the +/// component, its licences and its hashes. Everything else stays with the +/// supplier: properties (where it was found, the images it is in, the +/// licence review), copyright, references and the manufacturer. A list of +/// what is kept, so nothing added to the export later crosses unnoticed. +const RELEASED_COMPONENT_KEYS: [&str; 9] = [ + "type", "bom-ref", "name", "group", "version", "purl", "cpe", "licenses", "hashes", +]; + +/// The SBOM a supplier workspace releases to a connected customer workspace +/// (#1028): a CycloneDX 1.6 document of `entries` about `product`, holding +/// only what identifies each component, its licences and its hashes. +/// +/// No vulnerabilities, findings or provenance cross: the customer's own scan +/// finds the vulnerabilities. A confirmed custom licence keeps its name but +/// not its text, which may come from the supplier's own contract. +/// +/// # Arguments +/// +/// * `entries` - the SBOM entries of the target's latest scan +/// * `product` - the target, the version published and the supplier +pub fn released_cyclonedx( + entries: &[SbomEntry], + product: &ReleasedProduct<'_>, +) -> serde_json::Value { + let mut doc = cdx_frame(product.name, entries); + doc["metadata"]["component"]["version"] = serde_json::json!(product.version); + doc["metadata"]["component"]["supplier"] = serde_json::json!({ "name": product.supplier }); + let components: Vec = cdx_components(entries) + .into_iter() + .map(released_component) + .collect(); + cdx_dependencies(&mut doc, &components); + doc["components"] = serde_json::Value::Array(components); + doc +} + +/// `component` with only [`RELEASED_COMPONENT_KEYS`], and no licence text. +fn released_component(mut component: serde_json::Value) -> serde_json::Value { + if let Some(fields) = component.as_object_mut() { + fields.retain(|key, _| RELEASED_COMPONENT_KEYS.contains(&key.as_str())); + let licenses = fields + .get_mut("licenses") + .and_then(serde_json::Value::as_array_mut); + for choice in licenses.into_iter().flatten() { + if let Some(license) = choice + .get_mut("license") + .and_then(serde_json::Value::as_object_mut) + { + license.remove("text"); + } + } + } + component +} + /// The known vulnerabilities of `entries` as the document's /// `vulnerabilities`: one per CVE (or advisory without one), affecting every /// component it was found in, by whichever scanner and id. None, none set. @@ -677,7 +746,67 @@ pub fn spdx(entries: &[SbomEntry], subject: &str) -> serde_json::Value { #[cfg(test)] mod tests { use super::*; - use crate::models::{InImage, InImageBasis}; + use crate::models::{InImage, InImageBasis, VulnRef}; + + #[test] + fn a_released_sbom_keeps_what_identifies_each_component_and_nothing_else() { + let mut e = SbomEntry::new("t".into(), "pump-sdk".into(), "4.2".into(), "nuget".into()); + e.purl = Some("pkg:nuget/pump-sdk@4.2".into()); + e.cpe = Some("cpe:2.3:a:example:pump-sdk:4.2:*:*:*:*:*:*:*".into()); + e.hashes = vec![ComponentHash { + alg: "SHA-256".into(), + content: "ab".repeat(32), + }]; + e.download_url = Some("https://internal.example/feed/pump-sdk.4.2.nupkg".into()); + e.manufacturer_url = Some("https://example.com".into()); + e.concluded = Some(concluded("LicenseRef-Pump-EULA", Some("Pump EULA"))); + e.in_image = Some(InImage { + basis: InImageBasis::Declared, + images: vec!["pump-image".into()], + }); + e.known_vulnerabilities = vec![VulnRef { + id: "CVE-2026-0001".into(), + source: "osv".into(), + severity: Some("HIGH".into()), + url: None, + exploitation: None, + aliases: Vec::new(), + }]; + let product = ReleasedProduct { + name: "DR-4 Firmware", + version: "1.4.0", + supplier: "Test Antriebstechnik", + }; + + let doc = released_cyclonedx(std::slice::from_ref(&e), &product); + + let meta = &doc["metadata"]["component"]; + assert_eq!(meta["name"], "DR-4 Firmware"); + assert_eq!(meta["version"], "1.4.0"); + assert_eq!(meta["supplier"]["name"], "Test Antriebstechnik"); + assert!(doc.get("vulnerabilities").is_none(), "{doc}"); + let component = doc["components"][0].as_object().unwrap(); + let mut keys: Vec<&str> = component.keys().map(String::as_str).collect(); + keys.sort_unstable(); + assert_eq!( + keys, + ["bom-ref", "cpe", "hashes", "licenses", "name", "purl", "type", "version"], + "nothing beyond identity, licences and hashes" + ); + assert_eq!(component["licenses"][0]["license"]["name"], "Pump EULA"); + assert!(component["licenses"][0]["license"].get("text").is_none()); + let text = doc.to_string(); + for leaked in [ + "internal.example", + "pump-image", + "contract 4711", + "CVE-2026-0001", + ] { + assert!(!text.contains(leaked), "{leaked} crossed: {text}"); + } + // The product still depends on its component. + assert_eq!(doc["dependencies"][0]["dependsOn"][0], component["bom-ref"]); + } #[test] fn both_formats_list_every_component() { diff --git a/compliance-core/tests/released_sbom.rs b/compliance-core/tests/released_sbom.rs new file mode 100644 index 0000000..7dad332 --- /dev/null +++ b/compliance-core/tests/released_sbom.rs @@ -0,0 +1,37 @@ +//! The SBOM a supplier workspace releases to a customer workspace (#1028): +//! valid against CycloneDX 1.6. + +#![allow(clippy::expect_used, clippy::unwrap_used)] + +mod common; + +use compliance_core::models::{ComponentHash, SbomEntry}; +use compliance_core::sbom_docs::{self, ReleasedProduct}; + +#[test] +fn a_released_sbom_is_valid_cyclonedx() { + let mut sdk = SbomEntry::new("t".into(), "pump-sdk".into(), "4.2".into(), "nuget".into()); + sdk.purl = Some("pkg:nuget/pump-sdk@4.2".into()); + sdk.license = Some("MIT".into()); + sdk.hashes = vec![ComponentHash { + alg: "SHA-256".into(), + content: "ab".repeat(32), + }]; + // No purl: listed by its name and version. + let blob = SbomEntry::new( + "t".into(), + "vendor-blob".into(), + "7".into(), + "supplier".into(), + ); + let product = ReleasedProduct { + name: "DR-4 Firmware", + version: "1.4.0", + supplier: "Test Antriebstechnik", + }; + + let doc = sbom_docs::released_cyclonedx(&[sdk, blob], &product); + + assert_eq!(common::cyclonedx_errors(&doc), Vec::::new()); + assert_eq!(doc["components"].as_array().unwrap().len(), 2); +}