Acme dns-01 ignores zone if its a subdomain of root domain

Issue Description

ACME DNS-01 creates _acme-challenge record in parent zone instead of the subdomain’s own zone.

Consider Domain example.com and subdomain z1.example.com, each with its own DNS zone. Both are mail domains with automatic DNS management.
Zone Origin is empty on both. The help text says an empty origin means the domain name itself is used. The ACME provider uses the DNS-01 challenge.

Expected Behavior

The challenge record is created in the z1.example.com zone, the same as the other DNS records, because Zone Origin is empty and the domain zone must be used.

Actual Behavior

When acme is triggered for z1.example.com, the _acme-challenge.z1 record is created in the example.com zone, not in the z1.example.com zone. This breaks the challenge since the acme provider never sees the record.
All other DNS records for the mail domains, such as DKIM, are created in the correct zone. Only acme is affected.The challenge record is created in the z1.example.com zone, the same as the other DNS records, because zone origin is empty and the domain name should be used.

A workaround is to set zone origin explicitly to z1.example.com on the subdomain

Reproduction Steps

  1. Configure two domains, one a subdomain in its own zonefile
  2. Set automatic DNS and Certificate, trigger the ACME challenge
  3. Challenge record is created in the root zone instead of the subzone.

Stalwart Version

v0.16.x

Installation Method

Docker

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

Additional Context

DNS provider is deSEC.io but I dont think its relevant.
Annoyingly the bug report tool converted the example domains to links and then complained about them.

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

Your report matches what the source does, and it’s a bug. Here is what I found in the v1.0 source, crates/common/src/network/acme/order.rs.

For a DNS-01 challenge, the zone is chosen like this:

let zone = dns_parameters.origin.as_deref()
    .or_else(|| psl::domain_str(domain))
    .unwrap_or(domain);

If Zone Origin is empty, the code does not use the mail domain name. It falls back to psl::domain_str(domain), which returns the registrable domain from the Public Suffix List. For z1.example.com that is example.com. So _acme-challenge.z1.example.com is written into the example.com zone, which matches what you saw.

This contradicts the empty-origin help text, which says the domain name itself is used. I only checked the source. I didn’t check whether the DKIM and other record paths resolve the zone differently, or whether v0.16.x behaves the same way.

Your workaround is correct. Set Zone Origin explicitly to z1.example.com on the subdomain’s DNS server object.

If you can, check whether this still happens on v1.0. The upgrade guide is here: Overview | Stalwart

Relevant docs: Challenge types | Stalwart

A community member or staff member will follow up on the fix.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

This was a bug in how the ACME DNS-01 challenge picked its zone. With Zone Origin empty, it used the registrable domain of the name being validated (example.com for z1.example.com) and ignored the domain’s own name, while DKIM and the other records already use the domain name, as the help text says. Now an empty origin means the domain name for ACME too, so _acme-challenge.z1.example.com goes into the z1.example.com zone. Names outside the domain’s zone still fall back to their registrable domain.

The fix ships in next week’s Stalwart release. Until you’ve upgraded, keep Zone Origin set to z1.example.com; once you’re on that release you can clear it again if you like.