Rspamd
About
Rspamd is a "fast, free and open-source spam filtering system". DMS integrates Rspamd like any other service. We provide a basic but easy to maintain setup of Rspamd.
If you want to take a look at the default configuration files for Rspamd that DMS adds, navigate to target/rspamd/
inside the repository. Please consult the section "The Default Configuration" section down below for a written overview.
Enable Rspamd
Rspamd is presently opt-in for DMS, but intended to become the default anti-spam service in a future release.
DMS offers two anti-spam solutions:
- Legacy (Amavis, SpamAssassin, OpenDKIM, OpenDMARC)
- Rspamd (Provides equivalent features of software from the legacy solution)
While you could configure Rspamd to only replace some of the legacy services, it is advised to only use Rspamd with the legacy services disabled.
Switch to Rspamd
To use Rspamd add the following ENV config changes:
ENABLE_RSPAMD=1
# Rspamd replaces the functionality of all these anti-spam services, disable them:
ENABLE_OPENDKIM=0
ENABLE_OPENDMARC=0
ENABLE_POLICYD_SPF=0
ENABLE_AMAVIS=0
ENABLE_SPAMASSASSIN=0
# Greylisting is opt-in, if you had enabled Postgrey switch to the Rspamd equivalent:
ENABLE_POSTGREY=0
RSPAMD_GREYLISTING=1
# Optional: Add anti-virus support with ClamAV (compatible with Rspamd):
ENABLE_CLAMAV=1
Relevant Environment Variables
The following environment variables are related to Rspamd:
Overview of Rspamd support
Mode of Operation
Attention
Read this section carefully if you want to understand how Rspamd is integrated into DMS and how it works (on a surface level).
Rspamd is integrated as a milter into DMS. When enabled, Postfix's main.cf
configuration file includes the parameter rspamd_milter = inet:localhost:11332
, which is added to smtpd_milters
. As a milter, Rspamd can inspect incoming and outgoing e-mails.
Each mail is assigned what Rspamd calls symbols: when an e-mail matches a specific criterion, the e-mail receives a symbol. Afterward, Rspamd applies a spam score (as usual with anti-spam software) to the e-mail.
- The score itself is calculated by adding the values of the individual symbols applied earlier. The higher the spam score is, the more likely the e-mail is spam.
- Symbol values can be negative (i.e., these symbols indicate the mail is legitimate, maybe because SPF and DKIM are verified successfully). On the other hand, symbol scores can be positive (i.e., these symbols indicate the e-mail is spam, perhaps because the e-mail contains numerous links).
Rspamd then adds (a few) headers to the e-mail based on the spam score. Most important is X-Spamd-Result
, which contains an overview of which symbols were applied. It could look like this:
X-Spamd-Result default: False [-2.80 / 11.00]; R_SPF_NA(1.50)[no SPF record]; R_DKIM_ALLOW(-1.00)[example.com:s=dtag1]; DWL_DNSWL_LOW(-1.00)[example.com:dkim]; RWL_AMI_LASTHOP(-1.00)[192.0.2.42:from]; DMARC_POLICY_ALLOW(-1.00)[example.com,none]; RWL_MAILSPIKE_EXCELLENT(-0.40)[192.0.2.42:from]; FORGED_SENDER(0.30)[noreply@example.com,some-reply-address@bounce.example.com]; RCVD_IN_DNSWL_LOW(-0.10)[192.0.2.42:from]; MIME_GOOD(-0.10)[multipart/mixed,multipart/related,multipart/alternative,text/plain]; MIME_TRACE(0.00)[0:+,1:+,2:+,3:+,4:~,5:~,6:~]; RCVD_COUNT_THREE(0.00)[3]; RCPT_COUNT_ONE(0.00)[1]; REPLYTO_DN_EQ_FROM_DN(0.00)[]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_LAST(0.00)[]; DKIM_TRACE(0.00)[example.com:+]; HAS_ATTACHMENT(0.00)[]; TO_DN_NONE(0.00)[]; FROM_NEQ_ENVFROM(0.00)[noreply@example.com,some-reply-address@bounce.example.com]; FROM_HAS_DN(0.00)[]; REPLYTO_DOM_NEQ_FROM_DOM(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[receiver@anotherexample.com]; ASN(0.00)[asn:3320, ipnet:192.0.2.0/24, country:DE]; MID_RHS_MATCH_FROM(0.00)[]; MISSING_XM_UA(0.00)[]; HAS_REPLYTO(0.00)[some-reply-address@dms-reply.example.com]
And then there is a corresponding X-Rspamd-Action
header, which shows the overall result and the action that is taken. In our example, it would be:
X-Rspamd-Action no action
Since the score is -2.80
, nothing will happen and the e-mail is not classified as spam. Our custom actions.conf
defines what to do at certain scores:
- At a score of 4, the e-mail is to be greylisted;
- At a score of 6, the e-mail is marked with a header (
X-Spam: Yes
); - At a score of 11, the e-mail is outright rejected.
There is more to spam analysis than meets the eye: we have not covered the Bayes training and filters here, nor have we discussed Sieve rules for e-mails that are marked as spam.
Even the calculation of the score with the individual symbols has been presented to you in a simplified manner. But with the knowledge from above, you're equipped to read on and use Rspamd confidently. Keep on reading to understand the integration even better - you will want to know about your anti-spam software, not only to keep the bad e-mail out, but also to make sure the good e-mail arrive properly!
Workers
The proxy worker operates in self-scan mode. This simplifies the setup as we do not require a normal worker. You can easily change this though by overriding the configuration by DMS.
DMS does not set a default password for the controller worker. You may want to do that yourself. In setups where you already have an authentication provider in front of the Rspamd webpage, you may want to set the secure_ip
option to "0.0.0.0/0"
for the controller worker to disable password authentication inside Rspamd completely.
Persistence with Redis
When Rspamd is enabled, we implicitly also start an instance of Redis in the container:
- Redis is configured to persist its data via RDB snapshots to disk in the directory
/var/lib/redis
(or the/var/mail-state/
volume when present). - With the volume mount, the snapshot will restore the Redis data across container updates, and provide a way to keep a backup.
- Without a volume mount a containers internal state will persist across restarts until the container is recreated due to changes like ENV or upgrading the image for the container.
Redis uses /etc/redis/redis.conf
for configuration:
- We adjust this file when enabling the internal Redis service.
- If you have an external instance of Redis to use, the internal Redis service can be opt-out via setting the ENV
ENABLE_RSPAMD_REDIS=0
(link also details required changes to the DMS Rspamd config).
If you are interested in using Valkey instead of Redis, please refer to this guidance.
Web Interface
Rspamd provides a web interface, which contains statistics and data Rspamd collects. The interface is enabled by default and reachable on port 11334.
To use the web interface you will need to configure a password, otherwise you won't be able to log in.
Set a custom password
Add this line to your Rspamd custom-commands.conf
config which sets the password
option of the controller worker:
set-option-for-controller password "your hashed password here"
The password hash can be generated via the rspamadm pw
command:
docker exec -it <CONTAINER_NAME> rspamadm pw
Related: A minimal Rspamd compose.yaml
example with a reverse-proxy for web access.
DNS
DMS does not supply custom values for DNS servers (to Rspamd). If you need to use custom DNS servers, which could be required when using DNS-based deny/allowlists, you need to adjust options.inc
yourself. Make sure to also read our FAQ page on DNS servers.
Warning
Rspamd heavily relies on a properly working DNS server that it can use to resolve DNS queries. If your DNS server is misconfigured, you will encounter issues when Rspamd queries DNS to assess if mail is spam. Legitimate mail is then unintentionally marked as spam or worse, rejected entirely.
When Rspamd is deciding if mail is spam, it will check DNS records for SPF, DKIM and DMARC. Each of those has an associated symbol for DNS temporary errors with a non-zero weight assigned. That weight contributes towards the spam score assessed by Rspamd which is normally desirable - provided your network DNS is functioning correctly, otherwise when DNS is broken all mail is biased towards spam due to these failed DNS lookups.
Danger
While we do not provide values for custom DNS servers by default, we set soft_reject_on_timeout = true;
by default. This setting will cause a soft reject if a task (presumably a DNS request) timeout takes place.
This setting is enabled to not allow spam to proceed just because DNS requests did not succeed. It could deny legitimate e-mails to pass though too in case your DNS setup is incorrect or not functioning properly.
Logs
You can find the Rspamd logs at /var/log/mail/rspamd.log
, and the corresponding logs for Redis, if it is enabled, at /var/log/supervisor/rspamd-redis.log
. We recommend inspecting these logs (with docker exec -it <CONTAINER NAME> less /var/log/mail/rspamd.log
) in case Rspamd does not work as expected.
Modules
You can find a list of all Rspamd modules on their website.
Disabled By Default
DMS disables certain modules (clickhouse
, elastic
, neural
, reputation
, spamassassin
, url_redirector
, metric_exporter
) by default. We believe these are not required in a standard setup, and they would otherwise needlessly use system resources.
Anti-Virus (ClamAV)
You can choose to enable ClamAV, and Rspamd will then use it to check for viruses. Just set the environment variable ENABLE_CLAMAV=1
.
RBLs (Real-time Blacklists) / DNSBLs (DNS-based Blacklists)
The RBL module is enabled by default. As a consequence, Rspamd will perform DNS lookups to various blacklists. Whether an RBL or a DNSBL is queried depends on where the domain name was obtained: RBL servers are queried with IP addresses extracted from message headers, DNSBL server are queried with domains and IP addresses extracted from the message body (source).
Rspamd and DNS Block Lists
When the RBL module is enabled, Rspamd will do a variety of DNS requests to (amongst other things) DNSBLs. There are a variety of issues involved when using DNSBLs. Rspamd will try to mitigate some of them by properly evaluating all return codes. This evaluation is a best effort though, so if the DNSBL operators change or add return codes, it may take a while for Rspamd to adjust as well.
If you want to use DNSBLs, try to use your own DNS resolver and make sure it is set up correctly, i.e. it should be a non-public & recursive resolver. Otherwise, you might not be able (see this Spamhaus post) to make use of the block lists.
Providing Custom Settings & Overriding Settings
Rspamd config overriding precedence
Rspamd has a layered approach for configuration with local.d
and override.d
config directories.
- DMS extends the Rspamd default configs via
/etc/rspamd/local.d/
. - User config changes should be handled separately as overrides via the DMS Config Volume (
docker-data/dms/config/
) with either:./rspamd/override.d/
- Config files placed here are copied to/etc/rspamd/override.d/
during container startup../rspamd/custom-commands.conf
- Applied after copying any provided configs fromrspamd/override.d/
(DMS Config volume) to/etc/rspamd/override.d/
.
Reference docs for Rspamd config
- Config Overview, Quickstart guide, and Config Syntax (UCL)
- Global Options (
options.inc
) - Workers (
worker-controller.inc
,worker-proxy.inc
) - Modules (view each module page for their specific config options)
View rendered config
rspamadm configdump
will output the full rspamd configuration that is used should you need it for troubleshooting / inspection.
- You can also see which modules are enabled / disabled via
rspamadm configdump --modules-state
- Specific config sections like
dkim
orworker
can also be used to filter the output to just those sections:rspamadm configdump dkim worker
- Use
--show-help
to include inline documentation for many settings.
Using custom-commands.conf
For convenience DMS provides a single config file that will directly create or modify multiple configs at /etc/rspamd/override.d/
. This is handled as the final rspamd configuration step during container startup.
DMS will apply this config when you provide rspamd/custom-commands.conf
in your DMS Config volume. Configure it with directive lines as documented below.
Only use this feature for option = value
changes
custom-commands.conf
is only suitable for adding or replacing simple option = value
settings for configs at /etc/rspamd/override.d/
.
- New settings are appended to the associated config file.
- When replacing an existing setting in an override config, that setting may be any matching line (allowing for nested scopes, instead of only top-level keys).
Any changes involving more advanced UCL config syntax should instead add UCL config files directly to rspamd/override.d/
(in the DMS Config volume).
custom-commands.conf
syntax
There are 7 directives available to manage custom Rspamd configurations. Add these directive lines into custom-commands.conf
, they will be processed sequentially.
Directives:
# For /etc/rspamd/override.d/{options.inc,worker-controller.inc,worker-proxy}.inc
set-common-option <OPTION NAME> <OPTION VALUE>
set-option-for-controller <OPTION NAME> <OPTION VALUE>
set-option-for-proxy <OPTION NAME> <OPTION VALUE>
# For /etc/rspamd/override.d/<MODULE NAME>.conf
enable-module <MODULE NAME>
disable-module <MODULE NAME>
set-option-for-module <MODULE NAME> <OPTION NAME> <OPTION VALUE>
# For /etc/rspamd/override.d/<FILENAME>
add-line <FILENAME> <CONTENT>
Syntax:
- Blank lines are ok.
#
at the start of a line represents a comment for adding notes.<OPTION VALUE>
and<CONTENT>
will contain the remaining content of their line, any preceding inputs are delimited by white-space.
<MODULE NAME>
can also target non-module configs
An example is the statistics
module, which has config to import a separate file (classifier-bayes.conf
) for easier overrides to this section of the module config.
Example
# If you're confident you've properly secured access to the rspamd web service/API (Default port: 11334)
# with your own auth layer (eg: reverse-proxy) you can bypass rspamd requiring credentials:
# https://rspamd.com/doc/workers/controller.html#controller-configuration
set-option-for-controller secure_ip "0.0.0.0/0"
# Some settings aren't documented well, you may find them in snippets or Rspamds default config files:
# https://rspamd.com/doc/tutorials/quickstart.html#using-of-milter-protocol-for-rspamd--16
# /etc/rspamd/worker-proxy.inc
set-option-for-proxy reject_message "Rejected - Detected as spam"
# Equivalent to the previous example, but `add-line` is more verbose:
add-line worker-proxy.inc reject_message = "Rejected - Detected as spam"
# Enable Bayes auto-learning feature to classify spam based on Rspamd action/score results:
# NOTE: The statistics module imports a separate file for classifier-bayes config
# https://rspamd.com/doc/configuration/statistic.html#autolearning
set-option-for-module classifier-bayes autolearn true
# Disable the `chartable` module:
# https://rspamd.com/doc/modules/chartable.html
disable-module chartable
Advanced Configuration
DKIM Signing
There is a dedicated section for setting up DKIM with Rspamd in our documentation.
ARC (Authenticated Received Chain)
ARC support in DMS is opt-in via config file. Enable the ARC Rspamd module by creating a config file at docker-data/dms/config/rspamd/override.d/arc.conf
.
Example
For each mail domain you have DMS manage, add the equivalent example.com
sub-section to domain
and adjust the path
+ selector
fields as necessary.
sign_local = true;
sign_authenticated = true;
domain {
example.com {
path = "/tmp/docker-mailserver/rspamd/dkim/rsa-2048-mail-example.private.txt";
selector = "mail";
}
}
Using a common keypair
As with DKIM, the keypair can be shared across your configured domains.
Your ARC config can share the same DKIM private key + selector (with associated DNS record for the public key).
Abusix Integration
This subsection provides information about the integration of Abusix, "a set of blocklists that work as an additional email security layer for your existing mail environment". The setup is straight-forward and well documented:
- Create an account
- Retrieve your API key
- Navigate to the "Getting Started" documentation for Rspamd and follow the steps described there
- Make sure to change
<APIKEY>
to your private API key
We recommend mounting the files directly into the container, as they are rather big and not manageable with our custom-command.conf
script. If mounted to the correct location, Rspamd will automatically pick them up.
While Abusix can be integrated into Postfix, Postscreen and a multitude of other software, we recommend integrating Abusix only into a single piece of software running in your mail server - everything else would be excessive and wasting queries. Moreover, we recommend the integration into suitable filtering software and not Postfix itself, as software like Postscreen or Rspamd can properly evaluate the return codes and other configuration.