From dc9ca8dcd8fd1f260a1f317d4acbe467be53aa5c Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Tue, 6 Oct 2026 16:13:58 +0000 Subject: [PATCH] fix(plc): CVE alerts of PLC targets resolve, their issues sync (#519) --- compliance-agent/src/pipeline/orchestrator.rs | 32 +++++++++++++++++-- docs/guide/plc.md | 5 +++ .../release/staging-test-plan-after-v0.4.5.md | 22 +++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index bbc79ca..286e594 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -1288,7 +1288,7 @@ impl PipelineOrchestrator { if !all_sbom.is_empty() { if let Err(e) = self - .persist_control_app_sbom(target_id, scan_run_id, &target.name, all_sbom) + .persist_control_app_sbom(target, target_id, scan_run_id, all_sbom) .await { tracing::warn!(target_id, error = %e, "control-app SBOM persist failed"); @@ -1448,9 +1448,9 @@ impl PipelineOrchestrator { /// this is where PLC-device CVE coverage comes from. async fn persist_control_app_sbom( &self, + target: &OnboardedTarget, target_id: &str, scan_run_id: &str, - target_name: &str, mut entries: Vec, ) -> Result<(), AgentError> { if entries.is_empty() { @@ -1468,6 +1468,9 @@ impl PipelineOrchestrator { k.expose_secret().to_string() }), )?; + // Whether both lookups covered every component: only then are the + // alerts they no longer report gone (as in the code pipeline). + let mut complete = true; let mut alerts = match tokio::time::timeout( std::time::Duration::from_secs(600), cve_scanner.scan_dependencies(target_id, &mut entries), @@ -1475,18 +1478,21 @@ impl PipelineOrchestrator { .await { Ok(Ok(lookup)) => { + complete &= lookup.unchecked.is_empty(); self.record_osv_unchecked(scan_run_id, &lookup.unchecked) .await; lookup.alerts } Ok(Err(e)) => { tracing::warn!(target_id, error = %e, "control-app CVE scan failed"); + complete = false; 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"); + complete = false; self.record_cve_gap( scan_run_id, "OSV", @@ -1507,6 +1513,7 @@ impl PipelineOrchestrator { Ok(lookup) => { alerts.extend(lookup.alerts); if !lookup.unchecked.is_empty() { + complete = false; self.record_cve_gap( scan_run_id, &format!("NVD: {}", lookup.unchecked.join(", ")), @@ -1517,6 +1524,7 @@ impl PipelineOrchestrator { } Err(_) => { tracing::warn!(target_id, "CODESYS CVE match timed out"); + complete = false; self.record_cve_gap( scan_run_id, "NVD", @@ -1543,8 +1551,26 @@ impl PipelineOrchestrator { } } let new_notifs = self - .persist_cve_alerts(target_id, target_name, &alerts) + .persist_cve_alerts(target_id, &target.name, &alerts) .await?; + // What the code pipeline does at its end: a complete lookup resolves + // the alerts it no longer reports, and a managed repository's CVE + // issues follow. + if let Err(e) = + crate::pipeline::vex_lifecycle::resolve_gone(&self.db, target_id, &alerts, complete) + .await + { + tracing::warn!(target_id, "Marking resolved CVE alerts failed: {e}"); + } + if let Some(code) = target.code_artifact() { + let repo = RepoView::from_target(target, code, &self.secrets); + if let Err(e) = self + .sync_cve_issues(&repo, target_id, &alerts, complete) + .await + { + tracing::warn!(target_id, "CVE issue sync failed: {e}"); + } + } tracing::info!( target_id, components = entries.len(), diff --git a/docs/guide/plc.md b/docs/guide/plc.md index 6afd985..79566fc 100644 --- a/docs/guide/plc.md +++ b/docs/guide/plc.md @@ -144,6 +144,11 @@ guard-aware), cleartext/insecure communication (CWE-319), insecure protocol port The **SBOM** view lists the CODESYS libraries (`pkg:codesys/@`) and the runtime; matching runtime components (e.g. the `Cmp*` / `3SLicense` libraries) surface real CODESYS advisories as CVE alerts. +A CVE alert a later scan no longer finds (the project now references a fixed +runtime or library version) is marked resolved, and its VEX status becomes +`fixed`, as for code targets; this needs both lookups (OSV and NVD) to have +covered every component. For a PLC project in a managed Git repository, the CVE +issues in the repository follow, as for code. ## Dynamic testing — ICS protocol probe diff --git a/docs/release/staging-test-plan-after-v0.4.5.md b/docs/release/staging-test-plan-after-v0.4.5.md index 32be563..b8d393f 100644 --- a/docs/release/staging-test-plan-after-v0.4.5.md +++ b/docs/release/staging-test-plan-after-v0.4.5.md @@ -33,6 +33,7 @@ together on stage in one pass before the next prod promotion. | #498 (4/4) | Draft ENISA notifications (CRA Art. 14) for actively exploited vulnerabilities | | #498 (follow-up) | ENISA deadlines evaluated by the agent; one notification per CVE | | #516 | Secret scanning with Betterleaks instead of gitleaks | +| PLC CVE fix | CVE alerts of PLC targets resolve; their issues sync | **Customer-visible on the next prod rescan** is marked **[visible]**: these change what a customer sees on their existing targets, without them doing @@ -724,6 +725,27 @@ Use the log4j target of check 31. - **[visible]** more secret findings on some targets (new Betterleaks rules); a few existing ones show another rule name. +### 34. PLC targets: CVE alerts resolve and their issues sync + +Before, a PLC target's CVE alerts were never marked resolved and never +created or closed issues in a managed repository. + +- **Do:** upload `fixtures/nightly/plc/line_control.projectarchive` (CODESYS + Control for Linux SL 3.5.16.0, many CODESYS CVEs) as a PLC target; then + edit the archive so the device descriptor names a newer runtime (e.g. + `3.5.22.40`), re-upload, rescan. **Expect:** the CVEs fixed before + 3.5.22.40 are marked resolved with VEX status `fixed` (by the scan); a + person's `not_affected` stays. Log: `CVE alerts no longer found marked + resolved`. +- **Do:** make the NVD lookup fail (e.g. block `services.nvd.nist.gov`) + and rescan. **Expect:** nothing is resolved (the lookup was incomplete), + and the scan run lists the CVE gap. +- **Do:** a PLC project in a managed Gitea repository with critical/high + CODESYS CVEs. **Expect:** CVE issues are created in the repository, and + closed once the runtime is updated. +- **[visible]** PLC targets' fixed CVEs leave the open list after the next + rescan; managed PLC repositories get CVE issues. + ## After the pass - The nightly job on `main` is green with the new mobile targets.