Certificates for hosts outside Salt's zones: HTTP-01 through a proxy group #81

Merged
calvin merged 6 commits from calvin/certificates-http01 into master 2026-11-15 07:01:51 +00:00 AGit
Owner

A customer keeps the DNS of their own domain elsewhere and only points a CNAME at the
load balancers. Salt can now get and renew a certificate for that host and serve it.
Nothing changes for a group or a certificate that does not use it.

The design as built (the eight points of the brief)

  1. Stateless HTTP-01. A proxy group has two new settings, http01_enabled (default off)
    and http01_provider_id. With them the generated configuration has one rule in the
    port 80 frontend, ahead of the redirect. The thumbprint is the RFC 7638 thumbprint of
    the provider's account key (SaltDns.Certificates.Thumbprint, tested with the RFC
    example key). Shaker is not changed and is told no tokens. One group answers for one
    provider: an HTTP-01 certificate through a group whose provider differs is refused,
    and a group's provider cannot be deleted while the group uses it.
  2. Kind external: exactly one host, no wildcard (refused with the reason), the host in
    no active zone of any organisation (own zone: use the normal certificate; another
    organisation's zone: refused, without naming whose). It belongs to the organisation and
    to the group, which serves it without an attachment.
  3. Pre-check before every order and every renewal, with Edges.resolve/1, a thin public
    wrapper over the lookup of the Name servers page (the same edge_resolver). No order
    is placed if the host does not point at the group; the message says what the host
    resolves to and what it should be. (What counts as "the group's addresses" was
    tightened after review, see below.)
  4. Order: the issuer asks for http-01; no TXT and no CAA record is written. Before the
    provider is told to validate, Salt asks for http://<host>/.well-known/acme-challenge/<token>
    itself (no redirect followed, 5 second limits) and fails the order with what came back.
  5. Routing: a route for a host in no zone was already allowed (route validation checks no
    zone); address records are not kept for it (the address plan only places names that lie
    in a zone). Verified, and covered by a test.
  6. Surfaces: console (a third choice in Certificates with the pre-check result and the
    exact record, and the bare-domain note; the HTTP-01 setting in the group settings; the
    certificate page), REST API and OpenAPI (host with proxy_group_id; needs the
    certificates grant of zone any and the proxy grant; http01_enabled and
    http01_provider_id on PATCH /proxy/groups/{group}), certificate events and the
    group's change history for the audit, the metric label host (external).
  7. Docs: docs/certificates.md, docs/shaker.md, docs/status-and-roadmap.md,
    CHANGELOG, README line.
  8. Tests: see below.

What differs from the brief, and why

  • The pre-check compares the addresses the host ends up at with the group's confirmed node
    addresses (see the review section). It does not read the CNAME chain hop by
    hop: the resolver the brief names returns addresses only, and a second resolver was
    not to be written. A CNAME to the group's name and A or AAAA records that are a subset
    of the nodes' addresses both pass; one foreign address fails.
  • CAA is not read (the resolver cannot). A CAA record that leaves the provider out fails
    the order with the provider's message. Documented.
  • The rule only answers tokens made of base64url characters (path_reg), so nothing else
    is echoed back. The brief's rule used path_beg.
  • No weekly budget of new certificates for external hosts: Salt has no public suffix
    list to know the registered domain. The daily limit of orders per certificate applies.
  • Zone grants: an external certificate has no zone, so a certificates grant of zone
    any is needed (and the proxy grant).

The rule as rendered

frontend salt_http_redirect from salt_http
    bind :::80 v4v6
    http-request return status 200 content-type text/plain lf-string "%[path,field(-1,/)].<thumbprint>\n" if { path_reg ^/[.]well-known/acme-challenge/[A-Za-z0-9_-]+$ }
    http-request redirect scheme https code 301

Migration

20261124090000_certificates_http01: new nullable columns certificates.kind and
certificates.proxy_group_id (references proxy_groups, nilify on delete),
proxy_groups.http01_enabled (default false) and proxy_groups.http01_provider_id
(references certificate_providers, nilify on delete), and certificates.zone_id loses
its NOT NULL (only an external certificate has none). Safe while the old code runs: old
inserts and updates do not touch the new columns. down deletes external certificates.

Security

The thumbprint is a hash of the public key; it lets nobody else obtain a certificate,
because the provider issues only to the account that completes an order and the account
key never leaves the encrypted store. It does mean the load balancers of a group with the
setting on answer the challenge path for every host, before routing and any backend.
Documented in docs/shaker.md. The self-check fetches a customer-controlled host name,
but only after the pre-check found it pointing at the group's own load balancers.

What was run, and what was only read

Run: a real HAProxy 3.4.7 container with the rendered file answers the challenge path
with token.thumbprint for any host, before the redirect, and still redirects everything
else (test/salt_dns/proxy/haproxy_integration_test.exs, tagged integration and docker).
The real Shaker binary (unchanged, the exchange test) accepted a state with the rule and
reported ok. The unit suite (1392 tests), and the integration tests of the certificate and
proxy modules (250 tests), pass locally; format, credo --strict and compile
--warnings-as-errors are clean. Integration tests of this change (they need the database):
http01_test.exs, http01_runner_test.exs, certificate_external_test.exs,
certificates_external_test.exs, the HAProxy container test and the exchange test.
Unit tests: thumbprint, names, the rendered configuration with and without the setting,
the issuer against a small ACME server of the test suite (issuer_http01_test.exs).

Only read: the docs of HAProxy 3.4 for lf-string and path_reg (then proven by running).

Not covered

No order at a real certificate authority, no real outside domain, no real load balancer
on port 80 from the internet, no Pebble run for HTTP-01, CAA of the customer's domain,
IPv6-only hosts, a customer DNS host that rewrites answers.

Review fixes (second commit, same PR)

  • HIGH 1a, ownership by route. An external certificate is ordered, and renewed, only for a
    host that is a route host of the same proxy group, in the same organisation. The route
    must exist first. A host that lies in no active zone can be routed by one group only
    (first come; the refusal says "is not available" and does not say who holds it). Wildcard
    routes and hosts inside a zone are not limited. This is checked in Proxy, not by a
    constraint, so two simultaneous requests could in theory both pass; the certificate
    check at order time reads the route again.
  • HIGH 1b, shared providers. A provider that belongs to no organisation is refused for
    HTTP-01 unless the operator sets SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS=on (new,
    default off, documented in docs/configuration.md with the risk). The provider of a
    group must belong to the group's organisation, checked when the group is saved and again
    before every order. The hosted case (one operator organisation, one group, its own
    provider, routes for many customers' hosts) works without the switch.
  • HIGH 1c, addresses. An address counts only when a node of the group that is not retired
    has it and has reported (its last signed status is within the group's status_max_age),
    and no node of another organisation's group claims it, typed in or as the address Salt saw
    it connect from. The strongest notion that exists is the signed status, which a node
    cannot fake without its key; Salt does not verify that a typed address is really the
    node's, so the self-check also proves that the address answers with this group's key
    authorisation. An address two organisations claim is nobody's: both lose it. Names the
    organisation controls (extra names, route hosts) are no longer used as evidence.
  • MEDIUM 2, self-fetch. The host is resolved once; every address must be a confirmed address
    of the group and a public one (SaltDns.AddressFilter: no loopback, private, link-local,
    unique-local, CGNAT, multicast), unless the test-only option :http01_allow_private is
    set. Salt connects to exactly that address with the host name in Host, follows no
    redirect, reads at most 512 bytes, stops after 8 seconds, and tells the caller only the
    status and whether it matched.
  • LOW: renewal re-checks group, route, zones, provider, failed-order limit and the pre-check;
    a certificate whose group or route is gone, or whose host a zone now covers, is disabled
    with the reason (event retired) like a zone certificate whose zone goes; host names need
    two labels and may not be localhost, an IP literal or end in a dot (Salt has no public
    suffix list and no dependency for one, so co.uk passes our check and the provider
    refuses it); at most 5 failed HTTP-01 orders per organisation in 24 hours, refused with the
    time they are allowed again; the zone-only paths (zone_caa, publish, unpublish, CAA
    sync, others_claim) no longer dereference zone_id for an external certificate;
    docs and CHANGELOG say that rolling the migration back deletes external certificates, that
    a customer's own HTTP-01 behind the load balancers is not possible while the setting is
    on, and give the order of steps for an operator (add the route, tell the customer the
    CNAME, wait until it resolves, order the certificate).
  • No migration change. One new environment variable, SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS.

Second review (third commit)

  • Route lock. The first-come check takes pg_advisory_xact_lock(hashtext('salt_dns.route:' || host))
    inside the transaction of put_route and replace_routes, before it looks, and holds it
    until the commit. before_order (first order and every renewal) and the request refuse a
    host that another group also routes, with the same non-revealing words (is not available).
    The migration prints outside hosts routed by more than one group; SaltDns.Release.duplicate_outside_routes/0
    lists them at any time; the operator must remove all but one route. Tests: proxy_route_race_test.exs
    (two tests on committed data, outside the sandbox) and http01_review_test.exs
    "routes that more than one group holds".
  • Address claims. Only a node that reported recently contests or claims an address. The older
    reported claim keeps it: the age is when the address was first typed in for that node
    (shaker_nodes.address_claims, new nullable column kept by set_addresses/4), the node's
    enrolment time for older rows, ties by node id. The connection address (suggested_address)
    is not a claim. The refused side gets a plain message ("also claimed by another organisation,
    which claimed it first"), a certificate event address_contested, and a row in its group's
    change history (once a day). There is no installation-level audit table, so the operator
    gets a log warning, a telemetry event and SaltDns.Release.address_collisions/0.
  • The self-fetch ignores the AddressFilter allowlist (AddressFilter.public_only?/1).
  • The console looks the host up when the field is left (phx-debounce="blur"). Req/Finch/Mint read
    no proxy environment variable (checked in the dependency sources), so nothing to configure.
  • Docs: reserving a host by routing it first, removing the route as the remedy, and that
    activating a zone retires other organisations' external certificates for hosts it covers.

Coverage and the third review (fourth commit)

  • Coverage. The quality step measures the suite without the database tests. The HTTP-01 logic
    is now in modules that need no database, each with unit tests: Http01.Claims (precedence),
    Http01.Precheck (verdicts, words, address names, the failed-order limit) and
    Http01.Challenge (which address is asked, and the real fetcher against a local server).
    lib/salt_dns/certificates/http01.ex keeps the database queries and is not in the skip
    list; its pure functions have unit tests. Measured with CI's command (MIX_ENV=test mix coveralls):
    90.2% (it was 88.4%). The threshold is unchanged, no file was added to the skip list.
  • Zone squat. A route for a host inside another organisation's active zone is refused ("is not
    available"); routes that already break it are listed by SaltDns.Release.duplicate_outside_routes/0, not deleted.
  • Claim age. The migration backfills shaker_nodes.address_claims with the migration time for
    every stored address; an unrecorded claim counts as the last of all, never as the enrolment time.
  • Pre-claim squat. A typed-in address counts for precedence only when corroborated by the address
    Salt itself saw the node connect from, recently. Corroborated beats uncorroborated; two
    corroborated claims go older-first; two uncorroborated claims are disputed and nobody keeps the
    address; one organisation alone keeps its uncorroborated address. The operator can assign an
    address (SaltDns.Release.assign_address/2, audited in the group's change history; new table
    proxy_address_assignments). The loser is told to ask the operator; every conflict is an event
    (daily). A node behind NAT can never corroborate; the assignment is its remedy (documented).
  • Blocked holder. A host routed by two groups gives the certificate an event route_conflict (at
    most daily), a log warning and a telemetry event.
  • Notes. Bulk replacements lock the hosts in sorted order (a test with overlapping replacements
    of different sizes deadlocks without it, 3 of 3 runs, and passes with it); the migration finds
    duplicate hosts first and tests zones only for those; the history-row and event dedup are
    check-then-insert, harmless, said in a comment.

Still open

A zone that becomes active after two routes exist is not re-checked until an order or renewal.
A node that cannot corroborate (NAT, tunnel) needs the operator's assignment in a dispute.
Nothing was run against a real certificate authority or outside domain.

Fourth review

  • Stale corroboration. The time Salt saw a node at its connection address was written only when the address changed, so a node connected for 20 minutes or more was never corroborated. It is now refreshed on connect and by every verified status of a connected node, with one conditional UPDATE (written at most every 5 minutes). Test: http01_review_test.exs "corroboration does not go stale" (goes through the real record_connection/2 with a 3-hour-old time).
  • Direct children count as own. A zone owned by a DIRECT child of the group's organisation counts as the group's own for the host and route ownership rules: exact and wildcard routes, routes_in_foreign_zones/0, and the HTTP-01 zone check. One level only; never the other direction; siblings and grandchildren are refused. Tests: "a group's own zones include its direct children's". Not done, a separate follow-up (S1): the group serving its children's zones and certificates; attach_certificate still refuses certificates of another organisation.
  • Zone activation takes the lock route changes share (shared for routes, exclusive for activation). Routes that already existed when a zone became active stay and are listed, not prevented. Test: "a route change waits for a zone that is becoming active".
  • A wildcard route above another organisation's zone is allowed; documented. A rolling-deploy note is in the docs. Assigning or unassigning an address records the operator and both groups (assign_address/3).
  • The exchange test that failed once: I could not make it deterministic. Candidates (not changed): free_port closes the port before use, the shared Endpoint restart, the 30-second eventually.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne

A customer keeps the DNS of their own domain elsewhere and only points a CNAME at the load balancers. Salt can now get and renew a certificate for that host and serve it. Nothing changes for a group or a certificate that does not use it. ## The design as built (the eight points of the brief) 1. Stateless HTTP-01. A proxy group has two new settings, `http01_enabled` (default off) and `http01_provider_id`. With them the generated configuration has one rule in the port 80 frontend, ahead of the redirect. The thumbprint is the RFC 7638 thumbprint of the provider's account key (`SaltDns.Certificates.Thumbprint`, tested with the RFC example key). Shaker is not changed and is told no tokens. One group answers for one provider: an HTTP-01 certificate through a group whose provider differs is refused, and a group's provider cannot be deleted while the group uses it. 2. Kind `external`: exactly one host, no wildcard (refused with the reason), the host in no active zone of any organisation (own zone: use the normal certificate; another organisation's zone: refused, without naming whose). It belongs to the organisation and to the group, which serves it without an attachment. 3. Pre-check before every order and every renewal, with `Edges.resolve/1`, a thin public wrapper over the lookup of the Name servers page (the same `edge_resolver`). No order is placed if the host does not point at the group; the message says what the host resolves to and what it should be. (What counts as "the group's addresses" was tightened after review, see below.) 4. Order: the issuer asks for `http-01`; no TXT and no CAA record is written. Before the provider is told to validate, Salt asks for `http://<host>/.well-known/acme-challenge/<token>` itself (no redirect followed, 5 second limits) and fails the order with what came back. 5. Routing: a route for a host in no zone was already allowed (route validation checks no zone); address records are not kept for it (the address plan only places names that lie in a zone). Verified, and covered by a test. 6. Surfaces: console (a third choice in Certificates with the pre-check result and the exact record, and the bare-domain note; the HTTP-01 setting in the group settings; the certificate page), REST API and OpenAPI (`host` with `proxy_group_id`; needs the `certificates` grant of zone `any` and the `proxy` grant; `http01_enabled` and `http01_provider_id` on `PATCH /proxy/groups/{group}`), certificate events and the group's change history for the audit, the metric label `host (external)`. 7. Docs: `docs/certificates.md`, `docs/shaker.md`, `docs/status-and-roadmap.md`, CHANGELOG, README line. 8. Tests: see below. ## What differs from the brief, and why * The pre-check compares the addresses the host ends up at with the group's confirmed node addresses (see the review section). It does not read the CNAME chain hop by hop: the resolver the brief names returns addresses only, and a second resolver was not to be written. A CNAME to the group's name and A or AAAA records that are a subset of the nodes' addresses both pass; one foreign address fails. * CAA is not read (the resolver cannot). A CAA record that leaves the provider out fails the order with the provider's message. Documented. * The rule only answers tokens made of base64url characters (`path_reg`), so nothing else is echoed back. The brief's rule used `path_beg`. * No weekly budget of new certificates for external hosts: Salt has no public suffix list to know the registered domain. The daily limit of orders per certificate applies. * Zone grants: an external certificate has no zone, so a `certificates` grant of zone `any` is needed (and the `proxy` grant). ## The rule as rendered ``` frontend salt_http_redirect from salt_http bind :::80 v4v6 http-request return status 200 content-type text/plain lf-string "%[path,field(-1,/)].<thumbprint>\n" if { path_reg ^/[.]well-known/acme-challenge/[A-Za-z0-9_-]+$ } http-request redirect scheme https code 301 ``` ## Migration `20261124090000_certificates_http01`: new nullable columns `certificates.kind` and `certificates.proxy_group_id` (references `proxy_groups`, nilify on delete), `proxy_groups.http01_enabled` (default false) and `proxy_groups.http01_provider_id` (references `certificate_providers`, nilify on delete), and `certificates.zone_id` loses its NOT NULL (only an external certificate has none). Safe while the old code runs: old inserts and updates do not touch the new columns. `down` deletes external certificates. ## Security The thumbprint is a hash of the public key; it lets nobody else obtain a certificate, because the provider issues only to the account that completes an order and the account key never leaves the encrypted store. It does mean the load balancers of a group with the setting on answer the challenge path for every host, before routing and any backend. Documented in `docs/shaker.md`. The self-check fetches a customer-controlled host name, but only after the pre-check found it pointing at the group's own load balancers. ## What was run, and what was only read Run: a real HAProxy 3.4.7 container with the rendered file answers the challenge path with `token.thumbprint` for any host, before the redirect, and still redirects everything else (`test/salt_dns/proxy/haproxy_integration_test.exs`, tagged integration and docker). The real Shaker binary (unchanged, the exchange test) accepted a state with the rule and reported ok. The unit suite (1392 tests), and the integration tests of the certificate and proxy modules (250 tests), pass locally; format, credo --strict and compile --warnings-as-errors are clean. Integration tests of this change (they need the database): `http01_test.exs`, `http01_runner_test.exs`, `certificate_external_test.exs`, `certificates_external_test.exs`, the HAProxy container test and the exchange test. Unit tests: thumbprint, names, the rendered configuration with and without the setting, the issuer against a small ACME server of the test suite (`issuer_http01_test.exs`). Only read: the docs of HAProxy 3.4 for `lf-string` and `path_reg` (then proven by running). ## Not covered No order at a real certificate authority, no real outside domain, no real load balancer on port 80 from the internet, no Pebble run for HTTP-01, CAA of the customer's domain, IPv6-only hosts, a customer DNS host that rewrites answers. ## Review fixes (second commit, same PR) * HIGH 1a, ownership by route. An external certificate is ordered, and renewed, only for a host that is a route host of the same proxy group, in the same organisation. The route must exist first. A host that lies in no active zone can be routed by one group only (first come; the refusal says "is not available" and does not say who holds it). Wildcard routes and hosts inside a zone are not limited. This is checked in `Proxy`, not by a constraint, so two simultaneous requests could in theory both pass; the certificate check at order time reads the route again. * HIGH 1b, shared providers. A provider that belongs to no organisation is refused for HTTP-01 unless the operator sets `SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS=on` (new, default off, documented in `docs/configuration.md` with the risk). The provider of a group must belong to the group's organisation, checked when the group is saved and again before every order. The hosted case (one operator organisation, one group, its own provider, routes for many customers' hosts) works without the switch. * HIGH 1c, addresses. An address counts only when a node of the group that is not retired has it and has reported (its last signed status is within the group's `status_max_age`), and no node of another organisation's group claims it, typed in or as the address Salt saw it connect from. The strongest notion that exists is the signed status, which a node cannot fake without its key; Salt does not verify that a typed address is really the node's, so the self-check also proves that the address answers with this group's key authorisation. An address two organisations claim is nobody's: both lose it. Names the organisation controls (extra names, route hosts) are no longer used as evidence. * MEDIUM 2, self-fetch. The host is resolved once; every address must be a confirmed address of the group and a public one (`SaltDns.AddressFilter`: no loopback, private, link-local, unique-local, CGNAT, multicast), unless the test-only option `:http01_allow_private` is set. Salt connects to exactly that address with the host name in `Host`, follows no redirect, reads at most 512 bytes, stops after 8 seconds, and tells the caller only the status and whether it matched. * LOW: renewal re-checks group, route, zones, provider, failed-order limit and the pre-check; a certificate whose group or route is gone, or whose host a zone now covers, is disabled with the reason (event `retired`) like a zone certificate whose zone goes; host names need two labels and may not be `localhost`, an IP literal or end in a dot (Salt has no public suffix list and no dependency for one, so `co.uk` passes our check and the provider refuses it); at most 5 failed HTTP-01 orders per organisation in 24 hours, refused with the time they are allowed again; the zone-only paths (`zone_caa`, publish, unpublish, CAA sync, `others_claim`) no longer dereference `zone_id` for an external certificate; docs and CHANGELOG say that rolling the migration back deletes external certificates, that a customer's own HTTP-01 behind the load balancers is not possible while the setting is on, and give the order of steps for an operator (add the route, tell the customer the CNAME, wait until it resolves, order the certificate). * No migration change. One new environment variable, `SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS`. ## Second review (third commit) * Route lock. The first-come check takes `pg_advisory_xact_lock(hashtext('salt_dns.route:' || host))` inside the transaction of `put_route` and `replace_routes`, before it looks, and holds it until the commit. `before_order` (first order and every renewal) and the request refuse a host that another group also routes, with the same non-revealing words (`is not available`). The migration prints outside hosts routed by more than one group; `SaltDns.Release.duplicate_outside_routes/0` lists them at any time; the operator must remove all but one route. Tests: `proxy_route_race_test.exs` (two tests on committed data, outside the sandbox) and `http01_review_test.exs` "routes that more than one group holds". * Address claims. Only a node that reported recently contests or claims an address. The older reported claim keeps it: the age is when the address was first typed in for that node (`shaker_nodes.address_claims`, new nullable column kept by `set_addresses/4`), the node's enrolment time for older rows, ties by node id. The connection address (`suggested_address`) is not a claim. The refused side gets a plain message ("also claimed by another organisation, which claimed it first"), a certificate event `address_contested`, and a row in its group's change history (once a day). There is no installation-level audit table, so the operator gets a log warning, a telemetry event and `SaltDns.Release.address_collisions/0`. * The self-fetch ignores the `AddressFilter` allowlist (`AddressFilter.public_only?/1`). * The console looks the host up when the field is left (`phx-debounce="blur"`). Req/Finch/Mint read no proxy environment variable (checked in the dependency sources), so nothing to configure. * Docs: reserving a host by routing it first, removing the route as the remedy, and that activating a zone retires other organisations' external certificates for hosts it covers. ## Coverage and the third review (fourth commit) * Coverage. The quality step measures the suite without the database tests. The HTTP-01 logic is now in modules that need no database, each with unit tests: `Http01.Claims` (precedence), `Http01.Precheck` (verdicts, words, address names, the failed-order limit) and `Http01.Challenge` (which address is asked, and the real fetcher against a local server). `lib/salt_dns/certificates/http01.ex` keeps the database queries and is not in the skip list; its pure functions have unit tests. Measured with CI's command (`MIX_ENV=test mix coveralls`): 90.2% (it was 88.4%). The threshold is unchanged, no file was added to the skip list. * Zone squat. A route for a host inside another organisation's active zone is refused ("is not available"); routes that already break it are listed by `SaltDns.Release.duplicate_outside_routes/0`, not deleted. * Claim age. The migration backfills `shaker_nodes.address_claims` with the migration time for every stored address; an unrecorded claim counts as the last of all, never as the enrolment time. * Pre-claim squat. A typed-in address counts for precedence only when corroborated by the address Salt itself saw the node connect from, recently. Corroborated beats uncorroborated; two corroborated claims go older-first; two uncorroborated claims are disputed and nobody keeps the address; one organisation alone keeps its uncorroborated address. The operator can assign an address (`SaltDns.Release.assign_address/2`, audited in the group's change history; new table `proxy_address_assignments`). The loser is told to ask the operator; every conflict is an event (daily). A node behind NAT can never corroborate; the assignment is its remedy (documented). * Blocked holder. A host routed by two groups gives the certificate an event `route_conflict` (at most daily), a log warning and a telemetry event. * Notes. Bulk replacements lock the hosts in sorted order (a test with overlapping replacements of different sizes deadlocks without it, 3 of 3 runs, and passes with it); the migration finds duplicate hosts first and tests zones only for those; the history-row and event dedup are check-then-insert, harmless, said in a comment. ## Still open A zone that becomes active after two routes exist is not re-checked until an order or renewal. A node that cannot corroborate (NAT, tunnel) needs the operator's assignment in a dispute. Nothing was run against a real certificate authority or outside domain. ## Fourth review * Stale corroboration. The time Salt saw a node at its connection address was written only when the address changed, so a node connected for 20 minutes or more was never corroborated. It is now refreshed on connect and by every verified status of a connected node, with one conditional UPDATE (written at most every 5 minutes). Test: `http01_review_test.exs` "corroboration does not go stale" (goes through the real `record_connection/2` with a 3-hour-old time). * Direct children count as own. A zone owned by a DIRECT child of the group's organisation counts as the group's own for the host and route ownership rules: exact and wildcard routes, `routes_in_foreign_zones/0`, and the HTTP-01 zone check. One level only; never the other direction; siblings and grandchildren are refused. Tests: "a group's own zones include its direct children's". **Not done, a separate follow-up (S1):** the group serving its children's zones and certificates; `attach_certificate` still refuses certificates of another organisation. * Zone activation takes the lock route changes share (shared for routes, exclusive for activation). Routes that already existed when a zone became active stay and are listed, not prevented. Test: "a route change waits for a zone that is becoming active". * A wildcard route above another organisation's zone is allowed; documented. A rolling-deploy note is in the docs. Assigning or unassigning an address records the operator and both groups (`assign_address/3`). * The exchange test that failed once: I could not make it deterministic. Candidates (not changed): `free_port` closes the port before use, the shared Endpoint restart, the 30-second `eventually`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
Certificates for hosts outside Salt's zones: HTTP-01 through a proxy group
All checks were successful
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline was successful
ci/woodpecker/pr/integration Pipeline was successful
a629b4b06d
A customer keeps the DNS of their own domain elsewhere and only points a CNAME at the
load balancers. Salt can now get and renew a certificate for that host and serve it.
Nothing changes for a group or a certificate that does not use it.

## The design as built (the eight points of the brief)

1. Stateless HTTP-01. A proxy group has two new settings, `http01_enabled` (default off)
   and `http01_provider_id`. With them the generated configuration has one rule in the
   port 80 frontend, ahead of the redirect. The thumbprint is the RFC 7638 thumbprint of
   the provider's account key (`SaltDns.Certificates.Thumbprint`, tested with the RFC
   example key). Shaker is not changed and is told no tokens. One group answers for one
   provider: an HTTP-01 certificate through a group whose provider differs is refused,
   and a group's provider cannot be deleted while the group uses it.
2. Kind `external`: exactly one host, no wildcard (refused with the reason), the host in
   no active zone of any organisation (own zone: use the normal certificate; another
   organisation's zone: refused, without naming whose). It belongs to the organisation and
   to the group, which serves it without an attachment.
3. Pre-check before every order and every renewal, with `Edges.resolve/1`, a thin public
   wrapper over the lookup of the Name servers page (the same `edge_resolver`). No order
   is placed if the host does not point at the group; the message says what the host
   resolves to and what it should be.
4. Order: the issuer asks for `http-01`; no TXT and no CAA record is written. Before the
   provider is told to validate, Salt asks for `http://<host>/.well-known/acme-challenge/<token>`
   itself (no redirect followed, 5 second limits) and fails the order with what came back.
5. Routing: a route for a host in no zone was already allowed (route validation checks no
   zone); address records are not kept for it (the address plan only places names that lie
   in a zone). Verified, and covered by a test.
6. Surfaces: console (a third choice in Certificates with the pre-check result and the
   exact record, and the bare-domain note; the HTTP-01 setting in the group settings; the
   certificate page), REST API and OpenAPI (`host` with `proxy_group_id`; needs the
   `certificates` grant of zone `any` and the `proxy` grant; `http01_enabled` and
   `http01_provider_id` on `PATCH /proxy/groups/{group}`), certificate events and the
   group's change history for the audit, the metric label `host (external)`.
7. Docs: `docs/certificates.md`, `docs/shaker.md`, `docs/status-and-roadmap.md`,
   CHANGELOG, README line.
8. Tests: see below.

## What differs from the brief, and why

* The pre-check compares the addresses the host ends up at with the addresses of the
  group's nodes and of the group's address names. It does not read the CNAME chain hop by
  hop: the resolver the brief names returns addresses only, and a second resolver was
  not to be written. A CNAME to the group's name and A or AAAA records that are a subset
  of the nodes' addresses both pass; one foreign address fails.
* CAA is not read (the resolver cannot). A CAA record that leaves the provider out fails
  the order with the provider's message. Documented.
* The rule only answers tokens made of base64url characters (`path_reg`), so nothing else
  is echoed back. The brief's rule used `path_beg`.
* No weekly budget of new certificates for external hosts: Salt has no public suffix
  list to know the registered domain. The daily limit of orders per certificate applies.
* Zone grants: an external certificate has no zone, so a `certificates` grant of zone
  `any` is needed (and the `proxy` grant).

## The rule as rendered

```
frontend salt_http_redirect from salt_http
    bind :::80 v4v6
    http-request return status 200 content-type text/plain lf-string "%[path,field(-1,/)].<thumbprint>\n" if { path_reg ^/[.]well-known/acme-challenge/[A-Za-z0-9_-]+$ }
    http-request redirect scheme https code 301
```

## Migration

`20261124090000_certificates_http01`: new nullable columns `certificates.kind` and
`certificates.proxy_group_id` (references `proxy_groups`, nilify on delete),
`proxy_groups.http01_enabled` (default false) and `proxy_groups.http01_provider_id`
(references `certificate_providers`, nilify on delete), and `certificates.zone_id` loses
its NOT NULL (only an external certificate has none). Safe while the old code runs: old
inserts and updates do not touch the new columns. `down` deletes external certificates.

## Security

The thumbprint is a hash of the public key; it lets nobody else obtain a certificate,
because the provider issues only to the account that completes an order and the account
key never leaves the encrypted store. It does mean the load balancers of a group with the
setting on answer the challenge path for every host, before routing and any backend.
Documented in `docs/shaker.md`. The self-check fetches a customer-controlled host name,
but only after the pre-check found it pointing at the group's own load balancers.

## What was run, and what was only read

Run: a real HAProxy 3.4.7 container with the rendered file answers the challenge path
with `token.thumbprint` for any host, before the redirect, and still redirects everything
else (`test/salt_dns/proxy/haproxy_integration_test.exs`, tagged integration and docker).
The real Shaker binary (unchanged, the exchange test) accepted a state with the rule and
reported ok. The unit suite (1392 tests), and the integration tests of the certificate and
proxy modules (250 tests), pass locally; format, credo --strict and compile
--warnings-as-errors are clean. Integration tests of this change (they need the database):
`http01_test.exs`, `http01_runner_test.exs`, `certificate_external_test.exs`,
`certificates_external_test.exs`, the HAProxy container test and the exchange test.
Unit tests: thumbprint, names, the rendered configuration with and without the setting,
the issuer against a small ACME server of the test suite (`issuer_http01_test.exs`).

Only read: the docs of HAProxy 3.4 for `lf-string` and `path_reg` (then proven by running).

## Not covered

No order at a real certificate authority, no real outside domain, no real load balancer
on port 80 from the internet, no Pebble run for HTTP-01, CAA of the customer's domain,
IPv6-only hosts, a customer DNS host that rewrites answers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
HTTP-01 for external hosts: fixes from the review
Some checks failed
ci/woodpecker/pr/quality Pipeline failed
ci/woodpecker/pr/integration unknown status
ci/woodpecker/pr/image Pipeline was successful
dd7be5c37f
One organisation must not obtain a certificate through another's load balancer.

* An external certificate is ordered and renewed only for a host that is a route host of
  the same proxy group, in the same organisation; the route must exist first. A host in no
  zone can be routed by one group only (first come, refusal without naming the holder).
* The provider of a group must belong to the group's organisation. A provider shared by
  the installation is refused unless SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS=on (default off).
* An address counts only when a node of the group has reported recently and no other
  organisation's group claims it. Names the organisation controls are not evidence.
* The self-fetch resolves once, asks only a confirmed public address, sends the host in the
  Host header, reads at most 512 bytes, follows no redirect and shows no body text.
* Renewal re-checks group, route, zones, provider, failed-order limit and the pre-check; a
  certificate whose group or route is gone, or whose host a zone now covers, is disabled
  with the reason. At most 5 failed HTTP-01 orders per organisation a day. Stricter host
  names. Zone-only code paths no longer dereference zone_id for an external certificate.
* Docs and CHANGELOG: rollback of the migration deletes external certificates; a customer's
  own HTTP-01 behind the load balancers is not possible while the setting is on; order of
  steps for an operator.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
HTTP-01 for external hosts: second review
Some checks failed
ci/woodpecker/pr/quality Pipeline failed
ci/woodpecker/pr/integration unknown status
ci/woodpecker/pr/image Pipeline was successful
340d9288d8
* The first-come rule for routes takes a database lock on the host name (advisory,
  transaction level) before it looks, in every path that adds or replaces routes. Every
  order and renewal refuses a host that another group routes as well (routes from before
  the rule). The migration prints such hosts; SaltDns.Release.duplicate_outside_routes/0
  lists them.
* Only a node that reported recently can contest an address; the older reported claim
  keeps it (new nullable column shaker_nodes.address_claims, the time each address was first
  typed in; enrolment time for older ones). The refused side is told, gets a certificate
  event and a change-history row; the operator gets a log warning, a telemetry event and
  SaltDns.Release.address_collisions/0. The connection address is no claim.
* The self-fetch ignores the AddressFilter allowlist: public addresses only.
* The console looks the host up when the field is left, not on every keystroke.
* Docs: a host can be reserved by routing it first; activating a zone retires external
  certificates for hosts it covers.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
HTTP-01 for external hosts: coverage and the third review
Some checks failed
ci/woodpecker/pr/integration Pipeline is pending
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline was canceled
0d8a14cbf2
* The pure parts of the HTTP-01 code are separate modules without a database
  (Http01.Claims, .Precheck, .Challenge with its fetcher), with unit tests; the quality
  step's coverage is 90.2% (was 88.4%) without lowering the threshold or skipping files.
* A route for a host inside another organisation's active zone is refused; existing ones
  are listed, not deleted.
* A typed-in address counts for precedence only when corroborated by the address Salt saw
  the node connect from; corroborated beats uncorroborated, two corroborated go older-first,
  two uncorroborated are disputed. An operator assignment (Release.assign_address/2, audited,
  new table proxy_address_assignments) decides a dispute. Addresses typed in before claim
  times were recorded are dated by the migration (backfilled), not by enrolment.
* A host routed by two groups gives the certificate an event (daily), a log warning and a
  telemetry event.
* Bulk route replacements lock hosts in sorted order (no deadlock). The migration's
  duplicate-host query finds duplicates first, then tests zones.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
Merge origin/master into certificates-http01
All checks were successful
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline was successful
ci/woodpecker/pr/integration Pipeline was successful
a4d0243d9f
Both sides kept in CHANGELOG.md and lib/salt_dns/release.ex. Migration order:
20261124090000 (HTTP-01, claims, assignments) then 20261125090000 (invitations); neither
depends on the other.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
HTTP-01 for external hosts: fourth review
All checks were successful
ci/woodpecker/pr/image Pipeline was successful
ci/woodpecker/pr/quality Pipeline was successful
ci/woodpecker/pr/integration Pipeline was successful
0c9673e152
* Corroboration stays fresh: the time Salt saw a node at its connection address is
  refreshed on connect and by every verified status (conditional UPDATE, at most every
  5 minutes), so a node connected for hours stays corroborated.
* A zone of a direct child organisation counts as the group's own for routing hosts and
  ordering (one level, never the other direction). Applied in check_host_free,
  routes_in_foreign_zones/0 and the HTTP-01 zone check. Serving the children's
  certificates through the group (attach_certificate) is NOT part of this.
* Activating a zone takes the lock route changes share.
* Assigning an address records the operator and both groups in the audit.
* Docs: wildcard above another organisation's zone, rolling deploy note, ownership limits.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DnYzaTxC2GmdSpvCNyHNne
calvin merged commit e301f4e4d9 into master 2026-11-15 07:01:51 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
external/salt-dns!81
No description provided.