Issue certificates with DNS-01 validation
ACME certificate authorities such as Let's Encrypt can verify that you control a domain by asking you to publish a TXT record on its _acme-challenge name. This is the DNS-01 challenge. It is the only challenge type that can issue wildcard certificates, and it works for servers that are not reachable from the internet.
Domain Chief has two endpoints for this: one publishes a challenge value and one deletes it. A token with the domainchief:acme:write scope can call them and nothing else, so a server that renews certificates never holds a token that can change your other DNS records.
Use an existing client when one fits:
- Certbot for servers that run Certbot.
- acme.sh for servers that run acme.sh.
- lego for servers that run lego.
- cert-manager for Kubernetes clusters.
- Caddy for sites served by Caddy.
- The libdns provider for Go programs that use libdns, such as CertMagic.
- The ACME endpoints directly when you build or extend your own ACME client.
Before you start
Domain requirements
The domain must be in the team that owns the token and must use Domain Chief hosted DNS. The challenge records are published in the hosted DNS zone, so a domain that uses other nameservers cannot be validated this way.
Create a token
Create a team access token with only the domainchief:acme:write scope. Select the team that owns the domains you issue certificates for.
A team access token keeps working when the person who created it leaves the team, and it never switches to another team. See authentication for the token types and scopes for what the scope allows.
Anyone holding the token can obtain certificates for every domain in the team. Store it like any other credential and give each server or cluster its own token, so you can revoke one without affecting the others.
Use an existing client
Certbot
The certbot-dns-domainchief plugin adds a dns-domainchief authenticator to Certbot. Install it the same way you installed Certbot:
Code
Save the token in a credentials file that only the user running Certbot can read:
Code
Then request a certificate:
Code
Certbot stores the credentials path and reuses it for renewals. The plugin waits a fixed time for the record to reach the nameservers before Certbot asks for validation. Raise it with --dns-domainchief-propagation-seconds if validation fails because the record was not found.
acme.sh
acme.sh 3.1.7 and later include the dns_domainchief DNS API. Run acme.sh --upgrade if you use an older version. Give acme.sh the token in an environment variable and request a certificate:
Code
acme.sh saves the token in ~/.acme.sh/account.conf and reuses it for renewals.
The plugin waits until every hosted DNS nameserver serves each challenge value before acme.sh asks for validation, so you don't need --dnssleep. This usually takes one to three minutes per name. In DNS alias mode, a --domain-alias that does not start with _acme-challenge. also needs the domainchief:dns:write scope, and acme.sh does not wait for those records. The acme.sh wiki describes the options.
lego
lego v5.7.0 and later include the domainchief DNS provider. Give lego the token in an environment variable and request a certificate:
Code
The provider waits until every hosted DNS nameserver serves each challenge value before lego asks for validation. This usually takes one to three minutes per name, but lego stops waiting after 120 seconds by default. Set DOMAINCHIEF_PROPAGATION_TIMEOUT to 600 so a slower update doesn't fail the request. The lego provider documentation lists every option.
cert-manager
The cert-manager-webhook-domainchief webhook adds Domain Chief as a DNS01 solver for cert-manager. Install it into the cert-manager namespace:
Code
Store the token in a Secret the webhook can read:
Code
Reference the webhook from an issuer's DNS01 solver:
Code
The webhook publishes the challenge on the _acme-challenge name in the domain's own hosted DNS zone, so the cnameStrategy: Follow solver option is not supported.
The webhook waits until every hosted DNS nameserver serves the challenge value before cert-manager asks for validation. This usually takes one to three minutes per challenge, and cert-manager validates challenges for the same name one at a time, so a certificate for example.com and *.example.com takes a few minutes longer than one for a single name. While it waits, the challenge shows the warning Error presenting challenge: challenge for … is not served by every hosted DNS nameserver yet. That is expected, and cert-manager presents the challenge again until the value is published.
The chart documentation lists every chart value, including how to read the Secret from other namespaces for namespaced issuers and how to run multiple replicas.
Caddy
The caddy-dns/domainchief module adds Domain Chief as a DNS provider for Caddy. Caddy plugins are compiled into the binary, so you need a Caddy binary that includes the module. Get one in any of these ways:
- Download it from the Caddy download page. The link selects the module for you, and the page shows it as one extra feature.
- Add it to an installed Caddy with
caddy add-package github.com/caddy-dns/domainchief. This experimental command downloads a new binary with your current plugins plus this module and replaces the installed one. If a package manager installed Caddy, its next upgrade replaces the binary again and removes the module. - Build it yourself with xcaddy:
Code
Give the Caddy process the token in an environment variable, then reference it in the tls directive of each site:
Code
The module waits until every hosted DNS nameserver serves the challenge value before Caddy asks for validation. This usually takes one to three minutes per certificate, so you don't need to set propagation_delay.
The module documentation shows the JSON configuration and how to fix common errors.
libdns
Go programs that manage DNS through libdns, such as CertMagic, can use the libdns/domainchief provider. The Caddy module uses the same provider.
Code
With WaitForPublication enabled, AppendRecords returns once every hosted DNS nameserver serves the challenge value, so you can ask for validation right away. Enable it when you solve DNS-01 challenges. Checking the nameservers yourself only reaches the ones near you, which can serve the value before the others do.
The provider sends TXT records on _acme-challenge names to the ACME endpoints, so solving DNS-01 challenges only needs the domainchief:acme:write scope. Reading and changing other records needs domainchief:dns:read or domainchief:dns:write, and listing zones needs domainchief:domains:read. The provider documentation describes how it handles TTLs, record types and retries.
Publish and delete challenges
Use these requests when you build your own ACME client or add Domain Chief to one. The flow for each challenge is:
- Your ACME client receives a DNS-01 challenge and computes the TXT value.
- Publish the value on the
_acme-challengename. - Repeat the publish request until
statusispublished. - Tell the certificate authority to validate the challenge.
- Delete the value once validation finishes, whether it succeeded or not.
Publish a challenge value
Send the fully qualified challenge name and the value to publish ACME challenge:
Code
The name must start with _acme-challenge.. A trailing dot is accepted, so you can pass the name exactly as most ACME libraries return it. The value is the base64url-encoded challenge value, without padding.
You don't send the domain. Domain Chief finds it from the name, using the most specific matching domain in the team. A new value returns 201 Created with an ACMEChallenge that includes the domain it chose:
Code
Publishing is safe to repeat. If the value is already published, Domain Chief returns the existing challenge with 200 OK instead of adding a second record. The next step uses this to check the status.
Other values on the same name are kept. A certificate for both example.com and *.example.com needs two values on _acme-challenge.example.com, and you can publish both before validating either.
Wait until the value is published
A successful response means Domain Chief saved the value, not that every nameserver serves it. The certificate authority can query any of the hosted DNS nameservers, and a nameserver that does not serve the value yet fails the validation.
Repeat the same publish request every 5 to 10 seconds and read the status field. A repeated request does not add a second record or change the zone, so it doesn't delay the publication.
status | What to do |
|---|---|
pending | Keep polling. The value is saved but not in the hosted DNS zone yet. |
publishing | Keep polling. Some nameservers don't serve the value yet. |
published | Ask the certificate authority to validate the challenge. |
failed | Stop polling. Delete the value and publish it again later. |
Treat an unknown status like publishing and keep polling until your timeout.
A new value usually reaches every nameserver within one to three minutes. Until then, every other change to the same domain's hosted DNS, including deleting another challenge value, starts that wait again. When you validate several challenges for the same domain, such as example.com and *.example.com:
- Publish every value first.
- Poll until each one is
published. - Validate the challenges.
- Delete the values after all validations finish.
Set a timeout of at least 10 minutes. If a value is still not published by then, delete it and report the failure.
Stop polling once the value is published or you have deleted it. A publish request after the delete publishes the value again.
You don't need to look up the record on the nameservers yourself. A lookup only reaches the nameservers near you, which can serve the value before the others do.
Delete a challenge value
After validation, delete the value with delete ACME challenge. Pass the same name and value as query parameters:
Code
Only that value is deleted. Values for other challenges on the same name stay published, so concurrent renewals don't remove each other's records.
Deleting a value that is not published also succeeds, so a cleanup step can run safely after a failed or repeated attempt. If your client crashes before cleaning up, Domain Chief removes challenge values automatically after 24 hours.
Handle errors
Errors use the standard error response. Branch on the HTTP status and, for 409 responses, on the code:
| Status | Meaning | What to do |
|---|---|---|
401 | The token is missing, expired, or revoked. | Replace the token. |
403 | The token has neither domainchief:acme:write nor domainchief:dns:write. | Create a token with domainchief:acme:write. |
404 | No domain in the team matches the challenge name. | Check that the domain is in the token's team. |
409 with dns.not_hosted | The domain does not use hosted DNS. | Retrying does not help until the domain uses hosted DNS. |
409 with dns.zone_busy or dns.zone_changed | Another hosted DNS change for the domain was running. | Retry after a few seconds. |
422 | The name or value is invalid. | Fix the request using the messages in errors. |
5xx | Domain Chief could not complete the request. | Retry with a growing delay. Publishing and deleting are safe to repeat. |
Treat unknown code values as permanent failures and report the message to the person running the client.