MTA-STS on outgoing mail
When this server sends mail to a domain that enforces an MTA-STS policy, the mail leaves only over TLS with a verified certificate, to an MX the policy names. Everywhere else, outgoing mail uses opportunistic TLS as before: encrypted when the receiving server offers it, delivered anyway when it doesn't.
The outgoing mail server (Postfix) can't fetch an HTTPS policy itself. A
resolver does it for it: elpan-mail-sts, which runs
postfix-mta-sts-resolver
as elpan-mail-sts.service. elpan-mail-out requires the package, so every
server has it. The other direction, the policies of the server's own
domains, is Mail Transport Security.
What the resolver answers
For each destination domain, the outgoing mail server asks the resolver
over its socket, /run/elpan-mail-sts/socketmap.sock. Only the outgoing
mail server and root can reach it: the directory belongs to the resolver's
own account, with access for postfix alone. The resolver looks up
_mta-sts.<domain>, fetches and caches the policy, and answers:
| The destination's policy | What outgoing mail requires |
|---|---|
mode: enforce | TLS with a certificate valid for the MX's name, to an MX matching the policy's mx lines, with SNI. A delivery that can't meet it is deferred, and in the end returned to its sender. |
mode: testing, mode: none, no policy | Nothing more than usual. The resolver answers "not found". |
| Can't be fetched, nothing cached | Nothing more than usual. An unreachable policy host never holds up mail. |
The resolver caches policies in /var/lib/elpan/mail-sts/cache.db for
their max_age and refreshes them ahead of time. Its configuration is
/etc/elpan/mail-sts/mta-sts-daemon.yml, a configuration file the package
doesn't overwrite.
The order of the lookups
The outgoing mail server asks its own TLS policy map first and the resolver second, and takes the first answer:
smtp_tls_policy_maps = $elpan_smtp_tls_policy_maps, $elpan_mta_sts_policy_maps
So an entry for a destination in a map asked before the resolver wins over
the destination's published policy. The panel's own map has no entries
today; a map of yours goes in a drop-in in /etc/elpan/mail-out/main.cf.d/
(see Configuration drop-ins),
ahead of the resolver in smtp_tls_policy_maps. That is the way to exempt
a destination whose policy is broken, or to set the level for an outgoing
gateway's next hop: Postfix looks a relay host up like a domain, and a
relay host whose name publishes a policy of its own is held to it.
When the resolver is down, mail still flows
The resolver is named only while it runs. When it is ready, the unit
writes /var/lib/elpan/mail-out/config/main.cf.d/50-mta-sts.cf, which
sets $elpan_mta_sts_policy_maps to the resolver, and reloads the
outgoing mail server. When it stops, fails or is killed, the unit removes
the fragment and reloads again. Stopped, crashing, failing to start or not
installed, the resolver is simply not asked, and mail goes out without
MTA-STS.
Postfix treats a policy table it can't query as an error and defers the
message (4.7.5, "TLS policy lookup error"). A lookup that always named
the resolver would hold up every outgoing message, to every destination,
while the resolver was down.
Messages in flight between a crash and the reload are deferred and retried. A resolver that hangs while it still accepts connections isn't detected: Postfix waits for the lookup to time out, then defers.
To stop honouring MTA-STS on purpose:
systemctl disable --now elpan-mail-sts
The resolver logs to the journal (journalctl -u elpan-mail-sts), a
failed fetch as a warning with the domain. The manual page is
elpan-mail-sts(8).
See what outgoing mail requires
When an account holder says "mail to X stopped",
elpanctl mail tls probe <domain>
shows what outgoing mail would require for that destination, in the order the outgoing mail server asks:
- the panel's TLS policy map (your own maps in
/etc/elpan/mail-out/main.cf.d/are not read here), - the resolver's answer,
- the destination's own
_mta-stsrecord and policy, fetched directly and not cached, so a policy in testing mode shows too,
and a summary:
MTA-STS resolver: active; mail-out names it.
...
What mail-out requires
----------------------
TLS with a verified certificate, to an MX matching .gmail-smtp-in.l.google.com, gmail-smtp-in.l.google.com, smtp.google.com (MTA-STS enforce). A delivery that cannot meet it is deferred.
A probe asks the resolver as the outgoing mail server would, so it warms the resolver's cache.
The resolver may answer from its cache, and it caches the _mta-sts
record for the record's TTL, so it can lag behind a change for a while,
as any sender does. The third section of the probe shows what the
destination publishes now. As root,
/usr/lib/elpan/mail-sts/mta-sts-query <domain> fetches a policy without
the cache, too.
elpanctl mail tls status
checks the server's side now and stores it for the admin view's This Server box: the certificate the incoming mail server shows a sender without SNI, and whether the resolver runs and outgoing mail names it. The worker runs the same check every hour.