fix(malware): an unreachable or silent clamd is logged as an error #539
No files matched your search
@@ -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!(
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user