skip to content

A DKIM private key for example.com's selector s2025a was found committed to a public repository — what do you do, in what order, and what breaks?

level: seniorimportance: must knowfreq 34%

answer

  1. public since the push
  2. new selector first
  3. no polite overlap this time
  4. who else holds that key
  5. reports keyed by selector

basics

~20 s

Treat the key as compromised from the commit: publish a new key under a new selector, switch signing, and revoke s2025a with an empty p= at once rather than after the usual overlap, accepting that mail still in flight fails DKIM.

solid answer

~50 s

The key is public from the moment it was pushed, and RFC 6376 section 8.3 is blunt: whoever holds it can send mail signed by the domain that advertises the matching public key. So: generate a new key pair on the signer, publish it at a new selector such as `s2026a`, check that a test message passes with `header.s=s2026a`, switch every signing host, and then publish `s2025a` with an empty `p=` straight away instead of keeping it for the normal validation interval. Legitimate mail still queued with the old signature will fail DKIM and must rely on another aligned pass for DMARC; that cost is accepted. Then scope it: is the same key behind any other selector or domain, who held it, and do DMARC aggregate rows for `s2025a` show passes from addresses you do not operate since the commit date? Finally, fix how a private key reached a repository.

go deeper

for a junior

Recall that a leaked DKIM private key lets others produce signatures that verify for the domain, so the old selector must be revoked and a new key used.

for a middle

Explain why the usual overlap is dropped: the leaked selector is emptied right after signing moves, and in-flight mail fails DKIM as a result.

for a senior

Run the response in order, scope where else the key was used, read aggregate rows by selector for unauthorised passes, and fix the custody failure.

for a principal

Have the runbook, owner and key custody in place beforehand, so a leak is a same-day rotation rather than an improvised outage decision.

## Why removing the commit does not fix it A **DKIM private key** is the only thing that makes a signature with `d=example.com` verify against the public key at `s2025a._domainkey.example.com`. RFC 6376 section 8.3 states the exposure: a compromised private key "means an intruder or malware can send mail signed by the domain that advertises the matching public key". Rewriting the repository's history is good hygiene, but copies may already exist, so the key must be treated as known to others **from the commit time**. The remedy is to make that key worthless, which only DNS can do. ## The response, in order 1. **Generate a new key pair on the signing system**, at the strength the domain's policy requires, never by copying a key from elsewhere. 2. **Publish it under a new selector**, for example `s2026a`; never reuse `s2025a`. 3. **Check it**: the record resolves from outside, and a test message shows `dkim=pass` with `header.s=s2026a` in `Authentication-Results`. 4. **Switch every signing host** to the new selector. 5. **Revoke `s2025a` at once** by publishing it with an empty `p=`. RFC 6376 names compromise as one reason the empty value exists. 6. **Destroy every copy** of the leaked private key on systems you control. 7. **Scope and monitor**, then **fix the cause**. Steps 1 to 5 belong on the same day. If the new key cannot be ready quickly, revoking first is still defensible: unsigned mail is usually a smaller harm than mail anyone else can sign as you. ## What breaks, and why it is accepted | | Planned rotation | Leaked key | |---|---|---| | Old record kept after the switch | for a validation interval of days | no, revoked immediately | | Mail in flight with the old signature | verifies normally | fails with `PERMFAIL (key revoked)` | | Main risk being managed | breaking legitimate mail | others signing as the domain | The failures are bounded. A receiver ignores a signature that failed this way and judges the message on what else passes; with an aligned SPF pass, DMARC still passes. The broken messages are the ones signed before the switch and verified after the revocation. Two limits remain: - **Caches**: a verifier that fetched the old record before the revocation can keep using it until its TTL runs out. - **Already delivered mail**: revocation recalls nothing; it only stops future verifications succeeding, which also means old genuine messages presented again no longer verify. ## Scoping the exposure - **Same key elsewhere**: check whether that private key also sits behind another selector or another domain's record; revoke each of them. - **Other secrets**: a repository that held one private key may hold signing configuration for others. - **Holders**: list every person and system that had the key. RFC 5863 section 3.1 wants it in as few hands as possible and keys withdrawn when a holder leaves. - **Window**: the exposure runs from the first commit, not from when it was noticed. ## Evidence after the fact - **DMARC aggregate reports** carry, per row, the `source_ip`, the DKIM `domain`, the `selector` (required since RFC 9990, May 2026) and the result. Rows where `s2025a` passed from addresses you do not operate, between the commit and the revocation, point to use you did not authorise. - After the revocation, rows for `s2025a` should show only failures; passes there most likely mean a verifier still holds a cached copy. - Test messages from each signing host confirm none still signs with the old selector. ## What not to do - **Do not reuse `s2025a`** for the new key: old signatures and new would share one name, and every later report row for it becomes ambiguous. - **Do not wait for the scheduled rotation**: a cadence limits how long an unnoticed exposure lasts, it is not a response to a known one. - **Do not generate the replacement key on a workstation** and copy it to the signer, which repeats the path that leaked the first one. - **Do not stop at the selector you were told about**: the same key material may sign under another name. ## Fixing the process RFC 5863 section 3.1 describes the custody this incident broke: the key generated **as close to the signing point as possible**, existing **in exactly one location**, excluded from backups and network shares, under one named owner. Add a secret scan on commits, and rehearse the rotation so the next one is routine.

  • If the new DKIM key cannot be published for a day, do you still revoke the leaked selector now?
    Usually yes. Revoking first leaves the domain's mail unsigned for a while, so DMARC rests on aligned SPF passes; leaving the leaked key published lets others sign as the domain. Unsigned is the smaller harm, and the new selector can follow.
  • Is rewriting the repository's history to remove the DKIM key worth doing?
    As hygiene, yes: it stops the key spreading further from that copy. As remediation, no: anyone who cloned it still has the key. Only revoking the selector in DNS and signing with a new key makes the leaked one worthless.
  • Why not simply wait for the scheduled DKIM rotation date?
    A cadence bounds how long an unnoticed exposure can last; it is not a response to a known one. Every day the leaked selector stays published, signatures made with the key keep verifying for the domain.

  • Deleting the file from the repository fixes the leak.
  • Keep the leaked selector published for a week so in-flight mail survives.
  • Reuse the leaked selector's name with the fresh key to avoid changes.
  • A leaked DKIM key lets anyone read the domain's mail.
  • Wait for the next scheduled rotation; the cadence covers leaks.