skip to content

In Cloudflare for SaaS, a customer pointed a live shop domain's CNAME at your target and visitors saw TLS errors for minutes; why, and how do you avoid it next time?

level: seniorimportance: nice to knowfreq 22%

answer

  1. validation that needs the traffic first
  2. two statuses before the DNS flip
  3. pre-validate the hostname
  4. TXT or Delegated DCV

basics

~20 s

The custom hostname used automatic HTTP DCV, which can only finish after the CNAME points at Cloudflare, so the name had no certificate until the CA validated it. Pre-validate the hostname and issue the certificate by TXT or Delegated DCV before the cutover.

solid answer

~40 s

With `ssl.method` set to `http`, Cloudflare serves the CA's token from the edge, which works only after `shop.customer.com` resolves to Cloudflare; real-time hostname validation likewise waits for the CNAME. During that window browsers reach Cloudflare for a name with no matching certificate, so handshakes fail until `ssl.status` turns `active`. The zero-downtime order is: create the custom hostname early with `txt` validation; have the customer pre-validate ownership with the `_cf-custom-hostname` TXT record or the HTTP token on their current origin until `status` is `active`; have them add the `_acme-challenge` TXT records from `ssl.validation_records`, or set up Delegated DCV once, until `ssl.status` is `active`; only then change the CNAME. Watch token expiry (7 days for Let's Encrypt, 14 for Google Trust Services and SSL.com) and the customer's CAA records.

code

json · 17 lines
json
{
  "id": "<HOSTNAME_ID>",
  "hostname": "shop.customer.com",
  "status": "active",
  "ssl": {
    "method": "txt",
    "type": "dv",
    "status": "pending_validation",
    "validation_records": [
      {
        "status": "pending",
        "txt_name": "_acme-challenge.shop.customer.com",
        "txt_value": "<TOKEN_FROM_THE_CA>"
      }
    ]
  }
}

go deeper

for a junior

Remember that a custom hostname needs both its ownership and its certificate validated, and that some methods only finish after the customer's DNS change.

for a middle

Explain which validation methods complete before the CNAME changes, TXT and Delegated DCV, and which only after, automatic HTTP and real-time.

for a senior

Run onboarding as a checklist: create early, pre-validate, issue the certificate, confirm both statuses through the API, then cut over, watching token expiry, CAA and Workers on DCV paths.

for a principal

Choose the default onboarding flow per customer segment, trading a few minutes of downtime for simpler setup, and decide when Delegated DCV is worth asking customers for.

## What went wrong The custom hostname was created with **automatic HTTP DCV** (`ssl.method` set to `http`), and probably relied on **real-time hostname validation**. Both wait for the customer's DNS change: - With automatic HTTP DCV, Cloudflare asks the certificate authority (CA) for a token and serves it from the edge at a `/.well-known/pki-validation/` path. That only works once `shop.customer.com` resolves to Cloudflare, and until the CA has checked it and the certificate is deployed, `ssl.status` is not `active`. - With real-time validation, Cloudflare validates the hostname only after it sees the customer's CNAME. That takes seconds at best and stretches along the retry backoff if the customer is slow. So at the moment of the CNAME change, browsers reached Cloudflare for a name with no matching edge certificate, and handshakes failed until issuance completed. The docs describe exactly this short downtime window for the automatic methods. ## The zero-downtime order 1. **Create the custom hostname early**, with a certificate method that does not need the cutover: `txt`, optionally automated with Delegated DCV. 2. **Pre-validate the hostname.** The customer adds the `ownership_verification` TXT record at `_cf-custom-hostname.shop.customer.com`, or serves the `ownership_verification_http` token at `/.well-known/cf-custom-hostname-challenge/<id>` on their current origin. Wait for `status: active`. 3. **Validate the certificate before the cutover.** Fetch `ssl.validation_records` with a `GET` after creation, since the `POST` response may not carry them yet, and have the customer add those TXT records under `_acme-challenge`. Wait for `ssl.status: active`. 4. **Only then** does the customer change the CNAME to the SaaS target. Both validations are done, so the first request finds a certificate. For teams that prefer HTTP DCV, the docs give an alternative: create the hostname with `"ssl": {"method": "http", "type": "dv"}`, pre-validate it by TXT, and have the customer serve the HTTP DCV token from `ssl.validation_records` on their current live origin, so the CA validates against today's DNS. ## Delegated DCV for the long run TXT tokens have to be placed again whenever a certificate is issued. **Delegated DCV** removes that chore: the customer places one record, `_acme-challenge.shop.customer.com CNAME shop.customer.com.<delegation hostname>`, using the value shown under **DCV Delegation for Custom Hostnames**. Cloudflare then writes the TXT tokens there at each issuance and renewal. The record must stay in place, and it needs a new value if the SaaS zone moves to another account. ## Traps on the way - **Token lifetime**: Let's Encrypt DCV tokens expire after 7 days; Google Trust Services and SSL.com tokens after 14. Tokens sent too far ahead must be refreshed. - **TXT is not exclusive**: for a non-wildcard hostname, Cloudflare still attempts HTTP validation once the CNAME points at the target, even when TXT was chosen, although `ssl.method` itself takes one value. - **Wildcards** cannot use HTTP DCV at all; use TXT or Delegated DCV. - **CAA**: the customer's CAA records, or those on the provider's target, can block the CA; the error appears in `ssl.validation_errors`. - **A Worker as fallback origin** must pass `/.well-known/pki-validation/*` and `/.well-known/acme-challenge/*` through unchanged. - **Slow customers**: hostname validation retries spread over seven days with gaps of up to four hours; a `PATCH` that repeats the hostname's `ssl` method and type asks for an immediate recheck. ## Confirming readiness before the flip A successful TLS handshake is not proof: Cloudflare can complete a handshake with another matching certificate before `ssl.status` changes, so the custom hostname details from the API are the source of truth. Before telling the customer to change the CNAME: 1. `GET` the custom hostname and confirm `status` is `active`. 2. Confirm `ssl.status` is `active` and `ssl.validation_errors` is empty. 3. Confirm the minimum TLS version and custom origin server, if any, are what the customer expects. ## Matching method to customer | Customer's priority | Hostname validation | Certificate validation | |---|---|---| | No downtime at all | TXT or HTTP-token pre-validation | TXT or Delegated DCV, before the cutover | | Fewest steps | real-time, on the CNAME | automatic HTTP, after the cutover |

  • The SaaS zone uses a Worker as its fallback origin, and new custom hostname certificates stay pending; what should you check?
    Cloudflare's DCV troubleshooting checklist says a Worker serving as the fallback origin must pass `/.well-known/pki-validation/*` and `/.well-known/acme-challenge/*` through unmodified. If the Worker answers or rewrites those paths, the CA cannot read its token. Check `ssl.validation_errors` on the custom hostname for the CA's own message.
  • How does Delegated DCV keep certificate renewals hands-off for SaaS customers?
    The customer places one CNAME, `_acme-challenge.<their hostname>` pointing at their hostname under your DCV delegation hostname, copied from the Custom Hostnames page. Cloudflare then writes the TXT tokens there for every issuance and renewal. The record must stay, and its value changes if your SaaS zone moves to another account.
  • A customer added their CNAME two days after you created the custom hostname; why might validation still lag, and how do you hurry it?
    Hostname validation retries follow a backoff spread over seven days, with gaps growing to four hours, so the next check may be hours away. Sending a `PATCH` that repeats the hostname's original `ssl` method and type triggers an immediate recheck instead of waiting for the next retry.

  • Choosing TXT stops Cloudflare from ever trying HTTP validation for the hostname.
  • Hostname pre-validation also issues the custom hostname's certificate.
  • DCV tokens never expire, so they can be sent to customers weeks ahead.
  • Wildcard custom hostnames can be validated with automatic HTTP DCV.
  • Once the custom hostname's status is active, the DNS cutover is safe.