From: William Lallemand Date: Mon, 23 Nov 2026 18:07:54 +0000 (+0000) Subject: BUG/MEDIUM: acme: match DNS challenges against all TXT records X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=c005617716521ebf8ef4b3afbe46bacb93cd68f4;p=haproxy.git BUG/MEDIUM: acme: match DNS challenges against all TXT records A certificate covering a domain and its wildcard requires two dns-01 TXT values at the same _acme-challenge name. The DNS parser retains both records, but the ACME resolver callback only copied the first one. With challenge-ready dns, one authorization could therefore never match its expected value and renewal would time out. Copy all TXT records into an owned singly linked list in one response-tree traversal, using istdup() for each value. Match each challenge against any entry and free the complete list on replacement, allocation failure, and resolver teardown. Keep successful empty-list responses valid as before and leave CLI readiness unchanged. This should be backported to 3.4, where the DNS propagation pre-check was introduced by 631fd5f99b. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 42f695948..b8ca23b9b 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -34688,17 +34688,17 @@ challenge-ready [,]* It is also possible to signal the "cli" readiness using the ACME.challenge_ready() lua function. - dns - perform a DNS pre-check by resolving the TXT record for + dns - perform a DNS pre-check by resolving the TXT records for "_acme-challenge." using the configured "default" resolvers section, not the authoritative name servers. The challenge is not - submitted until the TXT record matches the expected token. Results + submitted until a TXT record matches the expected token. Results may therefore be affected by DNS caching at the resolver level. The delay between resolution attempts is controlled by "dns-delay". This option is independent of the CLI command, so no human intervention is required. - For dns-01, the TXT record at "_acme-challenge." is - resolved and must match the expected token. For dns-persist-01, + For dns-01, the TXT records at "_acme-challenge." are + resolved and one must match the expected token. For dns-persist-01, the TXT record at "_validation-persist." is resolved and only its presence is checked. diff --git a/include/haproxy/acme_resolvers-t.h b/include/haproxy/acme_resolvers-t.h index dde061210..491ef03e8 100644 --- a/include/haproxy/acme_resolvers-t.h +++ b/include/haproxy/acme_resolvers-t.h @@ -8,6 +8,11 @@ struct dns_counters; /* TXT records for dns-01 */ +struct acme_rslv_txt { + struct acme_rslv_txt *next; + struct ist value; /* owned TXT value */ +}; + struct acme_rslv { enum obj_type obj_type; /* OBJ_TYPE_ACME_RSLV */ @@ -19,7 +24,7 @@ struct acme_rslv { int result; /* RSLV_STATUS_* — NONE until done */ int error_code; /* RSLV_RESP_* from the error callback */ struct task *acme_task; /* ACME task to wake on completion, or NULL */ - struct ist txt; /* first TXT record found */ + struct acme_rslv_txt *txt; /* owned list of TXT records */ int (*success_cb)(struct resolv_requester *, struct dns_counters *); int (*error_cb)(struct resolv_requester *, int); }; diff --git a/src/acme.c b/src/acme.c index a1da89bd0..377af2a7d 100644 --- a/src/acme.c +++ b/src/acme.c @@ -3013,20 +3013,24 @@ re: for (auth = ctx->auths; auth != NULL; auth = auth->next) { if (auth->ready == ctx->cfg->cond_ready) continue; - /* for dns-01, verify the TXT record content matches the - * expected token. for dns-persist-01, only check that - * the record exists since the resolver cannot read - * multiple strings within a single TXT entry */ + /* For dns-01, at least one TXT record must match the expected + * token. For dns-persist-01, only check that a record exists. + */ if (auth->rslv->result == RSLV_STATUS_VALID) { if (strcasecmp(ctx->cfg->challenge, "dns-01") == 0) { - if (isteq(auth->rslv->txt, auth->token)) { + struct acme_rslv_txt *txt; + + for (txt = auth->rslv->txt; txt != NULL; txt = txt->next) { + if (isteq(txt->value, auth->token)) + break; + } + if (txt) { auth->ready |= ACME_RDY_DNS; } else { send_log(NULL, LOG_NOTICE, - "acme: %s: dns-01: TXT record mismatch for \"_acme-challenge.%.*s\": expected \"%.*s\", got \"%.*s\"\n", + "acme: %s: dns-01: no matching TXT record for \"_acme-challenge.%.*s\": expected \"%.*s\"\n", ctx->store->path, (int)auth->dns.len, auth->dns.ptr, - (int)auth->token.len, auth->token.ptr, - (int)auth->rslv->txt.len, auth->rslv->txt.ptr); + (int)auth->token.len, auth->token.ptr); all_ready = 0; } } else if (strcasecmp(ctx->cfg->challenge, "dns-persist-01") == 0) { diff --git a/src/acme_resolvers.c b/src/acme_resolvers.c index 0659b757b..68ab49b90 100644 --- a/src/acme_resolvers.c +++ b/src/acme_resolvers.c @@ -17,40 +17,60 @@ #include #include -/* success callback, copy the TXT string to rslv->txt */ +static void acme_rslv_clear_txt(struct acme_rslv *rslv) +{ + struct acme_rslv_txt *txt; + + while (rslv->txt) { + txt = rslv->txt; + rslv->txt = txt->next; + istfree(&txt->value); + free(txt); + } +} + +/* Success callback, copy all TXT records to rslv->txt. */ static int acme_rslv_success_cb(struct resolv_requester *req, struct dns_counters *counters) { struct acme_rslv *rslv = objt_acme_rslv(req->owner); struct resolv_resolution *res; struct eb32_node *eb32; struct resolv_answer_item *item; + struct acme_rslv_txt *txt; if (!rslv) return 1; rslv->result = RSLV_STATUS_INVALID; + acme_rslv_clear_txt(rslv); res = req->resolution; if (!res) goto done; - /* XXX: must fail on multiple TXT entries for the same dn */ - - /* copy the data from the response tree */ + /* The response tree is shared and its records may be purged after this + * callback. Copy each TXT record into an owned list in a single pass. + */ for (eb32 = eb32_first(&res->response.answer_tree); eb32 != NULL; eb32 = eb32_next(eb32)) { item = eb32_entry(eb32, typeof(*item), link); - /* only handle 1 entry */ - if (item->type == DNS_RTYPE_TXT) { - int len = item->data_len; - - if (len > DNS_MAX_NAME_SIZE) - len = DNS_MAX_NAME_SIZE; - rslv->txt = istdup(ist2(item->data.target, len)); - break; + if (item->type != DNS_RTYPE_TXT) + continue; + txt = malloc(sizeof(*txt)); + if (!txt) + goto error; + txt->value = istdup(ist2(item->data.target, item->data_len)); + if (!isttest(txt->value)) { + free(txt); + goto error; } + txt->next = rslv->txt; + rslv->txt = txt; } - rslv->result = RSLV_STATUS_VALID; + goto done; + +error: + acme_rslv_clear_txt(rslv); done: /* if there's no other DNS task for this acme task, wake up acme_task */ if (HA_ATOMIC_SUB_FETCH(rslv->dnstasks, 1) == 0) { @@ -88,7 +108,7 @@ void acme_rslv_free(struct acme_rslv *rslv) HA_SPIN_UNLOCK(DNS_LOCK, &rslv->resolvers->lock); } free(rslv->hostname_dn); - istfree(&rslv->txt); + acme_rslv_clear_txt(rslv); free(rslv); }