HUB
Sign inSign up
srs-milter logo

0kaba0/srs-milter

By 0kaba0

•Updated 3 days ago

Image
Networking
0

43

0kaba0/srs-milter repository overview

⁠srs-milter

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⁠

CI Go 1.27 License: AGPL v3

⁠What it does

  • Forward: the envelope sender [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.
  • Reverse: a recipient in the SRS domain is checked at 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.
  • Compatible by default: 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, and the tests check the output against that implementation's own test vectors.
  • Bounded replies (optional): a valid SRS address is a relay to the original sender for anyone who has seen it once. With a reply store the milter counts the messages each address turned back and refuses the next one past 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.

⁠Postfix configuration

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.

⁠Environment

VariableDefaultWhat
MODEbothforward, reverse or both
SRS_DOMAINrequireddomain of the rewritten addresses
SRS_SECRETrequiredsigning secret
SRS_SECRET_PREVIOUSthe secret before it: verifies, never signs
SRS_HASH_ALGORITHMsha1HMAC of the address: sha1, sha256, sha512
SRS_HASH_LENGTH4characters of the hash in the address, 6 bits each
SRS_HASH_MIN_LENGTHSRS_HASH_LENGTHshortest hash still accepted, for the days after the length was raised
SRS_SEPARATOR=character after SRS0 and SRS1: =, + or -
SRS_VALIDITY_DAYS21days an address turns bounces back
MAX_REPLY_BYTES0largest message to an SRS address, headers and body; 0: no limit
REPLY_STOREnonewhere replies are counted: none, sqlite, redis
MAX_REPLIES10messages one address turns back while valid; read with a store
SQLITE_PATH/data/replies.dbfile of REPLY_STORE=sqlite
REDIS_ADDRhost:port of REPLY_STORE=redis
REDIS_SENTINEL_ADDRS, REDIS_SENTINEL_MASTER, REDIS_SENTINEL_USERNAME, REDIS_SENTINEL_PASSWORDSentinels instead of REDIS_ADDR
REDIS_USERNAME, REDIS_PASSWORD, REDIS_DB
REDIS_KEY_PREFIXrequired with rediscounts live at <prefix>replies:<address>
LOCAL_DOMAINScomma-separated domains whose senders keep their address
DB_DRIVER, DB_DSNmysql, nonewith a DSN, a sender's domain is also looked up in a database (mysql or postgres)
LOCAL_DOMAIN_SQL_QUERYSELECT 1 FROM domain WHERE domain = ? AND active = 1one placeholder, the domain; any row means local
DB_MAX_OPEN_CONNS4
DOMAIN_CACHE_SIZE, DOMAIN_CACHE_TTL_SECONDS, DOMAIN_CACHE_MISS_TTL_SECONDS10000, 300, 300cache of the database's answers
LISTEN_ADDR, METRICS_ADDR0.0.0.0:8894, 0.0.0.0:8081milter; /metrics, /healthz, /readyz
MILTER_READ_TIMEOUT_SECONDS, MILTER_WRITE_TIMEOUT_SECONDS3600, 60
LOG_LEVELinfodebug
⁠The reply count

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.

⁠When it cannot decide

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.

⁠Repository

PathWhat
app/gothe milter, Go 1.27, go test ./...
helmthe chart; every variable above is a value
helm_valuesvalues for the yarilo stand: one release on relay-fwd-out, both directions
hack/releasesign-chart.sh: the keyless cosign signature of a released chart
artifacthub-repo.ymlArtifact Hub repository metadata, pushed by artifacthub.yaml

⁠Development and release

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.

Tag summary
Recent tags
Content type
Image
Digest
sha256:9da7c1f5d…
Size
14.8 MB
Last updated
3 days ago
docker pull 0kaba0/srs-milter:latest