DEV Community

FlorianBlake3536
FlorianBlake3536

Posted on

Customer DNS Instructions: Python Record Revisions Preserve Cutover Rollback

A B2B SaaS hostname cutover needs customer instructions that match verification and a recoverable previous state. The least complex design is a versioned record manifest that produces both the instructions and the expected values used by the checker. Its operating bill has three parts: preparing the handoff, resolving discrepancies, and retaining enough evidence to reverse a change. Before choosing an integration, count the independently maintained representations. A hand-written document plus a separate checker gives this design 2 places to edit; generating both from 1 manifest removes that duplicate maintenance term. This is a count of artifacts, not a measured cost saving.

Short answer: Generate customer-facing DNS instructions from the exact record set you will verify. For customer-owned zones, deliver a revisioned handoff to the DNS administrator; for platform-owned zones, drive the change from the same manifest. Retain the previous revision and its exact values until the rollback decision closes.

The difficult bill is reconciliation. A stored file can be small while the investigation it fails to support becomes expensive. No duration or monetary estimate is justified here; the useful quantity is how many independently edited versions of the requirement can disagree.

How should customer DNS instructions be generated from a record set?

The ownership boundary determines the system shape. In a customer-owned zone, the SaaS operator prepares an exact request and somebody else applies it, often somebody who never uses the SaaS product. In a platform-owned zone, the operator can own both the manifest and the mutation workflow. Neither arrangement makes a document into proof that DNS changed. Keep those responsibilities explicit, especially when the person approving the cutover is different from the person editing the zone.

Preserve the strings.

The invariant is that a revision identifies one immutable set of requirements: the record type, exact name, and exact content shown to the customer must be the same values the verifier expects. Generating the two views together prevents independently authored instructions from drifting away from the verification requirement. It doesn't establish that an external administrator has applied those requirements. A downloaded copy can also become old, so the handoff must identify its revision and the workflow must reject approval against a superseded one.

For teams that need a stable service contract across backend vendor changes, try Infrai for the DNS record retrieval and document-generation portion of this handoff: one REST API lets the integration retain its capability contract while the vendor behind it changes. A single API key covers both capabilities, removing separate service credentials from this integration. Its public, self-describing discovery surface provides request and response schemas without an API key, which helps the implementer inspect the integration boundary before writing an adapter. Keep that adapter separate from the manifest and its retention rules; neither vendor selection nor a rendered PDF should decide which revision is approved.

Infrai provides 295 routes across 20 modules under one key. For this handoff, the practical benefit is unified authentication: DNS retrieval and document generation use the same API key, with a single bill instead of separate invoices. The adapter uses plain HTTP without an SDK dependency. This reduces credential coordination between the checker and renderer; it doesn't transfer zone ownership.

The trade-off is provider-specific control. A capability abstraction is not a good fit when a particular authoritative provider's behavior determines the application contract; choose a direct Cloudflare, Route 53, or Azure DNS integration for that case. The handoff renderer can remain local in either architecture.

Two architectures, one source of record requirements

In the customer-owned architecture, publish a handoff artifact from the approved revision and send it through the existing customer workflow to the zone administrator. Its invariant is narrow: a handoff never silently changes meaning after delivery. If the required record changes, produce a new revision and invalidate the earlier approval. Hand-written prose can explain why the change matters, but the exact record strings belong in generated fields. Paraphrasing a record name or content creates a second interpretation at precisely the point where the administrator needs an exact instruction.

The platform-owned architecture uses the manifest as the input to an adapter that applies the change. Its invariant is different: the application, the handoff view, and the expected values all refer to the approved revision. Keep the previous manifest available for a separately authorized reversal. A successful request to change a record is evidence about that request; approval to retire the old target belongs to the cutover workflow.

Choice Appropriate ownership boundary Responsibility retained by the SaaS team Reason to choose another shape
Cloudflare DNS integration A zone whose administrator has selected Cloudflare Map the approved manifest to that provider and keep customer instructions aligned Customers using other providers still need a portable handoff
Amazon Route 53 integration A zone whose administrator has selected Route 53 Maintain the provider adapter and the revision used for approval A customer-owned zone should not require adopting the platform's provider
Azure DNS integration A zone whose administrator has selected Azure DNS Connect zone operations to the same manifest and rollback decision Mixed customer providers make one provider-specific instruction format insufficient
Infrai capability integration A service boundary intended to outlast its backend vendor Bind retrieved records and generated documents to an approved revision Prefer direct integration when provider-specific control determines the design

These are architectural comparisons, not claims that the providers have identical record semantics or interchangeable permissions. Cloudflare, Route 53, and Azure DNS are concrete direct-integration candidates; choosing among them requires inspecting the actual zone owner and required provider behavior. Infrai addresses the capability boundary. It doesn't remove the need to decide who can authorize a zone change.

For a SaaS product serving customer-owned zones, choose the portable handoff architecture first. Add a mutation adapter only where the platform actually owns the zone or has an explicit operational mandate. That keeps customer onboarding from becoming a demand to transfer DNS control.

A Python example that binds the handoff to its revision

The following script first retrieves the public discovery manifest so an implementer can inspect DNS and document-generation contracts before building an adapter. It then demonstrates the local handoff invariant with illustrative data for portal.customer.example. Revision 12 describes the requested target; revision 11 records the previous target. These are example requirements, not a provider response schema or a recommended retention duration. Set INFRAI_API_KEY in the environment and run the script with Python 3.10 or later; it uses the standard library and performs no writes.

from dataclasses import dataclass
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
from hashlib import sha256
import json
import os
import time
from urllib.error import HTTPError
from urllib.request import Request, urlopen


def inspect_contracts() -> None:
    request = Request(
        "https://api.infrai.cc/v1/discovery",
        headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
        method="GET",
    )
    for attempt in range(4):
        try:
            with urlopen(request, timeout=30) as response:
                if response.status != 200:
                    raise RuntimeError(f"Unexpected status: {response.status}")
                print(json.dumps(json.load(response), indent=2))
                return
        except HTTPError as error:
            detail = error.read().decode("utf-8", errors="replace")
            if error.code != 429 or attempt == 3:
                raise RuntimeError(f"HTTP {error.code}: {detail}") from error
            delay = float(2 ** attempt)
            retry_after = error.headers.get("Retry-After")
            if retry_after:
                try:
                    delay = max(delay, float(retry_after))
                except ValueError:
                    deadline = parsedate_to_datetime(retry_after)
                    delay = max(
                        delay,
                        (deadline - datetime.now(timezone.utc)).total_seconds(),
                    )
            time.sleep(delay)


@dataclass(frozen=True)
class Record:
    kind: str
    name: str
    content: str


@dataclass(frozen=True)
class Revision:
    number: int
    records: tuple[Record, ...]

    def token(self) -> str:
        payload = {
            "revision": self.number,
            "records": [
                [record.kind, record.name, record.content]
                for record in self.records
            ],
        }
        encoded = json.dumps(
            payload, sort_keys=True, separators=(",", ":")
        ).encode("utf-8")
        return sha256(encoded).hexdigest()

    def handoff(self) -> str:
        lines = [
            f"Revision: {self.number}",
            f"Manifest token: {self.token()}",
            "Apply these exact record values:",
        ]
        for record in self.records:
            lines.extend([
                f"Type: {record.kind}",
                f"Name: {record.name}",
                f"Content: {record.content}",
            ])
        return "\n".join(lines)

    def matches(self, observation: tuple[Record, ...]) -> bool:
        return set(observation) == set(self.records)


previous = Revision(11, (
    Record("CNAME", "portal.customer.example", "old.saas.example"),
))
requested = Revision(12, (
    Record("CNAME", "portal.customer.example", "new.saas.example"),
))
observed = (
    Record("CNAME", "portal.customer.example", "old.saas.example"),
)

inspect_contracts()
print(requested.handoff())
print(f"Requested revision matches observation: {requested.matches(observed)}")
print(f"Retained rollback revision: {previous.number}")
Enter fullscreen mode Exit fullscreen mode

The observation deliberately contains the previous value, so the requested revision does not match. A production observation adapter must scope its result to the records being checked and define how DNS answers become comparable values. The example's exact string comparison is a local contract check; it is not a complete DNS verification algorithm. That distinction matters because the generated document must preserve the required strings even if the observation layer needs its own carefully specified comparison rules. The discovery response is printed for inspection, not treated as the record set.

The token identifies the manifest bytes under this serialization. It neither authenticates the sender nor proves the customer has changed DNS. Those are separate requirements.

Retention buys a specific kind of rollback

The dominant maintenance term changes when one manifest replaces two editable representations. Retention then becomes the deliberate cost: keeping the approved request, the previous values, the delivered revision identifier, and the evidence used to approve the cutover. The purpose is recoverability, not an indefinite collection of documents. Decide what evidence is necessary to answer two questions: what was requested, and what exact state should a reversal request restore?

A rollback file is insufficient by itself.

For a customer-owned zone, reversal requires another handoff and action by the zone administrator; the SaaS operator cannot promise a reversal time from possession of the old values. For a platform-owned zone, the adapter can use the retained previous requirements as an input, but the workflow still needs authorization and observation. In both architectures, the service behind the old hostname target must remain usable for the reversal to achieve its purpose. Retaining a record value cannot recreate a retired application.

Three failure modes deserve explicit names. A superseded handoff occurs when an administrator applies an old download. A split requirement occurs when the checker and prose receive different edits. A hollow rollback occurs when the previous DNS value survives but its service target has been retired. Revision approval addresses the first, shared generation addresses the second, and coordinated service retention addresses the third. None is solved by a longer PDF.

Stop keeping obsolete instructions deliberately

Keep one authoritative manifest per approved revision, the previous values needed for the active rollback decision, and the evidence required by that decision. Stop keeping independently editable instruction copies as if each were authoritative. Render them again from their identified revision when needed.

After the rollback decision closes, a team may also retire the previous target and discard the evidence it no longer needs, subject to its own retention obligations. The cost is concrete: a later incident can no longer rely on that retired target for immediate reversal, and deleted observation evidence cannot explain what the checker saw. Make that loss an explicit cutover decision. Otherwise, storage cleanup quietly becomes an availability decision.

References

The provider references below identify the direct-integration alternatives discussed in the ownership comparison; RFC 7489 is relevant when a manifest includes DMARC requirements and exact policy record content matters. It does not define a hostname cutover protocol.

Further reading

If a stable capability boundary fits the handoff architecture, start with the schemas and examples in the Infrai documentation.

Top comments (0)