Back to Terraform

Test the Edge: DNS, TLS, WAF, Cache and Origin Evidence

November 6, 2026 Wasil Zafar 27 min read

Build a small acceptance matrix that can distinguish configuration success from actual request-path correctness

Table of Contents

  1. Map Each Requirement to the Layer That Can Prove It
  2. Use Deterministic Harmless Requests and Bounded Waits
  3. Test the Negative Path Without Broadening the Exposure
  4. Correlate Failures with Safe Diagnostic Signals
  5. Define Acceptance for Cutover, Drift and Teardown

Map Each Requirement to the Layer That Can Prove It

A requirement is not a test until you name the layer that decides it. "The site must be private" can be satisfied by DNS, TLS, a WAF rule, an Access policy, or the application itself. Each produces a different refusal, and a test that only checks "not 200" passes for the wrong reason.

Start from the decision and walk outward. For each requirement, ask which component makes the allow, deny, hit, or miss call. The matrix row is that component plus one request that isolates it. If two layers could produce the observed result, the case is not yet a test.

The plan is a claim about the API, not the request path. With Terraform 1.17.1 and cloudflare/cloudflare 5.28.1, a successful apply proves the zone accepted the record, ruleset, or policy. It cannot prove that a resolver returns the record, that a certificate covers the name, that a rule fires on the request, or that a cache stores the response. Treat a green apply as the entry ticket.

Map Each Requirement to the Layer That Can Prove It
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    R["Requirement
private page, correct build, no cache leak"] --> Q{"Which layer decides?"} Q -->|"name to address"| D["DNS
authoritative and public resolver"] Q -->|"handshake"| T["TLS
SNI, chain, minimum version"] Q -->|"status, headers, redirect"| H["Edge HTTP
rules and cache"] Q -->|"allow, block, challenge"| S["Security
WAF and Access"] Q -->|"served content"| O["Origin
application and target health"] D --> DP["Probe: two resolvers
same answer set"] T --> TP["Probe: SNI handshake
SAN and minimum version"] H --> HP["Probe: fixed URL
status and cache header"] S --> SP["Probe: no identity, then
a synthetic identity"] O --> OP["Probe: marker header
plus origin Ray ID"] DP --> E{"Evidence agrees
at one layer?"} TP --> E HP --> E SP --> E OP --> E E -->|"yes"| A["Accept the row"] E -->|"no"| F["Correlate before changing config"] G["Green terraform apply"] -.->|"proves none of these"| E classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class R,Q,E primary; class D,T,H,S,O,DP,TP,HP,SP,OP secondary; class A ok; class F,G danger;

DNS proves reachability, not edge behavior. A proxied name returns Cloudflare addresses; a grey-clouded name returns the origin. Both can be correct for different requirements. Query the authoritative nameserver and a public resolver, because a stale recursive cache is a propagation observation, not a configuration defect.

TLS proves the handshake, not the HTTP decision. Present the exact hostname with SNI, read the chain and subject alternative names, and test the minimum version explicitly. A valid certificate says nothing about HSTS, HTTP redirects, or which ruleset runs after the handshake.

The edge HTTP response proves the composed rule order. Status, redirect target, and response headers are the observable result of redirect, transform, header, and cache rules. Two rules that look independent can compose into a different answer, so assert the final response rather than each rule in isolation.

Security decisions need the requesting identity. WAF and Access can both return 403, and a rate limit can return 429. The difference is whether a rule matched the request or an identity was missing. Send the request twice, once anonymous and once with a synthetic identity that should pass, and compare the signal rather than the code alone.

Origin readiness needs an origin-side observation. A 200 at the edge can come from cache, a Worker, or the application. Add a non-secret marker header from the app and log the Ray ID at the origin. If the marker and the origin log agree, the application actually served the request.

Four layers with four different kinds of proof A request crosses the resolver, the edge TLS and HTTP stack, and the origin. Each layer proves a different property, and a green Terraform apply proves none of them. Four layers, four different proofs Green apply: the API accepted the object. It is not a request-path observation. Client host + identity DNS resolver name to address Edge TLS, rules, WAF, cache Origin application and target Proves address and TTL proxy on or off Cannot cert or rules Proves chain, status, headers cache state and rule action Cannot application correctness Proves which build served and from where Cannot what the client saw A 200 at the edge can be cache, a Worker, or the origin. Only an origin marker plus its Ray ID distinguishes the three. The Ray ID joins edge and origin. DNS and TLS failures happen before it exists.
RequirementDecisive layerHarmless probePass signalWhat still cannot be proven
Name resolves to the edgeDNSAuthoritative nameserver and a public resolver, same nameSame answer set; a proxied answer is a Cloudflare addressCertificate, rules, cache
Certificate is trusted for the hostEdge TLSHandshake with SNI for the exact hostnameChain completes, SAN covers the host, validity is currentHTTP redirect, WAF, origin TLS
HTTP upgrades and pins HSTSEdge HTTPPlain HTTP without following redirects, then the HTTPS response301 or 308 to HTTPS, and Strict-Transport-Security on the HTTPS responseOrigin certificate, application auth
Probe path is blockedWAF custom ruleGET from a client with no credential403 with a cf-ray, rule ID in events, no origin logWhether other paths are blocked
Private page denies anonymousAccessGET without a JWT or service token302 to the team domain or 403; origin has no matching cf-rayWAF behavior on other paths
Personalized page is not sharedCacheTwo synthetic identities, same URLBYPASS or DYNAMIC, distinct bodies, no growing AgeOrigin correctness
Application build is the intended oneOriginGET, then read the marker response header and the origin logMarker matches the build and the Ray ID appears at originEdge cache behavior
Failover reaches the secondaryLoad balancer and originControlled health failure on the primaryPool critical event, secondary marker, a new Ray IDClient-side DNS caching

The table is the contract for the rest of the article. Every later section adds mechanics to one row: determinism, negative assertions, correlation, or acceptance. A row with no decisive probe is a requirement you cannot accept yet.

Use Deterministic Harmless Requests and Bounded Waits

A deterministic case fixes five things: method, host, path, headers, and identity. Change any one and the cache key, the rule match, or the Access decision can change. Put the run identifier in a header that is not part of the cache key, because a random query value guarantees a cache miss and tests nothing about policy.

Use a hostname or path that exists only for probes. A dedicated hostname gives you a separate Access application, a separate WAF scope, and a clean log filter. A path inside the production app is cheaper but risks sharing a cache key or an auth exception with real traffic; if you use one, make it read-only and public by design, not by exception.

Know what the cache key contains before you vary anything. By default it includes the host, the path, and the query string, and a cache rule can add headers or cookies. Vary a component that is in the key and you are testing a different object, not the same one twice.

Warm the cache with the same key you will assert. A first request establishes the object; a second identical request within the TTL proves storage. A miss on the second request is a defect only when the Ray ID shows the same colo and the response was eligible. A different colo can legitimately miss because the cache is local to the data center, unless Tiered Cache or Cache Reserve is part of the design.

Synthetic identity means a credential created for the test, not a borrowed human account. An Access service token scoped to the probe application is the cleanest choice: it is revocable, it is not a person, and its use is attributable. Give it the shortest duration that covers the window and never put the secret in a URL, a log, or a screenshot.

Harmless means read-only and boring. GET and HEAD against a page that changes nothing, with no real user data and no production cookie. If a case needs a write, use a synthetic record keyed by the run ID and delete it in the same run; a test that leaves state behind is a second change to accept.

A bounded wait is a deadline plus a reason. Each wait has a budget derived from the mechanism: DNS TTL, certificate issuance, cache purge, or monitor interval multiplied by consecutive count. Poll at a fixed interval, record every attempt, and stop at the deadline. A failure before the deadline is "not yet"; the same failure after it is a defect.

Do not encode the budget as a sleep. A fixed sleep either wastes the window or asserts too early. A retry loop that stops on the first pass gives you the observed transition time, which is the evidence you actually want in the report.

Transient and persistent differ by repetition, not by message. A 522 immediately after an origin or security-group change is expected while the path settles; the same 522 after the budget is a defect. Record the first failure and the last attempt so a reviewer can see the difference.

Use Deterministic Harmless Requests and Bounded Waits
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Freeze the case
method, host, path, headers, identity"] --> B["Build one cache key
no random query"] B --> C["Send the request at t0
record Ray ID and status"] C --> D{"Expected layer signal?"} D -->|"yes"| E["Record the pass
timestamp and evidence"] D -->|"no"| F{"Within the deadline?"} F -->|"yes"| G["Wait one interval
poll the same key"] G --> C F -->|"no"| H["Persistent failure
correlate before changing access"] B -.->|"random query added"| X1["Cache test invalid
every request is a miss"] C -.->|"different colo on retry"| X2["Local miss, not a defect
re-baseline in one colo"] C -.->|"credential expired"| X3["Rerun with a fresh
short-lived token"] E --> I["Attach evidence to the row"] H --> I classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A,B,C,D,F,G primary; class E,I ok; class H,X1,X3 danger; class X2 warn;

Record the observation, not the command. The artifact is the status, the Ray ID, the cache status, the timestamp, and the identity class. The command line that produced it is reproducible from the case definition; the secret that authenticated it is not part of the record.

A probe that cannot fail is not a probe. If the expected signal is "some 200", every misconfiguration that still returns a page passes. Assert the specific header, the body marker, or the cache state that only the intended path produces.

Run from more than one network only when the requirement is global. A laptop and a CI runner in one region prove one path. Anycast can route to a different colo and Access can apply a location policy, so a global requirement needs at least two vantage points and a note about which colo each one hit.

Test the Negative Path Without Broadening the Exposure

A negative test proves a control by being refused at the right boundary. The pass condition is not "the request failed"; it is "the request failed for the intended reason and never reached the origin." A block page served after the request reached the application is a detection, not a prevention.

Assert three things for every deny case. The client sees the expected refusal, the edge log names the rule or policy that produced it, and the origin log has no request with that Ray ID. Any two of the three is ambiguous; all three are evidence.

A 403 is not a diagnosis. WAF, Access, a rate limit, the origin's own firewall, and the application can all return it. The rule identifier, the challenge marker, the redirect to the Access login domain, and the presence or absence of an origin log separate them.

Deny the private path without a credential, then allow it with a synthetic one. The pair proves both halves: the control blocks the anonymous request and does not block the intended identity. A deny-only test can pass while the allow path is broken, which is an outage disguised as security.

Personalized responses need a cache-bypass assertion, not a cache-disable rule. Send the same URL as two synthetic identities and compare the bodies and cache status. A HIT carrying the first identity's body to the second is a disclosure; a BYPASS or DYNAMIC with distinct bodies is the expected result.

Do not broaden exposure to make a probe pass. A temporary IP allowlist, an Access bypass policy, a WAF skip for the probe path, or turning TLS off all convert a test failure into a production weakness. The control you disabled is the control you were testing.

Temporary exceptions need an owner, a scope, and a removal step. Scope to one host, one path, and one identity class; put the ticket and expiry in the rule description; remove it in the same change and rerun the deny case. Cloudflare rules do not expire on their own, so the expiry is a process guarantee, not a platform one.

The assumption boundary is part of the result. A staging hostname in the same zone shares zone-level rules but not host-scoped ones; a separate zone shares neither. A tunnel path is not the public load-balancer path. Write down which of those the matrix actually exercised.

Absence is also an assertion. The denial response should not leak an origin address, an internal hostname, a stack trace, or a debug header. Check the headers you receive, not only the status line.

A challenge is not a block. A managed challenge returns a page that a browser can solve, and a scripted probe may still be allowed after solving it. If the requirement is "block", assert the block action and the origin's silence, not the presence of a challenge page.

A denial that stops at the edge, and a shortcut that makes the test lie An anonymous request should be refused at the edge and never reach the origin. A synthetic identity should pass. An allowlist, Access bypass, or WAF skip routes the probe around the controls, so the test passes while the production path stays open. The denial must stop at the edge, not at the app Anonymous probe no cookie, no token expect refusal Synthetic identity service token, read-only expect the page Shortcut IP allowlist, Access bypass, or a WAF skip for the probe test passes, control false Edge controls WAF custom rule block, challenge, skip Access application allow, deny, bypass Cache rule and cache key store, bypass, vary The answer is produced here, before the origin. A challenge is not the same result as a block. Origin logs the Ray ID it received no request for a denied Ray ID X Assumptions to write down: same zone, same host, same identity class. A different zone proves a different rule set, and a tunnel path is not the public load-balancer path.

Correlate Failures with Safe Diagnostic Signals

The Ray ID is the join key, and it only exists after HTTP. Every edge response carries cf-ray, and Cloudflare forwards it to the origin, so the same value appears in the client response, the edge log, and the origin log. DNS and TLS handshake failures happen before that header exists, so they need resolver and handshake evidence instead.

Compare edge status with origin status before reading any message. An edge 200 with an origin status of zero means the response came from cache or from the edge, not from the application. An edge 5xx with an origin status of zero means the origin never answered. An edge 403 with an origin status of zero means the block happened at the edge. The pair localizes the failure before you open a dashboard.

Cache status is a decision, not a health signal. The cf-cache-status header reports HIT when storage succeeded, MISS when the lookup found nothing, BYPASS when a rule or request property skipped the cache, and DYNAMIC when the response was not eligible. A HIT on a page that should be private is a defect even when the status is 200 and the body looks right.

A response marker from the origin is worth more than a status code. Have the application return a build identifier and a region or instance marker in a header that is not secret. The edge can transform headers, so compare the marker with the origin's own log rather than trusting the client view alone.

Logpush is evidence with a data-minimization obligation. Select only the fields the matrix needs: Ray ID, host, path, edge and origin status, cache status, rule identifier, colo, and timestamp. Excluding request headers wholesale is safer than trying to redact cookies, authorization values, and query strings after the fact.

Absence in a sample is not absence in reality. A Logpush job with a sample rate, or an analytics view with aggregation, can miss a single probe. Use a Ray ID search for the precise request and state the sample rate when the only evidence is an aggregate.

Time is a signal too. Record the client timestamp, the edge timestamp, and the origin timestamp, and allow for clock skew and log delivery latency. A request that is "missing" from the origin log may simply not have been delivered yet; that is why the wait has a deadline.

Keep the evidence pack safe. A redacted header list, a status, a Ray ID, a TLS summary, and a rule identifier are enough to review a failure. A full verbose transcript with cookies, bearer tokens, and origin addresses is a new incident, not a diagnostic.

The failure taxonomy is small. A 403 for every identity is usually a rule or policy; a 403 for one identity points at that identity's group; a 200 with the wrong body is cache or origin; a 52x is connectivity or TLS to the origin. Use the first safe signal to choose the next check, not the error text.

The 52x family is origin connectivity. A 521 means the origin refused the connection, 522 means the connection timed out, 523 means the origin was unreachable, 525 means the TLS handshake failed, and 526 means the origin certificate was invalid. A 530 with a 1016 code is a different failure: no origin DNS answer, often a disabled or misconfigured fallback pool.

What each layer can prove, and the first safe signal to collect DNS and TLS failures have no Ray ID. Edge HTTP failures have a Ray ID but no origin log. Origin failures have both. The edge and origin status pair localizes the failure before any message is read. The signal ladder: four layers, one join key Layer First safe signal What it rules out DNS resolver answer, TTL same name at two resolvers no Ray ID exists yet certificate, rules, cache do not open an edge dashboard TLS chain, SAN, version SNI handshake for the host no Ray ID exists yet HTTP rules and cache TLS is not the HTTP decision Edge HTTP status, headers, cache Ray ID, edge status origin status is zero the application served it cache or an edge rule answered Origin Ray ID in origin log Ray ID plus marker header join the client to the origin an edge-only failure the request did reach the app Edge 200 and origin 0: cache or edge. Edge 403 and origin 0: edge decision. Edge 5xx and origin 0: the origin never answered. Origin 5xx: the app is the source. The pair is a localization tool, not a root cause.

Define Acceptance for Cutover, Drift and Teardown

Acceptance is three gates in one window: plan, behavior, and ownership. The plan proves the configuration matches the intended records; the matrix proves the request path behaves; the inventory proves nothing owned was left behind. A pass in one gate does not compensate for a fail in another.

Cutover starts with a baseline on the old path. Capture the same matrix rows before the change, from the same vantage points, and keep the old origin warm. The post-change comparison is meaningful only if the request, the identity, and the expected signal are identical.

Lower the TTL before cutover only where you control it. A grey-clouded record has a configurable TTL; a proxied record uses the edge's automatic TTL. For a DNS-only cutover, reduce the TTL ahead of the window and wait at least one old TTL before changing the answer. For a proxied cutover the record change is nearly immediate, but certificate issuance and monitor transitions are not.

A rollback trigger is part of the acceptance criteria. Name the row or gate that forces a rollback, the person who decides, and the action that restores the old path. A rollback that has never been rehearsed is a hope, not a control.

Drift is not one thing. Configuration drift is a managed attribute changed outside Terraform; state drift is an object deleted or replaced outside Terraform; provider drift is a new provider version reading the same object differently. A plan with detailed exit codes catches the first two for managed attributes and says nothing about an object nobody manages.

A no-change plan is necessary and not sufficient. terraform plan -detailed-exitcode returns zero when the managed attributes match. A dashboard-created WAF rule, cache rule, or Access application in the same zone produces no diff because it is not in state. Inventory by ownership prefix and compare the live list with the state list.

A refresh-only plan separates "the world changed" from "the config changed." Run it before a normal plan when you suspect an out-of-band edit, then run the normal plan to see whether the configuration must change. A persistent diff after both is either an intended configuration change or a provider representation issue, not an out-of-band edit.

Teardown is an acceptance test for ownership. Destroy in dependency order, then verify that the state is empty and the live inventory has no object carrying the run prefix. Account-scoped resources are the usual leftovers: load balancer monitors and pools, Logpush jobs, API tokens, and Access applications can outlive the zone-scoped objects that referenced them.

A shared zone is restored, not deleted. If the lab used a production zone, teardown must put back the zone settings it changed, including minimum TLS, HSTS, and Always Use HTTPS, then remove the probe hostname and its rules. Deleting the zone is correct only when the zone was created for the lab.

The matrix itself needs acceptance. It is code: review it, version it, run it in CI against a staging hostname, and fail closed when a signal is missing. A matrix that skips a row because a credential expired is a green build with an unproven requirement.

Exceptions expire. An accepted deviation needs an owner, a reason, a compensating check, and an expiry date. An exception without an expiry is a permanent weakening that the next reviewer will mistake for a requirement.

Deep Dive

Review the edge evidence pack

Execution status: design-only. No Cloudflare or AWS credential was used to produce this article, and these steps were not executed here. Versions: Terraform CLI 1.17.1, cloudflare/cloudflare 5.28.1, verified 6 November 2026.

Prerequisites. A zone you can delegate, a probe hostname covered by the certificate, a read-only probe path, an Access service token scoped to that hostname, a read-only API token, and access to the zone's HTTP and firewall logs. Keep the plan file, the matrix output, and the log excerpts together.

The evidence pack has five entries. Each one must be present, and the reviewer must be able to open it without rerunning the change.

GateArtifactPass conditionOn failure
ConfigurationSaved plan and the recorded exit codeExit code zero on the final planExplain or revert every remaining diff
BehaviorMatrix output with timestamps and Ray IDsEvery row passes at the same vantage points as the baselineCorrelate the row before changing config
SecurityDeny and allow pair plus origin log excerptsDeny stops at the edge; allow reaches the app; no origin request for the denied Ray IDRemove the exception, not the control
OwnershipLive inventory filtered by the run prefixNo probe object remains after destroyFinish teardown before closing the record
RollbackRehearsed restore of the old pathOld path answers and the matrix passes on itDo not start the cutover

Procedure.

  1. Freeze the change: record the commit, the plan file, and the exact matrix version. A matrix edited during the window invalidates the comparison.
  2. Capture the baseline on the old path with the same host, path, identity class, and cache key you will use after the change.
  3. Run the cutover, then wait only within the budgets: DNS TTL, certificate issuance, cache purge, and monitor interval times consecutive count.
  4. Poll the matrix until every row passes or its deadline expires. Record the first failure and the last attempt, not just the final result.
  5. Check the negative rows again. A cutover that opens the allow path while losing the deny path is a regression even when every 200 looks correct.
  6. Run a refresh-only plan and expect no unexplained changes, then run a normal plan with detailed exit codes and expect zero.
  7. Inventory the live objects by the run prefix, compare with the state list, and remove any probe object the destroy left behind.
  8. Sign the evidence pack or trigger the rehearsed rollback. Do not close the record with a row that is "probably propagation."

Expected observation. A clean sequence rather than a fixed duration: the record resolves, the handshake presents the expected chain, the probe path returns the intended status, the deny path stops at the edge, the personalized page bypasses the cache, the origin marker names the intended build, and the final plan is empty. A missing step is a finding even when the final status is 200.

Failure checks. A 403 with an origin log entry means the block happened too late. A HIT with a private body means the cache key or the response headers are wrong. A 200 with the wrong build marker means the edge served cache or the cutover did not reach the origin. A no-change plan with a live object outside state means the inventory gate, not the configuration gate, failed.

Cost and cleanup. The lab uses one probe hostname, a small number of requests, one Access service token, and a short log retention window. Destroy the probe rules and hostname, revoke the token, delete the Logpush job and its destination, and restore any shared zone setting. Keep the evidence pack and the saved plan until the change record closes.