A contact form can put a refund request into the correct support queue while its email notification fails authentication. Keep queue assignment durable before sending the notification. Then maintain the sending domain without making support staff guess which messages survived a key change.
TL;DR: Rotate DKIM by publishing a new selector, checking its public key, moving the signer, and observing authentication at a receiving mailbox before retiring the old selector. Keep the old public key available for messages signed before the switch. In a Node.js application, make those checks explicit deployment gates. SPF is a separate check; an SPF pass does not prove the new DKIM key works.
The useful before/after is small. Before: “The send call succeeded, so the change is healthy.” After: “The receiver verified the new selector, the signature aligns with the visible From domain, and the support notification is traceable to its queue event.”
Watch the receiver.
The examples below use an illustrative store domain, shop.example, with refund notifications going to a refunds queue. The selector names and sample counts are test inputs, not production measurements. The code uses TypeScript and Node.js built-ins; substitute a domain you control before querying public DNS.
1. Create a second selector without replacing the first
DKIM places a selector in the signature's s= tag and a signing domain in d=. The receiver uses those values to find the public key in DNS. A new selector gives the next key its own lookup name while previously signed messages can still find the previous key. RFC 6376 describes that lookup and discusses key rotation.
Picture the path in words: contact form → persisted support ticket and queue assignment → notification worker → DKIM signer → receiving mailbox → authentication evidence. Carry a correlation ID through that path. Keep message bodies, customer addresses, and private keys out of routine telemetry.
Start with key material. This standalone script creates a 2048-bit RSA key pair, writes the private key into a fresh temporary directory with restrictive file permissions, and prints only the public DNS value and the private-key path. RFC 8301 requires signers to use RSA keys of at least 1024 bits and recommends at least 2048 bits. Here, 2048 is an explicit implementation choice.
import { generateKeyPairSync } from "node:crypto"; import { mkdtempSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; const selector = "support-b"; const domain = "shop.example"; const { privateKey, publicKey } = generateKeyPairSync("rsa", { modulusLength: 2048, publicKeyEncoding: { type: "spki", format: "der" }, privateKeyEncoding: { type: "pkcs8", format: "pem" }, }); const directory = mkdtempSync(join(tmpdir(), "support-dkim-")); const privateKeyPath = join(directory, "private.pem"); writeFileSync(privateKeyPath, privateKey, { mode: 0o600 }); console.log({ name: `${selector}._domainkey.${domain}`, value: `v=DKIM1; k=rsa; p=${publicKey.toString("base64")}`, privateKeyPath, }); Move the private key into the signing service's protected key storage through your normal secret-management process. That integration depends on who signs the mail. An application that hands mail to an external signer must update that signer's configuration; generating a local key does not change an upstream signature.
Publish the printed public value under the new selector. Leave the old selector published. A DNS interface may represent a long TXT value as multiple quoted character strings within one record; those strings belong to one key, not several competing records.
The gate here is straightforward: the new public record exists, the private material is protected, and the deployment configuration identifies the intended selector. Don't switch the signer yet.
How should you verify email domain authentication before a DKIM switch?
Checking a control panel only proves that you entered a value there. Check the DNS answer too.
This second standalone script queries the new selector, joins the character strings within each TXT record, rejects multiple candidate key records, and checks that the public key parses as RSA. Set EXPECTED_DKIM_PUBLIC_KEY to the base64 p= value printed above. The equality check catches a particularly awkward deployment mistake: publishing one key while installing another.
import { createPublicKey } from "node:crypto"; import { resolveTxt } from "node:dns/promises"; const name = "support-b._domainkey.shop.example"; const expected = process.env.EXPECTED_DKIM_PUBLIC_KEY; if (!expected) throw new Error("Set EXPECTED_DKIM_PUBLIC_KEY"); const records = (await resolveTxt(name)).map(parts => parts.join("")); const candidates = records.filter(record => /^v=DKIM1(?:;|$)/i.test(record.trim()) ); if (candidates.length !== 1) { throw new Error("Expected exactly one DKIM key record"); } const tags = new Map( candidates[0].split(";").filter(part => part.trim()).map(part => { const position = part.indexOf("="); if (position < 1) throw new Error("Malformed DKIM tag"); return [ part.slice(0, position).trim(), part.slice(position + 1).trim(), ] as const; }) ); if (tags.get("p") !== expected) { throw new Error("Published public key differs from the expected key"); } const key = createPublicKey({ key: Buffer.from(expected, "base64"), format: "der", type: "spki", }); if (key.asymmetricKeyType !== "rsa") { throw new Error("Expected an RSA public key"); } console.log({ event: "dkim_dns_gate_passed", name }); Limitations matter here. This check handles the exact record generated in step 1; it is not a general DKIM record validator. A passing lookup is one observation from the resolver used by this process. It is not proof that every receiving system has the same answer. Account for DNS caching and the TTLs relevant to the change, including previously cached negative answers. RFC 2308 explains negative caching; this is why “the record was absent a minute ago” can matter even after publication. For example, a receiving resolver that cached an absent selector can continue returning that cached answer while your deployment resolver already sees the public key. Testing the same resolver repeatedly leaves that blind spot intact. Check the authoritative answer and the recursive resolvers relevant to your controlled tests, then allow the applicable cache lifetimes to elapse before treating publication as ready.
Keep the evidence.
Once DNS checks pass, configure the signer to use support-b and send a controlled notification through the actual delivery path. Use a test support ticket, with a synthetic correlation ID, and inspect the message received by a mailbox you control. Record the selector from its DKIM signature and the trusted receiving system's authentication result.
The receiver is the next gate. A locally parseable public key cannot tell you whether a relay modified signed content or whether the sending configuration still selects the old key.
3. Turn receiver evidence into a release decision
Keep three observations separate: the support ticket reached its queue, the sending system accepted the notification, and a receiver authenticated the message. Each answers a different operational question. A successful send response alone leaves the last question open.
For a controlled canary, inspect the receiving system's trusted Authentication-Results header. RFC 8601 describes that header and its trust boundaries. Don't accept an arbitrary header supplied by a contact-form sender as evidence. Also check alignment: under DMARC, a passing DKIM signature must align its signing domain with the visible From domain to satisfy the DKIM side of the policy. SPF has its own authentication and alignment path.
The following executable example evaluates evidence transcribed from controlled mailbox checks. It does not parse headers or verify signatures itself. Its exact-domain comparison deliberately tests a stricter condition than relaxed DMARC alignment, keeping this canary easy to review.
type Canary = { eventId: string; queue: string; selector: string; signingDomain: string; fromDomain: string; trustedReceiverDkim: "pass" | "fail" | "unknown"; }; const canaries: Canary[] = [ { eventId: "test-refund-001", queue: "refunds", selector: "support-b", signingDomain: "shop.example", fromDomain: "shop.example", trustedReceiverDkim: "pass", }, ]; function gate(samples: Canary[]): void { if (samples.length === 0) throw new Error("No receiver evidence"); for (const sample of samples) { const passed = sample.queue === "refunds" && sample.selector === "support-b" && sample.signingDomain === sample.fromDomain && sample.trustedReceiverDkim === "pass"; console.log(JSON.stringify({ event: "dkim_rotation_canary", eventId: sample.eventId, queue: sample.queue, selector: sample.selector, passed, })); if (!passed) throw new Error("Hold signer rollout"); } } gate(canaries); The fixture contains one synthetic success so the example runs independently. Replace it with collected evidence before making a release decision. Exercise rejection too: change the selector to support-a, or change the authentication result to fail, and the gate must stop the rollout. Include the refund and order-support notification paths if they use different signing configurations.
For ongoing metrics, use bounded labels such as queue, selector, and authentication outcome. Keep the per-ticket correlation ID in logs. This preserves a path back to one failed canary without making every support event a new metric series. The trade-off is an extra log lookup during investigation. Treat this as an instrumentation design choice, with retention and access controls appropriate to customer-support data.
Set alert thresholds from your traffic and response expectations. A small controlled canary can block a deployment on any failure; production aggregate reporting serves a different purpose and may arrive later. DMARC reports can add receiver-side evidence, but they do not replace the immediate mailbox check.
4. Keep overlap until the evidence supports retirement
“Why keep the old key if new messages pass?” Because new messages and already signed messages use different selectors. A queued message signed before the deployment still needs the old public key when a receiver verifies it. Decide the retirement window from your actual signing point, queue residence, retry policy, and DNS behavior. There is no universal waiting period established by these examples.
Write that decision down.
Preserving the old DNS record also makes a controlled signer rollback possible while the old private key remains authorized and protected. A compromise changes the decision: continuing to authorize a compromised key is a security concern, so routine overlap is not a substitute for incident response.
“Can passing SPF cover the change?” SPF checks the sending host against the envelope identity; it does not verify a DKIM signature. DMARC can pass through an aligned SPF result even when DKIM fails, which makes a green DMARC result insufficient evidence that the new selector works. Check DKIM explicitly. Nor does authentication guarantee inbox placement: this procedure validates an authentication change, while acceptance, filtering, and human visibility need their own observations.
The operational finish line is concrete: the support ticket remains traceable to its assigned queue, controlled recipients verify the intended selector, and the old selector is retired under a documented policy. That gives the next person on call evidence they can inspect instead of a deployment timestamp they have to trust.
Sources (References)
- RFC 6376, DomainKeys Identified Mail Signatures, including selectors and key management: https://datatracker.ietf.org/doc/html/rfc6376
- RFC 8301, DKIM cryptographic algorithm and key usage updates: https://datatracker.ietf.org/doc/html/rfc8301
- RFC 7208, Sender Policy Framework: https://datatracker.ietf.org/doc/html/rfc7208
- RFC 7489, DMARC authentication alignment and reporting: https://datatracker.ietf.org/doc/html/rfc7489
- RFC 8601, Authentication-Results and trust boundaries: https://datatracker.ietf.org/doc/html/rfc8601
- RFC 2308, negative caching of DNS answers: https://datatracker.ietf.org/doc/html/rfc2308

