Skip to content

Restrict the Rspamd controller socket to root and the mail user - #43

Open
byjpr wants to merge 1 commit into
claude/admiring-planck-25cvzffrom
claude/fix-19-rspamd-socket
Open

byjpr wants to merge 1 commit into
claude/admiring-planck-25cvzffrom
claude/fix-19-rspamd-socket

Conversation

@byjpr

@byjpr byjpr commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Closes #19

Changes

  • The Rspamd controller socket /run/rspamd/worker-controller.sock changes from 0666 (world-writable, set by simple-nixos-mailserver) to 0660, owner rspamd, group virtualMail. Access is now limited to:
    • root, i.e. the admin rspamc wrapper;
    • Dovecot's spam/ham learning (rspamd-learn-spam.sh / -ham.sh, piped from IMAP processes). Those run with mail_gid = virtualMail, so learning by moving mail into or out of Junk keeps working.
  • nginx, kresd and every other local service can no longer retrain the Bayes filter or change maps.
  • Rspamd runs unprivileged, and can only give the socket to a group it belongs to, so the service gets SupplementaryGroups=virtualMail. That grants it nothing else: mail homes are created 0700 (NixOS homeMode default) and Dovecot writes mail with umask 0077.

Testing

  • The generated rspamd.conf has bind_socket = "/run/rspamd/worker-controller.sock mode=0660 owner=rspamd group=virtualMail".
  • rspamd.service has SupplementaryGroups=virtualMail and redis-rspamd; systemd adds the two together.
  • The generated dovecot.conf has mail_gid = virtualMail.
  • All 5 provider example systems build. nixfmt, shellcheck and tofu validate pass.
  • Not exercised on a running server (socket creation as the rspamd user, learning via IMAP). It's on the docs/first-install.md list if First-install checklist, just status, robust relay credential permissions #41 is merged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01G22o7QQ17GRtkCqpJNFr9B


Generated by Claude Code

The controller socket accepts unauthenticated commands and was
world-writable (0666), so any local service could retrain the spam filter
or change its maps. It is now 0660, group virtualMail: root (the admin
rspamc wrapper) and Dovecot's spam/ham learning (mail processes run with
gid virtualMail) keep access. Rspamd joins that group only to be allowed
to chown the socket; mail homes are 0700 and mail files 0600.

Closes #19

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G22o7QQ17GRtkCqpJNFr9B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Low] Any local process can control Rspamd (world-writable controller socket)

2 participants