Postfix milter in Go for the Sender Rewriting Scheme (SRS). It rewrites the envelope sender of forwarded mail to an address in the forwarder's own domain, so the forward passes SPF, and turns a bounce to that address back to the original sender. Unlike a lookup table, a milter sees the whole message, so it can also bound what such an address accepts: how many messages, and how large.
Licensed under AGPLv3, see LICENSE. Website: yarilomail.org
[email protected] leaves as [email protected]. Senders of the local domains, the null sender and addresses already in the SRS domain are left alone. Another forwarder's SRS0 or SRS1 address becomes an SRS1 address that leads back to that forwarder.RCPT TO and replaced by the original sender at the end of the message. A forged, malformed or expired address is refused there with 550.MAX_REPLIES; MAX_REPLY_BYTES refuses a message too large to be a delivery status notification. A recipient check that sends no message is not counted.The Postfix that sends forwards out runs the milter in forward mode, the MX of the SRS domain in reverse mode; one Postfix that does the two uses both.
# forward
smtpd_milters = { inet:srs-milter:8894, default_action=tempfail }
# reverse: the SRS domain is accepted, the milter refuses what it does not turn back
relay_domains = fwd.example.org
smtpd_milters = { inet:srs-milter:8894, default_action=tempfail }
With MAX_REPLY_BYTES 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.
A message refused at its end, over the limit or with the store not answering, takes no reply from any of its addresses.
| Variable | Default | What |
|---|---|---|
MODE | both | forward, reverse or both |
SRS_DOMAIN | required | domain of the rewritten addresses |
SRS_SECRET | required | signing secret |
SRS_SECRET_PREVIOUS | the secret before it: verifies, never signs | |
SRS_HASH_ALGORITHM | sha1 | HMAC of the address: sha1, sha256, sha512 |
SRS_HASH_LENGTH | 4 | characters of the hash in the address, 6 bits each |
SRS_HASH_MIN_LENGTH | SRS_HASH_LENGTH | shortest hash still accepted, for the days after the length was raised |
SRS_SEPARATOR | = | character after SRS0 and SRS1: =, + or - |
SRS_VALIDITY_DAYS | 21 | days an address turns bounces back |
MAX_REPLY_BYTES | 0 | largest message to an SRS address, headers and body; 0: no limit |
REPLY_STORE | none | where replies are counted: none, sqlite, redis |
MAX_REPLIES | 10 | messages one address turns back while valid; read with a store |
SQLITE_PATH | /data/replies.db | file of REPLY_STORE=sqlite |
REDIS_ADDR | host:port of REPLY_STORE=redis | |
REDIS_SENTINEL_ADDRS, REDIS_SENTINEL_MASTER, REDIS_SENTINEL_USERNAME, REDIS_SENTINEL_PASSWORD | Sentinels instead of REDIS_ADDR | |
REDIS_USERNAME, REDIS_PASSWORD, REDIS_DB | ||
REDIS_KEY_PREFIX | required with redis | counts live at <prefix>replies:<address> |
LOCAL_DOMAINS | comma-separated domains whose senders keep their address | |
DB_DRIVER, DB_DSN | mysql, none | with a DSN, a sender's domain is also looked up in a database (mysql or postgres) |
LOCAL_DOMAIN_SQL_QUERY | SELECT 1 FROM domain WHERE domain = ? AND active = 1 | one placeholder, the domain; any row means local |
DB_MAX_OPEN_CONNS | 4 | |
DOMAIN_CACHE_SIZE, DOMAIN_CACHE_TTL_SECONDS, DOMAIN_CACHE_MISS_TTL_SECONDS | 10000, 300, 300 | cache of the database's answers |
LISTEN_ADDR, METRICS_ADDR | 0.0.0.0:8894, 0.0.0.0:8081 | milter; /metrics, /healthz, /readyz |
MILTER_READ_TIMEOUT_SECONDS, MILTER_WRITE_TIMEOUT_SECONDS | 3600, 60 | |
LOG_LEVEL | info | debug |
The address of one sender is the same for a whole day, so MAX_REPLIES is per original sender and day of forwarding, over the life of the address. The count is dropped two days after the address expires. sqlite keeps it in one pod's file, redis shares it between replicas. While the store does not answer, mail to SRS addresses gets 451 and the sending server retries.
A forward from a domain the database never answered for, with the database down, is tempfailed and waits in the queue; an answer once read stands for as long as the database is down.
| Path | What |
|---|---|
app/go | the milter, Go 1.27, go test ./... |
helm | the chart; every variable above is a value |
helm_values | values for the yarilo stand: one release on relay-fwd-out, both directions |
hack/release | sign-chart.sh: the keyless cosign signature of a released chart |
artifacthub-repo.yml | Artifact Hub repository metadata, pushed by artifacthub.yaml |
Work lands on develop through pull requests, with Lint and Test green; main takes releases only. develop carries -dev.N in helm/Chart.yaml, bumped in the PR that changes the image, and each merge builds the image in GHCR. A merge into main with a release version publishes <version> and latest to GHCR and Docker Hub, creates the release v<version>, and pushes the chart to oci://ghcr.io/yarilomail/charts/srs-milter, signed with cosign (see helm/README.md); Artifact Hub indexes it from there.
docker pull 0kaba0/srs-milter:latest