Virus scan
Hearth sends uploaded files to a ClamAV daemon (clamd) of your own and acts on its verdict. Files never leave your server for the scan.
The ClamAV container
hearth-clamav:
image: clamav/clamav:1.4
restart: unless-stopped
environment:
CLAMD_CONF_ConcurrentDatabaseReload: "no"
CLAMD_CONF_MaxThreads: "4"
CLAMD_CONF_StreamMaxLength: 2000M
CLAMD_CONF_MaxFileSize: 2000M
CLAMD_CONF_MaxScanSize: 2000M
CLAMD_CONF_AlertExceedsMax: "yes"
FRESHCLAM_CHECKS: "4"
volumes:
- ./data/clamav:/var/lib/clamav
healthcheck:
test: ["CMD", "clamdcheck.sh"]
interval: 30s
timeout: 40s
retries: 3
start_period: 300s
mem_limit: 5g
The repository's deploy/clamav builds the same image with a small
start script that restarts the container when clamd or freshclam stops.
- ClamAV holds about 1 GB of signatures in memory. A scan also holds the decoded file: a large photo takes several hundred MB, so four large scans at once can reach 4 GB. Give the container 5 GB.
ConcurrentDatabaseReload nokeeps one copy of the signatures in memory while they are reloaded, at the cost of about 25 seconds in which scans wait.StreamMaxLengthmust be at least the Largest file to scan you set in Hearth.AlertExceedsMax yesmakes clamd say when a file was beyond its limits, instead of answering that it is clean.FRESHCLAM_CHECKS 4looks for new signatures four times a day.
On the Hearth containers:
CLAMAV_ADDRESS: hearth-clamav:3310
CLAMAV_TIMEOUT_SECONDS: "120"
CLAMAV_RETRY_SECONDS: "60"
| Setting | Default | Meaning |
|---|---|---|
CLAMAV_ADDRESS |
empty (off) | clamd's host:port |
CLAMAV_TIMEOUT_SECONDS |
120 | how long clamd may stay silent during one scan, not a limit on the whole file; raise it (to 300, say) for bulk imports of large files |
CLAMAV_RETRY_SECONDS |
60 | before accepting: how long an upload waits for clamd when it does not answer (a reload or restart) before it is refused; 0 refuses at once. Also how long clamd may be silent before admins are told |
Choosing the mode
Go to Administration, Virus scan.
Under Scan uploads, choose:
- In the background (the default). An upload is accepted and usable at once, and checked within seconds by a background job. If a virus is found, the file stays where it is; its owner and the administrators are notified, and Files marks it "Virus found" for everyone who sees it.
- Before accepting. An upload is answered only after the verdict, and
an infected file is refused. Uploads take a little longer. If clamd
does not answer within
CLAMAV_RETRY_SECONDS, uploads are refused, never stored unscanned. - Off. Nothing is scanned.
Largest file to scan (100 MB by default) sets the size above which files are not sent to clamd. In every mode, pictures, videos and sound recognised by their content (not their name), and contents scanned before (copies, re-uploads, restored versions) are skipped.
Select Save.
The scanner's state
The page shows the scanner's Status (Answering, or Not answering with what that means for uploads), its Signatures, how long it has been Silent since, the Queue (Waiting, Checking now) and the Contents remembered as already scanned.
When clamd does not answer for longer than CLAMAV_RETRY_SECONDS,
administrators see a notice in the web app and a notification, and the
metric hearth_virus_scanner_up drops to 0 (Monitoring).
In the background mode, files uploaded meanwhile are checked when it
answers again.
When the signatures change, contents seen in the last week are scanned again at once, and everything else on a rolling monthly schedule, at low priority.
Viruses found
Viruses found lists each finding with the file's name, its owner, its path and the signature. A finding in an old version of a file says so. For each one:
- Delete moves the file to its owner's trash. It can be restored like any deleted file and stays marked there.
- Ignore treats the finding as a false alarm: the mark goes, and the same finding in the same file is not reported again.
A file's owner can also delete a marked file from its details in Files.
What people see
In the background mode, people see nothing until a virus is found; then the owner gets a notification and the file carries the mark. Before accepting, an infected upload fails with "The file was refused: it contains a virus", and the file is not stored.