DEV Community

JorisRhodes8286
JorisRhodes8286

Posted on

Python Staging DNS Zone — 4 Drift Gates Before Logistics Tenant Subdomain Activation

Choose a delegated staging zone when the tenant provisioner must prove that its credentials cannot change production records. TL;DR: Activate each logistics tenant subdomain only after its current intent matches published records. A subdomain inside the production zone can also work, but its write boundary depends on enforced name-and-type permissions. A label alone provides no such guarantee.

A logistics platform automatically allocates a portal hostname to every tenant. Staging rehearses that allocation before shipment notifications start pointing recipients at it. The operational question is whether the requested hostname and the published hostname still describe the same tenant. Choosing a zone boundary helps contain writes; reconciling intent against publication catches drift. Both belong in the decision.

Decision and failure boundaries

This architecture decision selects a delegated staging child zone. The parent retains control of the delegation, while the tenant provisioner receives management permissions for the child only. DNS delegation and management authorization are distinct mechanisms. RFC 1034 describes zones and delegation; it doesn't define the permissions of a DNS management API. Establish those permissions in the actual authorization system.

The invariant is precise: an active staging tenant must have a current intent revision whose managed records match the publication evidence accepted by the controller.

A successful write response is an intermediate event.

It is insufficient evidence for activation.

There are further boundaries. Matching authoritative answers doesn't demonstrate that recursive caches have refreshed, that a certificate is usable, or that the application routes a request to the intended tenant. Keep those as separate readiness checks. Nor does DNS containment authorize test notifications to real recipients. For this proposed workflow, use controlled recipients and exclude shipment identifiers and OTP values from DNS labels, record payloads, and reconciliation logs. These are application safeguards, not properties supplied by delegation.

The decision adds a child-zone lifecycle to operate. That overhead is justified here because automated tenant creation repeatedly exercises the writer, and acceptance depends on the difference between requested state and published state.

Does a production subdomain contain a staging writer?

Only when authorization actually restricts that writer.

The label stage is a naming convention; a delegated child is a DNS authority boundary. Neither fact alone establishes what a credential can modify.

Design Write boundary to establish Drift evidence Operational trade-off
Staging names inside the production zone Enforced restrictions on names and record types Compare managed staging RRsets within the shared zone Fewer zone objects, but precise permissions become a deployment requirement
Delegated staging child zone Child-only permissions, with parent delegation controlled separately Compare child records and verify parent delegation independently Explicit authority boundary, with an additional delegation lifecycle
Separate staging domain Permissions restricted to that domain's zones Compare records under a different namespace Namespace separation, with less representative production naming

The delegated child preserves a realistic parent-and-child arrangement for rehearsals. Its apex also carries zone infrastructure. Tenant cleanup must therefore target controller-owned names rather than deleting everything missing from a tenant manifest.

Permission evidence belongs in the deployment record. Demonstrate an allowed operation on a disposable staging record and an authorization denial for production through a policy test or dedicated permission-test fixture. Avoid destructive production probes. Review which identity can change the parent delegation, too: that identity sits outside the child writer's containment claim.

Mail needs its own review. RFC 7489 describes DMARC policy discovery and organizational-domain policy, including policy for subdomains. A delegated DNS child isn't proof of independent email policy. When staging sends shipment alerts using a subdomain, review sender authentication and policy separately from the portal's address records. DNS isolation doesn't establish inbox placement.

Four gates before tenant activation

The critical path has four gates: admitted names and record types, established credential scope, matching publication evidence, and an unchanged intent revision at activation. The Python example implements the first and third gates and invokes the fourth. Credential scope is a deployment prerequisite; passing a Boolean into this function wouldn't prove authorization.

This is application code against an injected store, not a DNS client. The example contract accepts normalized absolute lowercase names and canonical IPv4 address strings. Before calling it, the publication adapter must establish fresh observations from every authoritative server required by the policy. It supplies their A RRsets for this owner name, representing an absent RRset as an empty set. This proposed comparison includes TTL.

from ipaddress import IPv4Address

ZONE = "stage.example.com."
ADMITTED_NAME = "depot17.stage.example.com."


def activate_if_published(store, intent, observed_by_server):
    name = intent["name"]
    if name != ADMITTED_NAME or not name.endswith("." + ZONE):
        return "blocked: owner outside admitted tenant name"
    if intent["type"] != "A":
        return "blocked: unmanaged record type"

    values = frozenset(intent["values"])
    if not values:
        return "blocked: empty address set"
    for value in values:
        if str(IPv4Address(value)) != value:
            return "blocked: noncanonical address"

    expected = frozenset(
        (name, "A", intent["ttl"], value) for value in values
    )
    if not observed_by_server:
        return "pending: publication evidence missing"
    if any(answer != expected for answer in observed_by_server.values()):
        return "pending: published records differ"

    activated = store.activate_if_revision(
        tenant_id=intent["tenant_id"],
        revision=intent["revision"],
    )
    return "active" if activated else "pending: intent changed"
Enter fullscreen mode Exit fullscreen mode

For an illustrative fixture, use tenant depot17, intent revision 8, address 192.0.2.17, and TTL 300. These are test inputs, not observed production settings or a propagation promise. RFC 5737 reserves the address range containing that address for documentation. Replace the single admitted name with an allocation check against the tenant registry in a real controller. A suffix check alone cannot establish which tenant owns a name. The store operation must atomically compare the revision and record activation. Otherwise revision 9 can replace the requested address while the controller accepts observations collected for revision 8. In a race-condition test, pause the observer after it reads revision 8, update the desired address under revision 9, and then resume activation. The expected outcome is pending, even if every observed answer matches revision 8 perfectly. That fixture tests the relationship between evidence and intent rather than merely testing whether two address sets are equal.

Fail closed on malformed input, incomplete server coverage, expired observations, or query errors. The caller should retain a pending state with bounded retries instead of converting an exception into readiness.

One mismatch is enough.

Record which authoritative servers were checked. Sampling one cannot establish agreement among several. Separately, recursive resolvers can retain previous positive or negative answers according to caching rules; RFC 2308 covers negative caching. Rewriting an already-correct authoritative record doesn't invalidate those caches.

Operate the evidence, including deletion

Keep a reconciliation event containing the tenant ID, intent revision, managed owner name, expected RRset, observed RRsets, observation time, and decision. Apply access controls and retention appropriate to these identifiers. Notification bodies and OTP secrets have no role in that event. Operators can then distinguish a denied write from a missing publication, a stale observation, or a superseded request without inspecting message content.

Deletion deserves the same discipline. Mark the tenant for removal, reconcile only its owned records, verify authoritative absence, and retire the allocation according to an explicit reuse policy. Account for cached answers before assigning an old name to another tenant. Absence from a manifest is insufficient authority to delete a record whose ownership is unknown.

Test fixtures should change one boundary at a time: an old address, a stale intent revision, disagreement between authoritative servers, an unexpected record under a tenant name, and denied access outside staging. Exercise retries after successful and failed writes. The acceptance criterion is convergence without broad deletion or premature activation.

Observation has a cost. More publication checks consume queries and controller time; a delegated zone also needs lifecycle ownership. Set retry budgets and evidence retention deliberately. Track pending tenants by reason and age so delayed publication cannot disappear inside one aggregate success rate.

Rejected option and its valid use case

Sharing the production zone is rejected for this workflow because the design hasn't established the fine-grained permissions needed to contain the staging writer there. The delegated child makes the authority boundary explicit, and child-only credentials make that boundary relevant to management writes. Both pieces are required.

A shared zone remains valid when name-and-type restrictions are enforced and tested, especially when rehearsing the production zone's exact record arrangement matters more than operating a separate child. In either design, tenant activation should follow current publication evidence and application readiness. A tenant row marked created is the beginning of provisioning, not its completion.

References

Top comments (0)