Runbook — the virus check on uploaded documents
In plain language. Every document an applicant uploads — an ID card, a lease, a certificate — is now checked for viruses before it is stored. The check is done by a separate program, the virus scanner, running in its own container beside the application. If the scanner finds a virus, the file is refused. If the scanner cannot answer, the file is refused too, and the attempt is recorded so the applicant can prove they tried on time. This runbook covers keeping the scanner healthy, giving it its signatures on a limited connection, adding a country’s own detection rules, and switching the check off for a short, stated time in an emergency.
Spec: docs/specs/2026-08-10-upload-virus-scanning.md (including §4.7, a
country’s own rules). Plan: docs/plans/2026-09-22-upload-virus-scanning.md
(its decisions are cited here as D1…D17 and its measured facts as F1…F23).
Scope: every deployment. The service is clamav in docker-compose.yml and
docker-stack.yml. On the dev stack it is clamav-dev. In docker-compose.yml
(also under Coolify), a second service, freshclam, downloads the signatures, and
clamav has no network (docs/specs/2026-10-14-virus-scanner-without-network.md).
Words used here (glosses in docs/reference/plain-vocabulary.md):
- the scanner (
clamav, its daemonclamd) — the container that looks at files. - the scan spool — a small folder shared by the application and the scanner. A file sits there only for the seconds its scan takes. The folder is in memory on Compose and Swarm, and on disk on Coolify (section 10).
- all-match scanning (
ALLMATCHSCAN) — asking the scanner for every problem in a file, not only the first one. - the proof — the most recent time the scanner found both the test virus file (EICAR, a harmless string every scanner must flag) and our canary rule. Uploads are refused when the proof is missing or more than 90 seconds old.
- not checked — the mark on a stored file that was never scanned.
1. What the scanner is and what health says
/health has a row named “the virus check on uploaded documents”. When it is
down, the verdict is outage with the sentence “Citizens cannot submit — the
virus check on uploaded documents”, because every upload is being refused.
The application proves the scanner every 30 seconds, on its own timer, by asking it to scan a small PDF that holds the EICAR test file and our canary string. The health row only reads the result of the last proof. The reasons it can show:
| What the row says | What it means | What to do |
|---|---|---|
the scanner did not answer | The scanner is not running, not reachable, or took longer than 5 seconds | §11: check the container; docker compose restart clamav |
the scanner no longer finds the test virus file | It answers, but has no virus signatures loaded (an empty or damaged signature folder) | §2: restore the signature folder |
the scanner no longer reads detection rules | It answers, but our rule file did not load | Check opengov.yar is in the signature folder (§3); read the scanner’s log for YARA errors |
the virus check has not run since <time> | The last proof was good but is too old: the application’s proof timer stopped | Restart the application |
the virus scanner has not answered yet, watching for Ns | A fresh start, still inside its first 300 seconds | Wait; this is amber, not an outage (§11) |
switched off by the operator until <time>; … | The operator’s lever is on (§7) | Nothing, until the time passes |
The last two read degraded (amber) and page nobody. Every other one is an outage.
Measured timings (2026-09-22, native arm64 Mac, clamav/clamav-debian:1.5.4_base,
full signatures, our clamd.conf):
| What | Measured | Against |
|---|---|---|
| Proof scan, 20 runs back to back | max 23.9 ms, median 7.0 ms | PROOF_TIMEOUT_S = 5 s |
| Scanner memory after load | 997 MiB (dev scanner, after scans); 972 MiB (fresh start) | limit 2.5 GiB |
Fresh volume: docker compose up to the first good proof, signature download included | 13.4 s | SCANNER_BOOT_GRACE_S = 300 s |
The health row reads up at the application’s first proof after the scanner is
ready: the proof runs at boot and then every 30 seconds, so a fresh deploy reads up
within about 45 seconds, well inside the 300-second grace. That figure is the
scanner’s side, measured with the application’s own ClamdScanner; the full
/health round trip on a running application was not timed. An amd64 server under
emulation, or one scanning a large upload at the same moment, will be slower — the
5-second proof deadline leaves room for about 200 times the measured worst case.
2. The signature folder (clamav-db)
The virus signatures live in the named volume clamav-db, mounted at
/var/lib/clamav inside the scanner. On first start the image’s own start script
downloads them — about 119 MB — and keeps them current afterwards. In
docker-compose.yml that is the service freshclam. clamav mounts the folder
read only. It waits for freshclam to report main.cvd or main.cld, for at most
about 2.5 minutes, and then starts anyway.
A country with a limited or no connection copies the signatures in by hand. On a connected machine, let the same image download them into a local folder (checked 2026-09-22; the “Clamd was NOT notified” warning at the end is expected):
mkdir sigs
docker run --rm -v "$PWD/sigs:/var/lib/clamav" clamav/clamav-debian:1.5.4_base freshclam
# sigs/ now holds main.cvd, daily.cvd, bytecode.cvd and their .sign files
Carry sigs/ to the deployment host and copy it into the volume, using the same
image so the files get the scanner’s own owner. The volume is named
<project>_clamav-db; for the standard deployment, opengov-prod_clamav-db:
docker run --rm -v opengov-prod_clamav-db:/var/lib/clamav -v "$PWD/sigs:/src:ro" \
clamav/clamav-debian:1.5.4_base \
sh -c 'cp -R /src/. /var/lib/clamav/ && chown -R clamav:clamav /var/lib/clamav'
docker compose restart freshclam clamav
With main.cvd present the start script skips the download (F10).
Never mount a file or folder inside /var/lib/clamav. The start script changes
the owner of everything in that folder on every start, and a read-only file there
stops the container (F19).
3. A country’s own rules
A country can add detection rules — for example the ones its national computer emergency team publishes — without changing the platform. The rules are written in YARA, a common format for describing a suspicious file by the patterns inside it.
- Where. At the top of the signature folder, next to
opengov.yar, namedcountry-<source>.yar(for examplecountry-cert.yar). Sub-folders are silently ignored (F14), and so is a secondDatabaseDirectoryline. - Block or caution. A rule whose name starts
CAUTION_only warns the officer; the file is accepted. Every other name refuses the file, as a virus does. A mistyped prefix (Caution_,CAUTION-) therefore refuses — it fails safe. - When it takes effect. Within 60 seconds, without a restart (
SelfCheck 60in both settings files indeploy/clamav/). The scanner’s log showsSelfCheck: Database modification detected. Forcing reload.
Copy a file in. In docker-compose.yml, clamav mounts the signature folder read
only, so copy through freshclam:
docker compose cp country-cert.yar freshclam:/var/lib/clamav/country-cert.yar
docker compose exec freshclam chown clamav:clamav /var/lib/clamav/country-cert.yar
On Swarm and the dev stack the scanner is one container (clamav, clamav-dev).
Copy into it.
The updater leaves files it does not know alone (checked: a country-test.yar
survived a freshclam run, and was picked up at the next self-check).
Do not edit opengov.yar. At each start, the scanner copies it in fresh from
deploy/clamav/rules/opengov.yar (in docker-compose.yml, freshclam does). Each
start overwrites an edit inside the volume.
4. The part of YARA the scanner reads
The scanner reads a subset of YARA:
- no modules and no
import(a file withimport "pe"loads zero rules); - no
globalrules, no external variables, no pre-compiled rules; - at most 64 strings per rule, and every rule needs at least one string (a rule with no strings is skipped, with a warning in the log).
What a mistake does, measured: a syntax error drops the failing rules and keeps the rest; the scanner keeps running either way (F16). One bad rule file does not stop uploads. It only means some rules are silently missing — which is why §5 exists.
5. Testing a rule file before placing it
The scanner does not report how many rules each file loaded (F17). Check it by hand before placing the file:
docker compose exec -T clamav sh -c 'cat > /tmp/candidate.yar' < country-cert.yar
docker compose exec clamav clamscan -d /tmp/candidate.yar /etc/hostname
# "Known viruses: N" — N must equal the number of rules in the file.
Then ask the national team for a sample file their rule should match, and scan it:
docker compose exec -T clamav sh -c 'cat > /tmp/sample' < sample.pdf
docker compose exec clamav clamscan -d /tmp/candidate.yar /tmp/sample
# expect: /tmp/sample: YARA.<RuleName>.UNOFFICIAL FOUND
6. The canary cannot see your file
Our canary rule proves the scanner reads rules at all. It cannot prove that a country’s file loaded: a file that loaded zero rules looks exactly like one that loaded a hundred (spec §7.6). The pre-check in §5 is the only per-file count there is. Run it every time a rule file changes.
7. The operator’s lever
When the scanner is down during a filing deadline, an operator can switch the check off — but only until a stated time.
OPENGOV_VIRUS_SCAN=off
OPENGOV_VIRUS_SCAN_OFF_UNTIL=2026-09-23T18:00:00+00:00 # time zone required
Set both in the application’s environment and restart it. The application refuses to start when:
offis set with no expiry;- the expiry has no time zone;
- the expiry is already past;
- the expiry is more than 7 days away.
While it is on:
- the boot log says
VIRUS CHECK SWITCHED OFF by the operator until <time>; /healthreads degraded (amber, never green), naming the time;- every file accepted is stored as not checked, and officers see “Not checked” on it.
When the time passes, uploads are scanned again without a restart. To end it
early, set OPENGOV_VIRUS_SCAN=enforce (or remove both variables) and restart.
A misspelled variable in the process environment is silently ignored by the settings loader (F2) — check the boot log for the line above rather than assuming.
8. Memory
About 1 GiB resident with the full signatures loaded (F11). The container’s limit is 2.5 GiB, because a signature reload can briefly hold two copies. A host without that memory should not run the scanner at all; the lever (§7) is not a substitute for it.
9. Who can reach the scanner
clamd has no authentication. Anyone who can talk to it can send SHUTDOWN and stop
every upload. They can also ask it to scan any path inside its container.
docker-compose.yml, also under Coolify: nobody over a network. clamav runs
with network_mode: none. The application talks to clamd on a Unix socket in the
volume clamd-socket, which only clamav and opengov mount. clamd keeps port
3310 on its own loopback, for the health check only. freshclam has the internet
on the default bridge and nothing of ours. It never sees an upload.
- Never give
clamava network orports:. Compose refusesnetwork_modetogether withnetworksfor the whole project, so that mistake stops every service at the next deploy. - Never mount
clamd-socketin another service. - Never remove the
chownandchmodlines from the entrypoint ofclamav. clamd makes its socket as the userclamav, and Docker does not always give a new volume a folder that this user can write. Without the lines, the log ofclamavrepeats “Socket file /var/tmp/clamd.sock could not be bound: Permission denied”, and each upload is refused (#4405).
Swarm and the dev stack: only the application, over the scan network (D15).
- Never add another service to the
scannetwork. - Never publish port 3310 (
ports:). The dev stack publishes it on127.0.0.1only, on a developer’s laptop.
tests/ci/test_scanner_without_network.py and
tests/platform/virus_scan/test_spool_budget.py fail the build when one of these
rules breaks.
10. The scan spool
The spool is a 256 MiB volume (scan-spool). The application writes to it, and the
scanner mounts it read-only. At most 4 scans run at once (D16), and an upload is at
most 50 MiB, so 4 × 50 MiB fits with headroom.
Where the spool lives
- On Compose and Swarm, the spool is a
tmpfsvolume. It is in memory. - On Coolify, the spool is an ordinary disk volume. Coolify renames the volume and
drops its
driver_opts(#4356). - At boot, the application logs one line: “virus scan folder … is in memory” or "… is not in memory". The line gives the file-system type.
What can reach the disk when the spool is a disk volume
The application removes each scan file when the scan ends, also after an error or a
cancel. The application does not call fsync. The kernel writes a changed file to
the disk some time later. So a file that lives a few seconds is usually never written.
A lab test shows this. The lab used one kernel (write delay 30 seconds) and the
ext4 file system.
- A file held 3 seconds left no copy on the disk.
- A file held about 40 seconds left a full copy.
- Four uploads of 25 MiB at once left copies. Eight uploads of 10 MiB at once left none.
- A forced write (
fsync) left a copy.
The scan time limit is 30 seconds (OPENGOV_CLAMD_TIMEOUT_S). A stuck scanner can
hold a file about that long. No measurement of the kernel, the file system or the
write delay of the sandbox host exists.
The web framework also writes an upload above 1 MiB to a temporary file on the container disk, before the scan starts. This happens on Compose, Swarm and Coolify. A spool in memory does not change this.
The control for a country that needs more
Encrypt the disk of the host. Then nobody can read a scan file or a temporary file from the disk without the key. No one knows whether the sandbox host encrypts its disk.
A log line “virus scan spool is full” means the spool, not the scanner. Raise
the tmpfs size in both compose files and OPENGOV_VIRUS_SCAN_MAX_CONCURRENT
together (test_spool_budget.py checks the sum).
11. First deploy and restarts
Until the scanner first answers, uploads are refused and the health row reads amber (“has not answered yet”) for up to 300 seconds after the application started. After that window it reads outage. A scanner that worked and then stopped reads outage at once — the window covers first start only.
In docker-compose.yml, clamav waits for freshclam to have the signatures.
Without internet, docker compose up waits at most about 2.5 minutes. Two local
runs waited 53 and 85 seconds. Then it warns that freshclam is unhealthy, and
it goes on with exit code 0.
clamd then stops at each start and the restart policy starts it again, until the signatures exist. Until then uploads
stay refused. A copied-in main.cvd (section 2) ends this.
In docker-compose.yml, clamd is the main process of clamav. When clamd stops,
the container stops, and the restart policy starts it again. Plain Compose does not
restart a container that is only unhealthy. So a red health row with a running
clamav container means:
docker compose logs --tail 50 clamav freshclam
docker compose restart clamav
On the dev stack, the scanner’s image keeps its container running even after
clamd inside it dies. The same two commands apply to clamav-dev.
Under Swarm the service restarts on failure by itself (restart_policy: any).
Changing deploy/clamav/clamd.conf or deploy/clamav/rules/opengov.yar under
Swarm: a Swarm config cannot be changed in place, so rename it in
docker-stack.yml (for example clamd_conf_v2) before docker stack deploy.
Changing the settings of clamd in docker-compose.yml: they are in the entrypoint
of clamav, and the next deploy brings them. They are not in a file, because
Coolify does not copy a new file of the repository to its host. A new ./ bind
then mounts an empty folder, and the container stays in state created (#4376).
tests/ci/test_compose_binds_only_files_on_the_host.py refuses a new path on the
host, such as a ./ bind.
Coolify may not copy a changed file either. After a change to
deploy/clamav/rules/opengov.yar, compare the file on the host with the
repository.
That test file, test_compose_binds_only_files_on_the_host.py, also pins the
sha256 hash of deploy/clamav/rules/opengov.yar, the one repository file that the
compose file binds. The test fails when the file changes, and the Coolify host
then still holds the old copy. First, put the new file on the Coolify host. This
is a host change, and the owner approves it. Then put the new hash in
PINNED_HASHES in the test. The test never reads or changes the host.
To print the hash of a file, run shasum -a 256 deploy/clamav/rules/opengov.yar.
Run the same command on the host copy to compare the two copies.
The host check. scripts/release/check_scanner_rules.sh compares three copies of
the rules file. It only reads. Design: docs/specs/2026-10-27-scanner-rules-host-check.md.
- The repository copy is the file inside the application image.
- The host copy is the file that
freshclammounts. - The loaded copy is
/var/lib/clamav/opengov.yarin the volumeclamav-db. The scanner reads this copy.freshclamcopies the host copy there only when it starts.
The script prints one line and writes /var/lib/opengov/scanner-rules-status.json.
It exits with code 0 in every state. The state tells the operator what to do:
| State | Meaning | Action |
|---|---|---|
current | The three hashes are equal. | None. |
host_old | The host copy differs from the repository copy. | Put the repository copy on the host. The owner approves this host change. |
not_reloaded | The host copy is current and the loaded copy is not. | Restart freshclam. |
unknown | A read failed. | Read the message in the status file. |
If the host runs more than one stack, set OPENGOV_COMPOSE_PROJECT to the Compose
project of this stack. With two matching containers, the script reports unknown and
does not guess. OPENGOV_SCANNER_RULES_ALERT_CMD names a command. The script runs it
when a state other than current first appears.
Scheduling the host check. The Coolify host has no checkout of the repository.
scripts/install-scanner-rules-timer.sh copies check_scanner_rules.sh to
/usr/local/lib/opengov-scanner-rules/ and enables opengov-scanner-rules-check.timer
(every 15 minutes). The installer runs the check once and checks that
/var/lib/opengov/scanner-rules-status.json exists. Set OPENGOV_COMPOSE_PROJECT or
OPENGOV_SCANNER_RULES_ALERT_CMD in /etc/opengov-scanner-rules.env when the host
needs them. The owner approves the first install on the sandbox host.
The failed deploy of 2026-10-14 probably left an empty folder at
/data/coolify/applications/<app>/deploy/clamav/clamd-no-network.conf on the
sandbox host. Nothing uses it, so an operator can remove it.
12. What it does not do
A scanner reads a file’s contents. A clean, valid PDF that is a forged land title passes it, exactly as it passes the virus signatures (spec §6). The virus check is not fraud detection and must not be offered as such.