Skip to content

DNS challenge requires several CNAME in some cases #2386

@daschg

Description

@daschg

Welcome

  • Yes, I'm using a binary release within 2 latest releases.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).

What did you expect to see?

In my setup, the dns entries cannot be created via API. A second domain is served by cloudflare, where records can be created via API Calls.0
Acme supports cname alias to have a different zone serving TXT records for the challenge.
This is not working in lego with cloudflare when the dns zone for the challenge is different than the domain certs are requested.
Example:
Domain to request cert: test1.local.mydomain.de
Domain for challenge: challenge-domain.eu
Cname for _acme-challenge.local.mydomain.de is challenge-domain.eu

#dig +nocmd _acme-challenge.local.mydomain.de cname +noall +answer
_acme-challenge.local.mydomain.de. 150 IN CNAME  challenge-domain.eu.

challenge-domain.eu is the only zone setup up in cloudflare.

This setup works perfect with acme.sh because there is an option to pass the challenge domain

# ./acme.sh --log --issue -d test1.local.mydomain.de --challenge-alias challenge-domain.de --dns dns_cf
[Do 2. Jan 12:43:10 UTC 2025] Using CA: https://acme.zerossl.com/v2/DV90
[Do 2. Jan 12:43:10 UTC 2025] Single domain='test1.local.mydomain.de'
[Do 2. Jan 12:43:14 UTC 2025] Getting webroot for domain='test1.local.mydomain.de'
[Do 2. Jan 12:43:14 UTC 2025] Adding TXT value: DTXXXXXW0ZCkU3PakmP3Ub5WV-D46_rI9Ux7JAz9qZM for domain: _acme-challenge.challenge-domain.de
[Do 2. Jan 12:43:17 UTC 2025] Adding record
[Do 2. Jan 12:43:18 UTC 2025] Added, OK
[Do 2. Jan 12:43:18 UTC 2025] The TXT record has been successfully added.
[Do 2. Jan 12:43:18 UTC 2025] Let's check each DNS record now. Sleeping for 20 seconds first.
[Do 2. Jan 12:43:39 UTC 2025] You can use '--dnssleep' to disable public dns checks.
[Do 2. Jan 12:43:39 UTC 2025] See: https://github.com/acmesh-official/acme.sh/wiki/dnscheck
[Do 2. Jan 12:43:39 UTC 2025] Checking test1.local.mydomain.de for _acme-challenge.challenge-domain.de
[Do 2. Jan 12:43:39 UTC 2025] Success for domain test1.local.mydomain.de '_acme-challenge.challenge-domain.de'.
[Do 2. Jan 12:43:39 UTC 2025] All checks succeeded
[Do 2. Jan 12:43:39 UTC 2025] Verifying: test1.local.mydomain.de
[Do 2. Jan 12:43:40 UTC 2025] Processing. The CA is processing your order, please wait. (1/30)
[Do 2. Jan 12:43:43 UTC 2025] The retryafter=86400 value is too large (> 600), will not retry anymore.
[Do 2. Jan 12:43:43 UTC 2025] Removing DNS records.
[Do 2. Jan 12:43:43 UTC 2025] Removing txt: DTXXXXXW0ZCkU3PakmP3Ub5WV-D46_rI9Ux7JAz9qZM for domain: _acme-challenge.challenge-domain.de
[Do 2. Jan 12:43:47 UTC 2025] Successfully removed

Lego seems to use the top-level domain when looking up the zone in cloudflare leading to an error

# docker run --rm -e CLOUDFLARE_DNS_API_TOKEN=<redacted key> goacme/lego -a --email "<redacted email>" --domains "test.auth.mydomain.de" --dns cloudflare run
2025/01/02 11:22:20 No key found for account <redacted email>. Generating a P256 key.
2025/01/02 11:22:20 Saved key to /.lego/accounts/acme-v02.api.letsencrypt.org/<redacted email>/keys/<redacted email>.key
2025/01/02 11:22:20 [DEBUG] GET https://acme-v02.api.letsencrypt.org/directory
2025/01/02 11:22:20 [INFO] acme: Registering account for <redacted email>
2025/01/02 11:22:20 [DEBUG] HEAD https://acme-v02.api.letsencrypt.org/acme/new-nonce
2025/01/02 11:22:20 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/new-acct
!!!! HEADS UP !!!!

Your account credentials have been saved in your Let's Encrypt
configuration directory at "/.lego/accounts".

You should make a secure backup of this folder now. This
configuration directory will also contain certificates and
private keys obtained from Let's Encrypt so making regular
backups of this folder is ideal.
2025/01/02 11:22:20 [INFO] [test.auth.mydomain.de] acme: Obtaining bundled SAN certificate
2025/01/02 11:22:20 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/new-order
2025/01/02 11:22:21 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] acme: Could not find solver for: tls-alpn-01
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] acme: Could not find solver for: http-01
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] acme: use dns-01 solver
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] acme: Preparing to solve DNS-01
2025/01/02 11:22:22 [INFO] [test.auth.mydomain.de] acme: Cleaning DNS-01 challenge
2025/01/02 11:22:23 [WARN] [test.auth.mydomain.de] acme: cleaning up failed: cloudflare: failed to find zone mydomain.de.: zone could not be found
2025/01/02 11:22:23 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:23 [INFO] Deactivating auth: https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:23 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:23 Could not obtain certificates:
        error: one or more domains had a problem:
[test.auth.mydomain.de] [test.auth.mydomain.de] acme: error presenting token: cloudflare: failed to find zone mydomain.de.: zone could not be found

What did you see instead?

expectation is that the TXT record is created for _acme-challenge.challenge-domain.de in cloudflare and not for mydomain.de

How do you use lego?

Docker image

Reproduction steps

  1. setup a cname for _acme-challenge.local.mydomain.de. with value challenge-domain.eu.
  2. setup a second domain in cloudflare
  3. create api key with read and edit permissions to the zone
  4. run lego with cloudflare dns provider

Version of lego

lego version 4.21.0 linux/amd64

Logs

# paste output here
# docker run --rm -e CLOUDFLARE_DNS_API_TOKEN=<redacted key> goacme/lego -a --email "<redacted email>" --domains "test.auth.mydomain.de" --dns cloudflare run
2025/01/02 11:22:20 No key found for account <redacted email>. Generating a P256 key.
2025/01/02 11:22:20 Saved key to /.lego/accounts/acme-v02.api.letsencrypt.org/<redacted email>/keys/<redacted email>.key
2025/01/02 11:22:20 [DEBUG] GET https://acme-v02.api.letsencrypt.org/directory
2025/01/02 11:22:20 [INFO] acme: Registering account for <redacted email>
2025/01/02 11:22:20 [DEBUG] HEAD https://acme-v02.api.letsencrypt.org/acme/new-nonce
2025/01/02 11:22:20 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/new-acct
!!!! HEADS UP !!!!

Your account credentials have been saved in your Let's Encrypt
configuration directory at "/.lego/accounts".

You should make a secure backup of this folder now. This
configuration directory will also contain certificates and
private keys obtained from Let's Encrypt so making regular
backups of this folder is ideal.
2025/01/02 11:22:20 [INFO] [test.auth.mydomain.de] acme: Obtaining bundled SAN certificate
2025/01/02 11:22:20 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/new-order
2025/01/02 11:22:21 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] AuthURL: https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] acme: Could not find solver for: tls-alpn-01
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] acme: Could not find solver for: http-01
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] acme: use dns-01 solver
2025/01/02 11:22:21 [INFO] [test.auth.mydomain.de] acme: Preparing to solve DNS-01
2025/01/02 11:22:22 [INFO] [test.auth.mydomain.de] acme: Cleaning DNS-01 challenge
2025/01/02 11:22:23 [WARN] [test.auth.mydomain.de] acme: cleaning up failed: cloudflare: failed to find zone mydomain.de.: zone could not be found
2025/01/02 11:22:23 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:23 [INFO] Deactivating auth: https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:23 [DEBUG] POST https://acme-v02.api.letsencrypt.org/acme/authz/2146941123/123472384365
2025/01/02 11:22:23 Could not obtain certificates:
        error: one or more domains had a problem:
[test.auth.mydomain.de] [test.auth.mydomain.de] acme: error presenting token: cloudflare: failed to find zone mydomain.de.: zone could not be found

Go environment (if applicable)

$ go version && go env
# paste output here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions