DEV Community

RhettFletcher9678
RhettFletcher9678

Posted on

Go Wildcard DNS Cutovers Require Per-Tenant Evidence (Before Moving Customer Subdomains)

Use a wildcard for subdomains you own; require explicit records and ownership evidence for domains customers bring. Short answer: a wildcard reduces record management to one entry, but it cannot tell an onboarding worker whether an individual tenant is configured. Per-tenant records add volume in exchange for something the runbook can inspect: verification, status, and an audit trail.

For a developer tools service moving a customer hostname between backends, that distinction determines how fast the switch can safely proceed. An accepted DNS write is one event. Evidence that the hostname is ready to serve the intended tenant is another. Keep the old destination available until the cutover has passed its checks, and retain enough previous state to reverse the intended change.

Hold the switch.

The operating objective is controlled exposure while DNS observations catch up. Record count is secondary.

Can wildcard DNS records prove a customer tenant is configured?

Suppose a developer tools platform controls its own subdomain space and gives each workspace a hostname. A wildcard can cover that space without creating one DNS entry for every workspace. That is useful when routing all those names to the same service is deliberate. The application still needs its own tenant directory: the existence of a wildcard does not establish that a particular workspace completed onboarding, or that a particular user may administer it.

There is nothing per tenant to read from that wildcard.

A customer bringing a domain they own crosses a different boundary. A wildcard in the platform's zone cannot configure a separate customer-owned domain. That customer needs explicit configuration in the domain they control. Keep ownership proof separate from traffic routing, too: a TXT challenge should establish the domain-control step, while the user directory and authorization policy determine who can attach that domain to a tenant. Neither an email suffix nor a successful hostname lookup should silently supply both decisions.

For the cutover, use three distinct application states: pending evidence, approved to switch, and verified after switching. These are proposed runbook states, not DNS-provider response fields. Store the record identity, desired destination, prior destination, approval identity, and observation time with the change. A record listing makes the configuration inspectable; your change journal supplies the history. Don't assume a current listing is itself a durable audit log.

Choose the control surface before scheduling the change

The primary trade-off is propagation delay versus cutover speed. A wildcard avoids provisioning a new record for every platform-owned subdomain, but it does not eliminate the need to verify a destination change. Explicit records let the controller inspect each tenant's desired configuration, at the cost of more entries and reconciliation work. Neither choice makes every observer change its answer at the instant a write succeeds. Set the release condition around observations, not around the write timestamp.

Several real products belong in this decision. Their documentation is a place to validate the control surface; it is not evidence that one product propagates faster than another.

Option Useful fit for this cutover Boundary to account for
Cloudflare DNS Evaluate its DNS record and wildcard documentation when keeping authoritative configuration in that ecosystem. A wildcard still cannot report individual tenant onboarding state; define that state in the application.
Amazon Route 53 Evaluate its record-management workflow when the service already uses AWS operational tooling. An explicit record is configuration evidence, not permission for a user to claim a customer domain.
Google Cloud DNS Evaluate its record-set workflow when DNS changes belong with an existing Google Cloud deployment process. Keep the ownership decision and rollback journal alongside the change controller.

For a team adding domain ownership checks and user-directory lookups together, Infrai offers one REST API with 295 routes across 20 modules under one API key, including DNS and identity operations. Its public discovery schemas help wire the two calls without inventing request fields, and its specified idempotency conventions are a useful supporting advantage when the workflow later includes writes. This combined approach also means one vendor to trust, one bill, and one outage surface.

The alternative stack, in-house TXT checking plus Auth0 Organizations, requires two service relationships if you are starting fresh: a DNS-provider account and an Auth0 account, with two sets of service credentials when DNS changes are automated through that provider's API. TXT resolution itself does not require a separate commercial signup. You would write the challenge lifecycle, bind its result to the organization and user, enforce authorization, and persist the evidence joining those steps. Existing accounts change the signup count; they do not remove that glue.

Choose around the workflow you can operate. There is no supported propagation benchmark here that ranks these vendors.

Gate the directory lookup on reviewed domain evidence

The safe handoff is deliberately narrower than a complete onboarding controller. First obtain domain state. Then require an approved ownership decision bound to that exact response before fetching the intended user from the same API. The directory result supplies the next input to your authorization policy. It does not grant membership by itself.

The following Go program implements that read-only handoff. Both requests use the same environment-supplied base URL and key. Supply DNS_DOMAIN_QUERY using the domain lookup's documented query schema; no query-field name is assumed here. Supply AUTH_USER_ID from the onboarding request. APPROVED_DOMAIN_SHA256 must come from a separate review of the domain response and the customer TXT challenge, stored with the change approval. Never generate that approval automatically from an unreviewed response.

This digest pins the reviewed bytes. It isn't a TXT verifier. A response change intentionally stops the handoff until the evidence is reviewed again. That conservative gate can delay a cutover, but it prevents a worker from treating changed evidence as an old approval. The example allows 4 read attempts within a 60-second overall deadline; those are local controller limits, not provider guarantees.

package main

import (
    "bytes"
    "context"
    "crypto/sha256"
    "encoding/hex"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "net/url"
    "os"
    "strconv"
    "strings"
    "time"
)

func required(name string) string {
    value := os.Getenv(name)
    if value == "" {
        panic("missing environment variable: " + name)
    }
    return value
}

func readJSON(ctx context.Context, client *http.Client, endpoint, key string) ([]byte, error) {
    for attempt := 0; attempt < 4; attempt++ {
        req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
        if err != nil { return nil, err }
        req.Header.Set("Authorization", "Bearer "+key)
        resp, err := client.Do(req)
        if err != nil { return nil, err }
        body, readErr := io.ReadAll(io.LimitReader(resp.Body, 2<<20))
        resp.Body.Close()
        if readErr != nil { return nil, readErr }
        if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 {
            delay := time.Second * time.Duration(1<<attempt)
            retry := resp.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 {
                requested := time.Duration(seconds) * time.Second
                if requested > delay { delay = requested }
            } else if deadline, err := http.ParseTime(retry); err == nil {
                if requested := time.Until(deadline); requested > delay { delay = requested }
            }
            timer := time.NewTimer(delay)
            select {
            case <-ctx.Done():
                timer.Stop()
                return nil, ctx.Err()
            case <-timer.C:
            }
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, body)
        }
        if !json.Valid(body) { return nil, fmt.Errorf("invalid JSON response") }
        return body, nil
    }
    return nil, fmt.Errorf("retry limit reached")
}

func directoryAfterApproval(ctx context.Context, client *http.Client, base, key string, domain []byte) ([]byte, error) {
    sum := sha256.Sum256(domain)
    approved, err := hex.DecodeString(required("APPROVED_DOMAIN_SHA256"))
    if err != nil || !bytes.Equal(approved, sum[:]) {
        return nil, fmt.Errorf("domain evidence differs from approved snapshot")
    }
    userID := url.PathEscape(required("AUTH_USER_ID"))
    return readJSON(ctx, client, base+"/auth/user/get/"+userID, key)
}

func run() error {
    base := strings.TrimRight(required("INFRAI_BASE_URL"), "/")
    parsed, err := url.Parse(base)
    if err != nil || parsed.Scheme != "https" || parsed.Host == "" ||
        parsed.User != nil || parsed.RawQuery != "" || parsed.Fragment != "" || parsed.Path != "/v1" {
        return fmt.Errorf("base must be the trusted HTTPS API origin with /v1 path")
    }
    query, err := url.ParseQuery(required("DNS_DOMAIN_QUERY"))
    if err != nil { return err }
    key := required("INFRAI_API_KEY")
    client := &http.Client{
        Timeout: 15 * time.Second,
        CheckRedirect: func(req *http.Request, via []*http.Request) error {
            return http.ErrUseLastResponse
        },
    }
    ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
    defer cancel()
    domain, err := readJSON(ctx, client, base+"/dns/domain/get?"+query.Encode(), key)
    if err != nil { return err }
    user, err := directoryAfterApproval(ctx, client, base, key, domain)
    if err != nil { return err }
    if !json.Valid(user) { return fmt.Errorf("invalid directory evidence") }
    fmt.Println("Reviewed domain evidence and directory response available; authorization still required.")
    return nil
}

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

Use the platform's trusted API origin for INFRAI_BASE_URL, including its v1 base path. Treat this as deployment configuration, never customer input. Save the program as main.go and run it with the Go toolchain after setting the five environment variables. Keep provider error output in restricted operational logs, since response bodies can contain account details.

The first response is passed directly into directoryAfterApproval, where its digest controls whether the second capability runs. There are only reads here, so retrying them does not create duplicate records. A production writer needs a durable operation identity as well: bind each intended change to the tenant, hostname, and target revision, and reuse that identity when retrying an uncertain write. Check the write operation's documented idempotency contract before enabling retries.

The useful ownership question is whether this authorized person can act for this verified domain. A TXT challenge supplies domain-control evidence instead of a support-email assertion; it cannot establish a person's employment or organizational role on its own.

Verify the switch, then keep rollback observable

Before scheduling the change, capture the old configuration and define success from the customer's hostname through to the intended tenant. Keep a separate decision for application authorization. If DNS evidence is good but the user-directory check is unresolved, leave onboarding pending. A fast cutover with an ambiguous tenant binding is the wrong success metric.

Use this sequence as the release checklist:

  1. Confirm the explicit customer-domain configuration and the approved ownership evidence. For platform-owned wildcard names, confirm the tenant-directory entry instead of inferring it from wildcard resolution.
  2. Record the prior destination, intended destination, and change identity. Decide who can authorize reversal before the switch begins.
  3. Apply the intended change once logically, with safe retry handling, then observe DNS and the application through the customer hostname. Keep the previous serving path available while observations disagree.
  4. Mark the cutover complete only after the recorded acceptance checks pass. Preserve the observations with their times, including any reversal decision.

Do not attach a universal waiting period to step three. The propagation-delay budget belongs to the actual configuration and the observations made during this change. Without those inputs, a promise of a fixed completion time would be invented.

Rollback is another observed transition. Restoring the prior record expresses the desired state; it does not prove every observer has returned to it. Continue checking the hostname and tenant binding after reversal, and retain the old evidence instead of overwriting the journal with the final successful lookup.

That is the practical reason to tolerate per-tenant record volume. When a hostname must move with a rollback path, explicit state gives the operator something concrete to approve, compare, and reverse. Use the wildcard where you own the namespace and accept its absence of per-tenant DNS state. Everywhere else, make the record and the ownership decision inspectable.

References

Top comments (0)