Skip to content
AdminKit

How do you rotate a DKIM key without breaking signed mail?

AdminKit's DKIM check can confirm each step of a key rotation, which isn't as simple as swapping one DNS record: mail in transit when you switch keeps the old signature, and some receivers may still see the old selector. Publish the new key under a new selector, run both in parallel for an overlap period, then retire the old one.

By AdminKit team, Netbase JSC · Updated

Key takeaways

  • Never overwrite the key at a selector that is signing mail. Publish the new public key under a new selector, switch signing to it, and keep the old key published during an overlap.
  • M3AAWG recommends keeping the old public key unchanged for at least 7 and up to 30 days after the switch, then retiring it with an empty p= rather than deleting it.
  • Rotate on a schedule: M3AAWG’s current guidance is at least every six months, and immediately if a private key may have leaked.
  • Use RSA keys of at least 2048 bits where your DNS host allows it (RFC 8301), and confirm each published record with a DKIM check before moving to the next step.

Why does swapping the key in place break mail?

Because mail signed with the old private key can still be waiting for verification when DNS starts serving only the new public key. That mail then fails DKIM, even though nothing was wrong with it when it left your server.

DKIM signs outgoing mail with a private key and publishes the matching public key in DNS at a hostname built from a selector you choose: <selector>._domainkey.<yourdomain>. RFC 6376 §3.1 (canonical record on the IETF Datatracker) created selectors precisely so a domain can publish more than one key at once. Its own example moves from selector january2005 to february2005 by advertising both keys “concurrently for the transition period during which email may be in transit prior to verification”.

The window is longer than it looks. RFC 6376 warns that verifiers “can choose to defer validation, perhaps until the message is actually read by the final recipient”. Add queued retries, slow relays and mail sitting in a receiver’s pipeline, and some messages are verified hours or days after they were signed.

AdminKit’s DKIM check looks up one selector’s TXT record and validates its syntax and public key. That is what you want at each step below: proof that DNS publishes what you intended before anything depends on it. It does not verify a signed message, so it complements, not replaces, the overlap period. This rotation guide is part of AdminKit’s email authentication cluster, alongside the other DKIM, SPF and DMARC guides.

What does a safe rotation timeline look like?

A safe rotation never has a moment where only one key exists in DNS. The sequence below follows RFC 6376 §3.1 and the workflow in M3AAWG’s DKIM Key Rotation Best Common Practices (revised March 2019):

StepWhat you changeOld selectorNew selectorMove on when
1. PublishAdd the new public key under a new selector nameSigningPublished, unusedDKIM check shows the new record valid
2. WaitNothing; let the record propagateSigningPublished, unusedThe new record is visible to resolvers (see TTL guide)
3. SwitchPoint your mail server at the new private keyPublished, verifying old mailSigningNew messages carry s= with the new selector
4. OverlapNothing; keep both keys unchangedPublished, verifying old mailSigningAt least 7 days, up to 30 (M3AAWG)
5. RevokeReplace the old key with v=DKIM1; p=RevokedSigningOld selector shows an empty p=

Notes on each step:

  1. Choose a new selector name every time. RFC 6376 calls signers “ill-advised to reuse selectors for new keys”, because a receiver can then no longer tell a message that fails because its key was replaced from one that is forged. M3AAWG adds that reuse makes older messages fail re-validation and can trip receivers holding stale cached values. A date-based name (mail202611) or an incrementing one (selector-v2) avoids the collision. M3AAWG’s own example, sales-201309-1024, also encodes the mail stream and key size.
  2. Wait for the record to be visible everywhere. M3AAWG says to allow time for DNS propagation before signing with a new key. See DNS propagation and TTL explained for why a record you just published isn’t instantly seen by every resolver.
  3. Switch signing. The old selector’s record stays published and unchanged. This is what lets mail signed moments before the cutover still verify while new mail verifies against the new key.
  4. Hold the overlap. RFC 6376 sets no fixed length and asks only for “a reasonable validation interval”. M3AAWG puts a number on it: keep the old public key unchanged for a minimum of seven days, and up to 30 days.
  5. Revoke rather than delete. RFC 6376 §3.6.1 defines an empty p= as a revoked key. M3AAWG recommends this over deleting the record so the selector stays discoverable and visibly retired on purpose.

M3AAWG also suggests keeping one key ahead: publish the next public key in DNS as soon as you switch, so an emergency rotation only needs the mail administrator to change the signing key, with no DNS change and no propagation wait.

What do the DNS records look like at each stage?

An illustrative zone for example.com, with the key data shortened, looks like this. The old selector is mail202605, the new one is mail202611:

; Before rotation: one key, signing
mail202605._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBg...oldkey..."

; Steps 1-4: both keys published, signing has moved to mail202611
mail202605._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBg...oldkey..."
mail202611._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBg...newkey..."

; Step 5: old key revoked, new key signing
mail202605._domainkey.example.com.  TXT  "v=DKIM1; p="
mail202611._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBg...newkey..."

Two record tags matter during a rotation. An empty p= tells verifiers the key “has been revoked”; under RFC 6376 §6.1.2 they must treat a signature that points at it as a failed check (PERMFAIL (key revoked)). The RFC also says there is “no defined semantic difference” between a revoked key and a removed record, so deleting the record has the same effect on mail. The empty p= is an operational choice for clarity, not a different verdict.

The t=y flag marks a domain as testing DKIM. RFC 6376 says verifiers “MUST NOT treat messages from Signers in testing mode differently from unsigned email”, so a key left with t=y gives you no DKIM benefit. Do not carry it over into a production key.

How do you generate the new key pair?

Generate it on the signing host or with your provider’s tooling, and keep the private key there. RFC 6376 Appendix C shows openssl genrsa for this, though with a 1024-bit key; RFC 8301 has since said signers “SHOULD use RSA keys of at least 2048 bits” and forbids rsa-sha1 for signing and verifying. An example using the openssl-genrsa and openssl-rsa commands:

# Example only: create a 2048-bit private key for selector mail202611
openssl genrsa -out mail202611.private 2048

# Extract the public key; its base64 body (without the BEGIN/END lines) goes into p=
openssl rsa -in mail202611.private -pubout -out mail202611.public

RFC 8301 points out that RSA keys much longer than 1024 bits don’t fit in a single 256-octet TXT string, so a 2048-bit key is published as several quoted strings in one record. M3AAWG notes that your DNS servers must support EDNS0 or TCP for records this long. AdminKit’s DKIM record generator formats the selector._domainkey record and splits the key for you from a public key you paste; it never generates keys or sees the private one.

RFC 8463 adds Ed25519 keys (k=ed25519), whose base64 public key is only 44 octets and fits in a single string. Verifiers must implement it, and RFC 8463’s transition advice is to add it alongside an RSA signature, under a different selector, for backward compatibility. That makes it a second selector to rotate, not a replacement for RSA.

How do hosted providers handle rotation?

If a provider signs for you, it usually owns the private key and the rotation mechanics, and your part is DNS:

ProviderHow rotation worksWhat you do
Microsoft 365Two selectors, selector1 and selector2, published as CNAMEs to Microsoft-hosted keys; the Defender portal or Rotate-DkimSigningConfig switches between themKeep both CNAMEs in place; allow four days (96 hours) for the new key to start signing
Google WorkspaceGenerate a new record in the Admin console; the default prefix is google, and Google says to enter a different prefix if your domain already uses a google keyPublish the new TXT record; Google says DKIM can take up to 48 hours to start working
Third party via CNAMEM3AAWG describes three CNAMEs (key1, key2, key3) pointing at the vendor’s keys, so it can rotate one while another signsPublish the CNAMEs once; ask the vendor for its rotation dates

Microsoft’s documentation also notes that you cannot start another rotation until the current one has finished, and that switching from 1024 to 2048 bits applies to the next active selector. Google’s DKIM setup page recommends 2048-bit keys where your domain host supports them.

Which rotation mistakes break mail, and how do you spot them?

Most rotation failures come from doing a step too early or skipping one. These are the patterns to rule out:

Failure modeSymptomFix
Overwrote the key at the signing selectorDKIM fails for mail sent shortly before the changeUse a new selector; never edit the key behind a live one
Switched signing before the new record was visibleEarly messages on the new selector fail with no key foundConfirm the record with DKIM check and wait for propagation first
Revoked the old key too soonDelayed or deferred mail fails after the overlap endsKeep the old key 7–30 days (M3AAWG)
One mail stream still signs with the old keyThat stream’s DKIM fails after revocationInventory every sender; audit s= in sample messages
Key split wrongly or truncated in DNSDKIM check reports a syntax or key errorRe-paste as multiple quoted strings in one TXT record
t=y left on the production keyDKIM passes but gives no protectionRemove the t=y flag

M3AAWG recommends an audit shortly after each rotation, for example a week later: compare the d= and s= values in the DKIM-Signature of real messages against the selector you expect. AdminKit’s email header analyzer shows the DKIM verdict a receiver recorded in Authentication-Results for a message you paste; the selector the message was signed with is the s= tag of its DKIM-Signature header.

When should you rotate on a schedule, and when immediately?

Rotate on a schedule at least every six months, and immediately if you have reason to think a private key is exposed. Both follow the same dual-selector steps; only the timing differs.

M3AAWG’s document moved from a quarterly to a six-month recommendation in its 2019 revision, as a balance between risk and operational effort, and says simpler mail flows can rotate more often. Its example is rotating each April and October to avoid busy sales periods. If a key may be compromised (a breached mail server, an exposed backup, departing access that included key material), skip the calendar and rotate now.

Either way, confirm the new record with DKIM check before relying on it, and see DKIM selector and record mistakes that break signing for the syntax and publishing errors that most often undermine a rotation that otherwise followed the right sequence.

This guide is general information, not a security audit of your specific network — see our disclaimer for what AdminKit's guidance does and does not commit to.

Frequently asked questions

Why rotate a DKIM key that isn't showing any problem?

A DKIM key that's never rotated is a long-lived credential: the longer the same private key signs mail, the longer a single leak (a compromised mail server, a misconfigured backup, a departing admin's old access) stays exploitable without anyone necessarily noticing. M3AAWG's DKIM Key Rotation Best Common Practices treats periodic rotation as routine hygiene, separate from reacting to a known incident, and recommends rotating at least every six months. Regular rotation also keeps the procedure familiar, so an emergency rotation after a suspected leak is a known routine rather than an improvised one.

Can I just replace the TXT record at my existing selector in place?

You can, but it causes exactly the outage this guide is about avoiding. The moment you overwrite the record, any mail already sent (but still awaiting verification by a slower or queuing receiver) still carries a signature made with the old private key, while DNS now serves the new public key — verification fails for that mail. Publishing the new key under a brand-new selector name, instead of overwriting the old one, is what lets both keys be valid at once during the transition.

What does 'never reuse a selector name' actually mean in practice?

Pick a new selector label every time you rotate — something like a date-based name (mail202611) or an incrementing one (selector-v3) rather than reusing a generic label like 'default' or 'key1' again later. RFC 6376 §3.1 calls signers 'ill-advised to reuse selectors for new keys', because a receiver can then no longer tell a message that fails because its key was replaced from one that is forged. M3AAWG adds that reusing a name makes older messages fail any re-validation against the new key and can trip receivers holding stale cached values. Treat a selector as the identifier of one specific key, not a reusable slot.

How long should I keep the old selector's record published during rotation?

Long enough for the slowest legitimate mail signed before the cutover to still be verified by its receiver. M3AAWG's rotation document says to keep the old public key unchanged in DNS for a minimum of seven days and up to 30 days. RFC 6376 sets no number; it only advises keeping the old public key for 'a reasonable validation interval', noting that some verifiers defer validation until the recipient actually reads the message. Pick the longer end if your outbound queues retry for days.

How do I retire the old selector once the overlap period is over?

Publish "v=DKIM1; p=" at the old selector rather than deleting the record. RFC 6376 §3.6.1 defines an empty p= value as a revoked key, and a verifier must treat a signature that points at it as a failed check (PERMFAIL, key revoked). The RFC states there is no defined semantic difference between a revoked key and a removed record, so both make old signatures fail; M3AAWG recommends the empty p= form because the selector stays discoverable and visibly retired on purpose, which is easier to recognise if something is still signing with the old key.

Should my new key be RSA 2048 or Ed25519?

RFC 8301 requires RSA keys of at least 1024 bits and says signers should use at least 2048. RFC 8463 adds Ed25519 (k=ed25519), which verifiers must implement, and RFC 8463's transition advice is to sign with both, using a different selector for each, for backward compatibility. For most domains a 2048-bit RSA key is the practical default; Google Workspace and Microsoft 365 both offer 2048-bit keys in their own rotation settings.

Want AdminKit to watch this for you?

Free checks tell you the state today. Protective DNS and monitoring tell you when it changes.

Huy Nguyen (David), Founder and CEO of Netbase JSC

Talk to an expert

Huy Nguyen (David), Founder & CEO, Netbase JSC

Ask whether this fix applies to your setup, or get a second pair of eyes on your DNS and mail records.