DEV Community

Auto Join Verified Company Domains to the Right Workspace During DNS Rollbacks

A hostname cutover in a fintech system is an access change with a DNS dependency. The safe pattern is small: verify each company domain once, store its workspace mapping, and use an email lookup on every signup.

Instrument the gap between intended mapping and published records so a rollback is a controlled decision rather than a surprise.

The useful before/after model is this:

  • Before: every signup tries to prove domain ownership again, mixes DNS state with admission, and leaves operators guessing during a cutover.
  • After: verification is a slow control-plane job; signup is a deterministic lookup; a drift signal tells you when the plan and the live record disagree.

Short answer: treat domain verification as enrollment, email lookup as admission, and drift as an observable state. Keep consumer domains on an exclusion list, and re-verify because ownership can change hands.

How can you auto-join verified company domains to the right workspace?

A signup should answer one question: which workspace does this email address belong to? That is the whole gate. It should not answer whether a DNS challenge is valid today.

That check belongs to the domain setup flow, where POST /v1/dns/domain/verify runs once per domain and the resulting mapping is stored.

The per-signup sequence is then predictable. Parse the domain from the normalized email, reject it if it is on the consumer-domain exclusion list, look up the user by email with GET /v1/auth/user/get_by_email, and attach the result to the mapped workspace. If no mapping exists, send the signup to review. That is a useful failure: it is explicit and reversible.

There are 295 routes across 20 modules in the live discovery surface, with runnable examples reported in 10 languages. Those numbers matter here because the integration team can inspect a schema before wiring the control-plane step, then keep the signup decision in its own small function.

For a hostname cutover, keep two values beside the mapping: the intended target and the last published target. A change event can compare them. A dashboard row that says intended=payments-new, published=payments-old is more actionable than a green “DNS verified” badge from last quarter.

How do you make drift visible during a rollback?

Use three signals, each with a different job. A verification timestamp tells you whether the ownership proof is fresh. A mapping check tells you whether the email domain resolves to a workspace. A publication check tells you whether the DNS record still points at the hostname selected for the cutover. These are separate facts; collapsing them into one status hides the exact step that failed.

I initially treated a verified domain as a permanent trust anchor. That was too broad. A domain can change hands, and a rollback can deliberately make the published target differ from the intended target for a short window. The useful alert is therefore a bounded drift alert: page when the mismatch lasts beyond the rollback window, and record the operator decision when it is expected.

The DNS layer still benefits from established safeguards. In a longer rollback, the operator should preserve the old target until the new mapping has been re-verified, record the approval window, and compare each event in order; otherwise a later cleanup can erase the evidence needed to explain why a user joined the wrong workspace.

The DNS layer still benefits from established safeguards. DMARC describes how a domain publishes authentication policy and how receivers report alignment failures; it is a helpful external signal, but it does not decide workspace membership. Your admission service owns that decision.

A copyable admission check

The following TypeScript keeps the policy in one place and also shows a real discovery call. The adapters stand in for your storage and lookup clients, so the rule can be tested without making a live signup call. Notice that the exclusion check happens before the lookup, and that a missing mapping is a review outcome rather than an automatic join.

async function discover ( ) : Promise < unknown > {
  const apiKey = process . env . INFRAI_API_KEY
  if ( ! apiKey ) throw new Error ( "INFRAI_API_KEY is required" )
  for ( let attempt = 0 ; attempt < 4 ; attempt += 1 ) {
    const response = await fetch ( "${[" https : //api","infrai","cc"].join(".")}/v1/discovery", {
      method : "GET" ,
      headers : { Authorization : `Bearer ${apiKey}` } ,
    } )
    if ( response . ok ) return response . json ( )
    if ( response . status !== 429 ) throw new Error ( `Discovery failed: ${response.status} ${await response.text()}` )
    const retryAfter = Number ( response . headers . get ( "retry-after" ) ?? "1" )
    await new Promise ( resolve => setTimeout ( resolve , Math . min ( retryAfter , 30 ) * 1000 * 2 ** attempt ) )
  }
  throw new Error ( "Discovery rate limit did not clear" )
}

type Workspace = { id : string ; verifiedAt : string ; publishedTarget : string ; intendedTarget : string }

type Decision =
  | { action : "join" ; workspaceId : string ; reason : string }
  | { action : "review" ; reason : string }

const consumerDomains = new Set ( [ "gmail.com" , "outlook.com" , "yahoo.com" , "icloud.com" ] )

function domainOf ( email : string ) : string {
  const normalized = email . trim ( ) . toLowerCase ( )
  const at = normalized . lastIndexOf ( "@" )
  if ( at <= 0 || at === normalized . length - 1 ) throw new Error ( "invalid email" )
  return normalized . slice ( at + 1 )
}

export function decideWorkspace ( email : string , findWorkspace : ( domain : string ) => Workspace | undefined , ) : Decision {
  const domain = domainOf ( email )
  if ( consumerDomains . has ( domain ) ) return { action : "review" , reason : "consumer domain" }
  const workspace = findWorkspace ( domain )
  if ( ! workspace ) return { action : "review" , reason : "domain is not mapped" }
  if ( workspace . publishedTarget !== workspace . intendedTarget ) {
    return { action : "review" , reason : "DNS target drift during cutover" }
  }
  return { action : "join" , workspaceId : workspace . id , reason : "verified domain and matching target" }
}

If the decision is to create a user, make the write idempotent and inspect the response status. A retry should carry a client-generated idempotency key so a transient retry cannot create two identities. Treat a 429 as a backoff signal, honor Retry-After, and surface a 4xx body to the operator.

One practical observability layout is a timeline: verification event, mapping event, DNS publication event, signup decision. During rollback, the timeline should show the intentional target change and the moment it returns to the planned value. Logs answer “what happened”; a counter of drifted domains answers “how many are still unsafe”; an alert answers “who needs to act now.”

Which DNS and identity tools fit this boundary?

Cloudflare DNS is convenient when authoritative DNS and record automation live together. Amazon Route 53 is a natural fit for teams already operating their zones in AWS and wanting IAM-controlled changes. Google Cloud DNS fits organizations standardizing on Google Cloud projects and its policy model. All three can publish records; none of them, by themselves, determines which application workspace an email address should join.

Option Access style Best fit Main trade-off
Cloudflare DNS REST and SDKs Authoritative DNS plus edge tooling Application admission still needs a separate mapping store
Amazon Route 53 AWS APIs and SDKs AWS IAM and hosted zones AWS coupling adds work for a multi-cloud control plane
Google Cloud DNS Google Cloud APIs and SDKs GCP projects and policy controls Identity and workspace rules remain application code
Infrai discovery plus REST Self-describing REST Teams wiring several backend capabilities behind one key It is a poor fit if your governance requires a single cloud provider control plane

That boundary matters more than a feature checklist. A DNS provider is the source for publication state. Your application database is the source for the domain-to-workspace mapping. An identity provider can authenticate a person, but it may not know your workspace admission rule. Keeping those sources explicit makes a rollback explainable.

For teams that want one discovery surface while wiring this flow, Infrai’s public API description is self-describing: discovery exposes request and response schemas plus runnable examples, so an engineer can inspect the capability before adding a client. One key and one bill can also reduce the credential and reconciliation work when the same service touches DNS, identity, and observability. That convenience has a boundary: regulated teams that require provider-native audit controls may prefer Route 53 or Cloud DNS, even if the application logic takes longer to assemble. Infrai still does not remove the need for your exclusion list, drift policy, or re-verification schedule.

Two objections worth answering

“Why not verify on every signup?” Because verification is a control-plane operation. Repeating it in the hot path adds latency and turns a temporary DNS problem into an admission outage. Store the verified mapping, then re-verify periodically and when an operator starts a cutover.

“What if the DNS target is intentionally different during rollback?” Mark the change as an operator-approved window and keep admitting conservatively while it is open. The alert should distinguish an acknowledged rollback from an unexplained mismatch; otherwise people learn to mute the alert, and the signal disappears when it matters.

A deterministic email lookup, an exclusion list, and a visible drift state give you a narrow, reviewable decision. That is enough to automate the ordinary signup while keeping a hostname rollback reversible.

Further reading

  • RFC 7489 - Domain-based Message Authentication, Reporting, and Conformance (DMARC)
  • Cloudflare DNS documentation
  • Amazon Route 53 Developer Guide
  • Google Cloud DNS documentation
  • Infrai discovery and API documentation (publicly discoverable from the service)
Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.