Automate Certbot DNS Validation With a Scoped DNS Credential

Set up Certbot DNS-01 for a domain you control. Scope the Cloudflare token, verify the TXT challenge, and test automatic renewal.

FBFenwei BianAuthorNov 24, 2026
  • https
  • certbot
  • dns-validation
  • guide

Certbot's Cloudflare DNS plugin can create and remove the TXT record for a DNS-01 challenge in a zone you control. DNS-01 works for wildcard certificate validation. The renewal task needs a usable token every time it validates, so treat token custody and replacement as part of the certificate setup.

Confirm the challenge uses the zone you can edit

Let's Encrypt checks a TXT value at the ACME challenge name. For a certificate that covers example.com and *.example.com, the challenge owner is _acme-challenge.example.com. If the old certificate config points to a provider that no longer serves the zone, replacing the timer will not repair renewal. Check who is authoritative for the challenge name first.

Install the matching Certbot DNS plugin using the instructions for your platform. For Cloudflare, the plugin documentation specifies an API token with Zone:DNS:Edit on the necessary zone or zones. The zone restriction limits reach to the selected zone, but this permission can still edit DNS records beyond the one challenge label. Keep the token out of repositories, command arguments, build logs and shared images.

Store the credential separately and run issuance

Store the plugin INI file somewhere readable by the Certbot task and restricted from unrelated processes. The plugin reads the value named dns_cloudflare_api_token; put the actual value in the protected file through your approved secret-handling process. This example passes only a credential file path:

certbot certonly --dns-cloudflare --dns-cloudflare-credentials /approved/private/cloudflare.ini -d example.com -d '*.example.com'

Replace the names and path with your own. Quote the wildcard so the shell passes it as text. Include the apex explicitly if you need it; a wildcard for first-level subdomains does not cover the apex by itself.

If challenge creation succeeds but validation fails, check the value at the authoritative servers during a controlled test. The plugin's --dns-cloudflare-propagation-seconds option controls how long it waits before requesting validation. Raising the delay can help when the DNS change needs more time. It cannot fix a record written to the wrong zone or a scope error on the token.

Test the setup under the actual renewal identity

Run certbot renew --dry-run with the same task identity, plugin installation and credential access as the scheduled job. A dry run can still make real temporary changes in the DNS zone, so run it on a test lineage when possible and confirm challenge cleanup. After a real renewal, verify the certificate actually served by your HTTPS endpoint and confirm the reload or import step works. When rotating the token, prove the replacement can write and clean up a challenge before revoking the old credential.

Sources and further reading

About the author(s)

Software Developer & Writer • Namefi
FBAuthor

Fenwei Bian is a software developer in her thirties who spends her working hours in pull requests and her weekends with her hands in soil or sawdust. Years of open source on GitHub taught her that names are interfaces: a good one is clear, honest about what it does, and kind to whoever has to use it next.

She gardens because it rewards patience and punishes wishful thinking, and she does woodwork because a joint either fits or it doesn't. Both habits show up in how she writes about naming — measure twice, check the source, and don't sand over a rough spot and hope no one notices.

For Namefi she writes about how domain markets actually move, the practical trade-offs of tokenizing and flipping names, and picking a domain you'll still be glad you own in twenty years.

Related guides

Discuss this post

View the discussion on Namefi Discuss