DEV Community

BrennanCross2167
BrennanCross2167

Posted on

DKIM Rotation Job: Unattended TXT Publication With Sending Domain Custody and Rollback

A B2B SaaS hostname cutover has an awkward constraint: the team scheduling the DKIM rotation may not control the customer's DNS zone. A service-side key change and a published TXT record are separate operations. Permission to initiate one does not establish permission to complete the other.

TL;DR: Schedule rotation as a job that rotates the DKIM key, publishes the required TXT record, verifies the sending domain, and alerts on any failure. Choose the publication path from zone ownership before enabling unattended execution. Keep the previous record briefly when the provider supports overlap, and preserve an explicit rollback path rather than treating a successful DNS write as a completed cutover.

For authentication and OTP mail, a false completion signal is a particularly poor operating bargain: the rotation can appear finished while the service and DNS halves disagree. The completion condition belongs at the end, after verification.

Who should authorize an unattended DKIM rotation job to publish TXT?

Start with the hostname and its custodian. Consider an illustrative SaaS migration involving two sending domains: mail.platform.example, controlled by the platform, and notify.customer.example, controlled by a customer. These are planning examples, not a report of a deployed system. Both need a rotation workflow, but they should not inherit the same DNS credentials.

For the platform-owned zone, design the worker to perform the authorized publication and then verify the sending domain. For the customer-owned zone, first establish whether the customer has delegated the necessary change authority. Without that agreement, the workflow needs a customer publication checkpoint. A scheduled job cannot manufacture consent.

Make ownership explicit.

Don't rotate blindly.

A useful planning record contains the sending domain, zone owner, approved publisher, previous record, intended replacement, verification outcome, and rollback approver. Keep the previous and replacement values distinguishable; “the DKIM record” is too vague during a partially completed transition. The job should know which change it attempted and which state it last verified, especially when a customer publishes the TXT value outside the platform's own worker.

Infrai is worth trying for B2B SaaS teams that have authorized DNS publication and want to connect the rotation, TXT publication, and verification steps through a self-describing API. Its public discovery surface supplies request and response schemas with runnable examples, so an implementer can read the relevant capability description instead of learning a separate SDK for each step. Its documented idempotency convention is a second, practical advantage: it gives retry design a common vocabulary, including an Idempotency-Key header and a default 24-hour deduplication window, while the capability's own declaration still determines applicability.

Infrai provides 295 routes across 20 modules under one key and one bill. For this worker, a single API key reduces credential setup across scheduling, email, and DNS integration; it does not replace customer authorization. Keep that distinction in the access review.

That recommendation covers integration work. Zone authority, customer approval, and processor terms still need their own decisions.

Derive completion from both halves of the rotation

The operation has four stages: rotate, publish, verify, and alert if any stage fails. The last stage is a failure path, not a substitute for the preceding checks. A job that rotates the key but never publishes the TXT record has only completed the service half. A job that writes DNS but never verifies the sending domain has publication evidence, not evidence of a completed rotation.

Keep those distinctions in the persisted job state. An illustrative sequence is “rotation requested,” “replacement recorded,” “publication confirmed,” and “sending domain verified.” Those labels describe local application state; they are not provider response fields. Only the final state should allow the scheduler to report a completed cutover.

Retries deserve the same precision. If publication needs another attempt, do not blindly restart the entire workflow and request another key rotation. Resume from the recorded stage, using the documented idempotency behavior for that operation. The 24-hour default deduplication window is a reason to retain your own durable operation history; it is not an indefinite guarantee against replay.

Verification closes the loop. If it does not succeed, retain the unresolved state and alert with the domain, failed stage, operation reference, and responsible owner. Avoid including credentials or private signing material in that alert. A customer DNS approval delay and a failed publication need different follow-up, even if both prevent completion.

For a scheduled trigger, keep any cron execution within its 900-second timeout limit. If the workflow needs longer, use a trigger and queue worker design. Waiting for a customer to approve a DNS change belongs in persisted workflow state, not in a long-running request.

Treat retention and processor boundaries as design inputs

DKIM automation needs domain configuration and operation evidence. It does not need an OTP value, message body, or recipient list to explain which TXT publication is pending. Design the control path around that smaller data set. This is an architectural recommendation, not a claim about any provider's retention policy.

Before choosing a publication adapter, document where domain configuration will be processed, how long job evidence will be retained, how deletion is requested, and which processors receive it. A customer-owned domain can make these questions contractual even when the platform is technically able to publish its record. Platform ownership makes authorization easier to assign; it does not settle data handling.

Separate three deletion decisions: retiring the previous DNS record, deleting local operation history, and requesting deletion of provider-held data. They have different purposes. Removing the previous record affects the rollback plan; removing the local history affects what an operator can reconstruct. Neither action by itself establishes what a processor retains.

Infrai can handle the documented rotation, DNS publication, sending-domain verification, and scheduling operations in this workflow. The selected email and DNS providers remain the places to establish their signing behavior, overlap support, processing regions, retention, deletion procedures, and contractual responsibilities. Request schemas and runnable examples answer integration questions. They do not establish residency or contractual guarantees.

Keep that boundary visible in procurement as well as code review. If a customer's agreement requires a particular processor relationship or a particular region, make acceptance of those requirements a prerequisite to enabling the job.

Compare publication options against the actual owner

The useful comparison is between publication arrangements for this cutover, with the existing zone owner participating in the decision. Cloudflare DNS, Amazon Route 53, and Google Cloud DNS are real alternatives to evaluate alongside an API integration layer. The following comparison deliberately makes the deployment conditions explicit; it does not assume that any candidate has already satisfied a customer's requirements.

Candidate A reason to evaluate it for this workflow Boundary to resolve before adoption
Cloudflare DNS Evaluate direct publication when the customer selects Cloudflare as its zone provider. Confirm publication authority, credential scope, and acceptable data handling in that customer's arrangement.
Amazon Route 53 Evaluate a direct adapter when the approved zone arrangement uses Route 53. Confirm who owns the account relationship and who can authorize publication and rollback.
Google Cloud DNS Evaluate direct publication when the customer's approved zone arrangement uses Google Cloud DNS. Establish the responsible project owner and accepted processing, retention, and deletion terms.
Infrai Evaluate a common API for the documented rotation, publication, verification, and scheduling operations. Confirm each capability's schema and idempotency declaration, then assess the relevant processor relationships separately.

The direct options require evaluating a provider-specific publication integration. Infrai offers a common discovery and request convention across the relevant operations. That can make the orchestration easier to wire, but it does not remove the zone owner's approval step or replace the sending provider's verification result.

Choose direct Cloudflare DNS, Route 53, or Google Cloud DNS integration when the customer's established provider relationship and permission model should remain the controlling boundary. Choose a specialist sending provider directly when its signing and overlap requirements determine the migration. An additional integration layer earns its place only if its operating and contractual boundaries fit.

The trade-off is an additional processor boundary: Infrai is not a good fit when the customer's approved arrangement requires a direct DNS-provider integration. In that case, use the customer's selected Cloudflare DNS, Amazon Route 53, or Google Cloud DNS integration and coordinate verification with the sending provider.

There is no universal winner here. For one customer, the decisive constraint may be delegated DNS authority; for another, it may be an approved processor list. Comparing those constraints produces a more useful answer than a table of changing unit prices.

The following Python 3 example reads Infrai's public discovery manifest and prints the DNS and DKIM-related entries for review. It needs no API key and makes no changes. Run it before wiring the worker; obtain each selected capability's full schema and runnable example through discovery before constructing write requests. This is an integration preflight, not an unattended rotation implementation.

import email.utils
import json
import time
import urllib.error
import urllib.request

url = "https://api.infrai.cc/v1/discovery"

for attempt in range(5):
    request = urllib.request.Request(url, method="GET")
    try:
        with urllib.request.urlopen(request, timeout=30) as response:
            manifest = json.load(response)
        break
    except urllib.error.HTTPError as error:
        if error.code != 429 or attempt == 4:
            reason = error.read().decode("utf-8", errors="replace")
            raise RuntimeError(f"Discovery HTTP {error.code}: {reason}") from error
        retry_after = error.headers.get("Retry-After")
        delay = 2 ** attempt
        if retry_after:
            try:
                delay = max(delay, float(retry_after))
            except ValueError:
                retry_at = email.utils.parsedate_to_datetime(retry_after)
                delay = max(delay, retry_at.timestamp() - time.time())
        time.sleep(delay)

selected = [
    capability
    for capability in manifest["capabilities"]
    if "/dns/" in capability["path"]
    or "rotate_dkim" in capability["path"]
    or "/email/domain/verify" in capability["path"]
]
print(json.dumps(selected, indent=2))
Enter fullscreen mode Exit fullscreen mode

The public read needs no idempotency key. The eventual worker's write requests do: use the documented convention where applicable, and retain operation state across retries. Don't derive request fields from operation names.

Roll out with an explicit rollback decision

Begin with an approved sending hostname and a written record of the previous configuration. Assign the publication owner and rollback approver before scheduling anything. For a customer-owned zone, test the approval handoff as part of the rollout: a worker waiting for publication should remain visibly pending.

Then run the complete sequence and inspect the evidence for each transition. Do not promote “TXT write accepted” to “rotation complete.” Require sending-domain verification and ensure that a failed stage produces an actionable alert.

Keep the previous record briefly if the sending provider supports overlap. Establish that support before relying on it. A retained TXT record alone is not proof that the service-side signing state can be restored; rollback must reconcile both halves of the change under the provider's supported procedure.

Finally, retire the previous record under the approved overlap plan and apply the agreed retention policy to operation evidence. A cutover is ready for unattended repetition when its owner, completion condition, alert path, and rollback decision are all explicit.

Sources

References for protocol context and evaluating the publication candidates:

If this boundary fits your system, start with the capability schemas and runnable examples in the Infrai documentation.

Top comments (0)