Commit graph

337 commits

Author SHA1 Message Date
Martin Weinelt
3579eb0001
dovecot: restrict TLS cipher suites 2025-12-19 04:00:47 +01:00
Martin Weinelt
1415623586
dovecot: support X25519MLKEM768 hybrid kex 2025-12-19 03:13:47 +01:00
Martin Weinelt
e437760341
treewide: replace/remove dovecot2 service name
The unit name is now dovecot.service.
2025-12-19 02:52:55 +01:00
Martin Weinelt
33ba1ff52b
Switch to NixOS ACME module for certificate management
Drop most of the existing certificate handling, because we're effectively
duplicating functionality that NixOS offers for free with better
design, testing and maintainance than what we could provide downstream.

The remaining two options are to reference an
existing `security.acme.certs` configuration through
`mailserver.x509.useACMEHost` or to provide existing key material via
`mailserver.x509.certificateFile` and `mailserver.x509.privateKeyFile`.

Support for automatic creation of self-signed certificates has been
removed, because it is undesirable in public mail setups.

The updated setup guide now displays the recommended configuration that
relies on the NixOS ACME module, but requires further customization to
select a suitable challenge.

Co-Authored-By: Emily <git@emilylange.de>
2025-12-19 02:36:28 +01:00
Martin Weinelt
e04e5b7ea6
assertions: bump mailserver version for release check 2025-11-29 02:43:16 +01:00
Martin Weinelt
cbdf90f639
rspamd: fix DKIM signing for subdomains
With the eSLD normalization feature in rspamd subdomains actually use the
DKIM key for their parent domain, which simplifies the setup if you serve
multiple subdomains.

We however currently create DKIM key pairs for every given domain
name, no matter if it is a second-level domain or subdomain for one, so
disabling eSLD normalization aligns with the current intent behind our
configuration.

In the future it would be nice if we could reuse the parent domain DKIM
key for all its subdomains, but that requires some thought on how to
achieve that normalization in nixos-mailserver first.

Reapplies 1a3a618a30 to the correct
configuration file.
2025-11-16 19:29:16 +01:00
Martin Weinelt
b88e6182f0 Revert "rspamd: fix DKIM signing for subdomains"
This reverts commit 1a3a618a30.

This went into the wrong configuration file unfortunately
2025-11-16 19:26:22 +01:00
Martin Weinelt
b946f74261
mail-server/common: fix eval
CI has a shitty failure mode where jobs that don't eval get removed and
hydra-cli will still exit cleanly.
2025-11-16 18:41:47 +01:00
Martin Weinelt
1cb4295b74
Remove dovecot service name compat code 2025-11-16 18:18:22 +01:00
Martin Weinelt
db66559815 Merge branch 'srs' into 'master'
Add support for sender rewriting for forwards using postsrsd

See merge request simple-nixos-mailserver/nixos-mailserver!431
2025-11-16 14:00:07 +00:00
Martin Weinelt
1a3a618a30
rspamd: fix DKIM signing for subdomains
With the eSLD normalization feature in rspamd subdomains actually use the
DKIM key for their parent domain, which simplifies the setup if you serve
multiple subdomains.

We however currently create DKIM key pairs for every given domain
name, no matter if it is a second-level domain or subdomain for one, so
disabling eSLD normalization aligns with the current intent behind our
configuration.

In the future it would be nice if we could reuse the parent domain DKIM
key for all its subdomains, but that requires some thought on how to
achieve that normalization in nixos-mailserver first.
2025-11-16 14:55:41 +01:00
Martin Weinelt
eeda8ba39e
Add support for sender rewriting using postsrsd
With SRS we support forwarding of mails without (fully) breaking SPF
alignment.
2025-11-11 13:45:03 +01:00
Martin Weinelt
edb7b661e4
postfix: resolve main/master option deprecation 2025-11-10 02:56:51 +01:00
Martin Weinelt
b99f353ab8
postfix: unquote tls_config_file value
This can now be a path type due to changes applied to nixos unstable.
2025-11-10 02:51:46 +01:00
Martin Weinelt
a1532a552f
postfix: enable X25519MLKEM768 key exchange
This migrates the key exchange curve group configuration into the OpenSSL
configuration format, which is the only path forward to configure these.

We now prefer a hybrid key exchange for TLS handshake and as a client
we'll send key shares for that and pure X25519, while keeping backwards-
compat for P256 and P384.

The statistics for my personal mail server over the last month show a
clear trend for X25519 key exchanges:

    156 secp384r1
    225 secp256r1
    19541 x25519
2025-11-10 00:31:43 +01:00
Martin Weinelt
3555a546ab
Add support for SMTP TLS reports
When enabled the tlsrpt services will send out aggregated reports about
TLS connections the local Postfix made to interested parties, who set up
a `_smtp._tls` TXT record with a rua attribute.

Introduces mailserver.systemContact to specify an administrative contact
advertised in these automated reports.
2025-11-08 22:39:29 +01:00
Martin Weinelt
0812ca1e48
Use postfix-tlspol for DANE/MTA-STS policy lookups
Postfix with plain DANE only secures domains that configure DNSSEC and
publish TLSA records. With postfix-tlspol we support MTA-STS protected
connections and get caching for its policy results.

Finally, we use this as a stepping stone to build TLSRPT support on top.
2025-11-08 15:49:34 +01:00
Martin Weinelt
6dbbac29f9
Check release version compat
To move into a better position to align this project with nixpkgs
unstable breaking changes we now default to require a matching nixpkgs
release.
2025-11-08 13:39:33 +01:00
Antoine Eiche
9b57654b31 Only set acme.extraDomainNames when the certificate scheme is acme
Otherwise, certificate domains appear twice in the certificate, since
they are added by the acme module and the nginx module.
2025-10-02 09:36:14 +02:00
Giel van Schijndel
bf2b313365
fix(acme): request certificates for the extra domains too
Instead of just making it _possible_ to perform the name validation...
2025-09-28 19:03:32 +02:00
Martin Weinelt
1a2d7a4bf5
rspamd: restrict addresses we disable checks for to localhost
By default this includes private network subnets, but those should really
use authentication instead, if they want to skip checks.

Closes: #326
2025-08-25 04:12:30 +02:00
Martin Weinelt
fc955088e3
Respect configureLocally flag for redis 2025-08-08 00:01:45 +02:00
Martin Weinelt
43f87f5520
Tokenize dmarc reporter commandline 2025-08-08 00:01:45 +02:00
Martin Weinelt
aa06b2f489
Allow AF_UNIX sockets for dmarc reporter and allow group access
This is required to use redis over UNIX domain sockets.
2025-08-08 00:01:45 +02:00
Martin Weinelt
b76a547bec
treewide: reformat with nixfmt 1.0.0 2025-08-02 02:19:15 +02:00
Martin Weinelt
027e6bcd76
postfix: don't cast message_size_limit to string
On unstable this will become a signed integer and there was never a good
reason for this to be a string.
2025-08-02 02:11:11 +02:00
Martin Weinelt
2b240501e0
Introduce system name and domain options
Bring them up from the DMARC reporting section to the mailserver toplevel
so they become reusable for the upcoming TLSRPT integration.

We default to the first domain in the domains option, if not set
explicitly, so that `systemDomain` doesn't become a blocker for existing
setups. We still encourage picking out the intended one, which is likely
the one used for the MX hostname.

This also simplifies the DMARC reporting configuration, which doesn't
need to be so fine-grained.

Co-Authored-By: Emily <git@emilylange.de>
2025-07-09 01:44:10 +02:00
Martin Weinelt
d6d2053b80
dovecot: use marker option as unit name migration indicator
In nixpkgs we expose `services.dovecot.hasNewUnitName` option that can be
safely inspected to understand that whether to use the `dovecot` systemd
service name instead of `dovecot2`.
2025-07-07 01:10:19 +02:00
Martin Weinelt
f9a52ca4b5
dovecot: fix check for dovecot systemd unit name
and migrate the preStart script in systemd.nix as well.
2025-07-06 05:18:01 +02:00
Martin Weinelt
b38dc8085c
dovecot: add compat shim for dovecot unit name migration
In nixpkgs I renamed dovecot2 to dovecot and made dovecot2 an alias, so
adding the script to the alias does us no good.
2025-07-06 02:52:31 +02:00
emilylange
6ef1eb9ce1
assertions: fix eval error when mailserver.stateVersion is unset (null)
Eval does not stop on the first assertion failure it encouters.
Instead, it tries to evaluate all assertions and returns with a list of
those that failed.

This means our very top `config.mailserver.stateVersion != null`
assertion does not gate against any other assertions trying to compare
null against an integer.

The error prior to this commit can be reproduced by removing
`mailserver.stateVersion = 999;` in tests/lib/config.nix and then trying
to evaluate any of the tests:

~~~bash
# nix eval --raw .#checks.x86_64-linux.internal-unstable
error:
       … while evaluating the attribute 'outPath'
         at /nix/store/syvnmj3hhckkbncm94kfkbl76qsdqqj3-source/lib/customisation.nix:421:7:
          420|         drv.drvPath;
          421|       outPath =
             |       ^
          422|         assert condition;

       … while calling the 'getAttr' builtin
         at «internal»:1:500:
       (stack trace truncated; use '--show-trace' to show the full trace)

       error: cannot compare null with an integer
~~~
2025-06-21 20:15:46 +02:00
Martin Weinelt
f25495cabf
dovecot: fix custom index dir configuration for ldap users 2025-06-21 09:47:03 +02:00
Martin Weinelt
62ea8a7e00
dovecot: migrate to dedicated homedir and separate maildir paths
Per the dovecot documentation[0] we were previously running with an
unsupported home directory configuration, because we shared them among
all virtual users at /var/vmail.

After resolving this by creating per user home directories at
/var/vmail/%{domain}/%{user} this now also overlaps with the location of
the Maildir, which is not recommended.

As a result we now need to migrate our Maildirs into
/var/vmail/%{domain}/%{user}/mail, for which a small shell script is
provided as part of this change.

The script is included in the documentation because we cannot provide it
in time for users, because they might already be seeing the relevant
assertion and there is no safe waiting period that would allow us to skip
shipping it like that.

[0] https://doc.dovecot.org/2.3/configuration_manual/mail_location/
2025-06-21 09:46:32 +02:00
Martin Weinelt
64aca4f2ce
postfix: disable SHA1 for SMTP connections 2025-06-18 06:58:42 +02:00
Martin Weinelt
cf6ef5e9ca
Create per service debug logging toggles
Enabling the rspamd debug log drowns out everything else and should be
selected explicitly as needed.

The external test does not require it and removing it makes it much
(~40.5%) faster, since it now does not block on terminal output anymore.

Before:
```
Benchmark 1: nix build .#hydraJobs.x86_64-linux.external-unstable --rebuild
  Time (mean ± σ):     151.737 s ±  1.074 s    [User: 0.310 s, System: 0.289 s]
  Range (min … max):   150.321 s … 153.512 s    10 runs
```

After:
```
Benchmark 1: nix build .#hydraJobs.x86_64-linux.external-unstable --rebuild
  Time (mean ± σ):     90.531 s ±  0.557 s    [User: 0.054 s, System: 0.045 s]
  Range (min … max):   89.579 s … 91.278 s    10 runs
```
2025-06-17 22:02:31 +02:00
Martin Weinelt
6652b57dda
postfix: rearrange smtpd_tls_chain_files option 2025-06-16 07:27:03 +02:00
Martin Weinelt
c8f809fa76
postfix: migrate more options to services.postfix.config
I'm working on deprecating the top-level options, that configure main.cf
upstream in nixpkgs. With this change we stay ahead of the curve.

The `networks_style` option already defaults to `host` since Postfix 3.0,
so I dropped the setting.

```
$ postconf -d | grep networks_style
mynetworks_style = ${{$compatibility_level} <level {2} ? {subnet} : {host}}
````
2025-06-16 07:03:49 +02:00
Martin Weinelt
a2152f9807
treewide: remove overly broad with cfg
Makes it really hard to follow references and we were being explicit in
most places already anyway.
2025-06-15 05:39:20 +02:00
Martin Weinelt
fb56bcf747
treewide: remove global with lib
Instead inherit required functions from lib.
2025-06-15 05:08:47 +02:00
Martin Weinelt
1a7f3d718c
treewide: reformat with nixfmt-rfc-style 2025-06-15 03:39:44 +02:00
Martin Weinelt
c7497cd5f6
treewide: remove redundant parenthesis in nix code 2025-06-15 03:28:48 +02:00
Martin Weinelt
5f592b5960 Merge branch 'crypto-v2' into 'master'
postfix, dovecot: modernize and comment TLS settings

See merge request simple-nixos-mailserver/nixos-mailserver!413
2025-06-14 22:52:29 +00:00
Martin Weinelt
21ce4b4ff8
dovecot: disable Diffie-Hellman support
Recommended in the modern recommendation by Mozilla. Support for elliptic
curves is widespread and they are much faster.
2025-06-15 00:22:58 +02:00
Martin Weinelt
efebf59b13
dovecot: configure preferred elliptic curves 2025-06-15 00:22:57 +02:00
Martin Weinelt
4fd9508d41
postfix: drop tls_random_source config
The setting already defaults to /dev/urandom.
2025-06-15 00:22:57 +02:00
Martin Weinelt
3828b00dea
postfix: configure preferred curves and disable FFDHE
This aligns with the intermediate configuration recommended by Mozilla.
2025-06-15 00:22:57 +02:00
Martin Weinelt
e27326d317
postfix: refactor and prune TLS settings
- Groups settings between server and client
- Uses a range comparator for supported TLS versions
- Prune excluded primitives to what affects the supported TLS versions
2025-06-15 00:22:57 +02:00
Martin Weinelt
23cc9a3996 Merge branch 'postfix-cert-key' into 'master'
postfix: configure cert/key using smtpd_tls_chain_files

Closes #183

See merge request simple-nixos-mailserver/nixos-mailserver!410
2025-06-14 12:47:58 +00:00
Martin Weinelt
3f1c6960d3 Merge branch 'smptp-smuggling-cleanup' into 'master'
postfix: remove option to toggle SMTP smuggling workarounnd

See merge request simple-nixos-mailserver/nixos-mailserver!411
2025-06-12 22:57:43 +00:00
Martin Weinelt
f1bd4b8215
postfix: remove option to toggle SMTP smuggling workarounnd
It has been default enabled since Postfix 3.9 and can still be configured
from the NixOS option mentioned in the removal warning.

Removing the option makes our interface leaner.

Information is based on https://www.postfix.org/smtp-smuggling.html#long.
2025-06-13 00:21:16 +02:00