From 89ad1b0d4be28bac8315917b8638021888f81515 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:48:39 +0200 Subject: [PATCH] fix(malware): an unreachable or silent clamd is logged as an error On stage clamd was down for a day and the only trace was WARN lines, so the "ERROR/FATAL logs" alert never fired. Unreachable and timed-out clamd now log at ERROR; a refused file or an unreadable tree stays a warning. The scan run still records the malware stage as skipped, as before. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- compliance-agent/src/pipeline/clamav.rs | 22 +++++++++++++++++++ compliance-agent/src/pipeline/orchestrator.rs | 6 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/compliance-agent/src/pipeline/clamav.rs b/compliance-agent/src/pipeline/clamav.rs index 3122dd3..863eb23 100644 --- a/compliance-agent/src/pipeline/clamav.rs +++ b/compliance-agent/src/pipeline/clamav.rs @@ -69,6 +69,18 @@ pub enum ClamavError { Io(#[from] std::io::Error), } +impl ClamavError { + /// True when the clamd service itself is down (unreachable or silent), + /// as opposed to a problem with one file or the tree. Logged as an error + /// so the "ERROR/FATAL logs" alert fires: nothing else restarts clamd. + pub fn service_down(&self) -> bool { + match self { + Self::Unreachable(..) | Self::Timeout => true, + Self::Refused(_) | Self::Io(_) => false, + } + } +} + /// A clamd service. #[derive(Debug, Clone)] pub struct Clamd { @@ -397,6 +409,16 @@ fn finding(root: &Path, repo_id: &str, file: &Path, hash: &str, signature: &str) mod tests { use super::*; + #[test] + fn only_an_unreachable_or_silent_clamd_is_down() { + let refused = std::io::Error::from(std::io::ErrorKind::ConnectionRefused); + assert!(ClamavError::Unreachable("clamav:3310".into(), refused).service_down()); + assert!(ClamavError::Timeout.service_down()); + assert!(!ClamavError::Refused("INSTREAM size limit exceeded".into()).service_down()); + let unreadable = std::io::Error::from(std::io::ErrorKind::PermissionDenied); + assert!(!ClamavError::Io(unreadable).service_down()); + } + #[test] fn clamd_answers_are_read() { assert_eq!( diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index 977289c..a5a5db3 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -2117,7 +2117,11 @@ impl PipelineOrchestrator { findings.extend(scan.findings); } Err(e) => { - tracing::warn!("[{repo_id}] ClamAV did not complete: {e}"); + if e.service_down() { + tracing::error!("[{repo_id}] ClamAV did not complete: {e}"); + } else { + tracing::warn!("[{repo_id}] ClamAV did not complete: {e}"); + } self.skip_stage( scan_run_id, SkippedStage::new(