From 27e8c866bac212d37a03b9eda586952701cd1ee4 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Tue, 22 Sep 2026 20:34:06 +0000 Subject: [PATCH] fix(sbom): firmware SBOMs list what the manifests declare (#317) (#327) --- Cargo.lock | 63 +++++++++++++---- compliance-agent/Cargo.toml | 13 ++-- .../src/pipeline/firmware_sbom.rs | 68 ++++++++++++------- compliance-agent/src/pipeline/sbom/syft.rs | 5 +- compliance-core/src/models/sbom.rs | 6 ++ .../src/infrastructure/sbom.rs | 4 ++ compliance-dashboard/src/pages/sbom.rs | 12 +++- .../baselines/firmware-zephyr-example.json | 9 +-- .../nightly/baselines/fw-cargo-embedded.json | 2 +- fixtures/nightly/baselines/fw-espidf.json | 3 + .../nightly/baselines/fw-freertos-cmake.json | 1 + .../baselines/fw-freertos-lostbuild.json | 3 + fixtures/nightly/baselines/fw-platformio.json | 9 ++- .../baselines/fw-zephyr-example-pinned.json | 4 ++ .../nightly/baselines/fw-zephyr-pinned.json | 4 ++ fixtures/nightly/firmware/README.md | 9 ++- 16 files changed, 159 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4425fd4..c6be9bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,6 +104,12 @@ dependencies = [ "rustversion", ] +[[package]] +name = "arraydeque" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" + [[package]] name = "askama_escape" version = "0.13.0" @@ -2120,7 +2126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -2153,20 +2159,21 @@ checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "firmwerk-core" -version = "0.4.2" -source = "git+ssh://git@git.breakpilot.com:22222/platform/firmwerk.git?tag=v0.4.2#396dbd257ad02e867c4a875384a9bafd94f5ad8e" +version = "0.6.0" +source = "git+ssh://git@git.breakpilot.com:22222/platform/firmwerk.git?tag=v0.6.0#232caeb1997f900f114fcbc1c1f78036de1d7348" dependencies = [ "serde", "tempfile", "thiserror 1.0.69", "toml", "walkdir", + "yaml-rust2", ] [[package]] name = "firmwerk-repro" -version = "0.4.2" -source = "git+ssh://git@git.breakpilot.com:22222/platform/firmwerk.git?tag=v0.4.2#396dbd257ad02e867c4a875384a9bafd94f5ad8e" +version = "0.6.0" +source = "git+ssh://git@git.breakpilot.com:22222/platform/firmwerk.git?tag=v0.6.0#232caeb1997f900f114fcbc1c1f78036de1d7348" dependencies = [ "firmwerk-core", "serde", @@ -2180,8 +2187,8 @@ dependencies = [ [[package]] name = "firmwerk-sbom" -version = "0.4.2" -source = "git+ssh://git@git.breakpilot.com:22222/platform/firmwerk.git?tag=v0.4.2#396dbd257ad02e867c4a875384a9bafd94f5ad8e" +version = "0.6.0" +source = "git+ssh://git@git.breakpilot.com:22222/platform/firmwerk.git?tag=v0.6.0#232caeb1997f900f114fcbc1c1f78036de1d7348" dependencies = [ "firmwerk-core", "firmwerk-repro", @@ -2580,6 +2587,24 @@ dependencies = [ "foldhash 0.2.0", ] +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "foldhash 0.2.0", +] + +[[package]] +name = "hashlink" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a596f1b20ed2cc5ecac41a164aaebc7258057060f06c0cf7a2ba3991ee7990fb" +dependencies = [ + "hashbrown 0.17.1", +] + [[package]] name = "headers" version = "0.4.1" @@ -3755,7 +3780,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -4381,7 +4406,7 @@ dependencies = [ "once_cell", "socket2 0.5.10", "tracing", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -4742,7 +4767,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -4755,7 +4780,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -5639,10 +5664,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0" dependencies = [ "fastrand", - "getrandom 0.4.1", + "getrandom 0.3.4", "once_cell", "rustix 1.1.4", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -6782,7 +6807,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -7311,6 +7336,16 @@ dependencies = [ "lzma-sys", ] +[[package]] +name = "yaml-rust2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57e5b818a27a4cd30884ea380857a5e56f7ec3ba24a3990a3cc0b95af3238e18" +dependencies = [ + "arraydeque", + "hashlink", +] + [[package]] name = "yoke" version = "0.8.1" diff --git a/compliance-agent/Cargo.toml b/compliance-agent/Cargo.toml index b58e341..8fdd307 100644 --- a/compliance-agent/Cargo.toml +++ b/compliance-agent/Cargo.toml @@ -17,15 +17,16 @@ werkbank-exec = { path = "../werkbank-exec" } # Native firmware build/target detection for bare-metal & RTOS artifacts. # Same-company IP, used directly (not via CLI) so the whole firmwerk suite is # available to the onboarding classifier. Repo: git.breakpilot.com/platform/firmwerk; -# crates are firmwerk-* from tag v0.4.2. +# crates are firmwerk-* from tag v0.6.0 (declared-dependency SBOM, #38). # NOTE: CI must be able to fetch this # private repo (see the git-auth step in .gitea/workflows/ci.yml). -firmwerk-core = { git = "ssh://git@git.breakpilot.com:22222/platform/firmwerk.git", tag = "v0.4.2" } +firmwerk-core = { git = "ssh://git@git.breakpilot.com:22222/platform/firmwerk.git", tag = "v0.6.0" } # firmwerk-repro drives the reproducible build (NixBackend seal_and_build) that -# yields a sealed lock; `libraries_from_inputs` is the analysis-only fallback. -firmwerk-repro = { git = "ssh://git@git.breakpilot.com:22222/platform/firmwerk.git", tag = "v0.4.2" } -# firmwerk-sbom renders the bill of materials from a sealed lock (+ binary SCA). -firmwerk-sbom = { git = "ssh://git@git.breakpilot.com:22222/platform/firmwerk.git", tag = "v0.4.2" } +# yields a sealed lock. +firmwerk-repro = { git = "ssh://git@git.breakpilot.com:22222/platform/firmwerk.git", tag = "v0.6.0" } +# firmwerk-sbom renders the bill of materials from a sealed lock or, without a +# build, from the analysed plan (+ binary SCA). +firmwerk-sbom = { git = "ssh://git@git.breakpilot.com:22222/platform/firmwerk.git", tag = "v0.6.0" } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } diff --git a/compliance-agent/src/pipeline/firmware_sbom.rs b/compliance-agent/src/pipeline/firmware_sbom.rs index 6c918ab..5e2591e 100644 --- a/compliance-agent/src/pipeline/firmware_sbom.rs +++ b/compliance-agent/src/pipeline/firmware_sbom.rs @@ -169,34 +169,18 @@ fn component_to_entry(c: &firmwerk_sbom::Component, repo_id: &str) -> SbomEntry c.version.clone().unwrap_or_default(), manager.to_string(), ); - entry.purl = c.source.clone(); + entry.purl = c.purl.clone().or_else(|| c.source.clone()); + // A manifest that declares a range pins no version; carrying the requirement keeps the row + // honest instead of showing an empty version with no reason. + entry.version_requirement = c.declared.as_ref().and_then(|d| d.requirement.clone()); entry } -/// Analysis-only components from the build plan: the cross-toolchain plus the -/// resolvable fetched libraries, without a build. +/// Analysis-only components from the build plan, without a build: the cross-toolchain, the +/// dependencies the project's manifests declare, and the libraries detection identified in the +/// source. Firmwerk renders it into the same model as a sealed build, so both read the same way. fn analysis_entries(bp: &firmwerk_core::BuildPlan, repo_id: &str) -> Vec { - let mut entries = Vec::new(); - if let Some(id) = bp.toolchain.id.clone() { - let version = bp.toolchain.version.clone().unwrap_or_default(); - entries.push(SbomEntry::new( - repo_id.to_string(), - id, - version, - "toolchain".to_string(), - )); - } - for lib in firmwerk_repro::lock::libraries_from_inputs(&bp.inputs) { - let mut entry = SbomEntry::new( - repo_id.to_string(), - lib.name, - lib.revision, - "library".to_string(), - ); - entry.purl = lib.source; - entries.push(entry); - } - entries + sbom_to_entries(&firmwerk_sbom::Sbom::from_plan(bp, repo_id), repo_id) } #[cfg(test)] @@ -221,6 +205,42 @@ mod tests { ); } + #[tokio::test] + async fn a_zephyr_app_lists_what_its_west_manifest_declares() { + let entries = firmware_sbom_entries(&fixture("zephyr-pinned"), "t", ExecPolicy::default()) + .await + .expect("a west manifest forms a build plan"); + let find = |name: &str| entries.iter().find(|e| e.name == name); + let zephyr = find("zephyr").expect("zephyr itself is a component"); + assert_eq!(zephyr.version, "v3.6.0"); + assert_eq!( + zephyr.purl.as_deref(), + Some("pkg:github/zephyrproject-rtos/zephyr@v3.6.0") + ); + // An imported module is named even though its revision lives in zephyr's own manifest. + assert!(find("cmsis").is_some(), "{entries:?}"); + } + + #[tokio::test] + async fn a_declared_range_is_a_requirement_not_a_version() { + let entries = firmware_sbom_entries(&fixture("espidf"), "t", ExecPolicy::default()) + .await + .expect("an esp-idf project forms a build plan"); + let mdns = entries + .iter() + .find(|e| e.name == "espressif/mdns") + .expect("a declared component"); + assert_eq!(mdns.version, ""); + assert_eq!(mdns.version_requirement.as_deref(), Some("^1.2.0")); + // A pinned one carries its version. + let led = entries + .iter() + .find(|e| e.name == "espressif/led_strip") + .expect("a pinned component"); + assert_eq!(led.version, "2.5.3"); + assert_eq!(led.version_requirement, None); + } + #[tokio::test] async fn a_make_project_yields_its_toolchain() { let entries = firmware_sbom_entries(&fixture("make"), "t", ExecPolicy::default()) diff --git a/compliance-agent/src/pipeline/sbom/syft.rs b/compliance-agent/src/pipeline/sbom/syft.rs index aba1f1b..63d4ce5 100644 --- a/compliance-agent/src/pipeline/sbom/syft.rs +++ b/compliance-agent/src/pipeline/sbom/syft.rs @@ -39,6 +39,10 @@ pub(super) async fn run_syft(repo_path: &Path, repo_id: &str) -> Result, #[serde(rename = "type")] - #[allow(dead_code)] component_type: Option, purl: Option, licenses: Option>, diff --git a/compliance-core/src/models/sbom.rs b/compliance-core/src/models/sbom.rs index 2bc015c..e3ceb41 100644 --- a/compliance-core/src/models/sbom.rs +++ b/compliance-core/src/models/sbom.rs @@ -17,6 +17,11 @@ pub struct SbomEntry { pub name: String, pub version: String, pub package_manager: String, + /// The version requirement a manifest declares where it pins no exact version (`^1.2.0`, + /// `>=5.1.2`, a branch). Kept apart from `version`, which CVE matching joins on: a range must + /// never be read as the version in use. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub version_requirement: Option, pub license: Option, pub purl: Option, pub known_vulnerabilities: Vec, @@ -35,6 +40,7 @@ impl SbomEntry { name, version, package_manager, + version_requirement: None, license: None, purl: None, known_vulnerabilities: Vec::new(), diff --git a/compliance-dashboard/src/infrastructure/sbom.rs b/compliance-dashboard/src/infrastructure/sbom.rs index 2ed8532..9f5675b 100644 --- a/compliance-dashboard/src/infrastructure/sbom.rs +++ b/compliance-dashboard/src/infrastructure/sbom.rs @@ -19,6 +19,10 @@ pub struct SbomEntryData { pub name: String, pub version: String, pub package_manager: String, + /// What a manifest asks for where it pins no version (`^1.2.0`, a branch), shown instead of + /// an empty version cell. + #[serde(default)] + pub version_requirement: Option, pub license: Option, pub purl: Option, #[serde(default)] diff --git a/compliance-dashboard/src/pages/sbom.rs b/compliance-dashboard/src/pages/sbom.rs index bd1f6f7..43e6fb0 100644 --- a/compliance-dashboard/src/pages/sbom.rs +++ b/compliance-dashboard/src/pages/sbom.rs @@ -273,7 +273,7 @@ pub fn SbomPage() -> Element { } td { style: "font-family: var(--font-mono, monospace); font-size: 13px;", - "{entry.version}" + "{version_label(&entry)}" } td { "{entry.package_manager}" } td { @@ -650,6 +650,16 @@ fn pm_display_name(pm: &str) -> &str { } } +/// What to show in the version column. A dependency a manifest declares as a range (or a branch) +/// has no version to pin a CVE to, so the requirement is shown as such rather than an empty cell. +fn version_label(entry: &SbomEntryData) -> String { + match (entry.version.as_str(), entry.version_requirement.as_deref()) { + ("", Some(requirement)) => format!("{requirement} (declared)"), + ("", None) => "-".to_string(), + (version, _) => version.to_string(), + } +} + fn license_css_class(license: Option<&str>) -> &'static str { match license { Some(l) => { diff --git a/fixtures/nightly/baselines/firmware-zephyr-example.json b/fixtures/nightly/baselines/firmware-zephyr-example.json index ddfb3d3..2ffced7 100644 --- a/fixtures/nightly/baselines/firmware-zephyr-example.json +++ b/fixtures/nightly/baselines/firmware-zephyr-example.json @@ -12,10 +12,11 @@ "github:actions/upload-pages-artifact@v5.0.0", "github:zephyrproject-rtos/action-dco@v1.0.0", "github:zephyrproject-rtos/action-zephyr-setup@v1.0.15", - "toolchain:zephyr-sdk@", - "unknown:/tmp/compliance-scanner/repos/dev/Demo___Firmware_RTOS___Zephyr_example-application/.github/workflows/build.yml@unknown", - "unknown:/tmp/compliance-scanner/repos/dev/Demo___Firmware_RTOS___Zephyr_example-application/.github/workflows/dco.yml@unknown", - "unknown:/tmp/compliance-scanner/repos/dev/Demo___Firmware_RTOS___Zephyr_example-application/.github/workflows/docs.yml@unknown" + "library:cmsis_6@", + "library:hal_nordic@", + "library:hal_stm32@", + "library:zephyr@", + "toolchain:zephyr-sdk@" ], "findings": [], "cves": [], diff --git a/fixtures/nightly/baselines/fw-cargo-embedded.json b/fixtures/nightly/baselines/fw-cargo-embedded.json index a2672c2..6102d80 100644 --- a/fixtures/nightly/baselines/fw-cargo-embedded.json +++ b/fixtures/nightly/baselines/fw-cargo-embedded.json @@ -4,7 +4,7 @@ "code_scan" ], "sbom": [ - "toolchain:rustc@" + "toolchain:rustc@1.82.0" ], "findings": [], "cves": [], diff --git a/fixtures/nightly/baselines/fw-espidf.json b/fixtures/nightly/baselines/fw-espidf.json index 4e46861..2c17451 100644 --- a/fixtures/nightly/baselines/fw-espidf.json +++ b/fixtures/nightly/baselines/fw-espidf.json @@ -4,6 +4,9 @@ "code_scan" ], "sbom": [ + "library:esp-idf@", + "library:espressif/led_strip@2.5.3", + "library:espressif/mdns@", "toolchain:esp-idf-toolchain@" ], "findings": [], diff --git a/fixtures/nightly/baselines/fw-freertos-cmake.json b/fixtures/nightly/baselines/fw-freertos-cmake.json index 4efc5ed..5d76ec9 100644 --- a/fixtures/nightly/baselines/fw-freertos-cmake.json +++ b/fixtures/nightly/baselines/fw-freertos-cmake.json @@ -4,6 +4,7 @@ "code_scan" ], "sbom": [ + "library:freertos_kernel@V11.1.0", "toolchain:arm-none-eabi-gcc@" ], "findings": [], diff --git a/fixtures/nightly/baselines/fw-freertos-lostbuild.json b/fixtures/nightly/baselines/fw-freertos-lostbuild.json index 4efc5ed..8e649e4 100644 --- a/fixtures/nightly/baselines/fw-freertos-lostbuild.json +++ b/fixtures/nightly/baselines/fw-freertos-lostbuild.json @@ -4,6 +4,9 @@ "code_scan" ], "sbom": [ + "library:ARM CMSIS Core@", + "library:FreeRTOS@", + "library:STM32 HAL/CMSIS@", "toolchain:arm-none-eabi-gcc@" ], "findings": [], diff --git a/fixtures/nightly/baselines/fw-platformio.json b/fixtures/nightly/baselines/fw-platformio.json index a193803..1d3e4ca 100644 --- a/fixtures/nightly/baselines/fw-platformio.json +++ b/fixtures/nightly/baselines/fw-platformio.json @@ -1,10 +1,13 @@ { "scan_status": "completed", "skipped_stages": [ - "code_scan", - "firmware_sbom" + "code_scan" + ], + "sbom": [ + "library:bblanchon/ArduinoJson@7.0.4", + "library:espressif32@6.5.0", + "library:knolleary/PubSubClient@2.8" ], - "sbom": [], "findings": [], "cves": [], "registry_rules": [] diff --git a/fixtures/nightly/baselines/fw-zephyr-example-pinned.json b/fixtures/nightly/baselines/fw-zephyr-example-pinned.json index 4c850a9..200f568 100644 --- a/fixtures/nightly/baselines/fw-zephyr-example-pinned.json +++ b/fixtures/nightly/baselines/fw-zephyr-example-pinned.json @@ -4,6 +4,10 @@ "code_scan" ], "sbom": [ + "library:cmsis_6@", + "library:hal_nordic@", + "library:hal_stm32@", + "library:zephyr@", "toolchain:zephyr-sdk@" ], "findings": [], diff --git a/fixtures/nightly/baselines/fw-zephyr-pinned.json b/fixtures/nightly/baselines/fw-zephyr-pinned.json index 4c850a9..769fafe 100644 --- a/fixtures/nightly/baselines/fw-zephyr-pinned.json +++ b/fixtures/nightly/baselines/fw-zephyr-pinned.json @@ -4,6 +4,10 @@ "code_scan" ], "sbom": [ + "library:cmsis@", + "library:hal_nordic@", + "library:mbedtls@", + "library:zephyr@v3.6.0", "toolchain:zephyr-sdk@" ], "findings": [], diff --git a/fixtures/nightly/firmware/README.md b/fixtures/nightly/firmware/README.md index c396841..8517cdb 100644 --- a/fixtures/nightly/firmware/README.md +++ b/fixtures/nightly/firmware/README.md @@ -3,8 +3,8 @@ Each directory is uploaded as a source archive (the harness zips it) and exercises one Firmwerk build-system provider. Most are copied from Firmwerk's own provider tests (`crates/firmwerk-core/tests/fixtures`, Firmwerk v0.4.2), -extended with the manifests a real project carries (marked "+"), so the -baselines show when those start to reach the SBOM (#317): +extended with the manifests a real project carries (marked "+"), which the +SBOM reads as declared dependencies (#317): | Directory | Firmwerk fixture | Provider | |---|---|---| @@ -20,3 +20,8 @@ baselines show when those start to reach the SBOM (#317): | `yocto-layer` | (ours) | none: Yocto is not analysed yet, so the scan must record it | When Firmwerk's detection changes on purpose, refresh the copy and re-bless. + +The baselines record what each manifest declares (`library:zephyr@v3.6.0`, +`library:espressif/led_strip@2.5.3`) and, where a manifest gives a range +instead of a version, the row carries the requirement rather than a version a +CVE could be matched against.