Skip to main content

DKIM Keys

One key per server signs the mail of every domain on it and of the server's own mail hosts. Each signing domain's zone carries two CNAME records that never change, and the key itself is published in the server's zone, so the server replaces its key without touching any domain's zone.

For the server server1.example.net and the domain example.com:

; in the domain's zone, published once
d1.k7x2q9ab._domainkey.example.com. CNAME d1._domainkey.server1.example.net.
d2.k7x2q9ab._domainkey.example.com. CNAME d2._domainkey.server1.example.net.

; in the server's zone, rewritten at each rotation
d1._domainkey.server1.example.net. TXT "v=DKIM1; k=rsa; p=…"
d2._domainkey.server1.example.net. TXT "v=DKIM1; k=rsa; p=…"
  • d1, d2: the two slots. One signs; the other holds the previous key, still published for mail in transit, or the next one, published ahead of use.
  • k7x2q9ab: the server's selector tag, eight random characters made once and never changed, so that no other sender of a domain picks the same name. A signature's selector is d1.k7x2q9ab or d2.k7x2q9ab.
  • An empty slot has no TXT; the server's *._domainkey record answers it as revoked until the slot is first filled.

Every mail domain whose DKIM is on publishes the two CNAMEs, and so do the server's mail-out., mail. and bounces. hosts. A key is RSA 2048. It is never shown to an account holder: every domain on the server shares it, so the panel keeps it to the server.

Zones hosted elsewhere

The panel writes the CNAMEs into every zone it hosts. A domain whose DNS is at another provider fails DKIM until its owner adds the two CNAMEs there; the account holder sees them on the mail service's Sender Verification tab, and the account docs explain them. Servers upgraded from a release with one key per domain needed this once: the old per-domain TXT records stopped working at the upgrade.

Rotation​

A key signs for 90 days. Seven days before that, the next key is published in the other slot, and it takes over when it is seven days old and every authoritative name server of the server's zone answers it. The old key stays published; its slot is filled again 83 days later, at the next rotation. A daily task in the panel's worker does each step when it is due.

StateMeaning
PublishedIn DNS and installed in rspamd; nothing signs with it yet.
ActiveEvery domain signs with it.
RetiredNo longer signs; still published, so that mail signed with it before the switch still passes.
RevokedPublished as empty (p=), no longer installed: mail signed with it fails. Only after an emergency rotation.

The switch moves every domain's selector at once. rspamd's workers pick it up within five minutes; both keys are installed and published meanwhile, so no message goes out unsigned or fails.

Rotating now​

The page DKIM Keys under System shows the slots, their states and ages, and the next step, and offers three rotations. elpanctl does the same:

elpanctl dkim status
elpanctl dkim rotate
elpanctl dkim rotate --immediate
elpanctl dkim rotate --emergency
RotationWhat happens
Rotate (no option)The next key is published now, if none is yet. It starts signing after the 7-day lead, as at a scheduled rotation.
Rotate Immediately (--immediate)The next key is published if needed and starts signing five minutes later at the earliest, once every authoritative name server answers it, without the lead. The old key is retired, still published.
Emergency Rotation (--emergency)A fresh key is made, even if one is already published and waiting (it would have leaked too); it starts signing five minutes later at the earliest, once every authoritative name server answers it, and the old key is then revoked at once.
Emergency rotation

Use it when a key may have leaked, e.g. after a break-in on the server. Mail still in transit that the old key signed fails DKIM, and under the domains' DMARC policies it may be rejected. That is the point: nobody can sign with the leaked key any more.

Each slot's TXT has a TTL of five minutes (300 seconds), and a new key starts signing no sooner than five minutes after it was published, in every mode. A resolver, or a receiving server's DKIM check, keeps an answer for its TTL; a slot looked up just before it was refilled would otherwise still hold the previous key and fail the new key's signatures.

dkim rotate --immediate and --emergency therefore take at least five minutes. They wait for the switch, up to 15 minutes (--wait), and ask no question, so they run under -n. A switch the name servers have not answered in that time stays asked for: the daily task, or the command run again, completes it, and dkim status says which name server does not answer yet. From the admin page, the switch runs in the worker, which comes back when the five minutes are up and keeps checking for about 20 minutes more before it leaves the switch to the daily task. Two rotations asked for at the same moment run one at a time: the second is told that a rotation is already in progress.

Two immediate rotations in a row

Each rotation fills the slot that does not sign, which holds the key that signed until the previous rotation. Rotating twice within minutes replaces a key that mail in transit may still be signed with: dkim rotate warns when the key it replaces stopped signing less than seven days ago, and the admin page's confirmation says so. Wait a few days between two rotations unless the key leaked.

Where it goes​

The panel writes the server's keys as the configuration intent dkim-key (one document per installed key, keyed by its selector) and each signing domain's selector as dkim (see Server configuration). elpan-rspamd installs each key at /var/lib/elpan/dkim/key/<selector> and signs every domain with the key its selector names.