From dae80043e6466945879cdba3262b29b1aaa715ed Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Wed, 23 Sep 2026 13:37:12 +0000 Subject: [PATCH] fix(firmware): produce the firmware SBOM when detection finds firmware (#341) --- compliance-agent/src/pipeline/firmware_sbom.rs | 2 +- compliance-agent/src/pipeline/orchestrator.rs | 14 ++++++++++---- .../baselines/fw-make-onboarded-as-service.json | 10 ++++++++++ fixtures/nightly/firmware/README.md | 3 +++ fixtures/nightly/targets.json | 15 +++++++++++++++ 5 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 fixtures/nightly/baselines/fw-make-onboarded-as-service.json diff --git a/compliance-agent/src/pipeline/firmware_sbom.rs b/compliance-agent/src/pipeline/firmware_sbom.rs index 5e2591e..abee013 100644 --- a/compliance-agent/src/pipeline/firmware_sbom.rs +++ b/compliance-agent/src/pipeline/firmware_sbom.rs @@ -19,12 +19,12 @@ use compliance_core::ExecPolicy; use firmwerk_repro::ReproBackend; use firmwerk_sbom::ComponentKind; -/// Whether firmware SBOM applies to this target family. /// The `package_manager` values firmware SBOM entries use. The firmware step /// replaces exactly these, and the SBOM stage leaves them alone, so neither /// wipes the other's entries. pub const FIRMWARE_MANAGERS: [&str; 3] = ["firmware", "library", "toolchain"]; +/// Whether firmware SBOM applies to this target family. pub fn is_firmware_target(target_type: TargetType) -> bool { matches!( target_type, diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index ddbf225..21149dc 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -1134,9 +1134,8 @@ impl PipelineOrchestrator { /// Ingest the target's artifacts, classify (Firmwerk for firmware/RTOS/Yocto, /// heuristics otherwise), and store the detected classification on the target. - /// Best-effort — never fails the scan. - /// Ingest, classify and store the detected type. Returns where each artifact - /// was ingested (artifact id -> working path), so the caller scans the tree + /// Best-effort — never fails the scan. Returns where each artifact was + /// ingested (artifact id -> working path), so the caller scans the tree /// ingest already unpacked instead of unpacking it twice. async fn classify_and_store( &self, @@ -1157,6 +1156,7 @@ impl PipelineOrchestrator { } }; let working_paths = ingest_set.working_paths(); + let mut detected_firmware = false; match crate::classify::classify_target( target, &working_paths, @@ -1170,6 +1170,8 @@ impl PipelineOrchestrator { suggested = %classification.suggested, "Unified pipeline: classified target" ); + detected_firmware = + crate::pipeline::firmware_sbom::is_firmware_target(classification.suggested); if let (Some(oid), Ok(bson)) = (target.id, mongodb::bson::to_bson(&classification)) { let _ = self @@ -1192,7 +1194,11 @@ impl PipelineOrchestrator { // analysis over the already-ingested source — no build, no binary // upload. When no build plan forms (e.g. a Yocto layer), the run says // so rather than completing as if the firmware had no components. - if crate::pipeline::firmware_sbom::is_firmware_target(target.target_type) { + // What the code is decides, not only the type picked at onboarding: an + // STM32 project onboarded as "backend service" still gets its SBOM. + if detected_firmware + || crate::pipeline::firmware_sbom::is_firmware_target(target.target_type) + { if let Some(code) = target.code_artifact() { if let Some(path) = working_paths.get(&code.id) { let entries = match crate::pipeline::firmware_sbom::firmware_sbom_entries( diff --git a/fixtures/nightly/baselines/fw-make-onboarded-as-service.json b/fixtures/nightly/baselines/fw-make-onboarded-as-service.json new file mode 100644 index 0000000..2f6a7ee --- /dev/null +++ b/fixtures/nightly/baselines/fw-make-onboarded-as-service.json @@ -0,0 +1,10 @@ +{ + "scan_status": "completed", + "skipped_stages": [], + "sbom": [ + "toolchain:arm-none-eabi-gcc@" + ], + "findings": [], + "cves": [], + "registry_rules": [] +} diff --git a/fixtures/nightly/firmware/README.md b/fixtures/nightly/firmware/README.md index 9c7740b..fbed720 100644 --- a/fixtures/nightly/firmware/README.md +++ b/fixtures/nightly/firmware/README.md @@ -20,6 +20,9 @@ SBOM reads as declared dependencies (#317): | `c-sensor-node` | (ours) | Make; C/C++ SAST (#334): planted flaws in `Core/`, a vendored HAL in `Drivers/` that must not be reported | | `yocto-layer` | (ours) | none: Yocto is not analysed yet, so the scan must record it | +`make` is also onboarded as a backend service (`fw-make-onboarded-as-service`): +the firmware SBOM follows detection, not the type picked in the wizard. + 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`, diff --git a/fixtures/nightly/targets.json b/fixtures/nightly/targets.json index b0a213d..d1ea08f 100644 --- a/fixtures/nightly/targets.json +++ b/fixtures/nightly/targets.json @@ -106,6 +106,21 @@ } ] }, + { + "key": "fw-make-onboarded-as-service", + "name": "Firmware · Make, onboarded as a backend service", + "target_type": "backend_service", + "description": "The Make firmware project with the wrong type picked at onboarding: detection must still produce the firmware SBOM.", + "artifacts": [ + { + "kind": "source_archive", + "upload": "fixtures/nightly/firmware/make" + } + ], + "expect": { + "min_sbom_components": 1 + } + }, { "key": "fw-cmake", "name": "Firmware · CMake",