Rspamd DCC, Razor and Pyzor in one Go backend

Rspamd DCC, Razor, Pyzor support already exists, but the Razor and Pyzor route starts a Perl or Python program for every message. The rspamd-dcc-razor-pyzor project replaces that with one small Go backend called gozer. Your rspamd sends it one asynchronous HTTP request per message, and gozer queries all three networks in parallel inside its own process. No fork per message, no Perl or Python, and the message never touches disk.

The backend is a Docker container next to your rspamd, with no rspamd of its own.

In short: a tested install of gozer, the rspamd plugin and the Dovecot glue, plus four traps we hit while testing. Without a module section in rspamd.conf.local, every scan goes to 127.0.0.1:8077 and fails.

A nameserver that can’t resolve the backend logs an error, and one rspamd can’t reach leaves the plugin silent. Dovecot 2.4 rejects the repository’s 2.3 files. And rspamd’s own Razor setup reports a broken Razor as clean mail.

What the earlier version of this post got wrong

Correction (22 November 2026): we tested the backend, the plugin and the Dovecot glue again. The earlier version got these wrong:

  • Rspamd does ship Razor and Pyzor support. gozer replaces the wrapper that starts a client per message.
  • The plugin install missed a module section, so the plugin never read its config or reached the backend.
  • The cache key is the SHA-256 of the whole message, not of the body. Only identical copies hit the cache.
  • The image is about 11 MB unpacked and 4.6 MB to download, not 6 MB or 19 MB.
  • A resolver that answers “no such name” gives a clear log error. Only an unreachable nameserver is silent.
  • Dovecot needs four files and an environment file, not three, and the working 2.4 copies are in our Dovecot image.
  • The KAM converter carries 3,668 rules, not 3,200.
  • We removed timings we could not reproduce, “DCC is the fastest”, the old 268 MB size and the FAQ.

What rspamd already does for DCC, Razor and Pyzor

Rspamd’s external services module has a dcc, a razor and a pyzor scanner. DCC needs the dccifd daemon running next to rspamd. Razor and Pyzor talk to a local TCP port, 127.0.0.1:11342 and 127.0.0.1:5953 by default.

Something has to listen on those ports. The rspamd docs use systemd socket units with Accept=yes, which start a fresh razor-check or pyzor check process for each connection. Every scanned message pays for a fork and an interpreter start. You also keep Perl, Python and the DCC tools installed on the mail host.

Rspamd itself doesn’t wait for those processes, because it talks to the ports asynchronously. The trap is the shortcut: a Lua rule that runs razor-check directly. Rspamd scans in a single-threaded event loop, so a blocking call there stalls every message behind it.

gozer keeps the asynchronous part and drops the processes. The plugin sends one non-blocking request to gozer, and gozer runs all three clients as Go code in one long-running process.

If you keep rspamd’s own Razor and Pyzor units

We ran the socket units from the rspamd docs unchanged under systemd, with rspamd 4.3 scanning through them. Three things are worth knowing before you rely on them.

A broken Razor looks like clean mail. The Razor unit answers spam when razor-check exits 0 and ham for any other exit code. With the network down, razor-check exited 2 with “Bootstrap discovery failed”. The unit still answered ham, and rspamd added no Razor symbol at all, not even RAZOR_FAIL.

The error only reaches the journal:

journalctl -u 'razor@*' --since today | grep -i fail

Pyzor fails where you can see it. Offline, pyzor check sent nothing back and rspamd added PYZOR_FAIL. With nothing listening on the ports at all, both RAZOR_FAIL and PYZOR_FAIL fire. So only the Razor wrapper hides an error.

Razor looks up its servers again for every message. The docs tell you to create a Pyzor home for the _rspamd user but not a Razor home, and razor-check doesn’t create one. Without it, every check ran two discovery rounds before the lookup. In our run of three checks on 22 November 2026, that took about 1.8 seconds per check, against 1.1 seconds with a home.

Creating the home is not enough on its own. ProtectSystem=strict keeps it read-only, so Razor can’t save what it learns and still ran a discovery round on each check. This creates the home and lets the unit write to it:

sudo -u _rspamd -H razor-admin -create
sudo mkdir -p /etc/systemd/system/razor@.service.d
printf '[Service]\nReadWritePaths=/var/lib/rspamd/.razor\n' |
  sudo tee /etc/systemd/system/razor@.service.d/razor-home.conf
sudo systemctl daemon-reload

After one warm-up check, Razor went straight to its catalogue server. gozer doesn’t need any of this, because its Razor client keeps the discovery result in memory.

DCC, Razor and Pyzor in one paragraph each

All three are collaborative filters. They ask one question in different ways: have many other mail servers seen this exact message? Spam is bulk by nature, and bulk is what gives it away.

DCC (Distributed Checksum Clearinghouse) counts. It sends fuzzy checksums of the message to its servers and gets back how often they have been reported. A personal mail scores one, a newsletter scores in the millions. DCC says “bulk”, not “spam”.

Razor (Vipul’s Razor) matches signatures. It computes fuzzy fingerprints and checks them against a shared catalogue of reported spam. A check is a short conversation: discovery, greeting, server state, then the lookup.

Pyzor works the same way with a different digest. A public server counts how often a digest was reported as spam and how often it was whitelisted.

None of them replaces your Bayes classifier or your blocklists. They add one kind of evidence: brand-new spam that reads clean but goes out in huge volume. For where they sit in a full stack, see Rspamd Explained.

One Go binary, three clients, no forks

The first version was a Python shim that ran the Perl razor-check, the Python pyzor and the C dccproc once per message. It worked, but it dragged three toolchains and a process supervisor into the image. So we rewrote all three clients in Go and linked them into the backend:

  • gdcc: a clean-room Go DCC client that computes the same checksums as dccproc.
  • gazor: a Go Razor2 client that speaks the discovery and signature protocol of the Perl razor-agents.
  • gyzor: a Go Pyzor client that reproduces the SHA-1 digest of the Python client.

Each client has parity tests in its own CI that compare it with the original tool. The servers see the same fingerprints, so the switch is invisible on the wire.

gozer imports all three. It listens on port 8077 as a non-root user, and each /check runs the three lookups in parallel inside the process. A check takes about as long as the slowest network, not the sum of all three. The gazor client also keeps Razor’s discovery result between requests, so that step is not repeated for every message.

Diagram: the rspamd plugin dcc_razor_pyzor.lua sends one non-blocking POST /check with the shared token to gozer on port 8077; gozer holds the message in memory, keeps a cache of sha256(message) to verdict, and queries DCC, Razor and Pyzor in parallel in-process through gdcc, gazor and gyzor
One request from rspamd, three networks queried in parallel inside gozer. The cache key is the SHA-256 of the whole message, headers included.

What is left in the image

The image is built FROM a distroless static base with gozer as the entrypoint. It has no shell, no curl, no Perl or Python and no set-UID dccproc. The published image is about 11 MB unpacked and 4.6 MB to download for amd64, as reported by Docker and Docker Hub on 22 November 2026. Its healthcheck runs gozer health, because there is no shell to run anything else.

Every network can fail on its own. If the Razor servers drop off the internet, gozer returns what DCC and Pyzor had, and the healthcheck stays green because it only tests gozer itself. Such a partial verdict is not cached, so the next copy gets a fresh lookup.

The message never touches disk

gozer keeps the message in memory and computes every checksum there. It writes no temp file, not in /tmp and not in a tmpfs. A spool file is a window where someone’s mail sits on a filesystem, waiting for a backup job or a log line to copy it.

The cache follows the same rule. It stores the SHA-256 of the message and the verdict, never the message. With Redis as the cache the same holds: Redis stores hashes and verdicts too.

Only fingerprints leave the container: DCC checksums, Razor signatures and Pyzor digests. When you report spam, the networks get what reporting needs, and nothing more.

Hardening that is on by default

gozer runs as a non-root user and limits how many checks run at once. In the current image GOZER_MAX_CONCURRENT defaults to 8; newer gozer builds default to the number of CPUs.

Every POST needs the shared token, sent as Authorization: Bearer <token> or X-DRP-Token: <token>. A wrong or missing token gets 401. If you never set a token, gozer fails closed and answers 503 to every POST. A spam backend that takes anonymous “report this as spam” calls is an easy way to poison your filter.

The bundled compose file runs the container read-only, with cap_drop: ALL, no-new-privileges and no published host port. Only containers on the same Docker network can reach it, by service name. That is the baseline for any container that parses untrusted input.

Speed and the cache

We timed one run on 22 November 2026 with curl from a second container on the same Docker network, against the public servers. The first /check of a message took 0.79 seconds. Your number depends on your distance to the servers, and Razor’s conversation has the most steps. Rspamd waits for that answer asynchronously, so it doesn’t hold up other messages.

The same message sent again took 1.7 milliseconds and came back with X-DRP-Cache: hit. The lookup inside gozer is far faster than that; the README benchmark puts it at about 55 nanoseconds. The rest is the HTTP round trip.

The cache only helps for identical bytes. Its key is the SHA-256 of the whole message as the plugin sends it, headers included. The same body with another To or Message-ID was a miss in our test and took 0.39 seconds.

Defaults are a 300-second lifetime (GOZER_CACHE_TTL) and 4,096 entries (GOZER_CACHE_SIZE). The README benchmark reaches about 29,600 checks per second at a 90% hit rate and about 11,800 when every check misses. Those figures come from go test -bench against a synthetic backend that answers in 2 ms on a 32-core host, not from the real networks.

Running more than one scanner? Point GOZER_REDIS_URL at a shared Redis or Valkey and they share one cache. /report and /revoke are never cached, and they drop any cached verdict for that message.

Install rspamd DCC, Razor, Pyzor checks with gozer

There are three parts: the backend container, the rspamd plugin and the optional Dovecot feedback. Take them in order.

Step 1: start the backend

gozer refuses every POST until it has a token, and it isn’t published to the host. The bundled compose file handles both. From a clone of the repository:

cd docker
mkdir -p secrets && openssl rand -hex 32 > secrets/drp_token.txt
docker compose up -d

Your rspamd container must join the compose network to reach the backend at http://rspamd-drp:8077. The image is on Docker Hub as eilandert/rspamd-dcc-razor-pyzor if you’d rather pull than build. Test it by posting a raw message. --data-binary keeps the bytes intact, because the fingerprints are computed over them.

TOKEN=$(cat docker/secrets/drp_token.txt)

# scan a message
curl -s --data-binary @message.eml \
  -H "Authorization: Bearer $TOKEN" http://rspamd-drp:8077/check
# {"dcc":{"action":"unknown","bulk":null},"razor":{"hit":false},"pyzor":{"count":42,"wl":0}}

# user feedback — X-DRP-Token works in place of the Bearer header
curl -s --data-binary @spam.eml -H "X-DRP-Token: $TOKEN" http://rspamd-drp:8077/report
curl -s --data-binary @ham.eml  -H "X-DRP-Token: $TOKEN" http://rspamd-drp:8077/revoke

Step 2: install the rspamd plugin

The Lua plugin is not in the backend image, on purpose: it belongs in your rspamd. Install it in four steps:

  1. Copy the plugin and its two local.d files, and load the plugin from rspamd.local.lua.
  2. Set the backend URL and the same token in /etc/rspamd/local.d/dcc_razor_pyzor.conf.
  3. Add a module section to /etc/rspamd/rspamd.conf.local that includes that file.
  4. Check that rspamd sees your URL, then restart rspamd.

The copy commands for step 1:

cp rspamd/plugins/dcc_razor_pyzor.lua  /etc/rspamd/plugins/
cp rspamd/local.d/dcc_razor_pyzor.conf /etc/rspamd/local.d/
cp rspamd/local.d/groups.conf          /etc/rspamd/local.d/
echo 'dofile("/etc/rspamd/plugins/dcc_razor_pyzor.lua")' >> /etc/rspamd/rspamd.local.lua

The third line overwrites an existing local.d/groups.conf. If you already have one, copy the DRP group into it instead.

For step 2, these two lines in local.d/dcc_razor_pyzor.conf set the URL and the token:

url   = "http://rspamd-drp:8077/check";
token = "the-shared-secret";

Step 3 is what the old version of this post missed. Rspamd only reads a local.d file for a module that has a section in its config, and this plugin doesn’t ship one. Without it, the plugin uses its built-in default http://127.0.0.1:8077/check and no token. Every scan then logs shim request failed: Connection failed: Connection refused and never reaches gozer.

Add this module section to /etc/rspamd/rspamd.conf.local:

dcc_razor_pyzor {
  .include(try=true,priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/dcc_razor_pyzor.conf"
}
Diagram of how the plugin gets its settings: without a dcc_razor_pyzor section in rspamd.conf.local, local.d/dcc_razor_pyzor.conf is never read, the plugin uses 127.0.0.1:8077 with no token and logs Connection refused; with the section, the include loads the file and the scan reaches gozer at rspamd-drp:8077 with the shared token
The .include in rspamd.conf.local is what makes rspamd read local.d/dcc_razor_pyzor.conf.

For step 4, this should print your url and token:

rspamadm configdump dcc_razor_pyzor

If it prints Section dcc_razor_pyzor NOT FOUND instead, the module section from step 3 is missing.

After the restart you get three symbols in the DRP group, which adds at most 15 points:

  • DRP_DCC_BULK, weight up to 3: fires from 1,000 DCC reports and scores more as the count grows.
  • DRP_RAZOR, weight 1: fires on a Razor signature match.
  • DRP_PYZOR, weight 2: fires at five Pyzor sightings when the digest has no whitelist entries.

When rspamd cannot resolve rspamd-drp

Rspamd resolves the URL through its own configured nameserver, not the system resolver or Docker’s. If you point it at a local resolver set up for blocklist lookups, that resolver doesn’t know Docker service names.

What you see depends on the failure. If the nameserver answers that rspamd-drp doesn’t exist, every scan logs dcc_razor_pyzor.lua:125: shim request failed: unable to resolve host. If rspamd can’t reach its nameserver at all, the plugin logs nothing and rspamd only logs its generic cannot send DNS request. In both cases no DRP symbol ever fires.

The fix is to put the backend’s IP address in url instead of the service name. Docker can give the container a new address when it is recreated, so check the URL after a redeploy.

Step 3: Dovecot feedback

/check scans. /report and /revoke take human feedback: a user moves a message into Junk (report it as spam) or rescues one from Junk (revoke the report). Sieve can’t speak HTTP, so a small script called drp-report does the call, triggered by imapsieve. Moving into Junk sends POST /report, moving out sends POST /revoke.

Our eilandert/dovecot image already has all of this built in. On another Dovecot host you install four files and one environment file.

Take the files from that image directory, not from the rspamd-dcc-razor-pyzor repository. The repository’s 90-drp-sieve.conf uses Dovecot 2.3 syntax, which Dovecot 2.4.5 rejects with “Unknown section name: plugin”. Its sieve scripts also lack require "copy", so sievec refuses them.

  1. Copy drp-report to /usr/lib/dovecot/sieve-pipe/drp-report and make it executable (mode 0755).
  2. Copy 90-drp-sieve.conf to /etc/dovecot/conf.d/ and reload Dovecot with doveadm reload.
  3. Copy report-spam.sieve and report-ham.sieve to /usr/lib/dovecot/sieve/ and compile each one with sievec. Do this after the reload. On a running Dovecot, sievec uses the loaded config, and only that config knows the pipe extension.
  4. Write the backend URL and the token to /etc/dovecot/drp.env, as below.

The URL and token come from a file because Sieve’s external programs run with a scrubbed environment:

DRP_URL=http://rspamd-drp:8077
DRP_TOKEN=the-shared-secret

These are Dovecot 2.4 files; we have not tested this setup on Dovecot 2.3. drp-report always exits 0, even when the backend is down. A reporting hiccup never bounces a message or blocks the IMAP move. The worst case is one spam that doesn’t get reported.

Where this fits in the spam stack

Collaborative filtering is one layer. It catches high-volume campaigns as soon as they start, and it can’t help with a message sent only to you, because no crowd has seen it.

That’s why it pairs well with rules that judge a single message. Our rspamd-kam-rules converts 3,668 SpamAssassin KAM.cf rules to native rspamd Lua, without the Perl spamassassin module. We wrote that up in KAM.cf in Rspamd. Rules catch the content; DCC, Razor and Pyzor catch the volume; Bayes catches the drift.

Everything is open source. gozer and the deployment repository are on GitHub, and so are the gdcc, gazor and gyzor clients. The image is on Docker Hub, and the dockerized monorepo tracks the lot. All our repositories and images are listed on the where to find us page.