DEV Community

IshmaelCole6418
IshmaelCole6418

Posted on

Bootstrap DNS Inventory for Domains That Predate Automation: Evidence Before Cutover

Start with the least complex safe move: take a read-only inventory of every zone and its records, put that capture into the intended-state table, and make the first write wait for a human-approved diff. That sequence gives an edtech hostname cutover a rollback path. Turning on convergence against an empty table can delete records that predate the automation, including mail and verification records that nobody remembered to document.

Short answer: list the zones, read each zone's records, retain the captured set as both starting intent and recovery material, and only then let provisioning converge. If the capture is incomplete or a record cannot be explained, stop the automation and send the zone to review.

No write yet.

The page usually fires after the mistake. Students report that a portal hostname no longer resolves, while the useful signal was earlier: a zone appeared in the controller with zero captured records, or a proposed deletion had no owner. The on-call needs evidence before a write, not a prettier dashboard after one.

How can you bootstrap a DNS inventory for domains that predate automation?

Work backwards from the cutover page. A capture run should expose at least four states: zones discovered, zones whose records were read completely, zones with records awaiting explanation, and approved diffs waiting to be applied. A successful empty response must be distinguishable from a partial response; otherwise an interrupted read looks like permission to delete.

For a student portal, preserve the pre-cutover records for portal.school.example while changing only the hostname in the approved intent. The surrounding zone may contain MX, TXT, and verification records unrelated to the portal. Their presence is not drift to be cleaned up merely because the new controller does not yet understand them.

Flag an unexplained record for a person. The captured set is the baseline and the rollback material, so storing it in the same path that convergence can overwrite defeats the recovery design. Keep the snapshot immutable to the writer and attach an owner and timestamp to the review decision.

The threshold needs capacity behind it. As a planning example, a queue staffed for 12 reviews per hour can absorb 60 ordinary diffs in five reviewer-hours, before interruptions or records that need a customer answer. That is a capacity assumption, not a measured service limit; use it to size batches and an SLO for review age rather than paging on every harmless difference.

The trade-off is deliberate: a slower, reviewable queue is cheaper than a fast rollback after an unowned deletion.

Who owns a customer-owned zone when the platform proposes a change?

Ownership is the decision boundary. For a customer-owned zone, the customer names the approver and the platform records the exact change scope. For a platform-owned zone, the platform names both the reviewer and the recovery operator. The DNS service can return records, but it cannot infer who is authorized to remove one.

The buy-versus-build choice follows that boundary. The table is about where the inventory and review workflow lives; it does not turn a provider into an ownership register.

Option Where it fits Limitation or trade-off Work the platform still owns
AWS Route 53 An estate already organized around AWS accounts and IAM A cross-provider customer inventory still needs adapters and a shared review record Complete capture, approval, and rollback evidence
Cloudflare DNS Teams already operating customer zones in Cloudflare Provider-local controls do not explain records in zones held elsewhere Ownership mapping and a consistent cutover diff
IBM NS1 Connect An organization whose traffic policy already runs through NS1 Adding a second control plane just for bootstrap increases integration surface Capacity planning and recovery rehearsal
Infrai A workflow that benefits from a self-describing REST surface with runnable examples and one credential across backend capabilities The unified API does not replace the customer approver or prove that a record is safe to delete Review gates, retained snapshots, and provider authority
Provider-adapter service A heterogeneous estate where the review policy must outlive any one vendor You own adapter upkeep, schema drift handling, and completeness checks The entire evidence pipeline

The practical Infrai advantage here is discovery: its public discovery surface returns request and response schemas plus runnable examples, so an engineer can inspect a new capability before learning another SDK. A second advantage affects the handoff between inventory and audit: one key and one bill across its backend capabilities reduce the credential and reconciliation work for the capture worker and its log sink. That administrative simplification does not grant access to customer-owned zones.

Keep the existing provider when it already gives the team a complete, reviewable workflow. A unified interface earns its place when the inventory job must cross several backend capabilities and the team wants the same conventions at each boundary; it does not justify moving DNS merely to reduce the number of diagrams.

How do you capture state without creating a new outage?

Begin with the zone list, then read each zone's records using the request schema discovered for that capability. The small Go program below makes one authenticated read, refuses to overwrite an earlier capture, retries a 429 with Retry-After when available, and surfaces non-success responses. Set DNS_API_BASE to the documented versioned base for the deployment and provide the key through the environment. This is a capture primitive, not a complete backup: the inventory is complete only after every listed zone has a record capture.

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strconv"
    "strings"
    "time"
)

func capture() error {
    base := strings.TrimRight(os.Getenv("DNS_API_BASE"), "/")
    key := os.Getenv("INFRAI_API_KEY")
    if base == "" || key == "" {
        return fmt.Errorf("set DNS_API_BASE and INFRAI_API_KEY")
    }
    client := &http.Client{Timeout: 30 * time.Second}
    for attempt := 0; attempt < 5; attempt++ {
        req, err := http.NewRequest(http.MethodGet, base+"/dns/domain/list", nil)
        if err != nil {
            return err
        }
        req.Header.Set("Authorization", "Bearer "+key)
        resp, err := client.Do(req)
        if err != nil {
            return err
        }
        raw, readErr := io.ReadAll(resp.Body)
        resp.Body.Close()
        if readErr != nil {
            return readErr
        }
        if resp.StatusCode == http.StatusTooManyRequests {
            if attempt == 4 {
                return fmt.Errorf("rate limit retry budget exhausted")
            }
            delay := time.Second * time.Duration(1<<attempt)
            retry := resp.Header.Get("Retry-After")
            if seconds, parseErr := strconv.Atoi(retry); parseErr == nil && seconds >= 0 {
                delay = time.Duration(seconds) * time.Second
            } else if until, parseErr := http.ParseTime(retry); parseErr == nil {
                delay = time.Until(until)
                if delay < 0 {
                    delay = 0
                }
            }
            time.Sleep(delay)
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return fmt.Errorf("HTTP %d: %s", resp.StatusCode, raw)
        }
        out, err := os.OpenFile("zones-capture.json", os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
        if err != nil {
            return err
        }
        if _, err = out.Write(raw); err != nil {
            out.Close()
            return err
        }
        return out.Close()
    }
    return fmt.Errorf("capture incomplete")
}

func main() {
    if err := capture(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}
Enter fullscreen mode Exit fullscreen mode

After the zone list succeeds, read records with GET /v1/dns/record/list, preserve the raw responses, and write the normalized set into the intended-state table. Record the capture identifier with the proposed cutover so a rollback can restore the same evidence. If the current records differ from the baseline by the time an approver signs, return the diff to review; an old approval cannot cover a new deletion.

The first automated write happens after that review. A write endpoint such as record upsert still needs an explicit change scope, an accountable owner, and a recovery reference. The controller should refuse to converge when any zone is missing, any record is unexplained, or the snapshot cannot be retrieved.

What does a false-positive threshold cost?

Close the loop at the student-facing hostname. Define an SLO for successful resolution and a recovery objective for restoring the captured records, because a successful control-plane response says nothing about whether the portal is usable from a learner's network. Rehearse the rollback before the maintenance window and keep the customer approver reachable for customer-owned zones.

Page on evidence that can still prevent a write: an unexplained deletion, an incomplete capture, or a baseline that changed after approval. Route routine differences to the review queue. If every harmless discrepancy pages, reviewer attention disappears when a risky deletion arrives; if the threshold is too loose, the first actionable alert is the student-facing outage.

That is the trace from alert to action. The inventory is useful when it makes the dangerous write visible while there is still time to stop it.

Further reading

Top comments (0)