ARC sealing with arc-milter
arc-milter is a Postfix milter that adds an ARC set (RFC 8617) to each message the forwarding relay passes on. A Sieve redirect breaks SPF, and often the author's DKIM signature, for the receiver of the forwarded copy. The ARC set tells that receiver what the forwarder saw when the message first arrived, signed with the forwarder's key, so a receiver that trusts the forwarder can still deliver mail from a domain with a strict DMARC policy.
Where it runs
arc-milter runs on relay-fwd-out of yarilo-postfix, after dkim-milter-fwd, so its signature covers the forwarder's DKIM-Signature. relay-fwd-out carries the mail yarilo sends to other domains, so ARC applies to a redirect to another domain only. A redirect to a mailbox of a local domain goes from relay-fwd straight to delivery and is not sealed: it never leaves the installation.
The MX does not seal. It stamps inbound mail with an Authentication-Results in its own name (the authserv-id, its myhostname), and arc-milter copies that header. Nothing else may claim that name:
- rspamd on relay-mx removes an
Authentication-Resultswith that authserv-id that arrived from outside; - relay-mta, where every message comes from a login, drops one with a
header_rule, so a user cannot write results in the MX's name into a message a redirect then seals. A message attached inside keeps its header.checks
Sealing a message
At the end of the headers:
- arc-milter collects the ARC sets the message came with. If the newest
ARC-Sealsayscv=fail, the chain ended at that hop and nothing is added. The new instance is one above the highesti=any ARC field names, a broken one included, so a number is never used twice; a chain already at instance 50 gets nothing. - It reads the key (see below). A message that will not be sealed is accepted here, and Postfix sends the milter no body for it.
At the end of the message:
- It validates the chain: sets 1 to n, each with exactly one of the three fields; the newest
ARC-Message-Signatureagainst the body and fields; everyARC-Sealfrom n down to 1,cv=noneon the first andcv=passon the others. A key under 1024 bits fails its signature. The result is this hop'scv:nonewithout a chain,passorfail. - It adds instance n+1 at the top of the header:
ARC-Authentication-Results:i=, then the firstAuthentication-Resultswith the MX's authserv-id, as it stands; without one,<authserv-id>; none.ARC-Message-Signature:rsa-sha256,relaxed/, overrelaxed From(once more than it appears, so aFromadded later breaks it),Reply-To,Subject,Date,To,Cc,Message-ID,In-Reply-To,References,MIME-Version,Content-Type,Content-Transfer-Encoding, theList-*fields andDKIM-Signature.ARC-Seal:rsa-sha256with this hop'scv. A chain this hop found broken is sealedcv=fail, and that seal signs only its own set.
The body is streamed through the hashes and never held.
When it cannot seal
| Case | What happens |
|---|---|
| The key was read before; the database or Vault is down now | sealed with the cached key |
| The key was never read; the database or Vault is down | temporary failure: Postfix keeps the message and retries |
| No row for the seal domain with the ARC selector | passed on unsealed, counted as no_: a configuration gap, not an outage |
| A key lookup in DNS fails for any reason but a name that does not exist | temporary failure at the end of the message, never a cv=fail seal |
The same key name has kept failing so for DNS_ (4 hours) | that signature counts as failed and the message is sealed cv=fail, instead of waiting in the queue to the end of its life |
The newest ARC-Message-Signature uses simple header canonicalization and does not check | passed on unsealed, counted as simple_ |
All the key lookups of one message share one deadline, DNS_. Any answer from DNS clears a name's count of failures. DNS_ says where the first failure of each name is kept: memory (the default) in the process, so a restart or another replica starts the count again; redis, shared by the replicas and kept over restarts, under REDIS_ with a TTL of the grace plus a day. While Redis does not answer, the count goes on in the process.
WARNING
The last row exists because the milter protocol makes Postfix drop the space after a field's colon. arc-milter puts the usual single space back; an earlier hop that signed simple header bytes with no space or two cannot be checked here, and a cv=fail on a sound chain could not be undone by anyone after.
Keys
ARC defines rsa-sha256 only, so the key is RSA. It is a row in the same dkim table as dkim-milter's keys:
domainis the forwarder's domain, the one dkim-milter-fwd signs with and postsrsd rewrites to;selectorisarc, or after a rotationarc-<label>(arc-2027). dkim-milter never signs with these selectors, however new, so a DKIM selector may not be named so, and arc-milter refuses any otherARC_at start;SELECTOR private_is the PEM key encrypted with the Vault Transit keykey_ enc arc, never with dkim-milter'sdkim.
The key loads on the first message into the same kind of cache as dkim-milter's, and keeps sealing past its TTL while the row is read again.
Adding the key
umask 077
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out arc.key
openssl pkey -in arc.key -pubout -outform DER | base64 | tr -d '\n' > arc.pub
{ printf '{"plaintext":"'; base64 < arc.key | tr -d '\n'; printf '"}'; } | \
curl -s --cacert "$VAULT_CACERT" -H "X-Vault-Token: $VAULT_TOKEN" -d @- \
"$VAULT_ADDR/v1/transit/encrypt/arc" | jq -r '.data.ciphertext' > arc.enc
shred -u arc.keyThe private key goes to curl on its standard input, never as an argument, and is overwritten and deleted once encrypted. On macOS, where there is no shred, the last line is rm -P arc.. Then insert the row and publish the public key:
INSERT INTO dkim (domain, selector, public_key, private_key_enc)
VALUES ('fwd.example.org', 'arc', '<arc.pub>', '<arc.enc>');arc._domainkey.fwd.example.org. 3600 IN TXT "v=DKIM1; k=rsa; p=<arc.pub>"To rotate, publish the new selector's TXT record, insert a row with arc-<label>, set ARC_ to it, and remove the old row and record once the old seals are older than the record's TTL.
Vault Transit
arc-milter has a Transit key, a decrypt-only policy and a Kubernetes role of its own: key arc, policy arc-milter-decrypt, role arc-milter for the ServiceAccount arc-milter.
WARNING
Never give arc-milter dkim-milter's role or the key dkim. That key decrypts every client domain's DKIM key, and arc-milter parses the most hostile input there is: other servers' headers and DNS answers from the domains they name. A flaw in it must reach the ARC key alone.
vault write -f transit/keys/arc
vault policy write arc-milter-decrypt - <<'EOF'
path "transit/decrypt/arc" { capabilities = ["update"] }
EOF
vault write auth/kubernetes/role/arc-milter \
bound_service_account_names=arc-milter \
bound_service_account_namespaces=<namespace> \
policies=arc-milter-decrypt ttl=10mCheck both ways that the arc-milter role cannot decrypt with dkim, and dkim-milter's role cannot decrypt with arc.
Postfix configuration
On relay-fwd-out, after the DKIM signer:
smtpd_milters = { inet:dkim-milter-fwd:8891, default_action=tempfail },
{ inet:arc-milter:8893, default_action=tempfail }tempfail keeps a forward queued while the sealer is down. yarilo-postfix sets this through fwdOut.. Enable it only once an arc-milter pod is ready: with no ready pod behind the address, every forward waits.
Readiness
/ answers 200 once the key query has run and, with Vault, a login as the role has succeeded and the token may decrypt with the Transit key. A missing role, a wrong query or a policy without decrypt keep the pod not ready, with the reason logged.
Environment
| Variable | Default |
|---|---|
SEAL_ | none, required: d= of every seal and the key row's domain |
ARC_ | arc (or arc-<label>) |
AUTHSERV_ | none, required: the MX's authserv-id |
DNS_ | 10 |
DNS_ | 14400 |
DNS_ | memory (or redis) |
REDIS_, or REDIS_ with REDIS_ | none, one required with redis |
REDIS_, REDIS_, REDIS_ | none, none, 0 |
REDIS_, REDIS_ | none |
REDIS_ | none, required with redis |
LISTEN_ | 0. |
METRICS_ | 0. |
DB_ | postgres (or mysql) |
DB_ | none |
DB_ | 4 |
ARC_ | the seal domain's newest row with the ARC selector; two placeholders, the domain and the selector |
KEY_ | vault (or none for PEM in the column) |
KEY_, KEY_, KEY_ | 100, 600, 60 |
VAULT_, VAULT_ | none, required with vault |
VAULT_, VAULT_, VAULT_ | kubernetes, transit, arc |
VAULT_ | none |
MILTER_, MILTER_ | 3600, 60 |
LOG_ | none (debug for more) |
Helm chart
The chart in the repository's helm/ sets every variable above from its values; the chart's defaults are the code's. sealDomain and authservId are required; selector, dnsTimeoutSeconds, dnsTempfailGraceSeconds, dnsFailureStore and redis. set the rest of the sealing, and db., keyDecrypt, keyCache. and vault. (vault. defaults to arc) the key, as in dkim-milter's chart. networkPolicy. opens the milter port to the Postfix pods named there; on yarilo-postfix that is relay-fwd-out alone.
WARNING
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.
Logs and metrics
Logs are JSON on stdout, one line per message: arc: sealed with the instance, the cv it found and the selector, or the reason it was not.
| Metric | Meaning |
|---|---|
arc_ | sealed, chain_, instance_, simple_, no_, tempfail_, tempfail_, error |
arc_ | sealed messages by the cv found: none, pass, fail |
arc_ | key lookups that failed for a reason other than a missing name |
arc_ | of those, the ones taken as failed past the grace |
arc_ | Redis calls that failed; the count went on in the process |
arc_, arc_, arc_ | the key cache |