skip to content

When rotating a DKIM signing key by selector, in what order do you publish, switch and retire, and why does the old record stay published?

level: middleimportance: must knowfreq 42%

answer

  1. a new name, not new contents
  2. visible before first use
  3. mail still in queues
  4. verifiers may check late
  5. empty p= comes last

basics

~20 s

Publish the new key under a new selector, confirm it resolves, switch signing, keep the old record until queued and late-verified mail has cleared, then revoke the old record with an empty p= and destroy the old private key.

solid answer

~50 s

A DKIM verifier fetches the key named by the signature's own `s=` and `d=` tags, so a rollover moves signing to a new key record rather than rewriting the key inside the one verifiers are using. The order: generate the new key pair on the signer, publish it at a new selector such as `s2026b._domainkey.example.com`, wait until it resolves from outside and a test message shows `dkim=pass` with `header.s=s2026b`, then switch signing. The old record stays published because mail signed with the old key is still in retry queues (Postfix's `maximal_queue_lifetime` defaults to `5d`) and RFC 6376 section 5.2 warns that verifiers may defer validation, perhaps until the message is read. When that interval has passed, publish the old selector with an empty `p=` and destroy the old private key. Overwriting the live record instead breaks mail signed with the old key and, at verifiers still caching the old record, mail signed with the new one.

code

pseudocode · 8 lines
pseudocode
generate keypair NEW on the signer
publish TXT s2026b._domainkey.example.com = public(NEW)
wait until resolvable from outside
send test message; expect dkim=pass, header.s=s2026b
switch every signer to s=s2026b
wait the validation interval (queues + late verification)
publish TXT s2026a._domainkey.example.com = "v=DKIM1; p="
destroy private key OLD

go deeper

for a junior

Recall that a DKIM signature names its selector, so a new key goes under a new selector and the old one is kept for a while before being emptied.

for a middle

Explain the order, publish, check, switch, wait, revoke, and why overwriting the live record or revoking at the switch makes queued and late-verified mail fail.

for a senior

Size the overlap from real queue lifetimes and deferred verification, and prove each step with header.s on test messages and the old selector's rows in aggregate reports.

for a principal

Treat rotation as a routine, owned procedure with an inventory and checks, so it is rehearsed before the day a leak forces it in hours.

## Why DKIM rotates by selector A **DKIM signature** carries the signing domain in `d=` and a **selector** in `s=`. A verifier builds the key record's name from those two values, `<s>._domainkey.<d>`, fetches that one TXT record and checks the signature against it. It never looks at any other selector the domain publishes. That makes the selector the unit of rotation. RFC 6376 section 3.1 says selectors exist partly to "seamlessly replace public keys on a routine basis", and its own example moves a domain from a selector `january2005` to `february2005`, with **both public keys advertised concurrently** for the transition period during which mail may be in transit before verification. Replacing the key *inside* the current record looks simpler and fails in both directions: - a message signed with the old key and verified after the change fetches the new key and fails; - a verifier that cached the old record keeps failing new signatures until its cached copy expires. ## The rollover, step by step RFC 5863 section 3.5 gives an example key deployment and termination process. Condensed, a planned rollover is: 1. **Generate** the new key pair on the signing system, so the private key never travels. 2. **Publish** the public key at a new selector, for example `s2026b._domainkey.example.com`. 3. **Wait and check**: the record must resolve from outside your network, and a test message to a mailbox you control should show `dkim=pass` with `header.s=s2026b` in its `Authentication-Results` header field. 4. **Switch signing** to the new selector on every signing host. 5. **Keep the old record published** while mail signed with the old key can still be verified. 6. **Revoke** the old selector by publishing it with an empty `p=`, or remove it. 7. **Destroy** the old private key; RFC 5863 has the signer delete every copy, including in-memory ones, once it stops signing with it. ## How long the old record stays RFC 6376 section 5.2 gives no number. It says the old public key "should be retained for a reasonable validation interval" and that a signer should anticipate verifiers that "defer validation, perhaps until the message is actually read by the final recipient". Size that interval from what can still be in flight: - **Your own retry queue**: a message deferred by the receiver is retried for up to Postfix's `maximal_queue_lifetime`, `5d` by default, still carrying the signature it got when it was signed. - **Intermediate hops**: relays, gateways and forwarders hold mail in their own queues before the final verifier sees it. - **Late verification**: a verifier that checks when the message is opened, or a mail filter that re-checks it later, needs the key then. So the overlap is measured in days, not minutes, and the cost of a longer one is only a public key left in DNS for a while. ## What goes wrong at each boundary | Mistake | What a verifier sees | Effect | |---|---|---| | Signing before the new record exists | the key record does not exist | `PERMFAIL (no key for signature)` on every new message | | Overwriting the old record in place | a key that does not match older signatures | queued and late-verified mail fails | | Revoking the old selector at the switch | an empty `p=` | `PERMFAIL (key revoked)` for mail still in flight | | Never revoking or destroying the old key | a still-valid old key | a retired private key stays usable if it ever leaks | A failed DKIM signature does not by itself reject anything: the receiver ignores it and judges the message on what else passes, which for DMARC means another aligned pass. ## Confirming each step - Read `header.s` and the `dkim` result on test messages from every signing host, so no host is left on the old selector. - In DMARC aggregate reports, where RFC 9990 (May 2026) makes the `selector` element required, watch rows for the old selector fall to zero before you revoke it. - Keep an inventory of each selector's creation date, signing hosts and owner, so the next rotation starts from facts. ## Two timing details that catch people - **A name queried too early**: if anyone looked up the new selector before you published it, a resolver may hold the "no such name" answer for a while (how long is DNS caching, not DKIM). Waiting and testing from outside before the switch covers it. - **Revoke or remove**: RFC 6376 section 3.1 says a domain phasing out a key would probably just remove the record after the transition period, and that there is no defined semantic difference between a revoked and a removed key. Publishing the empty `p=` is the more explicit of the two, and it makes accidental reuse of the old selector name less likely.

  • Can several signing hosts move to the new DKIM selector at different times?
    Yes. While both key records are published, each signature names its own selector and verifiers fetch only that one, so hosts can switch one by one. The overlap ends only when the last host has switched and its old-selector mail has cleared. Test messages from each host, read for `header.s`, show which hosts have moved.
  • How do you know mail signed with the old DKIM key has cleared before you revoke it?
    Check that nothing in your own queue is older than the switch, then watch DMARC aggregate reports: each DKIM row names its selector, so passes for the old selector should fall to zero and stay there for a few days. Only then publish the empty `p=`.
  • Why destroy the old private key when signing stops rather than when the record is revoked?
    RFC 5863's termination process has the signer stop signing and delete every copy of the private key first, and the DNS record withdrawn later. Once signing has stopped the key has no legitimate use, while the public record must stay so mail already signed can still verify.

It is like a business changing its official stamp: register the new stamp with the bank before using it, keep the old one on file until every cheque already stamped with it has cleared, and only then mark the old one void.

  • Just paste the new public key over the current selector's record.
  • Start signing with the new key, then publish its record.
  • Delete the old key record the moment signing switches.
  • Verifiers try every selector a domain publishes until one works.
  • RFC 6376 sets a fixed overlap period for the old key.