Sender rewriting with srs-milter
srs-milter is a Postfix milter for the Sender Rewriting Scheme (SRS). A Sieve redirect sends a message on with its original envelope sender, and the receiver's SPF check then fails: the forwarder is not a server of the sender's domain. srs-milter rewrites the envelope sender into the forwarder's own domain, so the forward passes SPF, and turns a bounce to that address back to the original sender.
Where it runs
srs-milter runs on relay-fwd-out of yarilo-postfix, in mode both. relay-fwd-out carries the mail yarilo sends to other domains, and it is also the MX of the SRS domain:
- Port 587, forward. First of the milters, before dkim-milter-fwd and arc-milter. It changes the envelope sender only, which neither the DKIM signature nor the ARC seal covers; being first, a forward it cannot decide is held before anything is signed.
- Port 25, reverse. A listener of its own on a dedicated external address, the one the SRS domain's MX record names. It takes recipients in the SRS domain and nothing else, with no login, and srs-milter is its only milter.
relay-mx and relay-fwd do not run it. A redirect to a mailbox of a local domain is delivered by relay-fwd and never leaves the installation, so it needs no SRS.
Forwarding
The envelope sender user@sender. leaves as:
SRS0=HHHH=TT=sender.example=user@fwd.example.orgHHHH is the hash, an HMAC of the rest under the SRS secret, and TT the day the address was made. Left alone:
- the null sender;
- a sender of a local domain (see below);
- an address already in the SRS domain.
Another forwarder's SRS0 or SRS1 address becomes an SRS1 address that leads back to that forwarder, so the chain does not grow with each hop.
Local domains
A sender of a domain hosted here keeps its address: SPF passes for it as it is. The domains are a static list, a database query, or both. Answers of the database are cached; while the database is down an answer once read stands, and a forward from a domain never seen is tempfailed and waits in the queue rather than leaving without SRS.
Bounces
A recipient in the SRS domain is checked at RCPT TO:
- a valid address is accepted and replaced by the original sender at the end of the message;
- a forged, malformed or expired one is refused with
550.
An address turns bounces back for validityDays, 21 by default, the day it was made not counted.
Bounding replies
A valid SRS address is a relay to the original sender for anyone who has seen it once, for as long as it is valid. srs-milter can bound that:
- Reply count. With a reply store, it counts the messages each address turned back and refuses the next one past
replies.withmax 550. The address of one sender is the same for a whole day, so the limit is per original sender and day of forwarding. A recipient check that sends no message is not counted, and a message refused at its end takes no reply from any of its addresses. - Size.
replies.refuses withmaxBytes 552a message too large to be a delivery status notification.
The store is none by default: no count, as in other SRS implementations. sqlite keeps the count in one pod's file, redis shares it between replicas. The count is dropped two days after the address expires. While the store does not answer, mail to SRS addresses gets 451 and the sending server retries.
With replies. set, a message whose recipients are both SRS addresses and others gets 452 for the later kind, so the sender delivers them apart: the size limit is the whole message's. Without it they share a message.
Compatibility
The address format and the defaults (HMAC-SHA1, four characters of hash, 21 days, no reply count, no size limit) are those of libsrs2. With the same secret, addresses another SRS daemon issued still turn back.
TIP
Four characters of hash give about 16 million values, and nothing bounds guessing at the MX. A longer hash, such as 8, is the safer choice for a new installation; raise hashLength and set hashMinLength to the old length for validityDays, so addresses issued before still turn back.
Secrets
The signing secret comes from a Secret. A second key, previousKey, holds the secret before it: both verify, the first signs. To rotate, put the old secret under the previous key and a new one under the first, and remove the previous one after validityDays.
Postfix configuration
yarilo-postfix sets both sides through fwdOut. and fwdOut., which go together: one without the other does not render. On 587:
smtpd_milters = { inet:srs-milter:8894, default_action=tempfail },
{ inet:dkim-milter-fwd:8891, default_action=tempfail },
{ inet:arc-milter:8893, default_action=tempfail }On 25, the SRS domain alone:
relay_domains = fwd.example.org
smtpd_recipient_restrictions = reject_non_fqdn_recipient,
reject_unauth_destination,
check_recipient_access regexp:/etc/postfix/srs-recipients.regexp,
reject
smtpd_milters = { inet:srs-milter:8894, default_action=tempfail }The recipient table takes @fwd. and refuses everything else with 550, a subdomain of the SRS domain and localhost included.
tempfail keeps forwards and bounces queued while srs-milter is down; nothing else goes through it. Run more than one replica, with the redis store when replies are counted.
Environment
| Variable | Default |
|---|---|
MODE | both (or forward, reverse) |
SRS_ | none, required |
SRS_ | none, required |
SRS_ | none |
SRS_ | sha1 (or sha256, sha512) |
SRS_ | 4 |
SRS_ | SRS_ |
SRS_ | = (or +, -) |
SRS_ | 21 |
MAX_ | 0: no limit |
REPLY_ | none (or sqlite, redis) |
MAX_ | 10, read with a store |
SQLITE_ | / |
REDIS_, or REDIS_ with REDIS_ | none, one required with redis |
REDIS_, REDIS_, REDIS_ | none, none, 0 |
REDIS_, REDIS_ | none |
REDIS_ | none, required with redis |
LOCAL_ | none; comma-separated |
DB_, DB_ | mysql (or postgres), none |
LOCAL_ | SELECT 1 FROM domain WHERE domain = ? AND active = 1; one placeholder, any row means local |
DB_ | 4 |
DOMAIN_, DOMAIN_, DOMAIN_ | 10000, 300, 300 |
LISTEN_, METRICS_ | 0., 0. |
MILTER_, MILTER_ | 3600, 60 |
LOG_ | none (debug for more) |
Helm chart
The chart is published at oci:/ and signed with cosign; its README shows how to verify it. It sets every variable above from its values, and the chart's defaults are the code's: mode, srs. (srs. and srs. are required), replies. with replies., localDomains. and logLevel. replicaCount above 1 needs the none or redis store: the sqlite file is one pod's. networkPolicy. opens the milter port to the Postfix pods named there; on yarilo-postfix that is relay-fwd-out alone.
helm install srs-milter oci://ghcr.io/yarilomail/charts/srs-milter \
--version <version> -n mail -f my-values.yamlWARNING
A NetworkPolicy is enforced only by a CNI that implements it, such as Calico, Cilium, or the kube-router built into k3s. With flannel alone it is accepted and silently ignored.
Readiness and metrics
/ answers 200 once the domain query and the reply store answer; / and / are on the same port. Logs are JSON on stdout.
| Metric | Meaning |
|---|---|
srs_ | envelope senders seen: rewritten, relayed (another forwarder's SRS address, wrapped), long (rewritten past 64 octets), null, own, local, tempfail |
srs_ | recipients in the SRS domain: reversed, not_, malformed, bad_, expired, over_, too_, mixed, tempfail |
srs_ | calls to the reply store that failed; the message was tempfailed |
srs_ | lookups past the static list: hit, miss, stale (database down, old answer used), error |