Mail servers: publishing DNS records through Salt

A mail server can publish its own DNS records through Salt with an RFC 2136 dynamic update signed with TSIG. This page is the contract: which credential to create, which names and record types it may read and update, how the listener behaves on UDP and TCP, which zones accept updates, what the error codes mean, and a worked example.

Any RFC 2136 client works. Karta is one client that is tested against these rules (see Tested client: Karta); certbot, lego, nsupdate, DHCP servers and other RFC 2136 clients use the same server.

Prerequisites

  • The zone exists in Salt and its status is active. New zones start as pending until ownership is verified; pending and disabled zones do not accept updates. See Getting started.
  • The credential is a TSIG key of the organisation that owns the zone.
  • The zone section of the update names the zone itself (example.com), not a sub-domain. Records below the apex are written with their full name.
  • The client signs with the algorithm the key is pinned to (see TSIG algorithms).
  • The client's clock is correct. TSIG rejects a signature outside the allowed time window with BADTIME; run NTP.
  • The records are of a type Salt stores: A, AAAA, CNAME, MX, TXT, SRV, CAA, NS, DS, PTR, SVCB, HTTPS, TLSA or SSHFP. Apex SOA and NS and the DNSSEC types are managed by Salt and cannot be changed through an update. The mail preset grants only the types listed below.

Create a mail-preset TSIG key

In the web console:

  1. Open Credentials and choose New credential.
  2. Set Type to TSIG key.
  3. Choose Algorithm: hmac-sha256 (recommended), hmac-sha384 or hmac-sha512.
  4. Choose What is it for? → Mail platform.
  5. Choose the Zone.
  6. Optionally enter the extra names that may be CNAMEs: the MTA-STS policy host defaults to mta-sts.<zone>, and the tracking host a mail platform publishes is not predictable, so add it here. One relative name per line.
  7. Create the credential.

The secret is shown once. Salt generates the key name; it has the form <random>.<organisation id>.keys.salt-dns.invalid. Store the secret where the mail server can read it and nowhere else.

The preset covers the zone apex (example.com) by default. A key created through the Elixir API can also pass the preset's domains option (SaltDns.Credentials.create_mail_tsig_key/6, for example domains: ["@", "mail", "eu.mail"]): every name below is then granted under each selected domain as well as at the apex. The web console's mail preset currently grants the apex only. The _karta-records inventory is the exception: it is always at the zone apex only, never under a selected domain.

Names and record types the key may update

Z is the zone apex. D is each domain selected for the credential (by default only Z). Relative names are shown; in an update, write them fully qualified (_imaps._tcp.example.com.).

PurposeName relative to DTypes it may update
DKIM signing keys<selector>._domainkey.D — any name strictly below _domainkey.D, at any depth (for example sel1._domainkey.D, a.b._domainkey.D)TXT
MTA-STS policy_mta-sts.DTXT
SMTP TLS reporting (TLS-RPT)_smtp._tls.DTXT
BIMIdefault._bimi.DTXT
Karta ownership record_karta.DTXT
CalDAV / CardDAV discovery text_caldavs._tcp.D, _carddavs._tcp.DTXT
IMAP discovery_imaps._tcp.D, _imap._tcp.DSRV
POP3 discovery_pop3s._tcp.DSRV
Submission discovery_submission._tcp.D, _submissions._tcp.DSRV
CalDAV / CardDAV discovery_caldavs._tcp.D, _carddavs._tcp.DSRV
Autodiscover service_autodiscover._tcp.DSRV
Autoconfig hostautoconfig.DCNAME, A, AAAA
Autodiscover hostautodiscover.DCNAME, A, AAAA
MTA-STS policy host and other policy/tracking hostsmta-sts.D by default; the names entered at creation replace itCNAME
Karta inventory_karta-records.Z (zone apex only, never under D)TXT

Notes:

  • The DKIM pattern matches strict sub-domains of _domainkey.D. The name _domainkey.D itself, and every other name, is not writable.
  • CNAME and A/AAAA are granted at the same client hosts (autoconfig.D, autodiscover.D). DNS allows one or the other at a name, not both; the grant permits whichever the mail platform publishes.
  • Deleting a record or an RRset needs the same grant as adding it.

What the key may read

An update grant also permits reading every record type at the names it covers, because a writer must see what is already at the name before writing. So the key may read:

  • every record type at every name in the table above; and
  • the apex SOA and NS records (so clients can find the zone).

It may not read any other name. A signed query for a name or type outside this scope is answered REFUSED; it cannot be used to enumerate the rest of the zone. Within the scope, a missing name is NXDOMAIN and a name with no readable data is NODATA (both carry the zone SOA in the authority section). An ANY query returns every readable RRset at the name.

TSIG algorithms

Accepted algorithms:

  • hmac-sha256 (32-byte secret)
  • hmac-sha384 (48-byte secret)
  • hmac-sha512 (64-byte secret)

Each key is pinned to the algorithm chosen at creation. A request signed with any other algorithm is answered NOTAUTH with TSIG error BADKEY, even if that algorithm is otherwise allowed. hmac-md5, hmac-sha1 and hmac-sha224 are never accepted. Algorithm names are compared case-insensitively; a trailing dot on the wire is accepted.

The server log records the pinned algorithm and the one presented when it answers BADKEY. Set the algorithm explicitly in the client: several clients default to HMAC-MD5 or HMAC-SHA1.

UDP and TCP

The listener serves the same protocol on UDP and TCP, on port 53 in production (SALT_DNS_UPDATE_PORT changes it).

  • UDP requests up to 65,507 bytes are accepted; a larger datagram is dropped unread. Prefer TCP for an update that is large (many DKIM keys, or many changes in one message), as RFC 2136 section 2.1 allows.
  • UDP replies are at most 512 bytes unless the request carries an EDNS OPT record announcing more, in which case the server uses at most 1232 bytes. A signed reply that does not fit is replaced by an empty reply with the TC bit set, still correctly signed. Retry the request over TCP.
  • TCP messages are framed with the two-byte length prefix (RFC 1035 section 4.2.2). An idle connection is closed after 10 seconds. A connection carries at most 100 requests before the server closes it. At most 1000 connections are served at once.
  • Replies are signed when the request was signed. BADKEY and BADSIG answers are NOTAUTH with an unsigned TSIG record carrying the error; BADTIME is signed and carries the server's time in the TSIG other-data field.
  • A signed update is de-duplicated by its MAC for ten minutes: retransmitting the same signed packet (for example after a lost UDP answer) returns the first answer and does not apply the change twice.

Which zones accept updates

Only an active zone of the key's organisation answers an update, and the zone section must name that zone exactly. A zone that is unknown, belongs to another organisation, or is pending or disabled is answered NOTAUTH, so the existence of other zones is not revealed. Signed queries against such a zone are answered REFUSED.

Updates are applied atomically under the zone's lock: prerequisites are evaluated and the change is written in one transaction. A second client racing the same name sees the first client's result. Changes are recorded in the zone's history with source rfc2136 and the credential id.

Error codes

When an update is answered, it carries one rcode. The important ones for a mail server:

RcodeNumberWhen
NOERROR0The update was accepted. A no-op is also NOERROR (nothing changed).
FORMERR1The message is malformed, the zone section is missing or not SOA IN, or a prerequisite or update record has an invalid form (for example a non-zero TTL in a prerequisite, or non-empty data for a class ANY/NONE record).
SERVFAIL2The zone transaction failed, the zone is frozen, or the listener is temporarily too busy. Retry later.
NXDOMAIN3A "name is in use" prerequisite failed.
NOTIMP4The opcode is not QUERY or UPDATE.
REFUSED5The update is unsigned, the key's per-second limit was exceeded, a name or type is not granted, the record type is not supported, or a managed type (apex SOA/NS or a DNSSEC type) was named. For a query: the name or type is not readable.
YXDOMAIN6A "name is not in use" prerequisite failed.
YXRRSET7An "RRset does not exist" prerequisite failed.
NXRRSET8An "RRset exists" or value-dependent prerequisite failed: the RRset is gone or has changed since it was read. Re-read and retry.
NOTAUTH9The TSIG key name is unknown, the signature or time is wrong, the zone is not an active zone of the key's organisation, or the zone section names a different zone.
NOTZONE10A name in the prerequisite or update section is outside the zone.

A TSIG failure is NOTAUTH with a TSIG error code: BADSIG (16), BADKEY (17, including an algorithm that differs from the key's pinned one) or BADTIME (18). A client should report BADTIME as a clock problem.

Supported RFC 2136 prerequisites are the name-level "in use" / "not in use" and the RRset-level "exists" / "does not exist" / "exists with this exact value". Value-dependent RRsets are compared as sets; the TTL is ignored. Permission is checked before the prerequisite state, so a key cannot use prerequisite results to probe names outside its grants: those updates are REFUSED regardless of what exists.

The global TTL bounds are 60 to 604800 seconds, and an organisation may set a narrower range. A TTL outside the organisation's bounds is brought to the nearest bound and logged; it does not fail the update. CNAME conflicts follow RFC 2136 section 3.4.2.2: an add that would put a CNAME next to other data (or other data next to a CNAME) is silently ignored. Deletes and adds in one update are processed in order.

Rate limits

The listener limits every verified key to 50 requests per second, counted in fixed one-second windows across all names and both transports. Queries and updates both count. When the limit is exceeded, the request is answered REFUSED with a signed reply; the change is not applied. A mail server publishing many domains should back off and retry, or publish one domain at a time. (An operator can raise the limit with the listener's key_per_second option.)

Two further limits protect the listener and normally stay invisible:

  • 100 requests per second per source IP. Beyond it, packets are dropped without a reply.
  • 20 authentication failures per minute per source IP. Beyond it, packets that fail TSIG verification are dropped without a reply. A correct key is unaffected.

The per-key counter is incremented only after the signature has verified, so a spoofed key name cannot spend a real key's budget.

Worked example with nsupdate

The values in angle brackets come from the console when the credential is created; the secret is shown once. dns.example.com stands for the update endpoint (the RFC 2136 listener). The zone is example.com and the mail server is mail.example.com.

nsupdate -y hmac-sha256:<key-name>:<base64-secret> <<'END'
server dns.example.com 53
zone example.com
update add _imaps._tcp.example.com.      3600 SRV 0 1 993 mail.example.com.
update add _imap._tcp.example.com.       3600 SRV 0 1 143 mail.example.com.
update add _pop3s._tcp.example.com.      3600 SRV 0 1 995 mail.example.com.
update add _submission._tcp.example.com. 3600 SRV 0 1 587 mail.example.com.
update add _submissions._tcp.example.com. 3600 SRV 0 1 465 mail.example.com.
update add _caldavs._tcp.example.com.    3600 SRV 0 1 443 mail.example.com.
update add _carddavs._tcp.example.com.   3600 SRV 0 1 443 mail.example.com.
update add _autodiscover._tcp.example.com. 3600 SRV 0 0 443 mail.example.com.
update add _caldavs._tcp.example.com.    3600 TXT "path=/dav/"
update add _carddavs._tcp.example.com.   3600 TXT "path=/dav/"
update add autoconfig.example.com.       3600 CNAME mail.example.com.
update add autodiscover.example.com.     3600 CNAME mail.example.com.
send
END

nsupdate prints the rcode when the answer is not NOERROR, for example update failed: REFUSED or update failed: NOTAUTH. Without the explicit hmac-sha256: prefix nsupdate signs with HMAC-MD5, which is refused.

Read a record back with dig, using the same key:

dig @dns.example.com _imaps._tcp.example.com. SRV \
  -y hmac-sha256:<key-name>:<base64-secret>

Delete the records when they are no longer published:

nsupdate -y hmac-sha256:<key-name>:<base64-secret> <<'END'
server dns.example.com 53
zone example.com
update delete _imaps._tcp.example.com. SRV
update delete autoconfig.example.com. CNAME
send
END

If the credential was created through the API with the sending domain mail added to domains, the same commands work with names under it, for example _imaps._tcp.mail.example.com. and autoconfig.mail.example.com., in the same zone example.com.

Tested client: Karta

Karta's RFC 2136 client (Karta.RFC2136) is tested against Salt with a mail-preset TSIG key: reads, a first publish, updates, adoption and removals, with hmac-sha256 and hmac-sha512. The integration tests compile Karta's own client modules and drive the listener, and a replay test re-sends the recorded packets byte for byte in CI, so the exercised wire format is Karta's, not a hand-written imitation. Karta sends every request over UDP and retries a truncated answer over TCP; this server signs truncated replies so that retry works.

Karta is one tested client, not a requirement. The contract above is plain RFC 2136 with TSIG; any conforming client works. More client recipes are in Clients and APIs.

See also