A Zero-Downtime Runbook for DKIM Key Rotation
DKIM key rotation feels like swapping a jet engine mid-flight, but a methodical dual-publishing strategy makes it a routine maintenance task.

That little knot in your stomach before you hit ‘apply’ on a major DNS change is a healthy survival instinct. For many IT and security teams, rotating a DomainKeys Identified Mail (DKIM) key feels like just such a moment—a high-stakes operation where one mistake could send your domain’s mail to the spam folder for days.
This fear is pervasive. We see it all the time: domains with DKIM keys that haven't been touched since they were first set up years ago. They use outdated 1024-bit RSA, signed by a long-gone admin, for a mail service that's been migrated twice. This isn't just poor hygiene; it's a security incident waiting to happen.
The good news is that key rotation doesn't have to be a crisis. With a proper understanding of DKIM selectors and a methodical runbook, it becomes a boring, repeatable, zero-downtime maintenance task. Let's build that runbook.
The Hidden Risks of Stale DKIM Keys
Before we get to the 'how', let's address the 'why'. If your mail is delivering and DMARC is passing, why poke the bear? Because a stale DKIM key introduces slow-burning risks that are invisible until they cause a major incident.
Compromise and Cryptographic Decay
The most obvious risk is key compromise. If an attacker gains access to your private key—perhaps via a compromised server, a leak from your email service provider, or a disgruntled insider—they can sign messages as you. They can send hyper-realistic phishing emails that will sail past spam filters and pass DMARC checks, all using your domain's pristine reputation. Rotating keys limits the window of opportunity for an attacker to use a stolen key.
There's also cryptographic decay. Standards evolve. The 1024-bit RSA keys that were standard a decade ago are now considered weak. RFC 8388 recommends keys of at least 2048 bits. A regular rotation schedule provides a natural opportunity to upgrade your cryptographic strength, keeping ahead of the curve as computing power makes older standards obsolete.
Operational Fragility
Stale keys create operational risk. Who generated that key? Where is the private key stored? If the only person who knew how your Salesforce DKIM was configured left the company two years ago, you have a problem. Regular, well-documented rotation procedures turn this tribal knowledge into an institutional capability. What's the right cadence? Most security frameworks, like those from NIST, recommend rotating cryptographic keys annually at a minimum. For high-value domains or those under strict compliance, quarterly isn't unreasonable. The goal is to make the process so routine it loses its terror.
Selectors: Your Secret Weapon for Seamless Rotation
The magic that makes zero-downtime rotation possible is built directly into the DKIM standard, specified in RFC 6376. It’s a concept called the 'selector'. Understanding this one piece of the puzzle is the key to unlocking safe rotations.
When an email is signed, the `DKIM-Signature` header includes several tags. One of the most important is the selector tag, `s=`. The value of this tag is an arbitrary string that points to a specific public key record in your domain's DNS. The receiving mail server sees `s=selector1` in the header, and to verify the signature, it queries DNS for a TXT record at `selector1._domainkey.yourdomain.com`.
This design is brilliant because it means you can publish multiple, parallel DKIM keys in your DNS, each with a unique selector. Your mail servers can be signing with `selector1` while a new key for `selector2` is already published and waiting in DNS. The world doesn't know or care about `selector2` until it sees a message signed with `s=selector2`.
Developing a Smart Naming Convention
Since the selector is an arbitrary string, don't squander the opportunity to make it meaningful. Using generic selectors like `default`, `key1`, or `google` is a missed opportunity. A good naming convention provides an audit trail at a glance.
Consider a scheme like `service-YYYYMMDD` or `service-qX-YYYY`. For a new key for your Google Workspace environment being rotated in the third quarter of 2024, you might use a selector like `google-q3-2024`. When you look at your DNS records a year from now, you'll know exactly what that key is for and when it was created, without having to dig through old change tickets.
The Zero-Downtime Rotation Playbook
This is the core runbook. Follow these steps methodically, and your rotation will be uneventful. We're aiming for boring.
Phase 1: Prepare and Publish the New Key
First, generate a new key pair using your mail service provider's interface or a tool like OpenSSL. Use a 2048-bit RSA key. Let's say our new selector is `mktg-202409`. You will create a new TXT record in your DNS at `mktg-202409._domainkey.yourdomain.com` containing the public key data. At this point, you have *not* configured your mail system to use this key. You are simply making it available in DNS. The old key and selector are still signing 100% of your mail.
Phase 2: Wait and Verify
Now, you wait. This is the 'dual-publishing' window. How long? At least 48 hours. This isn't about your record's TTL; it’s about ensuring that even the most obstinately cached DNS resolvers across the globe have had a chance to see your new record. Patience here prevents a world of pain later.
During this waiting period, verify the published key. Use command-line tools from multiple networks to ensure the key is resolvable and correct. Watch out for quoting issues or line breaks introduced by your DNS provider's web interface, which can invalidate the key.
$ dig TXT mktg-202409._domainkey.yourdomain.com +short
"v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz...DAQAB"
Many online DKIM testing tools also allow you to check a public key without receiving an email. Use them. Confirm the key length is 2048-bit and the syntax is valid.
Phase 3: Activate and Monitor
Once you've verified the new key is propagated and correct, it's time for the cutover. Go into your mail service provider's dashboard and switch the signing selector from the old one to the new one (`mktg-202409`). Send a few test emails to external mailboxes (Gmail, Outlook.com) and dive into the headers. Look for the `Authentication-Results` header and confirm you see `dkim=pass` with `header.s=mktg-202409`. For the next 24-72 hours, keep a close eye on your DMARC aggregate reports. Look for any unexpected dips in your DKIM pass rate.
Phase 4: Decommission the Old Key
After a safe waiting period—at least 7 days is a good starting point—you can decommission the old key. This waiting period is critical. It allows for any emails that were delayed in transit (e.g., sitting in a retry queue on a remote server) to be delivered and verified using the old key. First, remove the old key from your mail service configuration, ensuring it can no longer be used for signing. Then, and only then, delete the old TXT record from your DNS. The rotation is now complete.
Where Rotations Go Wrong
Even the best runbook can fail if you're not aware of the common pitfalls. Here are the three mistakes we see most often.
DNS Syntax and Copy-Paste Errors
The single most common failure point is incorrectly formatting the public key in the DNS TXT record. The `p=` value is a long, unbroken string of base64 characters. Many DNS providers have limits on TXT record string length and automatically split longer values into quoted chunks. This is usually fine, as RFC 7208 allows for it. However, a misplaced quote, a sneaky space, or an accidental line break copied from a text editor can render the entire key invalid. Always use a verification tool that understands how to correctly reassemble these split strings.
Forgetting About Third-Party Senders
You've successfully rotated the key for your primary mail flow from Google Workspace. Excellent. But what about the mail sent on your behalf by Salesforce, Zendesk, Mailchimp, or your billing platform? Each of these services should have its own DKIM configuration, with its own selector and key. A comprehensive key rotation policy must start with a complete inventory of all services authorized to send email for your domain. Your SPF record and DMARC reports are a good place to start building this inventory.
Premature Decommissioning
This one is born from impatience. An admin activates the new key, sees a few successful tests, and immediately deletes the old DNS record. An hour later, an email that was deferred by a recipient's greylisting server is redelivered. The receiving MTA looks at the `DKIM-Signature` header, sees the old selector, queries DNS, and gets an `NXDOMAIN` (domain does not exist). The result is a `dkim=fail` or `dkim=permerror`. If your DMARC policy is `p=reject`, that legitimate, delayed email is now undeliverable. The 7-day cool-down period before deleting the old key isn't optional; it's a critical safety buffer.
The takeaway
Rotating DKIM keys isn't about avoiding a single catastrophic failure; it's about building a resilient email security posture. It transforms a high-stakes, one-off event into a routine, low-risk operational process. By adopting a methodical approach with selectors and dual-publishing, you prove that your organization has mature control over its email infrastructure.
The next time you're auditing your DNS, ask yourself: when was the last time we rotated these keys? If the answer is 'never' or 'I don't know', you've just found your next project. Using a platform like MailSleuth.AI to continuously monitor your DMARC data can help you spot the fallout from a botched rotation—or confirm the success of a smooth one—before it impacts your entire domain.
We dissect phishing campaigns and email infrastructure so you don't have to.


