From e09c0d0a9d8cc5bc72113da5f53fb49e8530078a Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Sat, 26 Sep 2026 10:41:34 +0000 Subject: [PATCH] fix(scan): skipped stages name a file or tool, never a server path (#413) --- compliance-agent/src/ingest/mod.rs | 43 +++-- .../src/pipeline/firmware_sbom.rs | 71 +++++--- compliance-agent/src/pipeline/graph_build.rs | 3 +- compliance-agent/src/pipeline/orchestrator.rs | 168 +++++++++++------- compliance-core/src/models/mod.rs | 2 +- compliance-core/src/models/scan.rs | 79 +++++++- .../src/components/scan_runs.rs | 2 +- compliance-dashboard/src/i18n/texts.rs | 146 ++++++++++++++- 8 files changed, 405 insertions(+), 109 deletions(-) diff --git a/compliance-agent/src/ingest/mod.rs b/compliance-agent/src/ingest/mod.rs index 3da46ec..56b3bfb 100644 --- a/compliance-agent/src/ingest/mod.rs +++ b/compliance-agent/src/ingest/mod.rs @@ -12,7 +12,9 @@ pub(crate) mod blob; use std::collections::HashMap; use std::path::{Path, PathBuf}; -use compliance_core::models::{Artifact, ArtifactKind, DetectedFact, OnboardedTarget}; +use compliance_core::models::{ + Artifact, ArtifactKind, DetectedFact, OnboardedTarget, SkipCode, SkippedStage, +}; use compliance_core::{AgentConfig, NetGuard}; use crate::error::AgentError; @@ -89,14 +91,29 @@ pub struct IngestFailure { } impl IngestFailure { - /// The skipped-stage id to record it under: a missing or wrong archive - /// password has its own, so the dashboard can say what to do. - pub fn stage(&self) -> &'static str { - match self.error { - AgentError::ArchivePasswordRequired => "archive_password_required", - AgentError::ArchivePasswordWrong => "archive_password_wrong", - _ => "ingest", - } + /// The skipped stage to record: a missing or wrong archive password has + /// its own, so the dashboard can say what to do. Any other error stays in + /// the log; the run names only the artifact, never a server path. + pub fn skipped(&self) -> SkippedStage { + let name = self.artifact_name.as_str(); + let stage = match self.error { + AgentError::ArchivePasswordRequired => SkippedStage::new( + "archive_password_required", + SkipCode::ArchivePasswordRequired, + format!("{name} is password-protected and no password is set"), + ), + AgentError::ArchivePasswordWrong => SkippedStage::new( + "archive_password_wrong", + SkipCode::ArchivePasswordWrong, + format!("the stored password does not open {name}"), + ), + _ => SkippedStage::new( + "ingest", + SkipCode::ArtifactNotIngested, + format!("{name} could not be read"), + ), + }; + stage.about(name) } } @@ -695,8 +712,12 @@ mod tests { assert_eq!(set.by_artifact.len(), 1, "the URL is still ingested"); assert_eq!(set.failures.len(), 1); - assert_eq!(set.failures[0].stage(), "archive_password_required"); - assert_eq!(set.failures[0].artifact_name, "locked.zip"); + let skipped = set.failures[0].skipped(); + assert_eq!(skipped.stage, "archive_password_required"); + assert_eq!(skipped.code, Some(SkipCode::ArchivePasswordRequired)); + // The run names the file, never where it is stored. + assert_eq!(skipped.subject.as_deref(), Some("locked.zip")); + assert!(!skipped.reason.contains('/'), "{}", skipped.reason); } #[test] diff --git a/compliance-agent/src/pipeline/firmware_sbom.rs b/compliance-agent/src/pipeline/firmware_sbom.rs index abee013..9f6fee4 100644 --- a/compliance-agent/src/pipeline/firmware_sbom.rs +++ b/compliance-agent/src/pipeline/firmware_sbom.rs @@ -14,7 +14,7 @@ use std::path::Path; -use compliance_core::models::{SbomEntry, TargetType}; +use compliance_core::models::{SbomEntry, SkipCode, SkippedStage, TargetType}; use compliance_core::ExecPolicy; use firmwerk_repro::ReproBackend; use firmwerk_sbom::ComponentKind; @@ -24,6 +24,9 @@ use firmwerk_sbom::ComponentKind; /// wipes the other's entries. pub const FIRMWARE_MANAGERS: [&str; 3] = ["firmware", "library", "toolchain"]; +/// The scan run's stage id for the firmware SBOM. +const STAGE: &str = "firmware_sbom"; + /// Whether firmware SBOM applies to this target family. pub fn is_firmware_target(target_type: TargetType) -> bool { matches!( @@ -38,13 +41,13 @@ pub fn is_firmware_target(target_type: TargetType) -> bool { /// # Errors /// /// Why no firmware SBOM could be formed (no supported build system, a failed -/// analysis, a timeout), for recording on the scan run instead of completing -/// as if the firmware simply had no components. +/// analysis, a timeout), as the skipped stage to record on the scan run +/// instead of completing as if the firmware simply had no components. pub async fn firmware_sbom_entries( path: &Path, repo_id: &str, exec: ExecPolicy, -) -> Result, String> { +) -> Result, SkippedStage> { let p = path.to_path_buf(); let repo = repo_id.to_string(); let allow_build = exec.untrusted_code_allowed(); @@ -56,33 +59,47 @@ pub async fn firmware_sbom_entries( Ok(Ok(result)) => result, Ok(Err(e)) => { tracing::warn!(repo_id, error = %e, "Firmware SBOM: task join error"); - Err(format!("firmware analysis stopped unexpectedly: {e}")) + Err(gap( + SkipCode::FirmwareSbomFailed, + "firmware analysis stopped unexpectedly", + )) } Err(_) => { tracing::warn!(repo_id, "Firmware SBOM: build exceeded 15m; skipping"); - Err("firmware analysis took longer than 15 minutes".to_string()) + Err(gap( + SkipCode::FirmwareSbomFailed, + "firmware analysis took longer than 15 minutes", + )) } } } +/// A firmware SBOM that could not be formed, as the scan run records it. +fn gap(code: SkipCode, reason: &str) -> SkippedStage { + SkippedStage::new(STAGE, code, reason) +} + fn build_sbom_blocking( path: &Path, repo_id: &str, allow_build: bool, -) -> Result, String> { +) -> Result, SkippedStage> { let repo = firmwerk_core::Repo::new(path); let plan = match firmwerk_core::provider::analyze(&repo) { Ok(Some(bp)) => bp, Ok(None) => { - return Err( + return Err(gap( + SkipCode::FirmwareBuildUnknown, "no supported firmware build system found (Make, CMake, Zephyr, ESP-IDF, \ - PlatformIO, Arduino, embedded Rust, or recognisable SDK headers)" - .to_string(), - ) + PlatformIO, Arduino, embedded Rust, or recognisable SDK headers)", + )) } Err(e) => { tracing::warn!(repo_id, error = %e, "Firmware SBOM: firmwerk analyze failed"); - return Err(format!("firmware analysis failed: {e}")); + return Err(gap( + SkipCode::FirmwareSbomFailed, + "firmware analysis failed", + )); } }; @@ -130,11 +147,15 @@ fn build_sbom_blocking( if entries.is_empty() { // Detection worked but nothing resolved without a build: say so, so an // empty SBOM is not read as "this firmware has no components". - return Err(format!( - "{} build detected, but no components could be resolved without building it; \ - import a Firmwerk bundle for a complete firmware SBOM", - plan.provider - )); + return Err(gap( + SkipCode::FirmwareUnresolved, + &format!( + "{} build detected, but no components could be resolved without building it; \ + import a Firmwerk bundle for a complete firmware SBOM", + plan.provider + ), + ) + .about(plan.provider.to_string())); } Ok(entries) } @@ -196,12 +217,18 @@ mod tests { #[tokio::test] async fn a_tree_without_a_supported_build_system_says_why() { - let reason = firmware_sbom_entries(&fixture("yocto-layer"), "t", ExecPolicy::default()) - .await - .expect_err("a Yocto layer forms no build plan"); + let Err(skipped) = + firmware_sbom_entries(&fixture("yocto-layer"), "t", ExecPolicy::default()).await + else { + panic!("a Yocto layer forms no build plan"); + }; + assert_eq!(skipped.code, Some(SkipCode::FirmwareBuildUnknown)); assert!( - reason.contains("no supported firmware build system"), - "{reason}" + skipped + .reason + .contains("no supported firmware build system"), + "{}", + skipped.reason ); } diff --git a/compliance-agent/src/pipeline/graph_build.rs b/compliance-agent/src/pipeline/graph_build.rs index 7106a02..2cbd99c 100644 --- a/compliance-agent/src/pipeline/graph_build.rs +++ b/compliance-agent/src/pipeline/graph_build.rs @@ -69,8 +69,7 @@ impl PipelineOrchestrator { if self.source_only() { self.skip_stage( scan_run_id, - "dast", - compliance_core::models::SkippedStage::FEATURE_DISABLED, + compliance_core::models::SkippedStage::feature_disabled("dast"), ) .await; return; diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index af1ddef..a86bcad 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -91,10 +91,18 @@ impl PipelineOrchestrator { // Submodules are part of what the product ships (a HAL, an RTOS). let skipped = git_ops.update_submodules(&repo_path, &repo.git_url); if !skipped.is_empty() { + let names: Vec<&str> = skipped + .iter() + .filter_map(|line| line.split([' ', ':']).next()) + .collect(); self.skip_stage( scan_run_id, - "git_submodules", - &format!("not checked out, so not scanned: {}", skipped.join("; ")), + SkippedStage::new( + "git_submodules", + SkipCode::SubmodulesNotFetched, + format!("not checked out, so not scanned: {}", skipped.join("; ")), + ) + .about(names.join(", ")), ) .await; } @@ -139,12 +147,16 @@ impl PipelineOrchestrator { if !vendor.is_empty() { self.skip_stage( scan_run_id, - "sast_vendor_code", - &format!( - "vendor and third-party code is not analysed for SAST findings: {}; \ - it is still covered by the SBOM", - vendor.join(", ") - ), + SkippedStage::new( + "sast_vendor_code", + SkipCode::VendorCode, + format!( + "vendor and third-party code is not analysed for SAST findings: {}; \ + it is still covered by the SBOM", + vendor.join(", ") + ), + ) + .about(vendor.join(", ")), ) .await; } @@ -159,8 +171,8 @@ impl PipelineOrchestrator { // A failed analysis must not read as clean code. self.skip_stage( scan_run_id, - "sast", - &format!("semgrep did not complete: {e}"), + SkippedStage::new("sast", SkipCode::ToolFailed, "semgrep did not complete") + .about("semgrep"), ) .await; } @@ -178,8 +190,12 @@ impl PipelineOrchestrator { tracing::warn!("[{repo_id}] cppcheck failed: {e}"); self.skip_stage( scan_run_id, - "sast_c_cpp", - &format!("cppcheck did not complete: {e}"), + SkippedStage::new( + "sast_c_cpp", + SkipCode::ToolFailed, + "cppcheck did not complete", + ) + .about("cppcheck"), ) .await; } @@ -213,11 +229,15 @@ impl PipelineOrchestrator { for eco in crate::pipeline::sbom::unlocked_ecosystems(&repo_path) { self.skip_stage( scan_run_id, - "sbom_dependencies", - &format!( - "{} {}; {}, so the dependencies' versions (and their CVEs) are known", - eco.manifest, eco.problem, eco.remedy - ), + SkippedStage::new( + "sbom_dependencies", + SkipCode::DependenciesUnlocked, + format!( + "{} {}; {}, so the dependencies' versions (and their CVEs) are known", + eco.manifest, eco.problem, eco.remedy + ), + ) + .about(eco.manifest), ) .await; } @@ -265,13 +285,18 @@ impl PipelineOrchestrator { Ok(Ok(alerts)) => alerts, Ok(Err(e)) => { tracing::warn!("[{repo_id}] CVE scanning failed: {e}"); - self.record_cve_gap(scan_run_id, &format!("OSV: {e}")).await; + self.record_cve_gap(scan_run_id, "OSV", "the OSV lookup failed") + .await; Vec::new() } Err(_) => { tracing::warn!("[{repo_id}] CVE scanning timed out after 10 minutes"); - self.record_cve_gap(scan_run_id, "OSV: timed out after 10 minutes") - .await; + self.record_cve_gap( + scan_run_id, + "OSV", + "the OSV lookup timed out after 10 minutes", + ) + .await; Vec::new() } }; @@ -288,15 +313,20 @@ impl PipelineOrchestrator { if !lookup.unchecked.is_empty() { self.record_cve_gap( scan_run_id, - &format!("NVD, not checked: {}", lookup.unchecked.join(", ")), + &format!("NVD: {}", lookup.unchecked.join(", ")), + "these components were not matched in NVD", ) .await; } } Err(_) => { tracing::warn!("[{repo_id}] embedded-library CVE match timed out"); - self.record_cve_gap(scan_run_id, "NVD: timed out after 5 minutes") - .await; + self.record_cve_gap( + scan_run_id, + "NVD", + "the NVD lookup timed out after 5 minutes", + ) + .await; } } @@ -613,8 +643,15 @@ impl PipelineOrchestrator { // An attached artifact nothing analyses is recorded, never passed over: // a completed run must not read as "we looked and found nothing". for entry in &plan.unavailable { - self.skip_stage(scan_run_id, &entry.scan_type.to_string(), entry.reason) - .await; + self.skip_stage( + scan_run_id, + SkippedStage::new( + entry.scan_type.to_string(), + SkipCode::NotAnalysedYet, + entry.reason, + ), + ) + .await; } tracing::info!( target_id = %target_id, @@ -802,10 +839,15 @@ impl PipelineOrchestrator { crate::pipeline::plc::sbom::check_archive(std::path::Path::new(&archive)) { let name = a.display_name.as_deref().unwrap_or(&a.source_ref); + tracing::warn!(scan_run_id, archive = name, error = %e, "PLC archive not readable"); self.skip_stage( scan_run_id, - "plc_archive_sbom", - &format!("{name} is not a readable CODESYS project archive: {e}"), + SkippedStage::new( + "plc_archive_sbom", + SkipCode::ArchiveUnreadable, + format!("{name} is not a readable CODESYS project archive"), + ) + .about(name), ) .await; } @@ -886,12 +928,8 @@ impl PipelineOrchestrator { scan_run_id: &str, ) -> Result { if self.source_only() { - self.skip_stage( - scan_run_id, - "plc_runtime", - compliance_core::models::SkippedStage::FEATURE_DISABLED, - ) - .await; + self.skip_stage(scan_run_id, SkippedStage::feature_disabled("plc_runtime")) + .await; return Ok(0); } self.update_phase(scan_run_id, ScanPhase::PlcProvision) @@ -986,12 +1024,8 @@ impl PipelineOrchestrator { scan_run_id: &str, ) -> Result { if self.source_only() { - self.skip_stage( - scan_run_id, - "ics_probe", - compliance_core::models::SkippedStage::FEATURE_DISABLED, - ) - .await; + self.skip_stage(scan_run_id, SkippedStage::feature_disabled("ics_probe")) + .await; return Ok(0); } self.update_phase(scan_run_id, ScanPhase::IcsProbe).await; @@ -1062,13 +1096,18 @@ impl PipelineOrchestrator { Ok(Ok(a)) => a, Ok(Err(e)) => { tracing::warn!(target_id, error = %e, "control-app CVE scan failed"); - self.record_cve_gap(scan_run_id, &format!("OSV: {e}")).await; + self.record_cve_gap(scan_run_id, "OSV", "the OSV lookup failed") + .await; Vec::new() } Err(_) => { tracing::warn!(target_id, "control-app CVE scan timed out"); - self.record_cve_gap(scan_run_id, "OSV: timed out after 10 minutes") - .await; + self.record_cve_gap( + scan_run_id, + "OSV", + "the OSV lookup timed out after 10 minutes", + ) + .await; Vec::new() } }; @@ -1085,15 +1124,20 @@ impl PipelineOrchestrator { if !lookup.unchecked.is_empty() { self.record_cve_gap( scan_run_id, - &format!("NVD, not checked: {}", lookup.unchecked.join(", ")), + &format!("NVD: {}", lookup.unchecked.join(", ")), + "these components were not matched in NVD", ) .await; } } Err(_) => { tracing::warn!(target_id, "CODESYS CVE match timed out"); - self.record_cve_gap(scan_run_id, "NVD: timed out after 5 minutes") - .await; + self.record_cve_gap( + scan_run_id, + "NVD", + "the NVD lookup timed out after 5 minutes", + ) + .await; } } @@ -1206,12 +1250,7 @@ impl PipelineOrchestrator { // dashboard can ask for it. The others are still classified and scanned. for failure in &ingest_set.failures { tracing::warn!(target_id, artifact = %failure.artifact_id, error = %failure.error, "Unified pipeline: artifact not ingested"); - self.skip_stage( - scan_run_id, - failure.stage(), - &format!("{}: {}", failure.artifact_name, failure.error), - ) - .await; + self.skip_stage(scan_run_id, failure.skipped()).await; } let working_paths = ingest_set.working_paths(); let mut detected_firmware = false; @@ -1267,8 +1306,8 @@ impl PipelineOrchestrator { .await { Ok(entries) => entries, - Err(reason) => { - self.skip_stage(scan_run_id, "firmware_sbom", &reason).await; + Err(skipped) => { + self.skip_stage(scan_run_id, skipped).await; Vec::new() } }; @@ -1447,16 +1486,16 @@ impl PipelineOrchestrator { /// Record a stage the pipeline deliberately did not run. A skipped stage is /// not an error: the scan completes, and the dashboard shows it as skipped /// rather than failed. - pub(super) async fn skip_stage(&self, scan_run_id: &str, stage: &str, reason: &str) { - tracing::info!(scan_run_id, stage, reason, "pipeline stage skipped"); + pub(super) async fn skip_stage(&self, scan_run_id: &str, skipped: SkippedStage) { + tracing::info!( + scan_run_id, + stage = %skipped.stage, + reason = %skipped.reason, + "pipeline stage skipped" + ); let Ok(oid) = mongodb::bson::oid::ObjectId::parse_str(scan_run_id) else { return; }; - let skipped = compliance_core::models::SkippedStage { - stage: stage.to_string(), - status: "skipped".to_string(), - reason: reason.to_string(), - }; let Ok(entry) = mongodb::bson::to_bson(&skipped) else { return; }; @@ -1512,8 +1551,13 @@ impl PipelineOrchestrator { /// Record that CVE matching is incomplete for this run, and why: a lookup /// that failed must not read as components without CVEs. - async fn record_cve_gap(&self, scan_run_id: &str, reason: &str) { - self.skip_stage(scan_run_id, CVE_LOOKUP_STAGE, reason).await; + async fn record_cve_gap(&self, scan_run_id: &str, lookup: &str, reason: &str) { + self.skip_stage( + scan_run_id, + SkippedStage::new(CVE_LOOKUP_STAGE, SkipCode::CveLookupIncomplete, reason) + .about(lookup), + ) + .await; } pub(super) async fn update_phase(&self, scan_run_id: &str, phase: ScanPhase) { diff --git a/compliance-core/src/models/mod.rs b/compliance-core/src/models/mod.rs index eb15dcc..354c469 100644 --- a/compliance-core/src/models/mod.rs +++ b/compliance-core/src/models/mod.rs @@ -53,7 +53,7 @@ pub use pentest::{ }; pub use repository::ScanTrigger; pub use sbom::{SbomEntry, VulnRef}; -pub use scan::{ScanPhase, ScanRun, ScanRunStatus, ScanType, SkippedStage}; +pub use scan::{ScanPhase, ScanRun, ScanRunStatus, ScanType, SkipCode, SkippedStage}; pub use werkbank::{ CompleteRequest, CompleteResponse, DastCollect, Executor, HeartbeatAck, HeartbeatRequest, InputRef, Job, JobCollect, JobRecord, JobResult, JobRuntime, JobStatus, JobType, LeaseRequest, diff --git a/compliance-core/src/models/scan.rs b/compliance-core/src/models/scan.rs index e4ba427..0aed020 100644 --- a/compliance-core/src/models/scan.rs +++ b/compliance-core/src/models/scan.rs @@ -134,6 +134,49 @@ pub struct ScanRun { pub planned_phases: Vec, } +/// Why a stage was skipped, stable for the dashboard to word in the reader's +/// language. The stage's `reason` next to it is English prose for API +/// readers; neither ever carries a server path or a raw error (those go to +/// the log). +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] +#[serde(rename_all = "snake_case")] +pub enum SkipCode { + /// The deployment does not run this stage (e.g. DAST where only source + /// code is examined). + FeatureDisabled, + /// Git submodules could not be checked out; `subject` names them. + SubmodulesNotFetched, + /// Vendor and third-party directories left out of SAST; `subject` lists + /// them. + VendorCode, + /// An analysis tool did not complete; `subject` names it. + ToolFailed, + /// A package manifest without a lockfile; `subject` is the manifest. + DependenciesUnlocked, + /// An attached artifact no stage analyses yet (a firmware or container + /// image, a mobile package). + NotAnalysedYet, + /// A PLC project archive that could not be read; `subject` is its name. + ArchiveUnreadable, + /// An uploaded or linked artifact that could not be read; `subject` is + /// its name. + ArtifactNotIngested, + /// A password-protected archive without a password; `subject` is its name. + ArchivePasswordRequired, + /// An archive whose stored password is wrong; `subject` is its name. + ArchivePasswordWrong, + /// The firmware SBOM could not be built. + FirmwareSbomFailed, + /// No supported firmware build system was found in the sources. + FirmwareBuildUnknown, + /// A firmware build was detected, but no components resolve without + /// building it; `subject` is the build system. + FirmwareUnresolved, + /// Some components were not matched against known vulnerabilities; + /// `subject` names the lookup, and the components where known. + CveLookupIncomplete, +} + /// A pipeline stage that was planned but intentionally not executed. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct SkippedStage { @@ -141,21 +184,40 @@ pub struct SkippedStage { pub stage: String, /// Always `skipped` — present so the entry reads like a stage result. pub status: String, - /// Why it was skipped (`feature disabled`, …). + /// Why it was skipped, in English (`feature disabled`, …). pub reason: String, + /// Why, as a stable code; absent on runs recorded before codes existed. + #[serde(default)] + pub code: Option, + /// What it concerns, safe to show: a file or tool name, directories. + #[serde(default)] + pub subject: Option, } impl SkippedStage { /// The reason recorded when a deployment feature flag disables a stage. pub const FEATURE_DISABLED: &'static str = "feature disabled"; - pub fn feature_disabled(stage: impl Into) -> Self { + /// A skipped `stage`, why (`code`), and the English `reason`. + pub fn new(stage: impl Into, code: SkipCode, reason: impl Into) -> Self { Self { stage: stage.into(), status: "skipped".to_string(), - reason: Self::FEATURE_DISABLED.to_string(), + reason: reason.into(), + code: Some(code), + subject: None, } } + + /// The same, naming what it concerns. + pub fn about(mut self, subject: impl Into) -> Self { + self.subject = Some(subject.into()); + self + } + + pub fn feature_disabled(stage: impl Into) -> Self { + Self::new(stage, SkipCode::FeatureDisabled, Self::FEATURE_DISABLED) + } } impl ScanRun { @@ -192,6 +254,17 @@ mod skipped_stage_tests { let j = serde_json::to_value(&s).expect("serialize"); assert_eq!(j["stage"], "dast"); assert_eq!(j["status"], "skipped"); + assert_eq!(j["code"], "feature_disabled"); + } + + /// Runs recorded before codes existed still read. + #[test] + fn a_stage_without_a_code_still_reads() { + let s: SkippedStage = serde_json::from_value(serde_json::json!({ + "stage": "sast", "status": "skipped", "reason": "semgrep did not complete", + })) + .expect("deserialize"); + assert_eq!((s.code, s.subject), (None, None)); } /// Every phase the pipeline records must deserialize, or the run drops diff --git a/compliance-dashboard/src/components/scan_runs.rs b/compliance-dashboard/src/components/scan_runs.rs index 6bf5192..e11622a 100644 --- a/compliance-dashboard/src/components/scan_runs.rs +++ b/compliance-dashboard/src/components/scan_runs.rs @@ -160,7 +160,7 @@ fn scan_run_card(run: &ScanRun, lang: Lang) -> Element { for skipped in run.skipped_stages.iter() { li { strong { {stage_name(&skipped.stage, lang)} } - " — {skipped.reason}" + " — {scans::skipped_reason(skipped, lang)}" } } } diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index af9229e..f66f77a 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -392,12 +392,12 @@ pub mod scans { en: "Git submodules", }, "archive_password_required" => Text { - de: "Archiv-Passwort fehlt (unter „Prüfobjekte“ eingeben)", - en: "Archive password missing (enter it under Targets)", + de: "Archiv-Passwort fehlt (beim Prüfobjekt unter „Bearbeiten“ eingeben)", + en: "Archive password missing (enter it under the target's Edit)", }, "archive_password_wrong" => Text { - de: "Archiv-Passwort falsch (unter „Prüfobjekte“ ändern)", - en: "Archive password wrong (change it under Targets)", + de: "Archiv-Passwort falsch (beim Prüfobjekt unter „Bearbeiten“ ändern)", + en: "Archive password wrong (change it under the target's Edit)", }, "cve_lookup" => Text { de: "CVE-Abgleich unvollständig", @@ -463,6 +463,95 @@ pub mod scans { }; Some(text) } + + /// Why a stage was skipped, in the reader's language, from the agent's + /// stable code and the subject it names. A run recorded before codes + /// existed keeps its stored (English) reason. + pub fn skipped_reason( + skipped: &compliance_core::models::SkippedStage, + lang: super::super::Lang, + ) -> String { + use super::super::Lang; + use compliance_core::models::SkipCode; + let subject = skipped.subject.as_deref().unwrap_or_default(); + let Some(code) = skipped.code else { + return skipped.reason.clone(); + }; + match (code, lang) { + (SkipCode::FeatureDisabled, Lang::De) => "In dieser Umgebung nicht aktiviert.".into(), + (SkipCode::FeatureDisabled, Lang::En) => "Not enabled in this environment.".into(), + (SkipCode::SubmodulesNotFetched, Lang::De) => { + format!("Nicht ausgecheckt, daher nicht geprüft: {subject}") + } + (SkipCode::SubmodulesNotFetched, Lang::En) => { + format!("Not checked out, so not scanned: {subject}") + } + (SkipCode::VendorCode, Lang::De) => format!( + "Hersteller- und Fremdcode ohne Codeanalyse, in der Stückliste enthalten: {subject}" + ), + (SkipCode::VendorCode, Lang::En) => format!( + "Vendor and third-party code, left out of code analysis but in the SBOM: {subject}" + ), + (SkipCode::ToolFailed, Lang::De) => format!( + "{subject} wurde nicht fertig; was es prüft, gilt als nicht bewertet." + ), + (SkipCode::ToolFailed, Lang::En) => { + format!("{subject} did not complete; what it checks counts as not assessed.") + } + (SkipCode::DependenciesUnlocked, Lang::De) => format!( + "{subject} ohne Lockfile: Die Versionen der Abhängigkeiten und ihre CVEs sind nicht bekannt." + ), + (SkipCode::DependenciesUnlocked, Lang::En) => format!( + "{subject} without a lockfile: the dependencies' versions and their CVEs are unknown." + ), + (SkipCode::NotAnalysedYet, _) => super::coverage::reason(&skipped.reason) + .map_or_else(|| skipped.reason.clone(), |t| t.get(lang).to_string()), + (SkipCode::ArchiveUnreadable, Lang::De) => { + format!("{subject} ist kein lesbares CODESYS-Projektarchiv.") + } + (SkipCode::ArchiveUnreadable, Lang::En) => { + format!("{subject} is not a readable CODESYS project archive.") + } + (SkipCode::ArtifactNotIngested, Lang::De) => { + format!("{subject} konnte nicht gelesen werden.") + } + (SkipCode::ArtifactNotIngested, Lang::En) => format!("{subject} could not be read."), + (SkipCode::ArchivePasswordRequired, Lang::De) => { + format!("{subject} ist passwortgeschützt.") + } + (SkipCode::ArchivePasswordRequired, Lang::En) => { + format!("{subject} is password-protected.") + } + (SkipCode::ArchivePasswordWrong, Lang::De) => { + format!("Das gespeicherte Passwort öffnet {subject} nicht.") + } + (SkipCode::ArchivePasswordWrong, Lang::En) => { + format!("The stored password does not open {subject}.") + } + (SkipCode::FirmwareSbomFailed, Lang::De) => { + "Die Firmware-Stückliste konnte nicht erstellt werden.".into() + } + (SkipCode::FirmwareSbomFailed, Lang::En) => { + "The firmware SBOM could not be built.".into() + } + (SkipCode::FirmwareBuildUnknown, Lang::De) => "Kein unterstütztes Build-System gefunden \ + (Make, CMake, Zephyr, ESP-IDF, PlatformIO, Arduino, Embedded Rust)." + .into(), + (SkipCode::FirmwareBuildUnknown, Lang::En) => "No supported build system found \ + (Make, CMake, Zephyr, ESP-IDF, PlatformIO, Arduino, embedded Rust)." + .into(), + (SkipCode::FirmwareUnresolved, Lang::De) => format!( + "{subject}-Build erkannt, aber ohne Build lassen sich keine Komponenten auflösen. \ + Ein Firmwerk-Paket liefert die vollständige Stückliste." + ), + (SkipCode::FirmwareUnresolved, Lang::En) => format!( + "{subject} build detected, but no components resolve without building it. \ + A Firmwerk bundle gives the complete SBOM." + ), + (SkipCode::CveLookupIncomplete, Lang::De) => format!("Nicht abgeglichen: {subject}"), + (SkipCode::CveLookupIncomplete, Lang::En) => format!("Not matched: {subject}"), + } + } } /// The targets page. @@ -1090,10 +1179,10 @@ pub mod onboarding { }; pub const UPLOAD_FAILED_HINT: Text = Text { de: "Das Prüfobjekt wurde angelegt, aber nicht jede Datei kam an. Die Prüfung \ - wurde daher nicht gestartet. Fügen Sie die Datei unter „Prüfobjekte“ \ - erneut hinzu.", + wurde daher nicht gestartet. Fügen Sie die Datei beim Prüfobjekt unter \ + „Bearbeiten“ erneut hinzu.", en: "The target was created, but not every file arrived, so the scan was not \ - started. Add the file again under Targets.", + started. Add the file again under the target's Edit.", }; pub const DONE: Text = Text { de: "Prüfobjekt angelegt", @@ -2377,3 +2466,46 @@ mod coverage_tests { assert_eq!(reason("something new"), None); } } + +#[cfg(test)] +mod skipped_reason_tests { + use super::super::Lang; + use super::scans::skipped_reason; + use compliance_core::models::{SkipCode, SkippedStage}; + + #[test] + fn a_skipped_stage_reads_in_the_readers_language() { + let stage = SkippedStage::new( + "ingest", + SkipCode::ArtifactNotIngested, + "x could not be read", + ) + .about("firmware.zip"); + assert_eq!( + skipped_reason(&stage, Lang::De), + "firmware.zip konnte nicht gelesen werden." + ); + assert_eq!( + skipped_reason(&stage, Lang::En), + "firmware.zip could not be read." + ); + // A reason the agent took from the scan matrix is worded like the + // wizard words it. + let image = SkippedStage::new( + "firmware_static", + SkipCode::NotAnalysedYet, + "firmware images are not unpacked or analysed yet: scan the firmware sources, \ + or import a Firmwerk bundle for the image", + ); + assert!(skipped_reason(&image, Lang::De).starts_with("Firmware-Images werden noch nicht")); + } + + #[test] + fn a_run_from_before_codes_keeps_its_stored_reason() { + let old: SkippedStage = serde_json::from_value(serde_json::json!({ + "stage": "sast", "status": "skipped", "reason": "semgrep did not complete", + })) + .unwrap(); + assert_eq!(skipped_reason(&old, Lang::De), "semgrep did not complete"); + } +}