Files
nixos/modules/services/mail/learn-ham.sieve
JakeHillion 2ecc0031bf
commit-validation / validate-single-commit (pull_request) Successful in 8s
buildbot/nix-eval Build done. (633 warnings)
buildbot/nix-build Build done.
buildbot/nix-effects Build done.
mail: run an MX for jakehillion.me in a DMZ container
Add a DMZ network on VLAN 6 at home. cyclone routes the Olilo /29
(51.194.133.160/29) and 2a11:2646:14b6:2::/64 on-link into it, with
fe80::1 as the IPv6 gateway. It forwards TCP 25, 80, 465, 587 and 993
and ICMP to the mail addresses, lets DMZ traffic out to Olilo only from
those prefixes and never to TCP 25, and drops them as sources arriving
on any other interface. A new topology option, routedSubnets, exempts
the /29 from masquerading.

warlock carries VLAN 6 with no addresses of its own, for containers'
macvlans.

Add a mail service, placed on warlock, that runs an ephemeral container
on the DMZ with 51.194.133.162 and 2a11:2646:14b6:2::1:
- OpenSMTPD accepts mail for jakehillion.me on 25 with STARTTLS,
  filtered through rspamd, and delivers it to Dovecot over LMTP with a
  catch-all to jake@jakehillion.me. Authenticated submission is on 465
  and on 587 with STARTTLS required, leaving the client's address out of
  the Received header, and outbound mail relays through
  smtp-auth.mythic-beasts.com. OpenSMTPD only loads root-owned
  certificates, so the ACME certificate is copied to a root-owned
  runtime directory before it starts.
- Dovecot serves IMAP on 993 only, with a passwd-file shared with
  OpenSMTPD's auth table. A Sieve script files mail rspamd marks as spam
  into Junk, and moving mail into or out of Junk trains rspamd.
- rspamd keeps its learned state in a local Redis and treats no address
  ranges as local, so private senders get the same checks as any other.
  It applies senders' DMARC policies: quarantine failures are marked as
  spam and filed into Junk, and reject failures are refused. unbound
  resolves recursively for DNSBL lookups.
- ACME issues mx.jakehillion.me over HTTP-01.

The container runs with a private user namespace, and its state and
secrets are bind-mounted from the host with idmap so host ownership
carries through. It waits for the dmz VLAN device before starting, and
restarts when either mail secret changes. The mailboxes are backed up
to restic. Add fixed IDs for vmail, acme and redis-rspamd.

Test plan:
- Built cyclone.gw and warlock.cx toplevels; checked the nftables
  rules, the masquerade exemption and both 40-dmz.network files.
- Checked the container's nspawn flags (private users, idmap binds),
  networkd config, opensmtpd unit and smtpd.conf pki paths.
- Validated the generated dovecot.conf with doveconf, smtpd.conf with
  smtpd -n, the Sieve scripts with sievec and cyclone's ruleset with
  nft -c.
2026-11-07 16:51:35 +00:00

13 lines
269 B
Sieve

require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
}
# Moving spam to the bin isn't a sign it was ham
if string "${mailbox}" "Trash" {
stop;
}
pipe :copy "learn-ham";