Skip to content

Refuse to create DNS records next to conflicting existing ones - #37

Open
byjpr wants to merge 1 commit into
claude/admiring-planck-25cvzffrom
claude/fix-13-dns-conflicts
Open

byjpr wants to merge 1 commit into
claude/admiring-planck-25cvzffrom
claude/fix-13-dns-conflicts

Conversation

@byjpr

@byjpr byjpr commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Closes #13

Changes

  • scripts/dns-preflight.py runs in just apply before the Cloudflare step. It lists every record in the zones through the Cloudflare API, drops the ones already in our Terraform state, and stops with a list of conflicts:

    • another MX, A/AAAA, SRV or CAA record at a name we manage;
    • any record next to our CNAME (mta-sts.<domain>);
    • a TXT record with the same tag as ours (v=spf1, v=DMARC1, v=STSv1, v=TLSRPTv1, v=DKIM1). Unrelated TXT records such as site verifications are fine.

    DNS_PREFLIGHT=skip overrides it.

  • just check (any DNS host, including dns = "manual") now flags:

    • more than one SPF record (SPF permerror);
    • more than one DMARC record;
    • any MX record other than exactly 10 <fqdn>..

Testing

  • Preflight against a fake Cloudflare API with a typical "moved from Google Workspace" zone:
    • Flagged: the old aspmx.l.google.com MX, the old v=spf1 include:_spf.google.com record and an old v=DMARC1; p=none record.
    • Ignored: our own managed MX (ID in state), a google-site-verification TXT and an unrelated www A record.
    • Exit 1 with conflicts, 0 without.
  • The jq that builds the desired record list works with and without IPv6, and with an empty Terraform state.
  • All 5 provider example systems build. nixfmt, shellcheck and tofu validate pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01G22o7QQ17GRtkCqpJNFr9B


Generated by Claude Code

Cloudflare stores duplicate records happily: a second SPF record breaks
SPF (permerror), an old MX splits incoming mail, two DMARC/MTA-STS records
invalidate the policy. Before the Cloudflare step, scripts/dns-preflight.py
compares every name we manage with the zone's existing records (ignoring
the ones in our Terraform state) and stops with a list of conflicts
(DNS_PREFLIGHT=skip overrides). just check now also flags duplicate SPF or
DMARC records and any foreign MX, for every DNS host.

Closes #13

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01G22o7QQ17GRtkCqpJNFr9B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Medium] Existing DNS records collide with generated ones (duplicate SPF, extra MX)

2 participants