Draw the Two TLS Connections
A padlock in the browser is a statement about one connection, not two. The visitor's browser negotiates TLS with a Cloudflare data center, and Cloudflare separately negotiates TLS with your origin server. Those are different handshakes, with different certificates, different private keys and different trust stores. Treating them as one connection is the source of most "the certificate is valid, why is the site down?" incidents.
Two padlocks, two verifiers
The browser validates the edge certificate against public roots. Cloudflare validates the origin certificate against its own trust settings. A valid padlock says nothing about the second leg, and an origin certificate says nothing about what the browser trusts.
The first connection ends at the edge. The browser sends a TLS ClientHello with a server name indication, Cloudflare returns the certificate selected for that hostname, and the browser validates the chain against its public root store. That certificate is a managed edge certificate: Universal SSL by default, an advanced certificate pack, or a custom certificate you uploaded. The browser never sees your origin certificate, and your origin never sees the browser's TLS session.
The second connection begins after the edge decrypts. Cloudflare opens a new TLS connection to the origin, presents its own client capabilities, and validates the origin's certificate according to the zone's SSL/TLS mode. In Full (strict), the edge checks that the certificate is unexpired, chains to a trusted authority, and covers the hostname Cloudflare is targeting. In Full, it encrypts but accepts almost any certificate. In Flexible, there is no second TLS connection at all.
A third certificate can point the other way. Authenticated Origin Pulls adds a client certificate that Cloudflare presents to your origin, and the origin validates it against a CA you control. That certificate proves the connection came from Cloudflare; it does not replace the origin's server certificate. The origin still presents its own certificate so Cloudflare can validate the server, and the two directions are configured separately.
The trust stores are not interchangeable. A browser trusts public roots. The Cloudflare edge trusts public roots plus Cloudflare Origin CA. Your origin, when AOP is enabled, trusts the CA that signed the Cloudflare client certificate. An Origin CA certificate on the edge is the wrong certificate for the wrong verifier; a public certificate on the origin is perfectly valid. The question is always "who is checking this certificate, and what does that checker trust?"
Three parties, three checks. The same handshake looks different depending on who is validating it.
| Party | Certificate it validates | Trust store | What it cannot see |
|---|---|---|---|
| Browser | Edge server certificate | Public roots | Origin certificate and origin chain |
| Cloudflare edge | Origin server certificate in Full (strict) | Public roots plus Origin CA | The browser's validation result |
| Origin, with AOP enabled | Cloudflare client certificate | Your AOP CA | The edge certificate |
A TLS mode chooses behavior, not identity. The zone setting controls whether Cloudflare connects to the origin over HTTP or HTTPS and whether it validates the origin certificate. It does not issue, renew or install any certificate. Changing the mode can make a broken origin visible, but it cannot make a missing certificate exist. That separation is why the mode and the certificate lifecycle deserve separate changes and separate rollback plans.
The hostname is part of the check, not a label on the certificate. The browser uses SNI to tell the edge which hostname it wants. Cloudflare uses the target hostname on the origin connection, which may be the public hostname, an internal name, or the host in a Tunnel route. Full (strict) requires a Common Name or Subject Alternative Name that matches that target. A wildcard covers one level only, so a certificate for the apex and *.example.com does not cover api.staging.example.com.
Two failures look identical from a browser and are completely different. A browser certificate warning means the edge certificate is wrong or missing. A Cloudflare 526 means the edge certificate is fine but the origin certificate failed validation. The first is a visitor-facing trust problem; the second is an edge-to-origin trust problem. Figure 1 separates the two legs before the failure modes get mixed together.
%%{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 LR
subgraph C1["Connection 1: browser to edge"]
B["Browser
validates the edge certificate"]
E["Cloudflare edge
terminates TLS and re-originates"]
RB["Browser trust store
public roots only"]
end
subgraph C2["Connection 2: edge to origin"]
O["Origin server
presents its own certificate"]
RE["Edge trust store
public roots plus Origin CA"]
end
B -->|"TLS 1.2 or 1.3"| E
E -->|"new TLS connection"| O
B -. "checks issuer, SAN, dates" .-> RB
E -. "checks issuer, SAN, dates" .-> RE
O -. "sends leaf and intermediates" .-> RE
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 B,E primary;
class O,RB secondary;
class RE ok;
Read the diagram from the verifier backward. The browser validates only the edge certificate, so an expired origin certificate is invisible to it. The edge validates the origin certificate only in Full (strict), so in Full an expired origin certificate is invisible to everyone until you switch modes. The origin validates the AOP client certificate only when AOP is enabled, so a direct request to the origin can succeed even when the proxy path is locked down. Each leg has its own failure surface.
The separation also changes incident response. When a visitor reports a certificate warning, inspect the edge certificate and the hostname selection. When the edge reports 526, inspect the origin certificate, its chain and the target hostname. When a direct-to-origin request succeeds while the proxied request fails, inspect AOP and the origin listener. None of those investigations starts in the same place.
Version baseline. Behavior was checked against Terraform CLI 1.17.1 and the Cloudflare provider at 5.28.1 on 6 November 2026. Cloudflare's docs move faster than the provider schema; where they disagree, the schema wins for Terraform configuration and the API docs win for behavior the provider does not expose.
Choose Full Strict with a Validated Origin Trust Chain
Full (strict) is the production default because it is the only common mode that authenticates the origin. It does everything Full does, then adds three checks: the certificate must be unexpired, it must chain to a publicly trusted CA or Cloudflare Origin CA, and its Common Name or Subject Alternative Name must match the hostname Cloudflare is targeting. If any check fails, Cloudflare refuses the connection and returns a 526 instead of silently trusting the origin.
The expiry check is literal. Cloudflare requires the current time to fall between the certificate's not-before and not-after dates. A certificate that expired yesterday is not "probably fine because the browser still works"; the browser never validated it. The edge did, and the edge is the only party that can enforce it. That is why an origin certificate can expire without a single visitor noticing until the next cache miss or the next mode change.
The chain check is about intermediates, not just the leaf. The origin must serve the leaf certificate and any intermediate certificates needed to build a path to a trusted root. A missing intermediate is a common cause of 526 because some clients cache or repair chains and others do not. Cloudflare's error guidance explicitly lists "certificate chain is complete" as a review item. If the origin serves only the leaf, the edge may see a valid certificate it cannot chain.
The hostname check uses the target Cloudflare actually connects to. That is usually the public hostname, but it can be an internal hostname, an origin address with a Host header override, or a Tunnel service host. A certificate for the apex does not cover an internal origin name, and a wildcard covers one level, not a deeper staging host such as api.staging.example.com. The fix is either a certificate with the right SAN or an origin configuration that presents the name the certificate covers.
Full mode is encryption without authentication. Full establishes TLS to the origin, so the bytes are encrypted in transit, but it does not validate the certificate. A self-signed certificate, an expired certificate, or a certificate for the wrong hostname can all pass. That is useful for a short migration window when the origin cannot yet present a trusted certificate, and dangerous as a permanent state because it hides exactly the failures Full (strict) exists to catch.
Flexible is a legacy bridge, not a production default. Flexible encrypts only the browser-to-edge leg and connects to the origin over HTTP. The origin sees plaintext, every intermediary on the edge-to-origin path can read or modify it, and the origin cannot distinguish a Cloudflare request from any other HTTP client. If the origin redirects HTTP to HTTPS, Flexible creates a redirect loop because Cloudflare keeps requesting HTTP and the origin keeps redirecting to HTTPS. AOP does not apply in Flexible or Off.
Flexible has a port nuance that surprises people. Cloudflare documents Flexible as supported for HTTPS on port 443 only; HTTPS on other ports falls back to Full. That does not make Flexible safer on 443; it simply means the mode's behavior is narrower than the label suggests. If you inherit a zone on Flexible, treat it as an inventory problem: find every origin that lacks a trusted certificate, fix it, then move the zone to Full (strict).
Off is not a mode to leave enabled. Off redirects HTTPS requests to plaintext HTTP and removes the Always Use HTTPS option. Browsers mark the site as not secure, credentials travel in clear text, and AOP cannot apply. It exists for debugging and legacy cases, not for a site that accepts logins or payments.
Strict (SSL-only origin pull) is a separate Enterprise mode. It validates the origin certificate like Full (strict), but it always connects to the origin over TLS regardless of the scheme the visitor used. That closes the "visitor used HTTP, so the edge used HTTP" gap. It is not the same setting as Full (strict), and it is not available on every plan.
| Mode | Browser to edge | Edge to origin | Origin certificate validated | Typical failure |
|---|---|---|---|---|
| Off | Cleartext HTTP | Cleartext HTTP | No | Browser warns; credentials exposed |
| Flexible | HTTPS | HTTP | No | Redirect loop when the origin forces HTTPS; AOP inoperative |
| Full | HTTPS | HTTPS | No; trust and hostname are not checked | Expired or wrong-host certificate stays hidden |
| Full (strict) | HTTPS | HTTPS | Yes: chain, hostname and expiry | 526 on any mismatch |
| Strict (SSL-only origin pull) | Visitor scheme, but origin always HTTPS | HTTPS | Yes: chain, hostname and expiry | Enterprise-only; 526 on any mismatch |
The provider schema is narrower than the API in one important place. Cloudflare's API accepts origin_pull as an SSL mode value, but the cloudflare_zone_setting resource schema in provider 5.28.1 lists only off, flexible, full and strict for the SSL setting. Do not assume Terraform can set the Enterprise-only mode just because the API documents it. Check the schema for the pinned provider release, or manage that exception outside Terraform and document why.
The mode decision has failure branches, and they should be explicit. Figure 2 reads from the origin's capabilities outward: does it serve HTTPS, is the certificate valid, does the hostname match, and is there an origin-authentication layer. The diagram deliberately sends Flexible to a redirect-loop branch and Full to a hidden-failure branch, because those are the two ways a "working" configuration stores up an incident.
%%{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
M["Zone SSL/TLS mode"] --> Q1{"Origin serves HTTPS
on port 443?"}
Q1 -- "no" --> F["Flexible
edge to origin over HTTP"]
F --> F1["Origin redirects to HTTPS?
redirect loop"]
F --> F2["AOP cannot be enforced"]
Q1 -- "yes" --> Q2{"Chain trusted, unexpired,
intermediates present?"}
Q2 -- "no" --> D["526 Invalid SSL certificate"]
Q2 -- "yes" --> Q3{"CN or SAN matches
the target hostname?"}
Q3 -- "no" --> D
Q3 -- "yes" --> S["Full (strict)"]
M --> U["Full
encrypts but does not validate"]
U --> U1["Expired or mismatched
certificate stays hidden"]
S --> Q4{"AOP or Tunnel
in front of origin?"}
Q4 -- "AOP" --> A["Origin verifies
Cloudflare client cert"]
Q4 -- "Tunnel" --> T["Outbound connector
no inbound listener"]
Q4 -- "neither" --> N["Origin still reachable
by direct IP"]
D --> R["Fix chain, hostname or expiry
then retest before cutover"]
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 M,S primary;
class Q1,Q2,Q3,Q4,A,T,R secondary;
class F,U warn;
class F1,F2,U1,D,N danger;
Cutover order matters more than the mode value. Issue or install the origin certificate first, test it directly with the correct SNI, then switch the zone to Full (strict). If Terraform manages both the certificate and the setting, an explicit dependency is what prevents the setting from being applied before the certificate exists. A transient 526 during the apply is not a reason to fall back to Flexible; it is a signal that the ordering or the certificate is wrong.
The supporting settings belong in the same change. Set the minimum TLS version to 1.2 or higher, and enable TLS 1.3 unless a legacy client population prevents it. Always Use HTTPS gives visitors a 301 from HTTP to HTTPS at the edge, and Automatic HTTPS Rewrites repairs mixed-content links that would otherwise break after the redirect. These are zone-setting resources in provider 5.x, not fields on the zone resource.
Always Use HTTPS replaces origin redirects, not adds to them. Cloudflare recommends not performing redirects at the origin because they can create loops. If the origin already redirects HTTP to HTTPS, either remove that redirect or make sure Cloudflare reaches the origin over HTTPS. Under Full (strict) the second condition is true; under Flexible it is false, and the loop is structural.
HSTS is a one-way door and deserves its own change. The security_header zone setting enables Strict-Transport-Security, with max-age, include-subdomains and preload fields. Once a browser has seen a long max-age, it will refuse HTTP for that hostname until the value expires, even if you later turn HSTS off. Start with a short max-age, confirm every subdomain can serve HTTPS, then increase it. Do not enable preload until you are prepared to stay on the preload list.
A zone-wide mode is a blunt instrument. The setting applies to the zone unless a more specific rule overrides it. A single legacy hostname that cannot present a trusted certificate is not a reason to keep the whole zone on Full or Flexible. Isolate that hostname in its own zone or rule, with a termination plan, and keep the production default at Full (strict).
A 526 is evidence, not an outage to suppress. The correct response is to find which of the three checks failed: chain, hostname or expiry. Switching to Full makes the 526 disappear while leaving the origin unauthenticated, and switching to Flexible makes it disappear while leaving the traffic in clear text. Both convert a visible trust failure into an invisible one.
Manage Certificate Settings Without Leaking Private Keys
Start with the side that terminates TLS. A certificate is not a generic "SSL certificate"; it belongs to the edge, the origin, or the client-authentication direction. The five types below have different owners, different renewal behavior, and very different private-key exposure in Terraform. Confusing them is how a team ends up installing an Origin CA certificate on the edge or expecting Universal SSL to cover an origin.
| Certificate | Terminates at | Who trusts it | Private key lives | Terraform surface |
|---|---|---|---|---|
| Universal SSL | Cloudflare edge | Browsers | Cloudflare | No resource; enabled by default |
| Advanced certificate pack | Cloudflare edge | Browsers | Cloudflare | cloudflare_certificate_pack |
| Custom SSL | Cloudflare edge | Browsers | You; uploaded to Cloudflare, or Keyless | cloudflare_custom_ssl |
| Origin CA | Origin server | Cloudflare edge | You, on the origin | cloudflare_origin_ca_certificate |
| AOP client certificate | Origin server, as a client cert | Your origin | You; uploaded to Cloudflare | cloudflare_authenticated_origin_pulls_certificate |
Universal SSL is the default you should not disable casually. Cloudflare issues and renews a free, unshared, publicly trusted certificate for every activated zone. On a full setup it covers the apex and first-level subdomains; on a partial setup each proxied hostname gets its own certificate. Deeper subdomains need Total TLS or an advanced certificate. Disabling Universal SSL removes the fallback certificate, so any hostname without an advanced or custom certificate becomes unreachable over HTTPS.
Advanced certificate packs are for coverage and control. The cloudflare_certificate_pack resource orders an advanced certificate through the Advanced Certificate Manager add-on. It supports up to 50 hosts, multi-level subdomains, a chosen certificate authority, a chosen validation method and a validity of 14, 30, 90 or 365 days. It is still Domain Validated, so it is not the path to an organization-validated certificate.
Certificate packs cannot be updated in place. Every attribute forces a new resource. The zero-downtime pattern is create the new pack, wait until it is active, then remove the old pack. If both packs exist at once, that is intentional overlap, not a duplicate. A single-resource rotation needs create_before_destroy, but the two-pack pattern is easier to observe and roll back.
The documented wait flag is not in the 5.28.1 schema. Cloudflare's rotation guide tells Terraform users to set wait_for_active_status = true, but the cloudflare_certificate_pack resource schema in provider 5.28.1 does not expose that argument. Do not copy the guide blindly. Poll the certificate-pack data source for its status, gate the second apply on it, or use a separate apply step. The same discipline applies to any product doc that outruns the pinned provider.
Importing an existing pack is a trap for renewal. Cloudflare's guidance is explicit: importing a certificate pack is supported but not recommended, because a reissue can change the resource ID and leave Terraform state out of sync. If the pack is managed outside Terraform, read it with the data source and leave the lifecycle alone. If Terraform owns it, own the whole lifecycle: create, wait for active, then delete.
Custom certificates are an operational commitment. The cloudflare_custom_ssl resource uploads a certificate and private key for the edge. It is aimed at Business and Enterprise plans that need a specific CA or organization/extended validation. Cloudflare does not renew it for you; you upload the replacement before expiry and update the resource. Certificate pinning is only meaningful with custom certificates, and Geo Key Manager or Keyless SSL are the options when the private key must not be distributed to every data center.
Origin CA is for the edge, not the browser. A Cloudflare Origin CA certificate is signed by Cloudflare and trusted by the Cloudflare edge in Full (strict). It is free, available on all plans, and can be valid for 7, 30, 90, 365, 730, 1095 or 5475 days. It supports up to 200 SANs, wildcards at one level only, and no IP addresses. It is not publicly trusted, so visitors see a warning if you pause Cloudflare or switch the record to DNS-only.
Origin CA has no expiry notifications. Cloudflare's documentation states that it does not currently send expiration notifications for Origin CA certificates. A 15-year certificate is still a certificate with an expiry date, and the team that created it may not be the team that owns the hostname a decade later. Record the expires_on value in your inventory and monitor it like any other credential.
AOP certificates are client certificates, not server certificates. The zone-level cloudflare_authenticated_origin_pulls_certificate resource uploads a leaf certificate and private key that Cloudflare presents to your origin. The origin trusts the CA that signed it. Per-hostname AOP uses a separate certificate resource and association, and per-hostname settings take precedence over zone-level and global settings. Zone-level AOP certificates also apply to custom hostnames on a Cloudflare for SaaS zone, which is easy to miss.
Private keys are the real state problem. Marking a variable sensitive only redacts it from CLI output; Terraform still writes the value to state and to saved plan files. Anyone who can read the state backend, a plan artifact, or a terraform show -json dump can read the key. Remote state encryption, narrow backend access, short plan retention and a ban on attaching plan files to tickets are not optional if the key is in Terraform.
The exposure is not uniform across certificate types. Read the table by the "key in state" column, because that is the column an attacker with backend access can use.
| Certificate | Key in Terraform config | Key in state | Safer pattern |
|---|---|---|---|
| Universal or advanced | No | No | Let Cloudflare manage issuance and renewal |
| Origin CA | No; CSR only | No | Keep the key in a secret manager or on the origin |
| Custom SSL | Yes, unless custom_csr_id is used | Yes | CSR flow or Keyless SSL |
| AOP client certificate | Yes | Yes | External upload plus strict state controls |
Origin CA keeps the private key out of Terraform entirely. The cloudflare_origin_ca_certificate resource takes a certificate signing request, not a private key. Generate the key in your secret manager or on the origin, produce the CSR, and pass only the CSR. Terraform receives the signed certificate, its serial number and expires_on; the API response does not include a private key, and the data source does not expose one. Losing the key means reissuing the certificate, not recovering it from state.
Custom SSL and AOP put the key in the resource. Both resources require private_key, and both mark it sensitive. The API does not return the key on read, so Terraform cannot reconstruct it after the fact; the copy in state is the only copy Terraform has. If the key must never enter state, use the custom CSR flow and pass custom_csr_id instead of a key for custom SSL, or use Keyless SSL and keep the key on your own infrastructure. For AOP, generate and store the key outside Terraform, then decide deliberately whether Terraform or a secret workflow owns the upload.
Read-back behavior is part of the contract. For Origin CA, the certificate, its expiry and its serial number are computed; there is no private-key attribute. For custom SSL and AOP, the certificate metadata and expiry are readable, but the private key is not. That asymmetry is useful: it tells you which resources can be rebuilt from the API and which cannot. A resource whose key is write-only from Terraform's perspective needs a documented escrow and rotation procedure, not just a state backup.
Deletion is not the same as forgetting. Deleting an Origin CA certificate resource revokes the certificate; that is a security action, not cleanup. If you only want Terraform to stop managing a live certificate, remove it from state with terraform state rm and keep the certificate installed. Use prevent_destroy on certificates that must survive an accidental root-level destroy, and review that guard when the certificate is genuinely retired.
Expiry belongs in code and in monitoring. The expires_on attribute can feed a check block that warns when a certificate is close to expiry, but a check block produces a warning, not a hard stop. If the plan must fail, use a precondition on a data source or a policy check in CI. Pair either with an external monitor, because Terraform only evaluates when someone runs Terraform.
Rotation is a sequence, not a replacement. Create the new certificate, install it on the origin or upload it to the edge, verify the served chain and hostname, then remove the old one. For Origin CA, the old and new certificates can coexist because the origin chooses which one to serve; for edge certificates, the pack overlap is what avoids a gap. Never delete the old certificate before the new one is active and verified.
One owner per certificate is a security control. A certificate that two teams can rotate, two pipelines can replace and three runbooks mention will eventually be rotated twice in one week. Record the owner, hostnames, issuing method, expiry and rotation trigger with the Terraform root. The provider can enforce configuration; only ownership can enforce process.
Protect the Origin Beyond Turning on the Proxy
The proxy hides the address; it does not close the port. A proxied DNS record replaces the public answer with Cloudflare anycast addresses, but the origin still has an IP address. Historical DNS records, certificate transparency logs, direct scans and forgotten DNS-only records can reveal it. If port 443 is open to the world, an attacker can connect directly, skip the WAF, skip the TLS mode and skip every rule that assumes traffic arrives through Cloudflare.
Authenticated Origin Pulls is mTLS in the Cloudflare-to-origin direction. Cloudflare presents a client certificate, and the origin verifies it against a CA you configure. AOP requires Full or Full (strict); it does not apply in Off or Flexible. It is available on all plans, but the global, zone-level and per-hostname configurations are independent: enabling one does not enable another, and per-hostname takes precedence for the hostnames it covers.
Global AOP proves the network, not the account. The global configuration uses a Cloudflare-provided certificate shared across all Cloudflare accounts. It is enough to show that a request came through Cloudflare's network, but not that it came from your zone. Zone-level AOP uses a certificate you upload, which is exclusive to your account; that is the stronger claim. Per-hostname AOP goes further and scopes the certificate to specific hostnames.
AOP is not compatible with Cloudflare Tunnel. A Tunnel origin has no inbound listener for Cloudflare to present a client certificate to; the connection is outbound-only from the origin. Tunnel traffic is already authenticated by the connector's credentials, and AOP settings have no effect on a Tunnel hostname. Enabling AOP and Tunnel together is not defense in depth; it is a false sense of depth.
Network allowlists are a coarse filter, not an identity. Restricting the origin firewall to Cloudflare's published IP ranges stops casual direct connections, but IP allowlists are vulnerable to spoofing and the ranges change. Automate the list from Cloudflare's published ranges, alert on drift, and do not treat "the source IP is in the range" as proof that the request came from your zone. It pairs well with AOP, not as a replacement.
Tunnel removes the inbound path instead of filtering it. cloudflared makes an outbound connection to Cloudflare, and requests flow back through that connection. The origin needs no public IP and no inbound port. A healthy tunnel status only proves the connector is connected; it does not prove the route's Service URL, origin certificate or application is healthy. Test the route separately from the connector.
Tunnel TLS is configured on the route, not by the zone mode. The route's Service URL chooses HTTP or HTTPS to the local origin. For HTTPS origins, originServerName supplies the SNI and the expected certificate name, caPool supplies a private CA bundle, and TLS verification must stay on except during a temporary diagnosis. The zone SSL/TLS mode does not change the Service URL and does not validate the local certificate; cloudflared does that independently.
Private origins need an identity layer, not just a network layer. A Tunnel private route connects a CIDR range without exposing it publicly, and Cloudflare Access or an application-level identity check decides who can reach the service. Workers VPC is another supported way to reach private services over HTTPS. In both cases, the network path is private but the authorization decision is separate; do not confuse "not routable from the internet" with "authenticated."
Privacy is not authentication
A Tunnel or private route removes the inbound path; it does not decide who may use it. Access policy, application identity or mTLS still has to answer that question. Treating reachability as authorization leaves an internal service open to anyone who can reach the connector.
The controls answer different questions. AOP answers "did this connection come from Cloudflare?"; an allowlist answers "is this source address in a known range?"; a Tunnel answers "is there any inbound path at all?"; Access answers "is this user allowed to reach this application?" Figure 3 shows the before-and-after shape, and the table below makes the trade-offs explicit.
| Control | What it proves | Enforced at | Terraform surface | Main limit |
|---|---|---|---|---|
| Authenticated Origin Pulls, zone-level | Cloudflare presents a client certificate signed by your CA | Origin TLS listener, as mTLS | cloudflare_authenticated_origin_pulls_certificate plus cloudflare_authenticated_origin_pulls_settings | Requires Full or Full (strict); not compatible with Tunnel; you own the certificate lifecycle |
| Global AOP | The request came through the Cloudflare network | Origin TLS listener, as mTLS | cloudflare_zone_setting with tls_client_auth | Shared Cloudflare certificate; does not prove the request came from your account |
| Cloudflare IP allowlist | The source address is in Cloudflare's published ranges | Origin firewall or cloud security group | Cloud provider firewall resource; ranges from Cloudflare's published list | Vulnerable to IP spoofing; ranges change; no account or user identity |
| Cloudflare Tunnel | The origin has no inbound listener and the connector is authenticated to Cloudflare | Outbound connector plus edge | cloudflare_zero_trust_tunnel_cloudflared plus cloudflare_zero_trust_tunnel_cloudflared_config | AOP does not apply; local TLS is configured on the route, not by the zone mode |
| Tunnel private route | Only the tunnel path reaches the private CIDR | Private network plus edge | cloudflare_zero_trust_tunnel_cloudflared_route | Needs an authorization layer such as Access; network privacy is not user authentication |
Figure 3 makes the difference visible. The left panel is the common "we turned on the proxy" state: the edge is in front of the origin, but the origin still accepts a direct connection on 443. The right panel removes the inbound path with a Tunnel and keeps an explicit authorization layer. The failure arrow is the important part: a direct request should fail, and if it returns 200, the origin is still public.
A direct request is the test that matters. From outside your network, resolve the origin's old address and connect to port 443 with the public hostname as SNI. If the handshake succeeds and the application responds, the origin is reachable regardless of what the edge says. With AOP, the request should fail because the client did not present the Cloudflare certificate; behind a Tunnel, the address should not accept a connection at all.
The combinations are not interchangeable. A public origin with AOP and an allowlist is a reasonable legacy pattern. A Tunnel with Access is cleaner for a private application. A Tunnel with AOP is a configuration error because AOP has no inbound listener. An allowlist without AOP can be spoofed. Choose by the threat, not by the number of controls.
Terraform ownership should follow the pattern. A Tunnel deployment owns the tunnel, its configuration and its routes, and the DNS record that points at it. A public-origin deployment owns the AOP certificate, the AOP setting and the firewall rules, and it should not also own a second copy of the DNS record. Duplicate ownership is how a route survives a teardown or a firewall rule reopens a port that the design closed.
Migration is a sequence of removals. Inventory the origin addresses and DNS-only records, implement the chosen pattern, test the direct path, then remove the public exposure and old DNS answers. Keep the old path for a short, named rollback window; the rollback should be a deliberate re-enable, not a forgotten firewall rule.
Verify TLS, Redirects and Failure Behavior Independently
Verify each leg with the verifier that actually checks it. The browser's padlock tests the edge certificate. openssl s_client against the origin tests the certificate Cloudflare sees. A direct request tests whether the origin is reachable without the proxy. A redirect trace tests whether HTTP and HTTPS agree. Renewal evidence tests whether the certificate will still be valid next month. These are five different checks, and passing one says nothing about the others.
One passing check proves one leg
The edge certificate, the origin certificate, the redirect chain, the direct-to-origin result and the renewal date are independent facts. Record each one separately with a date, or a green padlock will hide a 526 waiting on the next cache miss.
Start with the edge certificate. Use openssl s_client with the public hostname and SNI, then inspect the issuer, subject, SANs and dates. The issuer should be a public CA, the SAN should include the hostname, and the not-after date should be in the future. If the issuer is Cloudflare Origin CA, the wrong certificate is on the edge. If the SAN does not match, the browser warning is correct and the edge certificate selection is wrong.
Then test the origin certificate directly. Connect to the origin address with the hostname Cloudflare uses, not the address alone, because SNI drives certificate selection. Inspect the same fields plus the chain: the leaf should be accompanied by the intermediate that leads to the trusted root. A certificate that looks valid in a browser but fails here is usually missing an intermediate, expired, or issued for a different name. A private CA is valid only if the edge has a custom origin trust store that includes it.
Do not accept the edge result as origin evidence. A cached response can be served with a perfectly valid edge certificate while the origin is down, expired or misconfigured. The edge certificate is checked on every new TLS handshake, but the origin check only happens when Cloudflare needs to contact the origin. A cache hit can hide a 526 until the next miss, which is why the origin check has to be independent.
Trace redirects with a method that shows every hop. A plain HTTP request should return a 301 to HTTPS when Always Use HTTPS is on. Follow the chain and confirm it terminates at a 200, not at another redirect. A loop usually means the origin is redirecting HTTP to HTTPS while Cloudflare is connecting over HTTP, which is the Flexible failure mode. A single redirect is the target; three or four hops suggest two layers are both trying to enforce HTTPS.
Test the direct-to-origin path from outside. Use the origin address with the public hostname as SNI, and expect a failure when AOP or a Tunnel is in place. A TLS handshake failure is the desired result for AOP; a connection refused or timeout is the desired result for a Tunnel. A successful HTTP response means the origin is still public, even if the proxied path is correctly configured. Record the result with the date and the source network, because firewall rules drift.
Renewal evidence has to come from the certificate, not the dashboard. Read the not-after date from the served certificate and compare it with the expires_on attribute in Terraform state. For Universal SSL, Cloudflare renews automatically, but the edge certificate still has a date. For an advanced pack, the data source's status and the certificate dates are the evidence. For Origin CA, there are no expiry notifications, so the date in your inventory is the only warning. For AOP, Cloudflare can send 30-day and 14-day alerts if you configure them.
A 526 recovery starts with the ray ID and the hostname. The ray ID identifies the request; the hostname identifies the certificate Cloudflare expected. Run the origin check with that hostname, then inspect chain, expiry and SAN in that order. Fix the certificate or the origin name, verify the origin directly, and only then retest through the edge. If you use Full as an emergency fallback, set a date and an owner for returning to Full (strict); an emergency fallback without an expiry becomes the new configuration.
Match the symptom to the leg before changing anything. The fastest way to make a TLS incident worse is to change the zone mode when the failing leg is the origin's certificate chain.
| Symptom | Most likely leg | First check |
|---|---|---|
| Browser certificate warning | Browser to edge | Edge issuer, SAN and dates |
| 526 invalid SSL certificate | Edge to origin | Origin chain, SAN and expiry |
| 525 handshake failure | Edge to origin | Protocol, cipher and port 443 |
| Redirect loop | Edge to origin | Origin redirect and SSL mode |
| Direct origin returns 200 | Origin exposure | AOP, allowlist and Tunnel |
The lab below is deliberately failure-oriented. It asks you to verify the healthy state, then break the origin certificate in a controlled way and observe the 526. The point is to see which leg fails, which dashboard signal changes, and which command produces the evidence. Do it in a lab zone, never against a production hostname.
Verify both TLS legs
Status: design-only. Use a lab zone and a staging origin. No production credentials, no customer hostnames and no real private keys are needed. Replace every hostname and address with your own placeholders.
Prerequisites. Terraform CLI 1.17.1, provider 5.28.1, OpenSSL, curl, a lab hostname proxied through Cloudflare, and an origin you can reconfigure. The origin can be a local web server with a self-signed certificate for the failure step.
Steps. First record the edge certificate's issuer, SANs and dates. Then record the origin certificate the same way, using the hostname Cloudflare targets. Confirm the zone setting is Full (strict) and the minimum TLS version is at least 1.2. Trace one HTTP request through the redirect chain. Test the direct origin path and confirm it fails when AOP or a Tunnel is enabled. Finally, replace the origin certificate with one that has the wrong SAN, observe the 526, and restore the correct certificate.
| Check | Evidence to collect | Pass condition | Failure signal |
|---|---|---|---|
| Edge certificate | openssl s_client with the public hostname | Public CA, SAN matches, dates valid | Origin CA issuer, wrong SAN, expired |
| Origin certificate | openssl s_client with the origin address and SNI | Trusted chain, SAN matches, dates valid | Self-signed, missing intermediate, expired |
| Redirect | curl -sIL on the HTTP URL | One 301 to HTTPS, then 200 | Loop, 200 on HTTP, multiple hops |
| Direct origin | curl --resolve to the origin address | Connection rejected when AOP or Tunnel is on | 200 means the origin is still public |
| Mode read-back | Terraform state or a refresh plan | ssl is strict; min_tls_version is 1.2 or higher | flexible, full, or a missing setting |
| Renewal | openssl x509 -noout -dates -issuer plus expires_on | Not-after date is beyond the review threshold | Expired or within the renewal window |
Expected observation. The edge certificate and the origin certificate have different issuers and different expiry dates. The edge certificate is publicly trusted; the Origin CA certificate is not. The HTTP request redirects once and terminates at 200. The direct origin request fails when the protection is working. The deliberate wrong-SAN certificate produces a 526, and restoring the correct certificate clears it without changing the zone mode.
Failure check. The lab fails if the direct origin request returns 200, if the edge certificate is issued by Origin CA, if the redirect trace loops, or if the only evidence of renewal is a dashboard label with no certificate date. It also fails if the 526 is "fixed" by switching to Full or Flexible without recording why the origin certificate was invalid.
Cost and cleanup. The lab uses one zone, one hostname, one origin and, optionally, one Tunnel. Delete the DNS record, the Tunnel, the AOP certificate and the test certificate when finished. Revoke any Origin CA certificate you issued for the lab; deleting the Terraform resource is a revocation, not just a state cleanup.
Evidence to keep. Sanitized openssl output for both legs, the redirect chain, the direct-origin result, the mode and minimum TLS values, the 526 ray ID, and the certificate dates before and after the fix. Store the evidence with the lab notes, not with the private keys.
Close with the three questions the configuration must answer. Which certificate does the browser validate, which certificate does Cloudflare validate, and who can reach the origin without either? Full (strict), a managed or custom edge certificate, a deliberate origin certificate, and an origin path that is authenticated or private are the answers that make the padlock mean something. A TLS mode is a policy; a certificate is evidence; origin protection is reachability. Verify all three separately, and do not let a green padlock hide a red origin.
Next in the Series
In Rulesets and WAF: Phases, Expressions and Security Policy Ownership, we'll explore Configure ordered security behavior while keeping one authoritative owner for each shared ruleset.