DEV Community

Tenant Notice Cutovers: Reconcile SPF, DKIM, and DMARC TXT Records Before Switching

Move tenant notices only after the intended sending-domain records match published DNS and a test message demonstrates the intended authentication alignment. Preserve the previous sending path until the rollback decision is closed. A successful publication request is too weak a condition for moving rent reminders or maintenance notices.

TL;DR: Publish SPF, DKIM, and DMARC TXT records through one idempotent reconciliation job, record which revision it verified, and gate hostname cutover on that evidence. Treat rollback as another explicit desired revision. One job gives the operator a coherent decision boundary; it doesn't make separate DNS records a transaction.

For a property manager moving notices onto notices.harbor.example, the interesting question is whether the published records still represent the approved sending configuration when traffic moves. DMARC evaluates alignment between the visible author domain and an authenticated SPF or DKIM identity. Its processing rules, described in RFC 7489, make an operational distinction unavoidable: finding three TXT records doesn't establish that an actual notice will pass DMARC.

Decision: make drift the cutover boundary

Use a revisioned manifest as the job input. It should identify the sending hostname, the envelope sender domain, the DKIM signing domain and selector, the DMARC policy owner, and the exact TXT values that the operator intends to publish. Those domains can differ; the alignment relationship is what needs deliberate review. A hostname label by itself cannot express that relationship.

The example below uses notices.harbor.example for both the visible author domain and envelope sender domain, with a DKIM signing domain of the same name. Its record owners are therefore notices.harbor.example, tenant2026._domainkey.notices.harbor.example, and _dmarc.notices.harbor.example. These names are illustrative, and the public key must come from the actual signer. This keeps the example about publication and evidence rather than pretending that a sample key could authenticate a real message.

Three invariants govern the decision. The job may change only the records it owns. Verification must refer to the same manifest revision as publication. The old sending configuration must remain available for the agreed rollback interval, including the credentials and signing material needed to use it. A saved TXT snapshot alone cannot restore a sending service. Keep the snapshot.

From a storage perspective, the manifest is intent, DNS observations are externally visible state, and the job journal is evidence connecting the two. These have different lifetimes and failure boundaries. Persisting a revision doesn't publish it; accepting a DNS write doesn't prove that the reader used for verification has observed it; observing a record doesn't prove that the mail system used the corresponding identity. Collapsing these events into a single green status makes drift difficult to diagnose and rollback difficult to authorize.

How should one job verify SPF, DKIM, and DMARC TXT records?

Start with exact record reconciliation, then evaluate authentication using a message sent through the proposed path. RFC 7489 distinguishes SPF alignment from DKIM alignment and permits a DMARC pass when either aligned mechanism passes. Requiring both mechanisms to pass can be a reasonable local acceptance rule, but it is stricter than the protocol's DMARC pass condition. Label that choice as policy.

For this cutover, use the stricter rule during the test: require the intended envelope domain to pass SPF, the intended signature to pass DKIM, and the visible author domain to align as configured. Capture the receiving system's authentication result together with the manifest revision and test message identity. This is evidence for that test path, not a promise about every receiver. DMARC aggregate reports can support subsequent observation, but they are a separate feedback channel rather than a synchronous publication receipt.

A record-presence check misses concrete failures: the signer can use a different selector from the one published, and SPF can authenticate an envelope identity that doesn't align with the visible author. A DMARC record can request monitoring while an operator assumes it requests rejection; p=none doesn't request rejection. These cases all deserve explicit names in the journal: selector mismatch, identity misalignment, and policy drift. Presence isn't proof.

There is also stale verification: a worker verifies revision 17, another worker approves revision 18, and the first worker marks the hostname ready. Prevent this in the job store with a conditional state transition against the revision. Serializing changes to a sending hostname reduces competing writes, although that lock cannot prevent an independent administrator from editing DNS. Read the owned records again before approving cutover and invalidate readiness whenever observed state differs from the approved manifest.

Compare the scope of each change

The choice is how much state to reconcile and how to explain partial completion. None of the following approaches removes the need to observe DNS or test the sending identity.

  • Three independent edits: Small, visible changes. Failure boundary: A completed edit can coexist with two obsolete records. Decision for tenant notices: Reserve for tightly supervised changes with a separate evidence log.
  • One revisioned reconciliation job: A retry can converge on one approved manifest. Failure boundary: Publication can complete only partially before an interruption. Decision for tenant notices: Use for the cutover, with explicit pending and verified states.
  • Replace all TXT records at each owner: Simple desired-state comparison. Failure boundary: Unrelated TXT values can be removed unless included deliberately. Decision for tenant notices: Reject unless the complete record set is exclusively managed.

The middle option costs more state management. It needs durable inputs, a retry policy, an ownership rule, and a place to retain observations. That work buys an answer to a specific operational question: which approved configuration did this worker actually verify? The trade-off is extra coordination for a defensible change boundary; request counts and a tidy dashboard are secondary.

Critical path: reconcile, observe, then authorize

The Python below specifies an adapter contract rather than an executable DNS integration. Supply a DNS adapter and a durable job store; their method names describe required behavior, not standardized network endpoints. The DNS adapter must compare logical TXT values, accounting for any presentation or chunking differences, and preserve unrelated TXT data. Its ownership ledger must identify the previous managed values, so it can replace an obsolete SPF or DMARC value instead of blindly appending another one.

from dataclasses import dataclass
@dataclass(frozen=True)
class Manifest:
    domain: str
    revision: int
    selector: str
    spf: str
    dkim: str
    dmarc: str
    def records(self):
        return {
            self.domain: self.spf,
            f"{self.selector}._domainkey.{self.domain}": self.dkim,
            f"_dmarc.{self.domain}": self.dmarc,
        }

def reconcile(manifest, dns, jobs, mail_probe):
    # This lease serializes cooperating workers for the hostname.
    with jobs.hostname_lease(manifest.domain):
        if not jobs.is_current(manifest.domain, manifest.revision):
            return "superseded"
        desired = manifest.records()
        jobs.save_intent_and_prior_owned_values_once(manifest, dns)
        for owner, value in desired.items():
            dns.ensure_owned_txt(owner, value)
        observed = dns.observe_owned_txt(tuple(desired))
        if observed != desired:
            jobs.record_pending(manifest, observed)
            return "pending_dns"
        # Reuse the persisted test identity on retries.
        proof = mail_probe.ensure_result(manifest)
        if proof is None:
            return "pending_message"
        if not proof.matches_manifest_and_passes_local_policy(manifest):
            jobs.record_failed_probe(manifest, proof)
            return "blocked"
        observed = dns.observe_owned_txt(tuple(desired))
        if observed != desired:
            jobs.record_pending(manifest, observed)
            return "pending_dns"
        # The store atomically checks the revision and records evidence.
        if jobs.mark_verified_if_current(manifest, observed, proof):
            return "verified"
        return "superseded"

Idempotency depends on the contracts behind those calls. ensure_owned_txt must be a no-op when the owned value already matches. Saving the prior state once must survive retries without replacing the original rollback snapshot with a partially changed state. The probe needs a persisted identity so that retrying a DNS job doesn't automatically generate another tenant-facing notice. Send the probe to a controlled test recipient. The store's conditional transition protects its own readiness decision; it cannot atomically commit that decision with public DNS. There remains a window in which an external edit can follow the last observation. Continued reconciliation and a final observation at the traffic-change boundary reduce that exposure. Claiming transaction isolation across the job store, DNS, and a receiving mail system would promise a property this design doesn't provide.

Handle transport exceptions as unfinished work, recording the operation and retrying with a bounded backoff policy. After an ambiguous write result, observe before attempting another change. A retry budget should end in a visible pending or blocked state, never an inferred success; credentials errors and conflicting ownership need operator review rather than an endless loop. Choose the observation deadline to fit the actual DNS configuration and cutover window instead of embedding a universal propagation timer.

Test interruption after each of the three writes, then rerun the same revision and check that it converges without duplicating managed values or deleting unrelated TXT records. Also test a stale worker, an unexpected selector, an authentication pass with failed alignment, and a rollback whose previous signer is unavailable. These are proposed acceptance tests, not reported benchmark results.

In operation, retain the intended revision, observed values, probe outcome, and last error; a single success counter cannot explain a partial publish.

Rejected option: restore the snapshot and immediately switch back

Restoring the prior owned values is useful as a rollback operation, but immediate traffic reversal assumes that writing the old values also restores every observer's view and the old sending path. The rollback job should instead create a new revision containing the approved prior intent, reconcile it, and collect fresh evidence. Don't move the revision counter backward or reuse an earlier verification receipt.

An immediate reversal has a valid use case when the previous sending path has deliberately remained ready and current evidence already establishes that its authentication requirements are met. Even then, preserve both configurations for the planned overlap where they are compatible, and inspect their actual owners and selectors before assuming that coexistence is safe. If two configurations require incompatible values at the same owner, the rollback plan must name that conflict before cutover.

For tenant notices, the decision remains narrow: move the hostname when the approved records and the observed sending identity agree, and retain enough working state to repeat that decision in reverse. DNS publication is one step in that decision. It isn't the receipt for the whole change.

References

RFC 7489, Domain-based Message Authentication, Reporting, and Conformance (DMARC), including identifier alignment, policy discovery, and reporting: https://datatracker.ietf.org/doc/html/rfc7489

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.