Ku bood nuxurka
Korur
Ku laabo kiisaska

Edge Security as Code: DNS, TLS and Email Authentication Under Version Control

Every DNS record in Terraform, strict TLS to the origin, proxied application hosts, and SPF, DKIM and DMARC enforcement with reporting, on a defined path to p=reject.

Who can change our DNS, and would anyone notice if they did? For most companies the domain is the least governed system they own, even though it decides where customers' browsers connect and whose email is trusted as theirs. For Fepatex, a B2B supplier whose clients include companies in defence and automotive manufacturing, Korur brought the whole domain under version control: every record, the TLS mode and the email authentication policy are Terraform, changed only through a reviewed plan.

Client
Fepatex B.V.
Website
fepatex.nl
Engagement
DNS, edge and email authentication as code
Managed as code since
October 2026
TLS to origin
Full (strict)
DMARC policy
Quarantine, with aggregate reporting
Industry
B2B supplier

Context

Fepatex's domain carries far more than a website. It routes the five production applications Korur built and operates for Fepatex: the API, the staff portal, the client portal, the offer pages and the webshop. It carries the company's Microsoft 365 mail, Teams and device enrollment. It authorises the outside services that send email on Fepatex's behalf. A wrong record in that zone can take an application offline, send customers to the wrong server, or let someone else send mail that looks as if it came from Fepatex.

The zone is hosted on Cloudflare, which sits in front of the application hosts as a proxy and TLS endpoint. Korur's task was to make that edge reviewable and dependable: one place that describes every record, a controlled way to change it, and email authentication that tells receiving mail servers what to do with mail that is not genuinely Fepatex's.

The problem

A domain managed only in a web dashboard has three weaknesses that rarely show until something goes wrong.

  • No history and no review. Anyone with dashboard access can change or delete a record, and nothing records why. Recovering from a mistake means remembering what the record used to be.
  • Unclear edge protection. Whether an application host is proxied, which TLS mode is used towards the origin, and whether plain HTTP is redirected are settings that can drift without anyone noticing. A host that is not proxied exposes its origin directly; a TLS mode that does not validate the origin certificate allows an attacker on the path to impersonate the origin.
  • Spoofable email. Without SPF, DKIM and an enforced DMARC policy, anyone can send mail with the company's domain in the sender address. For a supplier, that is the opening for invoice fraud and phishing aimed at its own customers, who trust mail from that domain.

Clients in regulated manufacturing increasingly ask their suppliers about exactly these points: how the domain is protected, whether email is authenticated, and who can change either.

Architecture

The Cloudflare account is managed by its own Terraform root in Korur's infrastructure repository. The root holds the zone settings for every domain in the account and one file of records per zone. Fepatex's zone file lists every record in the zone, so the file is the zone: what is not in the file does not exist in production after the next apply.

How the records of the zone are grouped and treated
GroupExamplesTreatment
Application hostsAPI, staff portal, client portal, offer pages, webshop, sign-inProxied through Cloudflare to one origin record, which itself is proxied; strict TLS to the origin
WebsiteThe www hostProxied
Microsoft 365Mail exchange, autodiscover, Teams and device enrollment recordsDNS only, as Microsoft's services require
Email authenticationSPF, DKIM keys, DMARCDNS only; DMARC reports go to Cloudflare's DMARC management
Other company systemsThe apex website host and a small number of hosts outside the platformDNS only today; candidates for review, see the last section

At the edge, the zone runs in strict TLS mode: Cloudflare connects to the origin over HTTPS and validates the origin certificate, so a connection cannot be intercepted between Cloudflare and the cluster without detection. Every plain HTTP request is redirected to HTTPS at the edge. The origin, Fepatex's Kubernetes platform on Microsoft Azure, accepts HTTPS only and only from Cloudflare's published address ranges, so the proxied hosts cannot be reached by going around Cloudflare.

For email, the zone publishes three layers. SPF lists the systems allowed to send for the domain: Microsoft 365, an email signature service and one on-premises sender. DKIM keys are published for Microsoft 365 and for two further services that send mail as the domain, so their messages carry a verifiable signature. DMARC ties the two together and tells receivers to quarantine mail that fails both, while sending aggregate reports that show who is sending as the domain.

What we built

Decision 1

Decision
The whole zone in Terraform, one file per zone, with every record in it.
Why
A file in version control gives each record an author, a reason and a history. A change is a pull request with a plan that shows exactly which records will be created, changed or removed; a mistake is reverted by reverting a commit. Keeping every record in the file, not only the ones Korur needs, means the file is a complete description of the zone and the plan reports any record that appeared outside it.
Alternative rejected
Managing only the application records in code and leaving the rest in the dashboard. Smaller, but the zone would then have two sources of truth and nobody could say from the code what the zone contains.

Decision 2

Decision
Adopt the live zone by import, without a single change on the first apply.
Why
The zone already served production mail and applications. The records and the zone's TLS mode were written into Terraform exactly as they were live, then imported, so the first apply changed nothing that a user or a mail server could notice. Improvements came afterwards as separate, reviewable changes.
Alternative rejected
Recreating the zone from code. Cleaner on paper, but any mismatch would have meant lost mail or an unreachable application on the day of the switch.

Decision 3

Decision
Plan on a pull request, apply on merge, never from a laptop, with separate tokens for planning and applying.
Why
The apply step can only use the plan produced by a pull request run and compares it with a fresh plan first, so nothing reaches the zone without a reviewed plan. The planning token can only read; the applying token can edit records and settings but cannot create or delete a zone. No one needs personal dashboard rights to make a routine change.
Alternative rejected
Applying from an engineer's machine. Faster for one change, but the state of the zone then depends on whose laptop ran last.

Decision 4

Decision
Strict TLS to the origin and HTTPS everywhere at the edge.
Why
Full TLS without validation encrypts the connection but accepts any certificate, so it does not prove that Cloudflare is talking to the real origin. Strict mode validates the origin certificate. The origin accepts no plain HTTP at all, so redirecting every HTTP request to HTTPS at the edge is both the secure and the only working behaviour.
Alternative rejected
Flexible mode, which talks to the origin over plain HTTP. It shows a padlock to the visitor while the second half of the connection is unencrypted.

Decision 5

Decision
Every application host proxied, behind one proxied origin record.
Why
The application hosts all point to one origin name, which itself is proxied. The public DNS therefore never reveals the address of the cluster, and Cloudflare's DDoS protection and TLS termination apply to every application. Moving the origin later is one record change instead of one per application.
Alternative rejected
DNS-only records pointing straight at the cluster's address. They would expose the origin and bypass the edge protection.

Decision 6

Decision
DMARC at quarantine with aggregate reporting now, and a defined path to reject.
Why
Moving straight to reject risks losing legitimate mail from a sender nobody had listed. Quarantine already stops spoofed mail from reaching inboxes, and the aggregate reports show every source that sends as the domain. Once the reports show that all legitimate senders pass, the policy moves to reject, as a one-line, reviewed change.
Alternative rejected
A monitoring-only policy (p=none). It produces reports but protects nobody.
"_dmarc.<domain>/TXT" = {
  type    = "TXT"
  content = "v=DMARC1; p=quarantine; rua=mailto:<cloudflare-dmarc-reports>"
  proxied = false
}
"<domain>/TXT/spf" = {
  type    = "TXT"
  content = "v=spf1 ip4:<on-premises-sender> include:<microsoft-365> include:<signature-service> ~all"
  proxied = false
}
"api.<domain>/CNAME" = {
  type    = "CNAME"
  content = "<origin>.<domain>"
  proxied = true
}
Excerpt of the email authentication records, with the domain, addresses and selectors replaced by placeholders

Evidence

Everything in this document can be read in the Terraform root: the zone's records file, the zone settings and the modules that apply them. Part of it can also be checked by anyone from the outside, because DNS is public: the DMARC record, the SPF record and the fact that the application hosts answer from Cloudflare.

Controls and where they are defined
ControlWhere it is defined
Every record of the zoneThe zone's records file in the Cloudflare Terraform root
Strict TLSThe zone settings, applied by the zones module
HTTPS redirect at the edgeThe zones module, for every zone in the account
Application hosts proxiedThe proxied flag on each application record
SPF, DKIM, DMARCTXT and CNAME records in the zone's records file
Plan on pull request, apply on mergeThe Cloudflare workflow of Korur's infrastructure repository

Outcome

Since October 2026, Fepatex's domain has been managed as code. Every record has a history, every change is a reviewed plan, and a record that appears outside that process shows up in the next plan. The application hosts are behind Cloudflare's proxy with strict TLS to an origin that accepts traffic from Cloudflare only. Mail that fails SPF and DKIM alignment is quarantined by receivers that honour DMARC, and the aggregate reports show who is sending as Fepatex.

What we would do next

  • Move DMARC from quarantine to reject once the aggregate reports show that every legitimate sender passes, so spoofed mail is refused outright.
  • Bring the apex website behind the proxy with strict TLS, as the www host and the applications already are, or redirect it to a host that is.
  • Review the remaining DNS-only hosts that sit outside the platform with Fepatex, and remove the ones that are no longer used so the zone exposes nothing it does not need.
  • Review the SPF record together with the move to reject, so that it lists exactly the senders the reports show.

Stack

  • Cloudflare
  • Terraform
  • GitHub Actions
  • SPF
  • DKIM
  • DMARC
  • Microsoft 365

Ma doonaysaa inaad sidoo kale sugto ganacsigaaga?

Wada hadal aan waajib ahayn. Qiimaha go'an.

Ma cabbiri karnaa sida aad halkan u timid?

Waxaan isticmaalnaa cookies-ka falanqaynta si aan u aragno bogagga shaqeeya iyo xayeysiiska halkan ku keenay. Haddaad diiddo, degelku si la mid ah ayuu u shaqeeyaa, mana dhigno wax cookies falanqayn ah. Siyaasadda cookies-ka