Files
netbird/proxy/internal
mlsmaycon 0f777152d9 [management,proxy] Enforce custom domain validation and scope claims per account
A custom domain row was created and bound to a live service whether or not
its CNAME ownership check ever succeeded. Validated was computed once, stored,
and read only by the dashboard listing, so an account that never proved DNS
control still had its hostname routed and a certificate ordered for it. The
domain string was also claimed globally, with no expiry, so an abandoned
unvalidated row blocked that name for every other account permanently.

Cluster derivation now matches a custom domain only when it is validated, and
reports "domain is not validated" so the API tells the caller what to fix.
Service updates no longer fall back to the previously derived cluster when
derivation fails, which was a way around the same check.

Claims carry a claimed_at date and are evicted after 24h without validation.
Uniqueness is now per (account_id, domain); the global constraint is dropped
and replaced by a manager-side rule that only one account may hold a validated
row for a name. That matches what the check actually proves: control of the
zone, not the identity of the requester, so the first account to validate owns
the name and a later one is refused. Creation pre-checks both cases and returns
AlreadyExists without naming the holding account.

An hourly job re-checks validated domains and, after three consecutive failed
lookups, marks them unvalidated and restarts their claim window, so a domain
whose DNS moved away stops being served and eventually frees the name. Custom
domains are capped per account because each one becomes an ACME order against
issuance rate limits shared by every account on the cluster.

ProxyMapping carries the verdict and the proxy refuses to set up routes, auth,
or certificate management without it, so the domain cannot be served if the
management-side gate is ever regressed. This makes management the required
first upgrade: a proxy on this version drops mappings from an older management
that does not set the field.

The migration drops the old constraint before AutoMigrate (dropping it rebuilds
the table on SQLite, discarding its indexes) and backfills claimed_at from the
upgrade time, so pre-existing unvalidated rows get a full window to validate
before they expire.
2026-08-08 04:47:49 +00:00
..