This package contains a DNS provider module for Caddy. It can be used to manage DNS records with Cloudflare accounts.
dns.providers.cloudflare
This module gives the user two ways of configuring API tokens.
- Separate Zone and DNS Tokens (Deprecated)
- Zone Token:
Zone.Zone:Readpermission for the domain(s) you're managing with Caddy - DNS Token:
Zone.DNS:Editpermission for the domain(s) you're managing with Caddy
- Zone Token:
- Single API Token (Recommended)
- API Token:
Zone.Zone:ReadandZone.DNS:Editpermissions for the domain(s) you're managing with Caddy
- API Token:
Note: Deprecated separate tokens support is only there for backward compatibility and might be removed in a future version of this module.
To use this module for the ACME DNS challenge, configure the ACME issuer in your Caddy JSON like so:
{
"module": "acme",
"challenges": {
"dns": {
"provider": {
"name": "cloudflare",
"api_token": "{env.CF_API_TOKEN}"
}
}
}
}tls {
dns cloudflare {
zone_token {env.CF_ZONE_TOKEN}
api_token {env.CF_API_TOKEN}
}
}tls {
dns cloudflare {env.CF_API_TOKEN}
}You can replace the {env.CF_*} placeholders with the actual auth token if you prefer to put it directly in your config instead of an environment variable, however it is less secure.
See the associated README in the libdns package for important information about credentials.
NOTE: If migrating from Caddy v1, you will need to change from using a Cloudflare API Key to a scoped API Token. Please see link above for more information.
If providing your API token via an ENV var which is accidentally not set/available when running Caddy, you'll receive this error from Cloudflare.
Double check that Caddy has access to a valid CF API token.
Some environments may have trouble querying the _acme-challenge TXT record from Cloudflare. Verify in the Cloudflare dashboard that the temporary record is being created.
If the record does exist, your DNS resolver may be caching an earlier response before the record is valid. You can instead configure Caddy to use an alternative DNS resolver such as Cloudflare's official 1.1.1.1.
Add a custom resolver to the tls directive:
tls {
dns cloudflare {env.CF_API_TOKEN}
resolvers 1.1.1.1
}
Or with Caddy JSON to the acme module: challenges.dns.provider.resolvers: ["1.1.1.1"].
In order for the DNS challenge to succeed, your domain must be resolved by a public DNS server. For instance, if your domain happens to be defined in /etc/hosts, or being resolved by a local DNS server, the challenge will fail with this error.
The issue can be fixed either by changing the DNS configuration of the system running Caddy, or by adding a custom resolver to the tls directive:
tls {
dns cloudflare {env.CF_API_TOKEN}
resolvers 1.1.1.1
}