Certificates for hosts outside Salt's zones: HTTP-01 through a proxy group #81
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "calvin/certificates-http01"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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)
http01_enabled(default off)and
http01_provider_id. With them the generated configuration has one rule in theport 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 RFCexample 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.
external: exactly one host, no wildcard (refused with the reason), the host inno 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.
Edges.resolve/1, a thin publicwrapper over the lookup of the Name servers page (the same
edge_resolver). No orderis 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.)
http-01; no TXT and no CAA record is written. Before theprovider 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.
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.
exact record, and the bare-domain note; the HTTP-01 setting in the group settings; the
certificate page), REST API and OpenAPI (
hostwithproxy_group_id; needs thecertificatesgrant of zoneanyand theproxygrant;http01_enabledandhttp01_provider_idonPATCH /proxy/groups/{group}), certificate events and thegroup's change history for the audit, the metric label
host (external).docs/certificates.md,docs/shaker.md,docs/status-and-roadmap.md,CHANGELOG, README line.
What differs from the brief, and why
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.
the order with the provider's message. Documented.
path_reg), so nothing elseis echoed back. The brief's rule used
path_beg.list to know the registered domain. The daily limit of orders per certificate applies.
certificatesgrant of zoneanyis needed (and theproxygrant).The rule as rendered
Migration
20261124090000_certificates_http01: new nullable columnscertificates.kindandcertificates.proxy_group_id(referencesproxy_groups, nilify on delete),proxy_groups.http01_enabled(default false) andproxy_groups.http01_provider_id(references
certificate_providers, nilify on delete), andcertificates.zone_idlosesits NOT NULL (only an external certificate has none). Safe while the old code runs: old
inserts and updates do not touch the new columns.
downdeletes 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.thumbprintfor any host, before the redirect, and still redirects everythingelse (
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-stringandpath_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)
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 aconstraint, so two simultaneous requests could in theory both pass; the certificate
check at order time reads the route again.
HTTP-01 unless the operator sets
SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS=on(new,default off, documented in
docs/configuration.mdwith the risk). The provider of agroup 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.
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.
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_privateisset. Salt connects to exactly that address with the host name in
Host, follows noredirect, reads at most 512 bytes, stops after 8 seconds, and tells the caller only the
status and whether it matched.
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 needtwo labels and may not be
localhost, an IP literal or end in a dot (Salt has no publicsuffix list and no dependency for one, so
co.ukpasses our check and the providerrefuses 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, CAAsync,
others_claim) no longer dereferencezone_idfor 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).
SALT_DNS_CERT_HTTP01_SHARED_PROVIDERS.Second review (third commit)
pg_advisory_xact_lock(hashtext('salt_dns.route:' || host))inside the transaction of
put_routeandreplace_routes, before it looks, and holds ituntil the commit.
before_order(first order and every renewal) and the request refuse ahost 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/0lists 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".
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 byset_addresses/4), the node'senrolment 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'schange 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.AddressFilterallowlist (AddressFilter.public_only?/1).phx-debounce="blur"). Req/Finch/Mint readno proxy environment variable (checked in the dependency sources), so nothing to configure.
activating a zone retires other organisations' external certificates for hosts it covers.
Coverage and the third review (fourth commit)
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) andHttp01.Challenge(which address is asked, and the real fetcher against a local server).lib/salt_dns/certificates/http01.exkeeps the database queries and is not in the skiplist; 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.
available"); routes that already break it are listed by
SaltDns.Release.duplicate_outside_routes/0, not deleted.shaker_nodes.address_claimswith the migration time forevery stored address; an unrecorded claim counts as the last of all, never as the enrolment time.
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 tableproxy_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).
route_conflict(atmost daily), a log warning and a telemetry event.
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
http01_review_test.exs"corroboration does not go stale" (goes through the realrecord_connection/2with a 3-hour-old time).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_certificatestill refuses certificates of another organisation.assign_address/3).free_portcloses the port before use, the shared Endpoint restart, the 30-secondeventually.🤖 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. 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