Domains and DNS

This page lists the DNS records a sending domain and a Karta installation need, and what Karta does with them today. Examples use example.com as the customer's sending domain and karta.example.net as the Karta installation.

Domain verification

An organisation's servers may send only from its verified domains: the From and Sender addresses and the envelope sender must all be at one. Owners and admins prove that their organisation controls a domain by publishing a TXT record with the domain's token, shown on its page (Karta.Domains.ownership_record/1):

_karta.example.com. 3600 IN TXT "karta-verification=7ul57bhsl242eyv72emg4zaybcu3mxdy"

Karta looks the record up without its DNS cache (Karta.Domains.check_ownership/2): when someone presses Check now on the domain's page, and every hour (Karta.Domains.Check) for every verified domain and for domains added in the last 7 days. The first check that finds it verifies the domain. The token is 160 random bits, so nobody can guess the record of a domain they do not control.

Publish the records before you add the domain, or expect a wait of up to an hour. Karta asks its validating resolver, and a resolver remembers an answer of "this name does not exist" for the zone's negative TTL (the last number of its SOA record, often an hour). A record looked up before it was published (by an earlier check, or by anyone using the same resolver) may therefore go on being "missing" for that long, and a DKIM key stays pending meanwhile, so nothing is signed. Nothing is wrong: check again after the hour, or publish the records first.

Sending depends on verification, so a record that disappears does not stop mail at once: a domain verified by its record keeps verification while checks have not found it for less than 7 days (the page says from when, and until when), and loses it at the first check after that. A record that is found again in the meantime ends the waiting. A lookup that fails (a timeout, SERVFAIL) changes nothing. Keep the record published for as long as the domain sends through Karta.

An administrator of the instance can still verify a domain without the record, after checking ownership by other means (Karta.Domains.verify_domain/1, or Verify without the record on the page; Managing organisations, servers and keys); such a verification does not depend on the record. Rules that hold either way:

  • a domain name is verified for at most one organisation at a time: a second organisation's record is found but not used ("taken") until the first loses verification, through its own record's absence or an administrator;
  • subdomains are separate domains (mail.example.com needs its own entry and its own record);
  • internationalised names are stored and compared in their ASCII (xn--) form;
  • withdrawing verification (Karta.Domains.unverify_domain/1) stops both sending and signing at once.

DNS health checks

The domain's page shows what receiving servers will find when they check its mail, and what to change (Karta.Domains.Health). Karta runs the checks every hour with the ownership check, and when owners or admins press Check now; the panel updates by itself when a check finishes. Each check is OK, Warning (works, but needs attention), Problem (receivers act on it) or Not set up (an optional record), with a sentence per finding, what to do, a record to publish where Karta can write it, and the records it found. A check whose lookups fail says so and keeps its result from before. When a check of a verified domain turns to Problem, the webhooks of the organisation's servers that want it get a domain.dns_failed event (once per problem).

CheckWhat it looks atProblems it reports
SPFthe domain's SPF record, evaluated for each address Karta sends fromno record or several; an address not authorised (IPv6 addresses are reported separately); a record that cannot be evaluated or needs more than 10 DNS lookups (9 or 10 is a warning); +all (?all or no all is a warning)
DKIMthe record of each pending, active and retiring keyno key or no active key; an active key whose record is missing or holds another key; a pending key not published yet, a retiring key already gone (warnings)
DMARCthe domain's policy, else its organisational domain'sno record, several, no valid p=; p=quarantine or reject while Karta's mail is not aligned; p=none, pct below 100, no rua (warnings)
MXwhere mail to the domain goesa null MX; no MX, an MX host without IPv4 or IPv6 address (warnings)
Reverse DNS and HELOeach sending address's PTR recordno PTR record, or one that does not lead back to the address; a PTR name other than the HELO name (warning)
Return pathwith KARTA_RETURN_PATH_DOMAIN: that domain's MX and SPF recordsno MX; the SPF problems above
MTA-STSthe _mta-sts record and the policy it announcesan invalid record; a policy that cannot be fetched or is invalid; an MX host the policy leaves out; testing or none mode, a record that announces another id than the policy Karta serves (warnings)
TLS-RPTthe _smtp._tls recordseveral, or one without valid rua= addresses; one without the address set in Karta (warning)
BIMIthe default._bimi recordseveral, or l=/a= that are not https: URLs; one that names another logo than the one uploaded to Karta, a DMARC policy that does not let a logo be shown (warnings)

Sending addresses. The SPF and reverse DNS checks use the addresses of the IP pools the organisation's servers use, and, for servers without a pool, the A and AAAA records of KARTA_OUTBOUND_HOSTNAME as KARTA_OUTBOUND_IP_FAMILY allows (IP pools). Point that name at the node's sending addresses.

Alignment. DMARC passes for Karta's mail when an active DKIM key's record is published (Karta signs with the From domain), or, without a return path domain, when SPF authorises every sending address. The DMARC check says whether moving to p=quarantine is safe on that basis.

Organisational domain. A domain without a DMARC record of its own gets its organisational domain's (example.com for mail.example.com, example.co.uk for mail.example.co.uk), as RFC 7489 says. Karta finds it with the Public Suffix List (Karta.PublicSuffix): the copy vendored in priv/public_suffix/public_suffix_list.dat (its source and date are in the README next to it) until Karta has fetched a newer one. Karta fetches the list every night from KARTA_PUBLIC_SUFFIX_URL (publicsuffix.org's by default), checks it (its size, both sections, rules every copy has), and keeps it in the database, where every node loads it within the hour (Configuration).

DKIM

Karta signs outgoing mail from a verified domain with the domain's active DKIM keys (Karta.Domains.KeySource, Karta.Auth.DKIM.Signer):

  • d= is the domain of the first From address, in ASCII form, so the signature aligns with From for DMARC;
  • Ed25519-SHA256 (RFC 8463) and RSA-SHA256 (2048, 3072 or 4096-bit keys); with an active key of each, every message carries two signatures, and receivers that do not check Ed25519 still verify the RSA one;
  • relaxed/relaxed canonicalisation, t= always set, never l= (the whole body is signed);
  • From, Reply-To, Subject, Date, To and Cc are oversigned (listed in h= once more than they occur, so they cannot be added later); Sender, Message-ID, MIME-Version, the Content- fields, In-Reply-To, References, List-Unsubscribe and List-Unsubscribe-Post are signed and oversigned when present; Resent-, the other List-* fields, Content-ID, Content-Description, Content-Language and Feedback-ID are signed when present; trace fields (Received, Return-Path) never.
  • Mail from a domain that is not verified, or that has no active key, is sent unsigned. A message that cannot be signed (for example, with no From field) is sent unsigned and the reason is logged.

Signing happens at delivery time, after tracking has changed the message, so the signature covers the copy each recipient receives.

Publishing a key

Each key is published as a TXT record at <selector>._domainkey.<domain>:

{:ok, key} = Karta.Domains.generate_dkim_key(domain, %{algorithm: "ed25519"})
Karta.Domains.DKIMKey.record_name(key, domain)
# "karta-tzcyac6v._domainkey.example.com"
key.public_key
# "v=DKIM1; k=ed25519; p=kXLUD9LcXSSWy3dWv6VaH8YEoKS48PRDBqX9RYtVV7Y="
karta-tzcyac6v._domainkey.example.com. 3600 IN TXT "v=DKIM1; k=ed25519; p=kXLUD9LcXSSWy3dWv6VaH8YEoKS48PRDBqX9RYtVV7Y="

An RSA record is longer than 255 octets; publish it as several strings of one TXT record, as Karta.Auth.DKIM.Key.dns_strings(key.private_key) cuts it.

Then activate the key. Activate on the domain's page (and Karta.Domains.Rotation.activate/2) looks its record up first, without the DNS cache, and refuses while the record is missing or holds another key: a key activated before its record is visible produces signatures that fail. (Karta.Domains.activate_dkim_key/2 activates without looking, for the console.)

Rotating keys

Rotation replaces a key without a moment in which mail is signed with a key receivers cannot find (dual publication):

  1. Rotate the active key on the domain's page (owners and admins; Karta.Domains.rotate_dkim_key/1). Karta generates a pending key of the same algorithm and size with a new selector, which replaces the active key; the active key keeps signing. Publish the new key's record next to the old one; where Karta publishes the domain's zone (below), it is published at once.
  2. Every hour Karta looks the new key's record up, without the cache. Once checks have found it for an hour (so that every name server of the zone has it, not only the one that answered), Karta activates the new key, and the old key starts retiring: it no longer signs, but its record stays. A check that does not find the record, or finds another key there, starts the hour again; a lookup that fails changes nothing. A domain that is not verified waits.
  3. A week after it started retiring, Karta retires the old key. Karta signs every delivery attempt with the keys active at that moment, so no mail leaves signed with a retiring key; the week is for receivers that check a signature again later (forwarding, mailing lists, mail that waits further down the way). Remove the retired key's record then; where Karta publishes the zone, it removes it.

The page shows each step: what the new key replaces and since when its record has been seen, which key is being replaced, when a retiring key will be retired. Retiring the new key cancels the rotation; a retiring key can be retired earlier by hand (if its private key may have leaked, for instance).

On a schedule. With KARTA_DKIM_ROTATE_AFTER_DAYS=180 (30 to 3650), the hourly check rotates an active key that has signed for that long, as if its owner had pressed Rotate, in every verified domain whose zone Karta publishes. The order is the one above and the waits are not shortened: the new key's record is published first and has to be seen for an hour, which is the TTL of the records Karta publishes, so that no resolver still holds an answer that the record does not exist; only then does the new key sign and the old one stop; the old record stays a week, far longer than any TTL and longer than mail usually waits. In a domain whose DNS Karta does not write, a rotation could not complete by itself and none is started; its owner rotates the key by hand. Without the setting Karta rotates no key by itself.

Publishing records through a DNS provider

Karta can write its own records of sending domains into the DNS server that holds their zones, through a DNS provider (Configuration: KARTA_DNS_PROVIDER, powerdns by default). Two providers are built in:

  • PowerDNS, through its HTTP API (KARTA_POWERDNS_URL, KARTA_POWERDNS_API_KEY, KARTA_POWERDNS_SERVER_ID and KARTA_POWERDNS_ZONES, the zones Karta may write to);
  • RFC 2136 dynamic update with TSIG (KARTA_DNS_RFC2136_*), which BIND, Knot, PowerDNS and other authoritative servers accept.

The RFC 2136 provider reads each name with a TXT and a CNAME query, the only types Karta writes, instead of an ANY query (whose answer a server may rightly keep minimal). Since those reads do not see other types, a new CNAME is sent with the condition that nothing at all is at its name; a server where an A or MX record is there answers YXDOMAIN, and the domain's page shows it. It sends every update over TCP, so that a lost answer to an update cannot be mistaken for a lost request (RFC 2136 §7.8); queries use UDP, and a truncated answer is asked for again over TCP.

A package compiled into the image can add another (Writing a DNS provider). Without a provider whose settings are set, nothing is published: the domain's page still shows every record to publish by hand.

For a verified domain in one of the zones the operator lists (or under one), Karta publishes:

  • the ownership record (_karta.<domain>, above);
  • the record of each pending, active and retiring DKIM key;
  • the tracking host's CNAME record;
  • for an MTA-STS policy Karta serves, the CNAME record of mta-sts.<domain> and the _mta-sts TXT record with the policy's id;
  • the TLS reports record, once an address is set;
  • the BIMI record of a logo uploaded to Karta.

SPF, DMARC and MX records are not written: they carry the domain owner's other senders and policies, so the DNS health checks suggest them instead. Nothing is written for a domain that is not verified (its organisation has not shown the name is theirs), or in a zone the operator has not listed.

Only Karta's own records. Every RRset Karta writes carries a marker naming the domain: a PowerDNS comment of the account karta, or an entry in the RFC 2136 provider's inventory TXT record at _karta-records.<zone>. Karta replaces and removes only marked RRsets, at the names and types above, and removes them when they are no longer needed (a retired key, a removed tracking host, policy or logo). An RRset someone else wrote at one of these names is taken over when it already holds exactly Karta's records, and left alone otherwise (for example a tracking host name that already has an address record): the page says which and why. No other name or type is touched.

When. Every hour, with the other checks, and when owners or admins press Show changes on the domain's page (a dry run: what would be added, replaced, taken over, removed or left alone, with the values) and then Publish the changes. Publishing writes only the changes that were looked at: if they are different by then, the page shows the new ones instead. Rotating a key, and changing the MTA-STS policy, the TLS reports' address or the logo, publishes at once. With nothing to change, nothing is sent: running again changes nothing, and the zone's serial stays as it is.

Serial and secondaries. All changes to a zone go in one call, which the provider applies whole or not at all. With PowerDNS, Karta does not edit the SOA record: PowerDNS raises the serial on changes made through its API when the zone's SOA-EDIT-API is set (zones created through the API have DEFAULT), and Karta asks a primary zone's secondaries to notify them; Karta refuses a primary zone without SOA-EDIT-API (its secondaries would never see the change) and secondary zones (the next transfer would undo it). An RFC 2136 server raises the serial and notifies its secondaries itself.

The domain's page shows when the records were last published and what went wrong, if anything; removing a domain from Karta leaves its records in the zone.

SPF

Karta does not publish SPF records; the SPF check (above) evaluates them. For receivers' SPF checks to pass, the SPF record of the envelope sender's domain must allow the addresses Karta sends from:

  • without VERP (the default), the envelope sender is the message's own (for example ann@example.com), so example.com's SPF record must include Karta's sending addresses, e.g. v=spf1 ip4:192.0.2.10 ip6:2001:db8::10 ~all;
  • with VERP (KARTA_RETURN_PATH_DOMAIN), the envelope sender is in the return path domain, so that domain needs the SPF record instead (see below).

DMARC

A DMARC policy on the sending domain passes when DKIM passes with an aligned d=, which Karta's signatures are (the From domain). Publishing the DMARC record is up to the domain owner; the DMARC check (above) reads it and says whether a stricter policy is safe. Karta does not process DMARC reports.

Reverse DNS and EHLO

Set KARTA_OUTBOUND_HOSTNAME to a name whose A and AAAA records point to Karta's sending addresses, and give those addresses PTR records with that name. Karta uses the name in EHLO, in the Message-IDs it makes and in delivery status notifications. Receivers commonly reject or penalise mail whose sending address has no matching reverse DNS.

Return paths (VERP)

With KARTA_RETURN_PATH_DOMAIN=rp.karta.example.net, each delivery uses an envelope sender of its own, b<recipient id><tag>@rp.karta.example.net, so that a later bounce names the recipient it is about (Delivery). That domain needs:

  • an MX record leading back to Karta, e.g. rp.karta.example.net. IN MX 10 mx.karta.example.net.;
  • an SPF record for Karta's sending addresses.

The domain receives the reports

The mx listener accepts a return path of this domain (when its tag is Karta's and it is not too old) and records the report against the recipient (Receiving mail). A hard bounce puts the address on the server's suppression list. Without the MX record, mail servers cannot report a failure, and Karta records only the synchronous outcomes.

MX for inbound mail

Not used yet: Karta does not receive mail for customer domains. Do not point a domain's MX records at Karta.

The tracking host

When tracking or one-click unsubscribe is used, KARTA_TRACKING_URL (for example https://track.example.net) must resolve to the reverse proxy, have a valid TLS certificate, and be proxied to KARTA_TRACKING_PORT. It serves every organisation by default. A verified domain can have a tracking host of its own, a CNAME record to Karta's:

click.example.com. 3600 IN CNAME track.example.net.

Mail from the domain then uses https://click.example.com in its links, its open pixel and its List-Unsubscribe URL, while the record is in place. See Tracking hosts of sending domains.

List-Unsubscribe

With list_unsubscribe turned on for a server and a tracking URL configured, Karta adds to each recipient's copy, unless the message already has its own List-Unsubscribe:

List-Unsubscribe: <https://track.example.net/u/AaG73ZA3fj2BHzw_o4OolyFyIekaKJeCYmlxy_8PBbs>
List-Unsubscribe-Post: List-Unsubscribe=One-Click

List-Unsubscribe-Post is added only for an https URL (RFC 8058). Both fields are covered by the DKIM signature, as RFC 8058 requires.

MTA-STS, DANE and TLS-RPT

For outbound delivery Karta reads the MTA-STS policies of recipient domains and follows them, uses the DANE TLSA records of their MX hosts when their DNS is signed (Delivery), and records the result of every TLS session for TLS reports (Delivery). For your own domains Karta can serve an MTA-STS policy and gives the TLS-RPT record to publish (below), and the DNS health checks read what you publish. Not yet: TLSA records. Domains that need verified TLS without publishing a policy can be listed in the :tls_policies setting (Delivery).

Hosting an MTA-STS policy

An MTA-STS policy (RFC 8461) tells senders to deliver to a domain's mail servers only over TLS with a valid certificate, and only to the hosts it names. It is a small text file served at https://mta-sts.<domain>/.well-known/mta-sts.txt, announced by a TXT record. Karta serves it for a verified domain (Karta.MTASTS.Hosting), so the domain needs no web server of its own. On the domain's page, owners and admins set:

  • Mode: testing (senders report TLS failures and still deliver), enforce (senders deliver only over TLS, to the listed hosts) or none (the policy is withdrawn);
  • MX hosts: the names senders may deliver to, one per line, or *.example.com for any one name under it. Use the domain's MX hosts fills them in from DNS; Karta never changes them by itself, because a policy that followed DNS would follow a forged answer too;
  • Senders keep it for (max_age): a day to a year.

Then publish the two records the page shows (or let Karta publish them, above):

mta-sts.example.com.  3600 IN CNAME track.example.net.
_mta-sts.example.com. 3600 IN TXT   "v=STSv1; id=6f1c0a9e2b7d4c3a5e8f;"

The CNAME points to the name tracking hosts point to (KARTA_TRACKING_CNAME, by default the tracking URL's host); Karta checks it every hour and on Check DNS, and serves the policy, and lets the reverse proxy get a certificate for the name, only while it is there (Certificates for tracking hosts covers both). The id is taken from the policy's text: it changes whenever the policy changes, and the record must change with it, or senders that know the policy keep the old one (the DNS health check says so).

Before enforcing. A policy in enforce mode makes senders that follow it refuse to deliver to an MX host that is not in it or whose TLS fails. Karta saves it only when every MX host of the domain is in the policy and accepts STARTTLS on port 25 with a certificate valid for its name, from a trusted authority (Karta.MTASTS.Probe: Karta connects, says EHLO and STARTTLS, checks the certificate and says QUIT; private and special addresses are never contacted). Otherwise the page lists what is wrong. Start in testing mode with a TLS reports address, and enforce once the reports show no failures. The hourly MTA-STS health check keeps watching that every MX host is covered.

Withdrawing. Senders keep a policy for max_age and keep enforcing it while they cannot fetch a newer one. To stop, set the mode to none and keep it published until max_age has passed; only a policy in mode none can be removed.

TLS reports

Senders that support TLS-RPT (RFC 8460) send a daily report of the TLS connections to the domain's mail servers, failed ones included, to the address in its _smtp._tls TXT record. On the domain's page owners and admins set that address, a mailbox you read (tls-reports@example.com) or an https: URL, and Karta gives the record (Karta.Domains.TLSReporting):

_smtp._tls.example.com. 3600 IN TXT "v=TLSRPTv1; rua=mailto:tls-reports@example.com"

Point the address at a route whose mode is report and Karta reads the reports it receives and shows them under the organisation's Reports (DMARC reports). Karta sends TLS reports about the domains it sends mail to (Reports).

Mailbox providers that support BIMI show a sender's logo next to its mail when the domain publishes a BIMI record and its DMARC policy is quarantine or reject. Some show a logo only with a mark certificate (a VMC or CMC) bought for it. On the domain's page owners and admins of a verified domain upload the logo (Karta.BIMI); Karta checks it against SVG Tiny Portable/Secure, the SVG profile BIMI requires (Karta.BIMI.SVG), and stores it only when it passes:

  • the <svg> element with version="1.2" and baseProfile="tiny-ps", no x= or y=, and a square viewBox;
  • a <title> first (the brand's name);
  • only the profile's elements and attributes: no scripts, animation, raster images, links, styles, event handlers or elements and attributes of other namespaces; references only to elements of the file (href="#id", url(#id));
  • no document type declaration, entities or processing instructions; at most 32 KB.

Most drawing tools can export SVG Tiny 1.2; the page lists what to change when a file does not pass. Karta serves the logo from its tracking host, https://<tracking host>/bimi/<sha256>.svg, as image/svg+xml; the name changes with the logo. The record to publish names it, and the mark certificate's https: URL when one is set (Karta publishes it as given and does not check it):

default._bimi.example.com. 3600 IN TXT "v=BIMI1; l=https://track.example.net/bimi/53b9…a1.svg; a=https://certs.example.com/vmc.pem;"