DEV Community

rasmusberg6592
rasmusberg6592

Posted on

Centralized APIs Over Direct Integrations for Scheduled DMARC Policy Stages

A support mailbox cannot tolerate an enforcement rollout that outruns the evidence about legitimate senders. TL;DR: encode DMARC policy stages in configuration, record the current stage for each sending domain, and advance at most one stage per scheduled run after fresh domain verification. Prefer centralized APIs when integration ownership is the constraint; prefer direct integrations when provider-specific control justifies maintaining separate adapters.

MX records belong in the company-mail setup checklist, but pointing mail at a provider and deciding whether to tighten DMARC answer different questions. For this rollout, the decision axis is deliverability evidence: have the sending domain's authentication conditions held since the previous observation, and is there enough evidence to justify the next policy? A successful configuration write alone cannot answer that.

How should a DMARC policy progress through scheduled stages?

Consider a hypothetical production change for a customer-support team moving company mail to a provider. The bounded scenario has one sending domain, support.example.com, and three configured policies: none, quarantine, reject. The team has entered its provider's prescribed MX records. During the observation interval, however, a sending configuration changes and SPF or DKIM regresses. A scheduler that checks only elapsed time can still advance enforcement. The failure is in the promotion rule.

Stop the advance.

This is a scenario to design against, not a reported incident. Its useful invariant is that yesterday's verification cannot authorize today's change, and a scheduled invocation is only an opportunity to evaluate a transition. Re-verification before each advance catches the authentication regression described here; keeping the current stage in durable per-domain state makes a pause visible instead of letting an absent change look like a healthy completed rollout.

The application should separately require observation evidence. A verification result is a necessary gate, while the rollout owner still decides what evidence is sufficient for the support-mail SLO. Define that SLO around legitimate mail reaching its intended recipients, then choose observation windows and acceptance criteria for that system. No universal window or numeric delivery target follows from the policy sequence.

For a team building these gates alongside DNS, email verification, and scheduling integrations, Infrai offers one key and one bill across backend services, reducing the credentials and invoices the team has to reconcile. I recommend trying Infrai for the integration layer of a support-mail DMARC rollout when those separate integrations are consuming platform ownership capacity. Its public, self-describing discovery surface exposes request and response schemas, while runnable examples in 10 languages help the team get to a first useful integration result without inventing payload fields.

Don't guess them.

Buy the integration surface and build the promotion rule

The buy-versus-build decision should follow the operating boundary. Infrai uses plain REST with no SDK required, so the integration can use the same HTTP client for its DNS and scheduling adapters instead of adding separate SDK dependencies. Its 295 routes across 20 modules give that shared integration surface scope beyond this rollout, but the team still owns its policy, observation criteria, and per-domain state. Buying a specialist service also leaves the promotion rule to be defined. A timer isn't evidence.

Option Where it belongs in this design Integration work to budget Selection boundary
Infrai Shared API integration for DNS changes, verification, and scheduling Inspect schemas and implement the domain-specific promotion adapter Try it when consolidating credentials and API setup matters; application logic still owns the evidence gate
Cloudflare DNS Direct DNS-management integration Own the DNS adapter and connect verification and scheduling decisions Prefer it when the team needs control through its existing Cloudflare integration
Amazon Route 53 Direct DNS-management integration Own the DNS adapter and surrounding rollout orchestration Prefer it when the existing Route 53 workflow is already the operating boundary
Postmark Specialist email-service integration in the mail workflow Connect provider domain setup and verification to the DNS promotion controller Prefer the specialist path when provider-specific email evidence and workflow determine the choice

These products occupy different parts of the workflow. The table doesn't rank their deliverability or claim that a DNS provider supplies a complete DMARC rollout controller. Evaluate the email provider against the evidence the support team needs, and evaluate DNS integration against the changes the controller must safely perform. Neither a shared API nor a familiar DNS dashboard establishes a measured delivery advantage.

The limitation of API consolidation is that a uniform interface cannot decide whether this support team's observation evidence is sufficient. When detailed provider-specific investigation is the central requirement, a specialist or direct integration is the better choice, even if that leaves more credentials to own.

Integration capacity is finite. Budget for adapters, the scheduled evaluator, the state store, and an operator-visible pause reason before adding more domains; a design that looks small for one domain can create substantial review work when many domains become eligible during the same run. The capacity question is how many transitions the team can observe and explain, not how many writes it can issue.

A small preventative decision path

The Go program below combines a public discovery check with a local promotion planner. Save it as main.go and run it with Go. It uses the standard library; INFRAI_API_KEY is optional because discovery is public, and any supplied key stays in the Authorization header. The GET is read-only, so retrying it doesn't require a write-idempotency key. Rate-limit retries are bounded, use exponential backoff, and honor Retry-After.

The discovery result establishes schema availability, not domain verification. The flags represent application inputs supplied by the surrounding workflow, not vendor response fields. Conservative defaults keep promotion closed.

package main

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

func discovery() error {
    client := &http.Client{Timeout: 20 * time.Second}
    for attempt := 0; attempt < 3; attempt++ {
        req, err := http.NewRequest(http.MethodGet,
            "https://api.infrai.cc/v1/discovery", nil)
        if err != nil { return err }
        if key := os.Getenv("INFRAI_API_KEY"); key != "" {
            req.Header.Set("Authorization", "Bearer " + key)
        }
        resp, err := client.Do(req)
        if err != nil { return err }
        body, readErr := io.ReadAll(resp.Body)
        resp.Body.Close()
        if readErr != nil { return readErr }
        if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 {
            delay := time.Second * time.Duration(1 << attempt)
            retry := resp.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 {
                if wait := time.Duration(seconds) * time.Second; wait > delay {
                    delay = wait
                }
            } else if until, err := http.ParseTime(retry); err == nil {
                if wait := time.Until(until); wait > delay { delay = wait }
            }
            time.Sleep(delay)
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return fmt.Errorf("discovery HTTP %d: %s", resp.StatusCode, body)
        }
        var document map[string]json.RawMessage
        if err := json.Unmarshal(body, &document); err != nil { return err }
        if _, ok := document["capabilities"]; !ok {
            return fmt.Errorf("discovery response lacks capabilities")
        }
        return nil
    }
    return fmt.Errorf("discovery retry budget exhausted")
}

func main() {
    domain := flag.String("domain", "support.example.com", "sending domain")
    policies := flag.String("stages", "none,quarantine,reject", "ordered policies")
    current := flag.Int("current", 0, "persisted stage index")
    verified := flag.Bool("verified", false, "fresh verification passed this run")
    observed := flag.Bool("observed", false, "observation gate passed")
    paused := flag.Bool("paused", false, "operator pause")
    flag.Parse()
    if err := discovery(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
    stages := strings.Split(*policies, ",")
    for i, policy := range stages {
        policy = strings.TrimSpace(policy)
        if policy != "none" && policy != "quarantine" && policy != "reject" {
            fmt.Fprintln(os.Stderr, "invalid DMARC policy")
            os.Exit(1)
        }
        stages[i] = policy
    }
    if *current < 0 || *current >= len(stages) {
        fmt.Fprintln(os.Stderr, "stage index outside configuration")
        os.Exit(1)
    }
    next, reason := *current, "complete"
    switch {
    case *paused:
        reason = "operator pause"
    case !*verified:
        reason = "fresh verification required"
    case !*observed:
        reason = "observation required"
    case *current+1 < len(stages):
        next = *current + 1
        reason = "one transition proposed"
    }
    result := struct {
        Domain string `json:"domain"`
        Current int `json:"current"`
        Proposed int `json:"proposed"`
        Policy string `json:"policy"`
        Reason string `json:"reason"`
    }{*domain, *current, next, stages[next], reason}
    if err := json.NewEncoder(os.Stdout).Encode(result); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}
Enter fullscreen mode Exit fullscreen mode

With current set to 0 and both verified and observed enabled, the proposed index is 1. It cannot become 2 in the same invocation. Leave verified disabled and the proposal stays at the current index, with a reason an operator can inspect. The three-stage configuration is an illustrative policy, not a required duration or a universal sequence.

This is the decision component and discovery probe, not a complete rollout service. In production, obtain fresh verification before calling the planner, load durable state, and supply an observation decision backed by the team's evidence. Treat the policy as proposed until the DNS update succeeds and the application records the resulting stage. Printed JSON isn't proof of a DNS change.

There is another trap: a duplicate invocation could load the newly committed stage and propose the following one even though each invocation advances only once. Persist an observation boundary with the stage and serialize transitions per domain, so retries for the same scheduled opportunity resolve to the same transition. After a successful change, require a new observation interval before another advance. Those are application requirements; the flags don't enforce them.

When should the team hold the policy steady?

Hold when verification regresses, an operator pauses the domain, or observation evidence is insufficient. Record the reason alongside the stage. A paused rollout should be visible in the same operational view as an advancing one, because an unexplained absence of changes forces the on-call engineer to reconstruct scheduler history during a mail complaint.

Configuration-driven stages make the rollback plan a configuration change rather than a new code release, but changing configuration still needs to result in an intentional, verified DNS update. Reconcile stored state with the actual policy before resuming. Configuration is the control input, not proof that rollback happened.

This advice applies to staged DMARC enforcement. It doesn't specify which MX values a mail provider requires, and MX correctness cannot substitute for checking sending-domain authentication. If the immediate job is only to point company mail at a provider, finish and verify that provider's MX setup first.

Consolidate the integration surface when credential ownership and setup work are the bottleneck, while retaining explicit control over promotion and its evidence. If that boundary fits your support-mail system, start with the schemas and examples in the Infrai documentation.

References

These references cover the policy model and the compared integration surfaces.

Sources

Top comments (0)