OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • Networking on OpenBSD
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • OpenBSD Desktop Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • OpenSMTPD Mail Server
          • Dovecot IMAP and POP3 Server
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound DNS Resolver
          • NSD Authoritative DNS Server
          • BIND DNS Server
        • Networking
          • OpenBGPD
          • rad
          • DHCP on OpenBSD
          • slaacd
        • Web
          • Apache HTTP Server
          • nginx Web Server
          • OpenBSD httpd Web Server
          • relayd Reverse Proxy
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • OpenSSH Server
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ Message Broker
        • Time
          • NTP Time Synchronization
        • Load Balancing
          • Build Redundant Load-Balanced Gateways
          • Load Balance Services with NAT or DSR
          • Build an HA HTTPS Load Balancer
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • How-to Guides
        • Installation and First Boot
          • Complete the First 30 Minutes After Installation
          • Check Hardware Compatibility Before Installing
          • Bootstrap Wi-Fi Firmware Without Ethernet
          • Run OpenBSD as a Virtual Machine Guest
          • Install OpenBSD on a VPS or Cloud Server
          • Install OpenBSD with Full-Disk Encryption
          • Dual-Boot OpenBSD on a UEFI System
          • Automate OpenBSD Installation with Autoinstall and PXE
        • Desktops and Laptops
          • Set Up OpenBSD as a Laptop or Workstation
          • Configure Laptop Power Management
          • Troubleshoot Web Browsers on OpenBSD
          • Use Plan 9 Tools on OpenBSD
          • Build a Minimal Desktop with suckless Tools
          • Install Z shell (zsh)
        • Networking and Remote Access
          • Create an Administrator Account with doas and SSH Keys
          • Configure Secure Remote Access with OpenSSH
          • Use FIDO Security Keys with OpenSSH
          • Configure Wi-Fi Roaming and Wired Failover
          • Troubleshoot PF, NAT, and Routing
          • Route Multiple VLANs with PF
          • Configure a Road-Warrior WireGuard VPN
          • Route IPv6 Networks without NAT
          • Test OpenBGPD with Two Providers
          • Unlock an Internal Service with an SSH Key
          • Build a Simple Router and Firewall
        • Servers and Services
          • Set Up WordPress on OpenBSD
          • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Security, Maintenance and Recovery
          • Establish a Conservative Security Baseline
          • Recover Access and Reset the Root Password
          • Collect OpenBSD Diagnostic Evidence
          • Troubleshoot Package Installation and Update Failures
          • Schedule Recurring Maintenance
          • Monitor an OpenBSD System
          • Back Up and Restore an OpenBSD System
          • Configure softraid RAID1
          • Recover an OpenBSD System That Does Not Boot
        • Building, Automation and Virtual Machines
          • Manage OpenBSD with Ansible
          • Build Third-Party Software from Ports
          • Build OpenBSD from Source
          • Plan a Docker Workload Migration to OpenBSD
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
        • Features
        • Installation
        • Architecture Overview
        • Configuration Structure
        • Enabling the Web Interface
        • Integration with smtpd(8)
        • Integration with Postfix
        • Mail Scanning with rspamc
        • Using Redis for Statistics
        • DKIM Signing and Verification
          • Signing Outgoing Mail
          • Verifying DKIM
        • DMARC and SPF
        • Bayes Training
        • Logging and Monitoring
        • Security Considerations
        • File Locations

        Rspamd

        Synopsis #

        Rspamd filters email using regular expressions, statistical analysis, SPF/DKIM/DMARC checks, and URL reputation. It integrates with mail servers such as OpenSMTPD, Postfix, and Exim.

        Follow the mail server’s documented integration procedure. The examples below use OpenBSD’s smtpd(8).

        Features #

        • Spam classification and scoring
        • Built-in support for DKIM, SPF, and DMARC validation
        • Statistical filtering with Redis backend
        • Milter and proxy protocol support
        • Web-based administration and status interface
        • Lua scripting engine for custom rules
        • Integration with antivirus and antiphishing backends

        Installation #

        Rspamd is not included in the OpenBSD base system. Install it using pkg_add(1):

        doas pkg_add rspamd
        

        The package configures a local Redis backend. Ensure Redis is installed and running for the enabled modules.

        To enable and start Rspamd:

        doas rcctl enable redis rspamd
        doas rcctl start redis rspamd
        

        The main configuration directory is located at:

        /etc/rspamd/
        

        The runtime data is located in:

        /var/db/rspamd/
        

        Architecture Overview #

        Rspamd uses a multi-process architecture composed of the following components:

        • controller: handles configuration reload, statistics, and HTTP requests
        • normal workers: perform spam checks and filtering
        • proxy workers: used when running behind MTAs in milter or proxy mode
        • rspamc: the client tool used to submit messages for classification or learning

        Configuration Structure #

        Rspamd separates its configuration into several files:

        File or DirectoryPurpose
        /etc/rspamd/rspamd.confMain configuration file
        /etc/rspamd/local.d/worker-proxy.incProxy worker settings
        /etc/rspamd/local.d/worker-controller.incController (HTTP admin interface) settings
        /etc/rspamd/local.d/worker-normal.incStandard filtering worker settings
        /etc/rspamd/modules.d/Individual module configurations

        After making changes to any configuration files, restart the service:

        doas rspamadm configtest && doas rcctl restart rspamd
        

        Enabling the Web Interface #

        Keep the controller bound to loopback and use an SSH tunnel for remote administration:

        Edit /etc/rspamd/local.d/worker-controller.inc:

        bind_socket = "127.0.0.1:11334";
        password = "replace-with-rspamadm-pw-output";
        enable_password = "replace-with-separate-rspamadm-pw-output";
        

        Generate the password hash using:

        doas rspamadm pw
        

        secure_ip grants trusted controller access; it is not a network allowlist. Use binding and PF for network restrictions. Put local changes in local.d rather than editing packaged defaults.

        Access the web UI at:

        http://localhost:11334/
        

        Integration with smtpd(8) #

        Install the OpenSMTPD integration package:

        doas pkg_add opensmtpd-filter-rspamd
        

        Follow /usr/local/share/doc/pkg-readmes/opensmtpd-filter-rspamd for the filter command and listener configuration. This integration uses OpenSMTPD’s filter protocol; a generic milter executable is not an OpenSMTPD filter. Preserve the existing TLS, actions, and relay restrictions when adding the filter. Validate both configurations with rspamadm configtest and smtpd -n, then test actual mail scanning and delivery.

        Integration with Postfix #

        To use Rspamd as a milter with Postfix:

        In /etc/rspamd/local.d/worker-proxy.inc:

        bind_socket = "127.0.0.1:11332";
        milter = yes;
        

        In /etc/postfix/main.cf:

        smtpd_milters = inet:127.0.0.1:11332
        non_smtpd_milters = inet:127.0.0.1:11332
        milter_protocol = 6
        milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
        

        Then restart Postfix:

        doas postfix reload
        

        Mail Scanning with rspamc #

        The rspamc tool can be used to manually scan messages, train the Bayesian classifier, or check scores:

        rspamc -h localhost:11333 < message.eml
        rspamc learn_spam < spam.eml
        rspamc learn_ham < ham.eml
        

        Using Redis for Statistics #

        Rspamd uses Redis for statistical storage and rate-limiting. Install and enable Redis:

        doas pkg_add redis
        doas rcctl enable redis
        doas rcctl start redis
        

        In /etc/rspamd/local.d/classifier-bayes.conf:

        backend = "redis";
        servers = "127.0.0.1";
        

        Restart Rspamd:

        doas rspamadm configtest && doas rcctl restart rspamd
        

        DKIM Signing and Verification #

        Signing Outgoing Mail #

        Generate DKIM keys:

        doas install -d -m 750 -o root -g _rspamd /etc/rspamd/dkim
        doas sh -c 'umask 077; rspamadm dkim_keygen -d example.org -s mail -k /etc/rspamd/dkim/example.org.mail.key' > example.org.mail.dns.txt
        

        Set permissions:

        doas chown _rspamd:_rspamd /etc/rspamd/dkim/example.org.mail.key
        doas chmod 0400 /etc/rspamd/dkim/example.org.mail.key
        

        In /etc/rspamd/local.d/dkim_signing.conf:

        domain {
          example.org {
            selector = "mail";
            path = "/etc/rspamd/dkim/example.org.mail.key";
          }
        }
        

        Publish the DKIM public key in DNS (output by dkim_keygen).

        Verifying DKIM #

        Rspamd verifies DKIM automatically if the dkim.conf module is enabled. Configuration is usually in /etc/rspamd/modules.d/dkim.conf.

        DMARC and SPF #

        Ensure the following modules are enabled and configured:

        • /etc/rspamd/modules.d/dmarc.conf
        • /etc/rspamd/modules.d/spf.conf

        Ensure the resolvers in /etc/resolv.conf can answer the DNS queries required by these checks.

        Bayes Training #

        Rspamd learns spam and ham from messages. Submit them via rspamc:

        rspamc learn_spam < spam.eml
        rspamc learn_ham < ham.eml
        

        Feed selected, correctly classified messages to these learning commands. Folder-based automation requires a separate, explicitly configured workflow; there is no generic learned module that watches mail folders.

        Logging and Monitoring #

        Logs are written to:

        /var/log/rspamd/rspamd.log
        

        Use rspamc stat to view live statistics:

        rspamc stat
        

        Use rspamadm configdump to inspect effective configuration:

        doas rspamadm configdump
        

        Security Considerations #

        • Run Rspamd as _rspamd with limited privileges
        • Use local sockets or restrict TCP listener access
        • Protect the controller interface with strong passwords and IP restrictions
        • Regularly update configuration files and rulesets
        • Validate SPF, DKIM, and DMARC policies for incoming mail

        File Locations #

        PathDescription
        /etc/rspamd/Configuration directory
        /var/log/rspamd/rspamd.logLog file
        /var/db/rspamd/Runtime and statistical data
        /etc/rspamd/dkim/DKIM private keys
        opensmtpd-filter-rspamd packageOpenSMTPD filter integration
        Report a bug
        • Synopsis
        • Features
        • Installation
        • Architecture Overview
        • Configuration Structure
        • Enabling the Web Interface
        • Integration with smtpd(8)
        • Integration with Postfix
        • Mail Scanning with rspamc
        • Using Redis for Statistics
        • DKIM Signing and Verification
          • Signing Outgoing Mail
          • Verifying DKIM
        • DMARC and SPF
        • Bayes Training
        • Logging and Monitoring
        • Security Considerations
        • File Locations