Skip to content

Let's Encrypt wildcard certificates over DNS-01

Issuing and renewing wildcard certificates via the DNS-01 challenge — provider plugins, propagation timing, and least-privilege API tokens.

A wildcard certificate (*.example.com) is the only way Let’s Encrypt will let you sign an arbitrary number of subdomains without registering each one in advance. Wildcards are restricted to the DNS-01 challenge — you must prove control of the zone, not just an HTTP path. This article covers the provider plugins, the API token scoping you actually want, and the renewal automation that does not break when DNS is slow.

How to verify

Check that a wildcard cert is in place and that its renewal config uses DNS-01:

sudo certbot certificates
openssl x509 -in /etc/letsencrypt/live/example.com/cert.pem -noout -text \
  | grep -E 'DNS:|Not After'
sudo grep -E 'authenticator|dns_' /etc/letsencrypt/renewal/example.com.conf
dig +short _acme-challenge.example.com TXT @1.1.1.1
sudo certbot renew --dry-run --cert-name example.com

The TXT lookup catches the most common failure: a previous run left a stale challenge record that confuses the next renewal.

What’s happening

DNS-01 works by writing a TXT record at _acme-challenge.<domain> with a token derived from your account key. The ACME server queries the authoritative nameservers for that record and signs the cert when it sees the expected value. For wildcards, Let’s Encrypt also checks _acme-challenge.<domain> for the apex even if you only requested *.example.com — both records must be present.

The “DNS provider plugin” is the piece of certbot (or alternative client) that calls your DNS API to create and delete the TXT record. Each plugin has its own credentials file and its own propagation delay assumption. certbot ships plugins for Cloudflare, Route 53, DigitalOcean, Google, OVH, and a handful of others; for unsupported providers, the acme-dns proxy or a manual hook is the fallback.

The credentials matter. A Cloudflare global API key has permission to delete every record in every zone on the account. The plugin only needs Zone:DNS:Edit on the specific zone — give it that and nothing more.

The procedure

  1. Install the right plugin. sudo apt install python3-certbot-dns-cloudflare (or python3-certbot-dns-route53, etc.). Verify it loaded with sudo certbot plugins.
  2. Create a scoped API token. In Cloudflare’s dashboard, generate a token with Zone:DNS:Edit on a single zone. In Route 53, attach an IAM policy granting route53:ChangeResourceRecordSets only on the hosted zone ID.
  3. Write the credentials file with 0600 permissions. sudo install -m 0600 /dev/null /etc/letsencrypt/cloudflare.ini && sudo tee /etc/letsencrypt/cloudflare.ini <<'EOF'\ndns_cloudflare_api_token = <token>\nEOF. The plugin refuses to read a credentials file with permissions wider than 0640.
  4. Issue the wildcard. sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini --dns-cloudflare-propagation-seconds 60 -d "example.com" -d "*.example.com" --email ops@example.com --agree-tos. The propagation-seconds flag is the wait before certbot tells ACME the TXT is live; raise it on providers with sluggish APIs.
  5. Confirm the renewal config persists the credentials path. sudo grep dns_cloudflare /etc/letsencrypt/renewal/example.com.conf. If you regenerate the token, update both the credentials file and the renewal config — certbot does not re-prompt.
  6. Add a deploy hook that reloads everything serving the wildcard. sudo tee /etc/letsencrypt/renewal-hooks/deploy/wildcard.sh <<'EOF'\n#!/bin/sh\nset -e\nsystemctl reload nginx\nsystemctl reload haproxy\nEOF\nsudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/wildcard.sh.
  7. Test the full path. sudo certbot renew --dry-run --cert-name example.com. The dry run hits staging, writes a real TXT, then deletes it — if your token lacks delete permission, the test fails here, not at first renewal.

Common pitfalls

  • A wildcard does not cover the apex automatically. *.example.com matches www.example.com but NOT example.com — request both in the same cert if you need both.
  • Cloudflare proxied zones (orange cloud) still respond to TXT lookups, but if your zone uses DNSSEC, propagation can take longer than the default 10 seconds — bump --dns-cloudflare-propagation-seconds 120 or higher.
  • Route 53 uses a different timing model: the plugin polls until the ChangeResourceRecordSets change is INSYNC before declaring victory. The propagation flag has less effect there.
  • Some DNS providers cache TXT lookups aggressively at their resolvers — if you see “DNS problem: NXDOMAIN looking up TXT”, confirm the record exists by querying an authoritative nameserver directly with dig +trace.
  • Storing the credentials file outside /etc/letsencrypt/ (e.g. in your home directory) means a umask change or a directory move can silently break renewal weeks later. Keep it next to the renewal config.

In the engagements we run, wildcard certs are paired with the DNS provider’s audit log: every TXT mutation is correlated to a known certbot run, and any unexplained record triggers a ticket. That kind of monitoring lives in Managed Operations — TLS is not “set and forget” once the wildcard is in place. For non-wildcard provisioning, see letsencrypt-certbot-basics.