The order of actions matters more than the actions themselves. It exists in this form because settings are applied without stopping the node: both keys can sit in the configuration at the same time, and the transition costs nothing.
The new key is added and enabled before the old one is touched. Not the other way around. First it appears in the configuration under a different selector, the settings are applied, and signing switches to it.
Removal waits for the queue. The old key is removed only when no queued message relies on it anymore. The manual gives an example: a message that chose a key with its header — you have to wait until such messages are delivered or bounced.
The same order works for other cryptographic material too. The manual names the TLS certificate: the form of the procedure is the same — add, switch, wait, remove.
The Hub puts the private parts on the node itself, into a locked-down directory (/etc/pmta/dkim, permissions 700, keys 600), and edits the signing line in the sending address block.
⚠️ A “bad signature” error right after rotation is almost always the DNS cache, not a defect. This has happened before: check the record’s lifetime instead of looking for a signature malfunction.
Order and timing:
| Step | When |
|---|---|
| publish the public part in DNS | in advance, one record lifetime before the switch |
| add the key to the configuration under a new selector | after publication |
| apply the settings | with a reload, not a restart |
| switch signing to the new key | right after applying |
| remove the old key | when the queue holds no messages depending on it |
The selector must be different. Two keys under one selector are not rotation but replacement: the old signature will stop verifying instantly.
How to tell the wait is over. There should be no messages in the queue that chose the old key with a header; the simplest is to wait until this domain’s queue empties or the messages bounce on expiry.
# both keys sit side by side until the queue empties <virtual-mta mta-news-1> domain-key sel2,example.com,/etc/pmta/dkim/private_key_example.com.txt domain-key sel1,example.com,/etc/pmta/dkim/private_key_old.txt </virtual-mta>
what people get wrong and how it ends3 mistakes▶
§ 1.6.2
§ 1.6.2
§ 1.6.2
4 relations
domain-keyGlobalThe line that attaches the key; during rotation there are temporarily two of them. § 1.6.2Apply a changed configuration without stoppingOne and the same command applies both adding the new key and removing the old one. § 1.6.2
smtp-server-tls-certificateGlobalA neighboring task with the same rhythm: the validity period runs out, and the replacement has to be prepared in advance. § 1.6.2http-api-keyGlobalChanging the key works the same way as changing a signing key: the new one is written, and the old one stops working on apply. inferenceFlush the name cacheThe procedure in which this command is one of the steps. inferenceHow the node signs messages and chooses a keyChanging a key means a new selector, which is why the selector is a separate value in the declaration. § 10.3.2
dig +short sel2._domainkey.example.com TXT pmta show queues '*/mta-news-1'
3 articles
◇How the node signs messages and chooses a keyThe key is chosen by the sending domain from the headers, going through the declarations from top to bottom.◇Do not send what will fail the check at the receiverThe node checks the SPF of its own mail before sending: if it fails, it bounces the message without waiting for someone else’s refusal.◇A message header with which the submitting side adjusts the signatureFive parameters in X-DKIM-Options: selector, domain, signing identity, query method and key list.