Safeguard
Developer Tools•

What is DNS as code, and why review DNS changes like code?

Keeping DNS records in version control gives you review, history and rollback. Here is how to start, what to automate and where it can go wrong.

Safeguard Security Team
4 min read

DNS as code means describing your records in files kept in version control and applying them with a tool, instead of editing them in a web console. Every change gets a reviewer, a history and a quick rollback. It reduces typos and surprise edits, and it makes dangling records easier to spot.

The problem it solves

A DNS zone is critical and often edited by hand. Someone adds a record during an incident, another person deletes one they do not recognise, and no one writes it down. A single wrong MX or NS entry can take down mail or the website for everyone.

Software teams solved the same problem for servers years ago by putting configuration in repositories. DNS is a small, well bounded part of the estate, which makes it a good place to start.

What you get

BenefitHow it helps security
Pull request reviewA second person sees the change before it goes live
HistoryYou can answer who changed the record, when and why
RollbackRestore the last known good state quickly
Drift detectionA scheduled comparison shows edits made outside the process
InventoryThe repository lists every record, with comments on owners
Policy checksAutomated tests can reject risky records

How to start

  1. Export the current zone from your provider into a file format your chosen tool reads.
  2. Commit it to a repository with limited write access and protected main branch.
  3. Add owner comments. For every record, note the service and the team that owns it.
  4. Plan, then apply. Use a tool that shows the difference between the file and the live zone before applying anything.
  5. Run it in CI. Pull requests run a dry run and post the diff. Merging to main applies it, using a narrowly scoped token. See securing DNS provider tokens.
  6. Detect drift. Run a nightly plan. If it finds changes you did not merge, alert.
  7. Close the console. After a trial period, limit console edits to a few people, with a break glass path for emergencies.

Checks worth automating

Write tests against the zone files. Examples that catch real mistakes:

  • No CNAME at the zone apex, which breaks other records. See CNAME at the apex.
  • Exactly one SPF record per name.
  • SPF includes stay under the lookup limit.
  • No CNAME targets on a list of platforms that you have retired.
  • No wildcard records on the main domain without an approved exception. See wildcard DNS risks.
  • Each record carries an owner comment.
  • TTL values within an agreed range.

Where it can go wrong

  • The pipeline becomes the target. Whoever controls the CI job controls your DNS. Protect the repository, branch rules, and the token the job uses.
  • A bad merge applies fast. Add a plan review step and keep a small change window for high risk records such as NS and MX.
  • Partial adoption. If half the team still edits in the console, the files and the live zone disagree. Drift alerts are the safety net.
  • Secrets in the repository. Records are not secret, but tokens are. Keep them in a secrets manager.
  • Unmanaged records. Records created by other tools, such as certificate automation, may need to be ignored by your plan so they are not deleted.

Linking to your dependency story

DNS tooling is software with its own dependencies and plugins. Treat the CI job like any build: pin versions, review updates, and scan the packages it pulls. Safeguard's SBOM and dependency scanning, reachability analysis and policy gates apply to that pipeline, and the free scan is at gold.safeguard.sh/scan.

Quick check

Is DNS as code worth it for a small team?

Often yes. Even ten records benefit from review and history, and the setup effort is a few hours.

What about emergency changes?

Keep a documented break glass path, then commit the change to the repository straight afterwards so the files match reality.

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.