carlos / platform Public

fresh gate: no cached addresses; CNAME targets must be our names

Astra round 2 on #724 (stopping rule): two P1s on the out-of-zone CNAME
target path, both about unproven IPv6. Structural fix: a fresh answer
never contains an address from a cache or one owned outside the
verified zone.

domains: ResolveAll returns FreshAnswer{Addrs, Target}. Per
authoritative reply, the CNAME chain is followed only while it stays in
the zone; the first hop out ends the read and becomes Target with no
addresses, and no AAAA query is sent. In-zone A addresses need an AAAA
reply ending at the same in-zone terminal with addresses or NODATA (the
zone's SOA in authority); NXDOMAIN, a chain leaving the zone, another
terminal, an empty reply without the SOA, or any error refuses. The
LookupIP seam and targetAll are gone. Resolve (the stamp's) is
unchanged.

edge: the gate opens on a Target only when it has no addresses and is
the apps domain or under it, or a wildcard parent or under one (label
boundaries; empty apps domain matches nothing). newIssuerWarm takes the
apps domain and parents from edge.go. A third-party target gets no fresh
shortcut and waits for the cache, as before #724.

The real-Go-resolver SERVFAIL tests (domains and edge) are deleted: no
cached resolution of a target is left for them to exercise. The loop
test now waits for its second pass before asserting (Astra R2 P2).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 473193f270de8cbea8217780f352c1f11b311f56 parent d21953f
8 files changed, +613 −437
  • docs/superpowers/notes/census-proposal-issuer-fresh-gate-724.md +2 −2
  • internal/domains/freshdns.go +183 −134
  • internal/domains/freshdns_test.go +140 −192
  • internal/edge/certwarm.go +64 −15
  • internal/edge/certwarm_fresh_test.go +217 −89
  • internal/edge/edge.go +2 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-issuer-fresh-gate-724.tsv +4 −4

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-issuer-fresh-gate-724.md b/docs/superpowers/notes/census-proposal-issuer-fresh-gate-724.md
index efe32d277..2b6cb59c7 100644
--- a/docs/superpowers/notes/census-proposal-issuer-fresh-gate-724.md
+++ b/docs/superpowers/notes/census-proposal-issuer-fresh-gate-724.md
@@ -4,7 +4,7 @@ Ruling `census-ruling-issuer-fresh-gate-724`. The independent reviewer approves
| unit | change | read sites | what changed |
|---|---|---|---|
-| `internal/edge/edge.go` `RunWithActivatorReady` | body | unchanged (5) | builds the cert warm through newIssuerWarm (certwarm.go) instead of newCertWarm with dnsGate(warmResolver, edgeIPs): the same cached DNS gate plus, when the cached lookup has no answer, one fresh look at the name's zone nameservers via domains.FreshResolver.ResolveAll (public nameserver addresses only, existing destination policy), bounded per pass and probe; the answer only decides whether to place an ACME order. No file or root-owned read added, same 5 sites. |
+| `internal/edge/edge.go` `RunWithActivatorReady` | body | unchanged (5) | builds the cert warm through newIssuerWarm (certwarm.go), now also passing the apps domain and the wildcard parents it already computes: the same cached DNS gate plus, when the cached lookup has no answer, one fresh look at the name's zone nameservers via domains.FreshResolver.ResolveAll (public nameserver addresses only, existing destination policy; no cached or out-of-zone address in the answer), bounded per pass and probe; an out-of-zone CNAME target opens the gate only when it is under the apps domain or a wildcard parent. The answer only decides whether to place an ACME order. No file or root-owned read added, same 5 sites. |
Envelopes re-pinned: `internal/domains`, `internal/edge`.
@@ -14,6 +14,6 @@ Recorded dispositions, which each change must still satisfy:
- `internal/edge/edge.go` `RunWithActivatorReady`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): the inline home-map arming (newHomeMap, one boot Refresh, Store, run) moves unchanged into the new Edge.ArmHomeMap and is called here as e.ArmHomeMap(); same refresh, same timeout, same order. The reads are moved, none added.;rev3=census-ruling-agent-start-demo-1;basis=Logs the combined explicit wildcard parents through demoWildcardDomains; no new watcher or read loop.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: invoke the local admission Close before HTTP/HTTPS draining and door shutdown in both dev and normal listeners. Preserve merged main's startup behavior and its census basis; the same five read sites, no new reads.;rev3=census-ruling-stateless-replicas-3;basis=Task 1b: defer stopping and joining the edge's replica jobs at shutdown. Existing five direct read sites unchanged; no new reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Wrap dev, HTTP and HTTPS listeners through ConfigureGroupHairpin before serving. Indirectly read protected root boot identity and group-ingress.json; kernel local/peer addresses mark local ingress, never HTTP headers. Agent edge uses verified public source for accounting; direct read sites unchanged and absent marker keeps original listeners. CI fix removes interface enumeration: local peer must match snapshot primary IPv4, an ingress IPv4 installed locally by root, or loopback; kernel destination must still be an ingress EIP on port 80/443. Merge 45cebde4 retains deferred stopReplicaProbes alongside group listener wrapping and shutdown admission closure.;rev3=census-ruling-demo-api-site-route;basis=Change the startup failure context from load routes to initialize because origin validation now runs during construction. Existing five read sites unchanged; no new read or runtime authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Invoke the agent shutdown timestamp hook synchronously at SIGTERM/SIGINT receipt before closing admission in dev and TLS paths. No read added.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5: registers the https and http servers with the connection drain (conns.serve) so a drain can close idle keep-alive connections; no read added
-Seal: `707018faaa1fee3b47abb78389ae7854264e76621cc316889061adb69bf13e10` → `10cc1d3ea30180daea3755e94148e898f4e518b98fc76f1f1be62e845d365541`.
+Seal: `707018faaa1fee3b47abb78389ae7854264e76621cc316889061adb69bf13e10` → `6f67706041cbc12604a2473c755560d374a0af442933f7f55de39eda892dc2a2`.
Overlay: `internal/provision/testdata/plan14-root-reads-issuer-fresh-gate-724.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/domains/freshdns.go b/internal/domains/freshdns.go
index 0e76f73b9..b2ce3fefe 100644
--- a/internal/domains/freshdns.go
+++ b/internal/domains/freshdns.go
@@ -24,10 +24,11 @@ import (
// behind it may hold a "no such name" for the same SOA minimum. Asking the
// zone's own nameservers is the one answer no cache can hold back.
//
-// The cached resolver (LookupNS, LookupHost, LookupIP) is still used for the names
+// The cached resolver (LookupNS, LookupHost) is still used for the names
// around the answer that we are not waiting on: the zone's NS set, the
-// nameservers' own addresses, and a CNAME target outside the zone (in
-// practice the deployment's own edge name).
+// nameservers' own addresses, and, for Resolve only, a CNAME target outside
+// the zone (in practice the deployment's own edge name). ResolveAll never
+// takes an address from the cache; it reports such a target unresolved.
//
// The nameservers are named by tenant DNS, so their addresses are tenant
// input: every one passes publicNameserver before a socket is opened, and
@@ -36,13 +37,6 @@ import (
type FreshResolver struct {
LookupNS func(ctx context.Context, name string) ([]*net.NS, error)
LookupHost func(ctx context.Context, host string) ([]string, error)
- // LookupIP is the cached resolver for one address family ("ip4" or
- // "ip6"). ResolveAll uses it for an out-of-zone CNAME target, asking
- // each family on its own: LookupHost asks both at once and, with Go's
- // default StrictErrors off, returns the A records with no error when
- // the AAAA query fails. nil makes ResolveAll refuse such a target;
- // Resolve does not use it.
- LookupIP func(ctx context.Context, network, host string) ([]net.IP, error)
// LookupCNAME is the cached resolver's canonical name, used only to
// skip a level that is an alias; nil skips that shortcut (verifyZone
// still refuses a wrong zone).
@@ -112,19 +106,35 @@ func freshPublicName(name string) bool {
// An authoritative "no such name" is a *net.DNSError with IsNotFound, the
// same shape the cached resolver gives, so callers classify both alike.
func (r *FreshResolver) Resolve(host string) ([]string, error) {
- return r.lookup(host, false)
+ ans, err := r.lookup(host, false)
+ return ans.Addrs, err
}
-// ResolveAll is Resolve with the name's AAAA records too (see askAll). It
-// shares Resolve's timeout, backoff and zone verification.
-func (r *FreshResolver) ResolveAll(host string) ([]string, error) {
+// FreshAnswer is ResolveAll's answer: the name's addresses of both
+// families, or the name outside the zone its CNAME chain leaves for. Never
+// both. Every address in it was owned by a name inside the verified zone,
+// in an authoritative reply from that zone's own nameserver; none came from
+// a cache.
+type FreshAnswer struct {
+ // Addrs are the A and AAAA addresses at the end of the in-zone chain.
+ Addrs []string
+ // Target is the first name outside the zone the chain points at,
+ // unresolved; Addrs is then empty.
+ Target string
+}
+
+// ResolveAll answers for every address a client could be sent to (the cert
+// warm's gate: a CA validating over IPv6 against a foreign AAAA fails even
+// when every A record is ours). It shares Resolve's timeout, backoff and
+// zone verification, and reads the replies by askAll's rules.
+func (r *FreshResolver) ResolveAll(host string) (FreshAnswer, error) {
return r.lookup(host, true)
}
-func (r *FreshResolver) lookup(host string, all bool) ([]string, error) {
+func (r *FreshResolver) lookup(host string, all bool) (FreshAnswer, error) {
name := strings.ToLower(strings.TrimSuffix(host, "."))
if !freshPublicName(name) {
- return nil, fmt.Errorf("%w: %s has no public zone", errNoAuthority, name)
+ return FreshAnswer{}, fmt.Errorf("%w: %s has no public zone", errNoAuthority, name)
}
now := time.Now
if r.Now != nil {
@@ -143,7 +153,7 @@ func (r *FreshResolver) lookup(host string, all bool) ([]string, error) {
}
if at, ok := r.failedAt[name]; ok {
r.mu.Unlock()
- return nil, fmt.Errorf("%w: %w for %s (since %s)", errNoAuthority, ErrBackingOff, name, at.UTC().Format(time.RFC3339))
+ return FreshAnswer{}, fmt.Errorf("%w: %w for %s (since %s)", errNoAuthority, ErrBackingOff, name, at.UTC().Format(time.RFC3339))
}
r.mu.Unlock()
@@ -153,7 +163,7 @@ func (r *FreshResolver) lookup(host string, all bool) ([]string, error) {
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
- ips, err := r.resolve(ctx, name, all)
+ ans, err := r.resolve(ctx, name, all)
if err != nil && !isNotFound(err) {
r.mu.Lock()
@@ -173,7 +183,7 @@ func (r *FreshResolver) lookup(host string, all bool) ([]string, error) {
r.failedAt[name] = now()
r.mu.Unlock()
}
- return ips, err
+ return ans, err
}
func isNotFound(err error) bool {
@@ -196,7 +206,7 @@ func isNotFound(err error) bool {
// target, tied to the zone that really holds the name. A level the cached
// resolver already knows to be an alias is skipped without asking anyone,
// since a CNAME cannot sit at a zone apex.
-func (r *FreshResolver) resolve(ctx context.Context, name string, all bool) ([]string, error) {
+func (r *FreshResolver) resolve(ctx context.Context, name string, all bool) (FreshAnswer, error) {
last := fmt.Errorf("%w: no zone found for %s", errNoAuthority, name)
zones := 0
for zone := name; strings.Contains(zone, "."); zone = zone[strings.Index(zone, ".")+1:] {
@@ -206,7 +216,7 @@ func (r *FreshResolver) resolve(ctx context.Context, name string, all bool) ([]s
nss, err := r.LookupNS(ctx, zone)
if err != nil || len(nss) == 0 {
if ctx.Err() != nil {
- return nil, last
+ return FreshAnswer{}, last
}
continue
}
@@ -222,25 +232,29 @@ func (r *FreshResolver) resolve(ctx context.Context, name string, all bool) ([]s
if err := r.verifyZone(ctx, s, zone); err != nil {
last = err
if ctx.Err() != nil {
- return nil, last
+ return FreshAnswer{}, last
}
continue
}
- ask := r.ask
+ var (
+ ans FreshAnswer
+ err error
+ )
if all {
- ask = r.askAll
+ ans, err = r.askAll(ctx, s, name, zone)
+ } else {
+ ans.Addrs, err = r.ask(ctx, s, name, zone)
}
- ips, err := ask(ctx, s, name, zone)
if err == nil || isNotFound(err) {
- return ips, err
+ return ans, err
}
last = err
if ctx.Err() != nil {
- return nil, last
+ return FreshAnswer{}, last
}
}
}
- return nil, last
+ return FreshAnswer{}, last
}
// aliased reports whether the cached resolver says zone is a CNAME to some
@@ -409,34 +423,24 @@ func (r *FreshResolver) verifyZone(ctx context.Context, server netip.AddrPort, z
return fmt.Errorf("%w: %s does not hold zone %s", errNoAuthority, server, zone)
}
-var (
- // errNoData: the server answered with authority that name (or the end
- // of its in-reply CNAME chain, if that is name itself) has no records
- // of the asked type.
- errNoData = errors.New("fresh dns: no records of that type")
- // errInZoneNoData: the chain ends at another name inside the zone and
- // the reply carries no records of the asked type for it.
- errInZoneNoData = errors.New("fresh dns: in-zone CNAME target with no records of that type")
-)
-
-// askType sends one non-recursive IN query of qtype (A or AAAA) for name to
-// server, which verifyZone has shown holds zone, and reads the answer. A
-// CNAME chain in the reply is followed; if it ends outside zone with no
-// address in the reply, askType returns that target, unresolved, for the
-// caller to resolve through the cache. A chain that loops or runs past
-// freshMaxCNAMEs is not an answer.
-func (r *FreshResolver) askType(ctx context.Context, server netip.AddrPort, name, zone string, qtype dnsmessage.Type) (ips []string, target string, err error) {
- reply, err := r.exchange(ctx, server, name, qtype)
+// ask sends one non-recursive IN A query for name to server, which
+// verifyZone has shown holds zone, and reads the answer. A CNAME chain in
+// the reply is followed; if it ends outside zone with no address in the
+// reply, the target goes to the cached LookupHost. A chain that loops, runs
+// past freshMaxCNAMEs, or ends inside zone with no address is not an
+// answer.
+func (r *FreshResolver) ask(ctx context.Context, server netip.AddrPort, name, zone string) ([]string, error) {
+ reply, err := r.exchange(ctx, server, name, dnsmessage.TypeA)
if err != nil {
- return nil, "", err
+ return nil, err
}
fqdn := name + "."
switch reply.RCode {
case dnsmessage.RCodeSuccess:
case dnsmessage.RCodeNameError:
- return nil, "", &net.DNSError{Err: "no such host", Name: name, Server: server.String(), IsNotFound: true}
+ return nil, &net.DNSError{Err: "no such host", Name: name, Server: server.String(), IsNotFound: true}
default:
- return nil, "", fmt.Errorf("%w: %s answered %s for %s", errNoAuthority, server, reply.RCode, name)
+ return nil, fmt.Errorf("%w: %s answered %s for %s", errNoAuthority, server, reply.RCode, name)
}
current := fqdn
@@ -454,117 +458,162 @@ func (r *FreshResolver) askType(ctx context.Context, server netip.AddrPort, name
break
}
if seen[next] || hops >= freshMaxCNAMEs {
- return nil, "", fmt.Errorf("%w: CNAME chain from %s loops or runs too long", errNoAuthority, name)
+ return nil, fmt.Errorf("%w: CNAME chain from %s loops or runs too long", errNoAuthority, name)
}
seen[next] = true
current = next
}
+ var ips []string
for _, rr := range reply.Answers {
- if rr.Header.Class != dnsmessage.ClassINET || !strings.EqualFold(rr.Header.Name.String(), current) {
- continue
- }
- switch b := rr.Body.(type) {
- case *dnsmessage.AResource:
- if qtype == dnsmessage.TypeA {
- ips = append(ips, netip.AddrFrom4(b.A).String())
- }
- case *dnsmessage.AAAAResource:
- if qtype == dnsmessage.TypeAAAA {
- ips = append(ips, netip.AddrFrom16(b.AAAA).String())
- }
+ if a, ok := rr.Body.(*dnsmessage.AResource); ok && rr.Header.Class == dnsmessage.ClassINET &&
+ strings.EqualFold(rr.Header.Name.String(), current) {
+ ips = append(ips, netip.AddrFrom4(a.A).String())
}
}
if len(ips) > 0 {
- return ips, "", nil
+ return ips, nil
}
- target = strings.TrimSuffix(current, ".")
+ target := strings.TrimSuffix(current, ".")
if target == name {
- return nil, "", errNoData
+ // Authoritative, the name exists, and it has no A record.
+ return nil, &net.DNSError{Err: "no A record", Name: name, Server: server.String(), IsNotFound: true}
}
if target == zone || strings.HasSuffix(target, "."+zone) {
// In-zone target this server gave no address for: no fallback to
// a cache that may hold an old one.
- return nil, "", errInZoneNoData
+ return nil, fmt.Errorf("%w: %s ends at in-zone %s with no address", errNoAuthority, name, target)
}
- return nil, target, nil
+ return r.LookupHost(ctx, target)
}
-// ask is askType for A, with Resolve's long-standing errors: no A record at
-// the name is "not found", and an in-zone target with no address is not an
-// answer at all.
-func (r *FreshResolver) ask(ctx context.Context, server netip.AddrPort, name, zone string) ([]string, error) {
- ips, target, err := r.askType(ctx, server, name, zone, dnsmessage.TypeA)
- switch {
- case errors.Is(err, errNoData):
- return nil, &net.DNSError{Err: "no A record", Name: name, Server: server.String(), IsNotFound: true}
- case errors.Is(err, errInZoneNoData):
- return nil, fmt.Errorf("%w: %s ends at in-zone target with no address", errNoAuthority, name)
- case err == nil && target != "":
- return r.LookupHost(ctx, target)
- }
- return ips, err
+// inZone reports whether name (lower case, no trailing dot) is zone or
+// under it.
+func inZone(name, zone string) bool {
+ return name == zone || strings.HasSuffix(name, "."+zone)
}
-// askAll is ask plus the name's AAAA records from the same server, for a
-// caller that must see every address a client could be sent to (the cert
-// warm's gate: a CA validating over IPv6 against a foreign AAAA fails even
-// when every A record is ours). The AAAA half may be authoritatively empty
-// only at the name itself; a CNAME target the reply gives no AAAA for may
-// sit in a delegated child this server does not answer for, so that, and
-// any other AAAA failure, fails the whole answer. When the A half ended at an
-// out-of-zone target, the target is resolved per family (targetAll) and
-// nothing more is asked here.
-func (r *FreshResolver) askAll(ctx context.Context, server netip.AddrPort, name, zone string) ([]string, error) {
- v4, target, err := r.askType(ctx, server, name, zone, dnsmessage.TypeA)
- switch {
- case errors.Is(err, errNoData):
- return nil, &net.DNSError{Err: "no A record", Name: name, Server: server.String(), IsNotFound: true}
- case errors.Is(err, errInZoneNoData):
- return nil, fmt.Errorf("%w: %s ends at in-zone target with no address", errNoAuthority, name)
- case err != nil:
- return nil, err
- }
- if target != "" {
- return r.targetAll(ctx, target)
- }
- v6, _, err := r.askType(ctx, server, name, zone, dnsmessage.TypeAAAA)
- switch {
- case err == nil:
- return append(v4, v6...), nil
- case errors.Is(err, errNoData):
- // The name itself, with no CNAME, has no AAAA: complete evidence.
- return v4, nil
- case isNotFound(err):
- // NXDOMAIN for AAAA right after addresses for A: inconsistent.
- return nil, fmt.Errorf("%w: %s gave A records but NXDOMAIN for AAAA", errNoAuthority, name)
- }
- return nil, err
+// zoneReply is one authoritative reply as askAll reads it.
+type zoneReply struct {
+ // addrs are the addresses of the asked type owned by terminal.
+ addrs []string
+ // terminal is where the in-zone chain ends: name itself, or the last
+ // in-zone CNAME target.
+ terminal string
+ // out is the first CNAME target outside the zone, if the chain leaves
+ // it; addrs and terminal are then empty and nothing after it counts.
+ out string
+ // nodata: no addresses, and the authority section carries the zone's
+ // own SOA, which is how an authoritative server says "this name exists
+ // and has no records of that type" (RFC 2308). A delegated child's
+ // referral carries NS records instead and is not NODATA.
+ nodata bool
}
-// targetAll resolves an out-of-zone CNAME target through the cache, one
-// family at a time, for askAll. Any failure of either family fails the
-// answer, and a target with no A is not one. "Not found" for ip6 after
-// addresses for ip4 is NODATA for a name that exists: no IPv6.
-func (r *FreshResolver) targetAll(ctx context.Context, target string) ([]string, error) {
- if r.LookupIP == nil {
- return nil, fmt.Errorf("%w: no per-family lookup for CNAME target %s", errNoAuthority, target)
- }
- v4, err := r.LookupIP(ctx, "ip4", target)
+// readZoneReply sends one IN query of qtype for name to server, which
+// verifyZone has shown holds zone, and reads the reply by askAll's rules:
+// the CNAME chain is followed inside the reply only while it stays in the
+// zone; the first hop out of the zone ends the read, and nothing the reply
+// says about that name or beyond is used, since this server is not its
+// authority. Addresses count only when owned by the in-zone terminal.
+// NXDOMAIN is a "not found" error; any other failure is an error.
+func (r *FreshResolver) readZoneReply(ctx context.Context, server netip.AddrPort, name, zone string, qtype dnsmessage.Type) (zoneReply, error) {
+ reply, err := r.exchange(ctx, server, name, qtype)
if err != nil {
- return nil, err
+ return zoneReply{}, err
}
- if len(v4) == 0 {
- return nil, fmt.Errorf("%w: CNAME target %s gave no IPv4 addresses", errNoAuthority, target)
+ switch reply.RCode {
+ case dnsmessage.RCodeSuccess:
+ case dnsmessage.RCodeNameError:
+ return zoneReply{}, &net.DNSError{Err: "no such host", Name: name, Server: server.String(), IsNotFound: true}
+ default:
+ return zoneReply{}, fmt.Errorf("%w: %s answered %s for %s", errNoAuthority, server, reply.RCode, name)
}
- v6, err := r.LookupIP(ctx, "ip6", target)
- if err != nil && !isNotFound(err) {
- return nil, err
+ current := name
+ seen := map[string]bool{current: true}
+ for hops := 0; ; hops++ {
+ next := ""
+ for _, rr := range reply.Answers {
+ if c, ok := rr.Body.(*dnsmessage.CNAMEResource); ok && rr.Header.Class == dnsmessage.ClassINET &&
+ strings.EqualFold(rr.Header.Name.String(), current+".") {
+ next = strings.TrimSuffix(strings.ToLower(c.CNAME.String()), ".")
+ break
+ }
+ }
+ if next == "" {
+ break
+ }
+ if !inZone(next, zone) {
+ return zoneReply{out: next}, nil
+ }
+ if seen[next] || hops >= freshMaxCNAMEs {
+ return zoneReply{}, fmt.Errorf("%w: CNAME chain from %s loops or runs too long", errNoAuthority, name)
+ }
+ seen[next] = true
+ current = next
}
- var out []string
- for _, ip := range append(v4, v6...) {
- if a, ok := netip.AddrFromSlice(ip); ok {
- out = append(out, a.Unmap().String())
+ out := zoneReply{terminal: current}
+ for _, rr := range reply.Answers {
+ if rr.Header.Class != dnsmessage.ClassINET || !strings.EqualFold(rr.Header.Name.String(), current+".") {
+ continue
+ }
+ switch b := rr.Body.(type) {
+ case *dnsmessage.AResource:
+ if qtype == dnsmessage.TypeA {
+ out.addrs = append(out.addrs, netip.AddrFrom4(b.A).String())
+ }
+ case *dnsmessage.AAAAResource:
+ if qtype == dnsmessage.TypeAAAA {
+ out.addrs = append(out.addrs, netip.AddrFrom16(b.AAAA).String())
+ }
+ }
+ }
+ if len(out.addrs) == 0 {
+ for _, rr := range reply.Authorities {
+ if _, ok := rr.Body.(*dnsmessage.SOAResource); ok && rr.Header.Class == dnsmessage.ClassINET &&
+ strings.EqualFold(rr.Header.Name.String(), zone+".") {
+ out.nodata = true
+ }
}
}
return out, nil
}
+
+// askAll is ResolveAll's reading of one verified server. The rules, all
+// from that server's authoritative replies and nothing from any cache:
+//
+// - The A reply decides the shape. A chain that leaves the zone answers
+// with Target and no addresses, and no AAAA query is sent: a CNAME
+// owner has no other records, so the AAAA reply could only repeat it.
+// - A reply with no addresses at the in-zone terminal is no answer: "not
+// found" when the terminal is the name itself, an error otherwise.
+// - With A addresses, the AAAA reply must end at the SAME in-zone
+// terminal with addresses or as NODATA (the zone's SOA in authority).
+// An AAAA reply that leaves the zone, ends elsewhere, is NXDOMAIN, is
+// empty without that SOA, or fails, is an inconsistency: an error.
+//
+// There are no partial answers: anything not covered above is an error.
+func (r *FreshResolver) askAll(ctx context.Context, server netip.AddrPort, name, zone string) (FreshAnswer, error) {
+ a, err := r.readZoneReply(ctx, server, name, zone, dnsmessage.TypeA)
+ switch {
+ case err != nil:
+ return FreshAnswer{}, err
+ case a.out != "":
+ return FreshAnswer{Target: a.out}, nil
+ case len(a.addrs) == 0 && a.terminal == name:
+ return FreshAnswer{}, &net.DNSError{Err: "no A record", Name: name, Server: server.String(), IsNotFound: true}
+ case len(a.addrs) == 0:
+ return FreshAnswer{}, fmt.Errorf("%w: %s ends at in-zone %s with no address", errNoAuthority, name, a.terminal)
+ }
+ aaaa, err := r.readZoneReply(ctx, server, name, zone, dnsmessage.TypeAAAA)
+ switch {
+ case err != nil && isNotFound(err):
+ return FreshAnswer{}, fmt.Errorf("%w: %s gave A records but NXDOMAIN for AAAA", errNoAuthority, name)
+ case err != nil:
+ return FreshAnswer{}, err
+ case aaaa.out != "" || aaaa.terminal != a.terminal:
+ return FreshAnswer{}, fmt.Errorf("%w: %s: the AAAA reply's chain does not end where the A reply's does", errNoAuthority, name)
+ case len(aaaa.addrs) == 0 && !aaaa.nodata:
+ return FreshAnswer{}, fmt.Errorf("%w: %s gave no AAAA records and no NODATA for %s", errNoAuthority, name, a.terminal)
+ }
+ return FreshAnswer{Addrs: append(a.addrs, aaaa.addrs...)}, nil
+}
diff --git a/internal/domains/freshdns_test.go b/internal/domains/freshdns_test.go
index 1a08f4d0e..c0fbf1a5c 100644
--- a/internal/domains/freshdns_test.go
+++ b/internal/domains/freshdns_test.go
@@ -123,7 +123,6 @@ type world struct {
hosts map[string][]string // name -> addresses (the cache)
routes map[string]*fakeAuthority // "ip:53" -> server
cnames map[string]string // name -> cached canonical name
- ipErrs map[string]error // "ip4 name" or "ip6 name" -> LookupIP error
mu sync.Mutex
dialed []string
}
@@ -147,23 +146,6 @@ func (w *world) resolver(now *time.Time) *domains.FreshResolver {
}
return nil, errNotFound
},
- LookupIP: func(_ context.Context, network, host string) ([]net.IP, error) {
- host = strings.TrimSuffix(host, ".")
- if err, ok := w.ipErrs[network+" "+host]; ok {
- return nil, err
- }
- var out []net.IP
- for _, a := range w.hosts[host] {
- ip := net.ParseIP(a)
- if (ip.To4() != nil) == (network == "ip4") {
- out = append(out, ip)
- }
- }
- if len(out) == 0 {
- return nil, errNotFound
- }
- return out, nil
- },
LookupCNAME: func(_ context.Context, host string) (string, error) {
if c, ok := w.cnames[host]; ok {
return c, nil
@@ -554,102 +536,165 @@ func aaaaRecord(name, ip string) dnsmessage.Resource {
}
}
-// ResolveAll reports every address a client could be sent to: a foreign
-// AAAA next to our A must show up, or a gate that requires all addresses to
-// be ours would pass a name the CA validates over IPv6 elsewhere.
-func TestFreshResolverResolveAllIncludesAAAA(t *testing.T) {
- fa := startAuthority(t, "example.com", func(q dnsmessage.Question, r *dnsmessage.Message) bool {
- r.Authoritative = true
- switch q.Type {
- case dnsmessage.TypeA:
- r.Answers = []dnsmessage.Resource{aRecord("shop.example.com.", edgeIP)}
- case dnsmessage.TypeAAAA:
- r.Answers = []dnsmessage.Resource{aaaaRecord("shop.example.com.", "2001:db8::66")}
- }
- return true
- })
- ips, err := oneZone(fa).resolver(clock()).ResolveAll("shop.example.com")
- if err != nil || len(ips) != 2 || ips[0] != edgeIP || ips[1] != "2001:db8::66" {
- t.Fatalf("ResolveAll = %v, %v; want [%s 2001:db8::66]", ips, err, edgeIP)
+// byType is an authority for example.com that answers A and AAAA queries
+// with the records given for each (nil: an empty answer), with authority,
+// and counts the AAAA queries it gets. nodata puts the zone's SOA in the
+// authority section of an empty answer, as a real server's NODATA does.
+type byType struct {
+ a, aaaa []dnsmessage.Resource
+ nodata bool
+ rcode6 dnsmessage.RCode
+ aaaaN atomic.Int32
+}
+
+func (b *byType) answer(q dnsmessage.Question, r *dnsmessage.Message) bool {
+ r.Authoritative = true
+ rrs := b.a
+ if q.Type == dnsmessage.TypeAAAA {
+ b.aaaaN.Add(1)
+ rrs = b.aaaa
+ r.RCode = b.rcode6
}
- // Resolve (the stamp's) is unchanged: A only.
- if ips, err := oneZone(fa).resolver(clock()).Resolve("shop.example.com"); err != nil || len(ips) != 1 {
- t.Fatalf("Resolve = %v, %v; want A only", ips, err)
+ r.Answers = rrs
+ if b.nodata {
+ r.Authorities = []dnsmessage.Resource{soaRecord("example.com")}
}
+ return true
}
-func TestFreshResolverResolveAllAcceptsAnEmptyAAAA(t *testing.T) {
- fa := startAuthority(t, "example.com", func(q dnsmessage.Question, r *dnsmessage.Message) bool {
- r.Authoritative = true
- if q.Type == dnsmessage.TypeA {
- r.Answers = []dnsmessage.Resource{aRecord("shop.example.com.", edgeIP)}
+func (b *byType) resolveAll(t *testing.T) (domains.FreshAnswer, error) {
+ t.Helper()
+ fa := startAuthority(t, "example.com", b.answer)
+ return oneZone(fa).resolver(clock()).ResolveAll("shop.example.com")
+}
+
+const v6 = "2001:db8::66"
+
+// In-zone A and AAAA: both families.
+func TestFreshResolverResolveAllIncludesAAAA(t *testing.T) {
+ b := &byType{a: []dnsmessage.Resource{aRecord("shop.example.com.", edgeIP)}, aaaa: []dnsmessage.Resource{aaaaRecord("shop.example.com.", v6)}}
+ ans, err := b.resolveAll(t)
+ if err != nil || ans.Target != "" || len(ans.Addrs) != 2 || ans.Addrs[0] != edgeIP || ans.Addrs[1] != v6 {
+ t.Fatalf("ResolveAll = %+v, %v; want [%s %s]", ans, err, edgeIP, v6)
+ }
+}
+
+// In-zone A and an authoritative NODATA for AAAA (the zone's SOA in the
+// authority section): A only.
+func TestFreshResolverResolveAllAcceptsNODATAForAAAA(t *testing.T) {
+ b := &byType{a: []dnsmessage.Resource{aRecord("shop.example.com.", edgeIP)}, nodata: true}
+ ans, err := b.resolveAll(t)
+ if err != nil || len(ans.Addrs) != 1 || ans.Addrs[0] != edgeIP {
+ t.Fatalf("ResolveAll = %+v, %v; want [%s]", ans, err, edgeIP)
+ }
+}
+
+// Every other AAAA outcome after in-zone A records is an inconsistency or
+// an unknown, and fails the answer.
+func TestFreshResolverResolveAllRefusesAnUnprovenAAAA(t *testing.T) {
+ a := []dnsmessage.Resource{aRecord("shop.example.com.", edgeIP)}
+ for name, b := range map[string]*byType{
+ // Empty with no SOA: a delegated child's referral looks like this.
+ "empty without SOA": {a: a},
+ "NXDOMAIN": {a: a, rcode6: dnsmessage.RCodeNameError},
+ "SERVFAIL": {a: a, rcode6: dnsmessage.RCodeServerFailure},
+ "leaves the zone": {a: a, aaaa: []dnsmessage.Resource{
+ cnameRecord("shop.example.com.", "cdn.other.test."), aaaaRecord("cdn.other.test.", v6)}},
+ "ends at another in-zone name": {a: a, nodata: true, aaaa: []dnsmessage.Resource{
+ cnameRecord("shop.example.com.", "www.example.com.")}},
+ } {
+ if ans, err := b.resolveAll(t); err == nil {
+ t.Errorf("%s: ResolveAll = %+v, want an error", name, ans)
}
- return true // AAAA: authoritative NODATA
- })
- ips, err := oneZone(fa).resolver(clock()).ResolveAll("shop.example.com")
- if err != nil || len(ips) != 1 || ips[0] != edgeIP {
- t.Fatalf("ResolveAll = %v, %v; want [%s]", ips, err, edgeIP)
}
}
-func TestFreshResolverResolveAllFailsOnABrokenAAAA(t *testing.T) {
- fa := startAuthority(t, "example.com", func(q dnsmessage.Question, r *dnsmessage.Message) bool {
- if q.Type == dnsmessage.TypeAAAA {
- r.RCode = dnsmessage.RCodeServerFailure
- return true
+// The A reply's chain leaves the zone: the answer is that target, with no
+// addresses (the reply's own records for it are not this zone's to give,
+// and are ignored), no AAAA query is sent, and no cache is asked for the
+// target.
+func TestFreshResolverResolveAllReportsAnOutOfZoneTarget(t *testing.T) {
+ b := &byType{a: []dnsmessage.Resource{
+ cnameRecord("shop.example.com.", "edge.oncarlos.test."), aRecord("edge.oncarlos.test.", edgeIP)}}
+ fa := startAuthority(t, "example.com", b.answer)
+ w := oneZone(fa)
+ r := w.resolver(clock())
+ lookupHost := r.LookupHost
+ var asked []string
+ r.LookupHost = func(ctx context.Context, host string) ([]string, error) {
+ asked = append(asked, host)
+ return lookupHost(ctx, host)
+ }
+ ans, err := r.ResolveAll("shop.example.com")
+ if err != nil || ans.Target != "edge.oncarlos.test" || len(ans.Addrs) != 0 {
+ t.Fatalf("ResolveAll = %+v, %v; want Target edge.oncarlos.test and no addresses", ans, err)
+ }
+ if n := b.aaaaN.Load(); n != 0 {
+ t.Fatalf("AAAA queries = %d, want none", n)
+ }
+ for _, h := range asked {
+ if strings.TrimSuffix(h, ".") == "edge.oncarlos.test" {
+ t.Fatal("the cache was asked for the out-of-zone target")
}
- r.Authoritative = true
- r.Answers = []dnsmessage.Resource{aRecord("shop.example.com.", edgeIP)}
- return true
- })
- if ips, err := oneZone(fa).resolver(clock()).ResolveAll("shop.example.com"); err == nil {
- t.Fatalf("ResolveAll = %v, want an error: the AAAA half is unknown", ips)
+ }
+ // Resolve, the stamp's, still follows the target through the cache.
+ if ips, err := w.resolver(clock()).Resolve("shop.example.com"); err != nil || len(ips) != 1 || ips[0] != edgeIP {
+ t.Fatalf("Resolve = %v, %v; want [%s]", ips, err, edgeIP)
}
}
-// An out-of-zone CNAME target goes to the cached LookupHost, which answers
-// for both families; its IPv6 addresses come through.
-func TestFreshResolverResolveAllTakesBothFamiliesFromTheCNAMETarget(t *testing.T) {
- fa := startAuthority(t, "example.com", authoritative(cnameRecord("shop.example.com.", "edge.oncarlos.test.")))
- w := oneZone(fa)
- w.hosts["edge.oncarlos.test"] = []string{edgeIP, "2001:db8::7"}
- ips, err := w.resolver(clock()).ResolveAll("shop.example.com")
- if err != nil || len(ips) != 2 || ips[1] != "2001:db8::7" {
- t.Fatalf("ResolveAll = %v, %v; want both families from the target", ips, err)
+// An in-zone chain to an in-zone terminal: that terminal's addresses, both
+// families.
+func TestFreshResolverResolveAllFollowsAnInZoneChain(t *testing.T) {
+ b := &byType{
+ a: []dnsmessage.Resource{cnameRecord("shop.example.com.", "www.example.com."), aRecord("www.example.com.", edgeIP)},
+ aaaa: []dnsmessage.Resource{cnameRecord("shop.example.com.", "www.example.com."), aaaaRecord("www.example.com.", v6)},
+ }
+ ans, err := b.resolveAll(t)
+ if err != nil || ans.Target != "" || len(ans.Addrs) != 2 {
+ t.Fatalf("ResolveAll = %+v, %v; want both families of www.example.com", ans, err)
}
}
-// Astra R2 (follow-up) P1: a CNAME target the AAAA reply gives nothing for
-// may sit in a delegated child this server does not answer for, so its
-// IPv6 addresses are unknown: ResolveAll fails rather than reporting A only.
-func TestFreshResolverResolveAllRefusesAnUnresolvedAAAATarget(t *testing.T) {
- fa := startAuthority(t, "example.com", func(q dnsmessage.Question, r *dnsmessage.Message) bool {
- r.Authoritative = true
- r.Answers = []dnsmessage.Resource{cnameRecord("shop.example.com.", "app.sub.example.com.")}
- if q.Type == dnsmessage.TypeA {
- r.Answers = append(r.Answers, aRecord("app.sub.example.com.", edgeIP))
- }
- return true
- })
- if ips, err := oneZone(fa).resolver(clock()).ResolveAll("shop.example.com"); err == nil {
- t.Fatalf("ResolveAll = %v, want an error: the target's AAAA is unknown", ips)
+// A chain that leaves the zone after an in-zone hop: the first name outside
+// is the Target, and the reply's addresses for it are ignored.
+func TestFreshResolverResolveAllStopsWhereTheChainLeavesTheZone(t *testing.T) {
+ b := &byType{a: []dnsmessage.Resource{
+ cnameRecord("shop.example.com.", "www.example.com."),
+ cnameRecord("www.example.com.", "cdn.other.test."),
+ cnameRecord("cdn.other.test.", "edge.oncarlos.test."),
+ aRecord("edge.oncarlos.test.", edgeIP),
+ }}
+ ans, err := b.resolveAll(t)
+ if err != nil || ans.Target != "cdn.other.test" || len(ans.Addrs) != 0 {
+ t.Fatalf("ResolveAll = %+v, %v; want Target cdn.other.test and no addresses", ans, err)
+ }
+ if n := b.aaaaN.Load(); n != 0 {
+ t.Fatalf("AAAA queries = %d, want none", n)
}
}
-// An IPv6-only name (AAAA, no A) is not reported as pointing anywhere the
-// gate could accept: the A half is authoritatively empty and ResolveAll
-// says "not found", so a caller requiring every address to be ours refuses.
+// Addresses owned by any name other than the in-zone terminal never count,
+// out of zone or not.
+func TestFreshResolverResolveAllIgnoresStrayAddresses(t *testing.T) {
+ b := &byType{
+ a: []dnsmessage.Resource{aRecord("shop.example.com.", edgeIP), aRecord("other.test.", "192.0.2.99")},
+ aaaa: []dnsmessage.Resource{aaaaRecord("other.test.", v6)},
+ nodata: true,
+ }
+ ans, err := b.resolveAll(t)
+ if err != nil || len(ans.Addrs) != 1 || ans.Addrs[0] != edgeIP {
+ t.Fatalf("ResolveAll = %+v, %v; want [%s]", ans, err, edgeIP)
+ }
+}
+
+// An IPv6-only name (AAAA, no A) gives no answer the gate could accept: the
+// A half is authoritatively empty and ResolveAll says "not found".
func TestFreshResolverResolveAllRefusesAnIPv6OnlyName(t *testing.T) {
- fa := startAuthority(t, "example.com", func(q dnsmessage.Question, r *dnsmessage.Message) bool {
- r.Authoritative = true
- if q.Type == dnsmessage.TypeAAAA {
- r.Answers = []dnsmessage.Resource{aaaaRecord("shop.example.com.", "2001:db8::66")}
- }
- return true
- })
- ips, err := oneZone(fa).resolver(clock()).ResolveAll("shop.example.com")
- if len(ips) != 0 || err == nil {
- t.Fatalf("ResolveAll = %v, %v; want no addresses and an error", ips, err)
+ b := &byType{aaaa: []dnsmessage.Resource{aaaaRecord("shop.example.com.", v6)}, nodata: true}
+ ans, err := b.resolveAll(t)
+ if err == nil || len(ans.Addrs) != 0 || ans.Target != "" {
+ t.Fatalf("ResolveAll = %+v, %v; want nothing and an error", ans, err)
}
}
@@ -673,7 +718,6 @@ func TestFreshResolverResolveAllBacksOffPerName(t *testing.T) {
if fa.queries.Load() != sent {
t.Fatal("ResolveAll inside the backoff queried again")
}
- // Another name is not held back by this one's failure.
if _, err := r.ResolveAll("www.example.com"); errors.Is(err, domains.ErrBackingOff) {
t.Fatal("a different name was backed off")
}
@@ -686,99 +730,3 @@ func TestFreshResolverResolveAllBacksOffPerName(t *testing.T) {
t.Fatal("ResolveAll after Backoff did not query again")
}
}
-
-// recursive is a stand-in for the box's recursive resolver, answering
-// every A and AAAA query through answer, for driving Go's own resolver.
-func recursive(t *testing.T, answer func(q dnsmessage.Question, r *dnsmessage.Message) bool) *net.Resolver {
- rec := startAuthority(t, "", func(q dnsmessage.Question, r *dnsmessage.Message) bool {
- r.RecursionAvailable = true
- return answer(q, r)
- })
- return &net.Resolver{PreferGo: true, Dial: func(ctx context.Context, _, _ string) (net.Conn, error) {
- var d net.Dialer
- return d.DialContext(ctx, "udp", rec.addr)
- }}
-}
-
-// Astra #724 R1 P1-1: an out-of-zone CNAME target is resolved one family
-// at a time. Go's resolver, asked for both at once, returns the A records
-// with no error when the AAAA query fails (StrictErrors is off), so an
-// unknown IPv6 half would read as "no IPv6". With A ours and AAAA SERVFAIL
-// for the target, ResolveAll refuses.
-func TestFreshResolverResolveAllRefusesATargetWhoseAAAAFailed(t *testing.T) {
- fa := startAuthority(t, "example.com", authoritative(cnameRecord("shop.example.com.", "target.other.test.")))
- res := recursive(t, func(q dnsmessage.Question, r *dnsmessage.Message) bool {
- if q.Type == dnsmessage.TypeAAAA {
- r.RCode = dnsmessage.RCodeServerFailure
- return true
- }
- r.Answers = []dnsmessage.Resource{aRecord(q.Name.String(), edgeIP)}
- return true
- })
- // The premise: the both-families lookup hides the failure.
- if ips, err := res.LookupHost(context.Background(), "target.other.test"); err != nil || len(ips) != 1 {
- t.Fatalf("premise: LookupHost = %v, %v; want the A record and no error", ips, err)
- }
- r := oneZone(fa).resolver(clock())
- r.LookupIP = res.LookupIP
- if ips, err := r.ResolveAll("shop.example.com"); err == nil {
- t.Fatalf("ResolveAll = %v, want an error: the target's AAAA is unknown", ips)
- }
- // Resolve (A only, the stamp's) still answers.
- r = oneZone(fa).resolver(clock())
- cachedHost := r.LookupHost
- r.LookupHost = func(ctx context.Context, host string) ([]string, error) {
- if strings.TrimSuffix(host, ".") == "target.other.test" {
- return res.LookupHost(ctx, host)
- }
- return cachedHost(ctx, host)
- }
- if ips, err := r.Resolve("shop.example.com"); err != nil || len(ips) != 1 {
- t.Fatalf("Resolve = %v, %v; want the A record", ips, err)
- }
-}
-
-// A target that exists and has no AAAA (NODATA, "not found" for ip6 after
-// addresses for ip4) is complete: A only.
-func TestFreshResolverResolveAllAcceptsATargetWithNoAAAA(t *testing.T) {
- fa := startAuthority(t, "example.com", authoritative(cnameRecord("shop.example.com.", "target.other.test.")))
- res := recursive(t, func(q dnsmessage.Question, r *dnsmessage.Message) bool {
- if q.Type == dnsmessage.TypeA {
- r.Answers = []dnsmessage.Resource{aRecord(q.Name.String(), edgeIP)}
- }
- return true
- })
- r := oneZone(fa).resolver(clock())
- r.LookupIP = res.LookupIP
- ips, err := r.ResolveAll("shop.example.com")
- if err != nil || len(ips) != 1 || ips[0] != edgeIP {
- t.Fatalf("ResolveAll = %v, %v; want [%s]", ips, err, edgeIP)
- }
-}
-
-// Either family failing at the target fails the answer; a target with no A
-// at all is not an answer either.
-func TestFreshResolverResolveAllNeedsBothFamiliesOfTheTarget(t *testing.T) {
- fa := startAuthority(t, "example.com", authoritative(cnameRecord("shop.example.com.", "target.other.test.")))
- temp := &net.DNSError{Err: "server misbehaving", IsTemporary: true}
- for name, errs := range map[string]map[string]error{
- "ip6 failed": {"ip6 target.other.test": temp},
- "ip4 failed": {"ip4 target.other.test": temp},
- "no A": {"ip4 target.other.test": errNotFound},
- } {
- w := oneZone(fa)
- w.hosts["target.other.test"] = []string{edgeIP, "2001:db8::7"}
- w.ipErrs = errs
- if ips, err := w.resolver(clock()).ResolveAll("shop.example.com"); err == nil {
- t.Errorf("%s: ResolveAll = %v, want an error", name, ips)
- }
- }
- // No LookupIP at all: ResolveAll cannot ask per family and refuses.
- w := oneZone(fa)
- w.hosts["target.other.test"] = []string{edgeIP}
- r := w.resolver(clock())
- r.LookupIP = nil
- if ips, err := r.ResolveAll("shop.example.com"); err == nil {
- t.Errorf("ResolveAll without LookupIP = %v, want an error", ips)
- }
-}
diff --git a/internal/edge/certwarm.go b/internal/edge/certwarm.go
index 68cc61837..430a3856c 100644
--- a/internal/edge/certwarm.go
+++ b/internal/edge/certwarm.go
@@ -926,7 +926,7 @@ func dnsGate(resolve func(string) ([]string, error), edgeIPs func() []string) fu
}
func dnsGateAt(resolve func(string) ([]string, error), edgeIPs func() []string, now func() time.Time) func(string) bool {
- gate := issuerDNSGateAt(resolve, nil, edgeIPs, now)
+ gate := issuerDNSGateAt(resolve, nil, nil, edgeIPs, now)
return func(host string) bool { return gate(host, nil) }
}
@@ -935,12 +935,25 @@ func dnsGateAt(resolve func(string) ([]string, error), edgeIPs func() []string,
// zone's SOA minimum, and so can the upstream resolver behind it, so the
// cert would wait that long after the customer's record exists. When the
// cached lookup fails or returns no addresses, and the caller's count
-// allows, the gate asks fresh (the zone's own nameservers, every address of
-// both families) and applies the SAME rule to that answer. A positive cached
-// answer decides alone, even one pointing elsewhere. The empty edge set
-// still refuses first, before any lookup. Nothing is kept between calls:
-// each look stands alone. now is the clock for the edge set's reuse.
-func issuerDNSGateAt(resolve, fresh func(string) ([]string, error), edgeIPs func() []string, now func() time.Time) func(string, *freshCount) bool {
+// allows, the gate asks fresh: the zone's own nameservers, read by
+// domains.FreshResolver.ResolveAll, which never puts a cached address or an
+// address owned outside the zone into its answer. The fresh answer opens
+// the gate in one of two ways:
+//
+// - Addresses (both families, Target empty): every one is in the edge
+// set, the same rule as the cached answer.
+// - A Target, the name outside the zone the chain leaves for, with no
+// addresses: the target is one of OUR names (ours, see edgeNames). The
+// console tells customers to CNAME to edge.<apps domain>, so that
+// covers every target we advertise. A target anywhere else (a CDN, a
+// third party) gets no fresh shortcut: the name waits for the cache,
+// as it did before #724.
+//
+// A positive cached answer decides alone, even one pointing elsewhere. The
+// empty edge set still refuses first, before any lookup. Nothing is kept
+// between calls: each look stands alone. now is the clock for the edge
+// set's reuse; ours nil matches nothing.
+func issuerDNSGateAt(resolve func(string) ([]string, error), fresh func(string) (domains.FreshAnswer, error), ours func(string) bool, edgeIPs func() []string, now func() time.Time) func(string, *freshCount) bool {
var (
mu sync.Mutex
cached map[string]bool
@@ -983,12 +996,19 @@ func issuerDNSGateAt(resolve, fresh func(string) ([]string, error), edgeIPs func
if fresh == nil || !count.take() {
return false
}
- ips, err = fresh(host)
+ ans, err := fresh(host)
if errors.Is(err, domains.ErrBackingOff) {
count.giveBack()
return false
}
- if err != nil || !allOurs(set, ips) {
+ if err != nil {
+ return false
+ }
+ if ans.Target != "" {
+ if len(ans.Addrs) != 0 || ours == nil || !ours(ans.Target) {
+ return false
+ }
+ } else if !allOurs(set, ans.Addrs) {
return false
}
log.Printf("edge: cert warm: fresh DNS look says %s points here (cache had no answer)", host)
@@ -1004,7 +1024,6 @@ var (
warmFreshResolver freshAllResolver = &domains.FreshResolver{
LookupNS: net.DefaultResolver.LookupNS,
LookupHost: net.DefaultResolver.LookupHost,
- LookupIP: net.DefaultResolver.LookupIP,
LookupCNAME: net.DefaultResolver.LookupCNAME,
Backoff: warmFreshBackoff,
}
@@ -1014,16 +1033,46 @@ var (
// families (domains.FreshResolver.ResolveAll), because a CA validating over
// IPv6 against a foreign AAAA fails even when every A record is ours.
type freshAllResolver interface {
- ResolveAll(host string) ([]string, error)
+ ResolveAll(host string) (domains.FreshAnswer, error)
+}
+
+// edgeNames reports whether a CNAME target is one of this deployment's own
+// names: the apps domain or a name under it, or a wildcard parent or a name
+// under one. Matching is on label boundaries ("xapps.example" is not under
+// "apps.example"), case and a trailing dot aside. An empty apps domain
+// matches nothing; parents may be nil.
+func edgeNames(appsDomain string, parents func() []string) func(string) bool {
+ under := func(name, domain string) bool {
+ domain = strings.TrimSuffix(strings.ToLower(strings.TrimSpace(domain)), ".")
+ return domain != "" && (name == domain || strings.HasSuffix(name, "."+domain))
+ }
+ return func(name string) bool {
+ name = strings.TrimSuffix(strings.ToLower(name), ".")
+ if strings.TrimSpace(appsDomain) == "" || name == "" {
+ return false
+ }
+ if under(name, appsDomain) {
+ return true
+ }
+ if parents != nil {
+ for _, p := range parents() {
+ if under(name, p) {
+ return true
+ }
+ }
+ }
+ return false
+ }
}
// newIssuerWarm is the cert warm as the edge runs it with a deployment
// store: the DNS gate over the cached resolver, with the fresh look (#724)
-// when the cache has no answer. The gate's edge-set reuse runs on the
-// warm's own clock.
-func newIssuerWarm(hosts func() []string, getCert func(*tls.ClientHelloInfo) (*tls.Certificate, error), edgeIPs func() []string, issuer IssuerGate, store release.Store) *certWarm {
+// when the cache has no answer, accepting a CNAME target only when it is
+// one of edgeNames(appsDomain, parents). The gate's edge-set reuse runs on
+// the warm's own clock.
+func newIssuerWarm(hosts func() []string, getCert func(*tls.ClientHelloInfo) (*tls.Certificate, error), edgeIPs func() []string, appsDomain string, parents func() []string, issuer IssuerGate, store release.Store) *certWarm {
var w *certWarm
- gate := issuerDNSGateAt(warmCachedLookup, warmFreshResolver.ResolveAll, edgeIPs, func() time.Time { return w.now() })
+ gate := issuerDNSGateAt(warmCachedLookup, warmFreshResolver.ResolveAll, edgeNames(appsDomain, parents), edgeIPs, func() time.Time { return w.now() })
w = newCertWarm(hosts, getCert, func(h string) bool { return gate(h, nil) }, issuer, store)
w.freshGate = gate
return w
diff --git a/internal/edge/certwarm_fresh_test.go b/internal/edge/certwarm_fresh_test.go
index 0f4a43278..56c0023bc 100644
--- a/internal/edge/certwarm_fresh_test.go
+++ b/internal/edge/certwarm_fresh_test.go
@@ -44,10 +44,11 @@ type dnsFake struct {
// once holds names whose answer is given once and then forgotten
// (an expiring cache entry, a record that changes).
once map[string]bool
+ full map[string]domains.FreshAnswer
}
func newDNSFake() *dnsFake {
- return &dnsFake{answers: map[string][]string{}, errs: map[string]error{}, calls: map[string]int{}, once: map[string]bool{}}
+ return &dnsFake{answers: map[string][]string{}, errs: map[string]error{}, calls: map[string]int{}, once: map[string]bool{}, full: map[string]domains.FreshAnswer{}}
}
func (f *dnsFake) lookup(h string) ([]string, error) {
@@ -77,7 +78,24 @@ func (f *dnsFake) lookup(h string) ([]string, error) {
return ips, nil
}
-func (f *dnsFake) ResolveAll(h string) ([]string, error) { return f.lookup(h) }
+// ResolveAll answers with the name's addresses, or with the whole answer
+// set by setAnswer.
+func (f *dnsFake) ResolveAll(h string) (domains.FreshAnswer, error) {
+ f.mu.Lock()
+ ans, ok := f.full[h]
+ f.mu.Unlock()
+ ips, err := f.lookup(h)
+ if ok {
+ return ans, nil
+ }
+ return domains.FreshAnswer{Addrs: ips}, err
+}
+
+func (f *dnsFake) setAnswer(h string, ans domains.FreshAnswer) {
+ f.mu.Lock()
+ f.full[h] = ans
+ f.mu.Unlock()
+}
func (f *dnsFake) set(h string, ips ...string) {
f.mu.Lock()
@@ -131,6 +149,7 @@ type issuerHarness struct {
mu sync.Mutex
hosts []string
edges []string
+ parents []string
ordered []string
}
@@ -168,19 +187,24 @@ func (h *issuerHarness) firstMiss(name string) (dnsMiss, bool) {
return m, ok
}
+// harnessApps is the apps domain the harness's warm is built with.
+const harnessApps = "apps.example"
+
// newIssuerHarness builds the production issuer warm over hosts, with the
// cached and fresh sources swapped for fakes (both "no such host" for every
-// name until set), an edge set of edgeV4 and edgeV6, and a fake clock.
+// name until set), an edge set of edgeV4 and edgeV6, apps domain
+// harnessApps, no wildcard parents until set, and a fake clock.
func newIssuerHarness(t *testing.T, hosts ...string) *issuerHarness {
t.Helper()
fresh := newDNSFake()
- h := buildIssuerHarness(t, fresh, hosts)
+ h := buildIssuerHarness(t, fresh, harnessApps, hosts)
h.fresh = fresh
return h
}
-// buildIssuerHarness is newIssuerHarness over any fresh source.
-func buildIssuerHarness(t *testing.T, fresh freshAllResolver, hosts []string) *issuerHarness {
+// buildIssuerHarness is newIssuerHarness over any fresh source and apps
+// domain.
+func buildIssuerHarness(t *testing.T, fresh freshAllResolver, appsDomain string, hosts []string) *issuerHarness {
t.Helper()
h := &issuerHarness{
clock: &fakeClock{t: time.Unix(1_800_000_000, 0)},
@@ -212,6 +236,12 @@ func buildIssuerHarness(t *testing.T, fresh freshAllResolver, hosts []string) *i
defer h.mu.Unlock()
return append([]string(nil), h.edges...)
},
+ appsDomain,
+ func() []string {
+ h.mu.Lock()
+ defer h.mu.Unlock()
+ return append([]string(nil), h.parents...)
+ },
nil,
nil,
)
@@ -486,7 +516,7 @@ func TestIssuerWarmFreshFailuresBackOffAndDoNotStallThePass(t *testing.T) {
Backoff: warmFreshBackoff,
Now: clock.now,
}
- h := buildIssuerHarness(t, fresh, []string{"a.customer.test", "b.customer.test"})
+ h := buildIssuerHarness(t, fresh, harnessApps, []string{"a.customer.test", "b.customer.test"})
h.clock = clock
h.w.now = clock.now
h.cached.set("b.customer.test", edgeV4)
@@ -522,7 +552,7 @@ func TestIssuerWarmFreshResolverIsTheIssuerInstance(t *testing.T) {
if !ok {
t.Fatalf("warmFreshResolver is %T, want *domains.FreshResolver", warmFreshResolver)
}
- if r.LookupNS == nil || r.LookupHost == nil || r.LookupIP == nil || r.LookupCNAME == nil {
+ if r.LookupNS == nil || r.LookupHost == nil || r.LookupCNAME == nil {
t.Fatal("the issuer FreshResolver is missing a cached lookup")
}
if r.Backoff != warmFreshBackoff || warmFreshBackoff != 5*time.Minute {
@@ -583,21 +613,14 @@ func TestIssuerWarmLoopOrdersOnAFreshLook(t *testing.T) {
}
h.fresh.set("shop.example.com", edgeV4)
h.clock.advance(warmDNSRetryFast)
- deadline := time.Now().Add(2 * time.Second)
- for !h.orderedHost("shop.example.com") {
- if time.Now().After(deadline) {
- t.Fatalf("not ordered through the loop (passes %d, fresh looks %d)", passes.Load(), h.fresh.count("shop.example.com"))
- }
- time.Sleep(time.Millisecond)
- }
- if passes.Load() < 2 {
- t.Fatalf("passes = %d, want the probe's pass", passes.Load())
+ waitCount(t, passes, 2, "passes")
+ if !h.orderedHost("shop.example.com") {
+ t.Fatalf("not ordered through the loop (fresh looks %d)", h.fresh.count("shop.example.com"))
}
}
// fakeDNSServer answers every query on a loopback UDP socket through
-// answer, a stand-in for both the zone's nameserver and the box's
-// recursive resolver.
+// answer, a stand-in for a zone's nameserver.
func fakeDNSServer(t *testing.T, answer func(q dnsmessage.Question, r *dnsmessage.Message)) string {
t.Helper()
pc, err := net.ListenPacket("udp", "127.0.0.1:0")
@@ -626,96 +649,201 @@ func fakeDNSServer(t *testing.T, answer func(q dnsmessage.Question, r *dnsmessag
return pc.LocalAddr().String()
}
-// Astra #724 R1 P1-1, end to end through newIssuerWarm and a real
-// FreshResolver. The zone's own nameserver answers shop.example.com with a
-// CNAME to target.other.test, out of zone; the box's recursive resolver
-// gives that target A = ours and SERVFAIL for AAAA. Go's resolver, asked for
-// both families at once, would return the A record with no error; the gate
-// must refuse, since the target's IPv6 is unknown.
-func TestIssuerWarmRefusesACNAMETargetWhoseAAAAFailed(t *testing.T) {
- name := func(s string) dnsmessage.Name { return dnsmessage.MustNewName(s) }
- hdr := func(n string, typ dnsmessage.Type) dnsmessage.ResourceHeader {
- return dnsmessage.ResourceHeader{Name: name(n), Type: typ, Class: dnsmessage.ClassINET, TTL: 60}
+// zoneFresh is a real FreshResolver for example.com, whose nameserver (at
+// a public test address, dialled on loopback) answers shop.example.com's A
+// and AAAA queries with a and aaaa, with authority, and an empty answer as
+// NODATA (the zone's SOA in authority). asked records every name the
+// resolver's cached LookupHost is asked for.
+func zoneFresh(t *testing.T, clock *fakeClock, a, aaaa []dnsmessage.Resource) (r *domains.FreshResolver, asked func() []string) {
+ t.Helper()
+ soa := dnsmessage.Resource{
+ Header: dnsmessage.ResourceHeader{Name: dnsmessage.MustNewName("example.com."), Type: dnsmessage.TypeSOA, Class: dnsmessage.ClassINET, TTL: 60},
+ Body: &dnsmessage.SOAResource{NS: dnsmessage.MustNewName("ns1.example.com."), MBox: dnsmessage.MustNewName("hostmaster.example.com."),
+ Serial: 1, MinTTL: 1800},
}
authority := fakeDNSServer(t, func(q dnsmessage.Question, r *dnsmessage.Message) {
r.Authoritative = true
- switch qn := strings.ToLower(q.Name.String()); {
+ qn := strings.ToLower(q.Name.String())
+ switch {
case q.Type == dnsmessage.TypeSOA && qn == "example.com.":
- r.Answers = []dnsmessage.Resource{{Header: hdr("example.com.", dnsmessage.TypeSOA), Body: &dnsmessage.SOAResource{
- NS: name("ns1.example.com."), MBox: name("hostmaster.example.com."), Serial: 1, MinTTL: 1800}}}
- case qn == "shop.example.com.":
- r.Answers = []dnsmessage.Resource{{Header: hdr("shop.example.com.", dnsmessage.TypeCNAME), Body: &dnsmessage.CNAMEResource{CNAME: name("target.other.test.")}}}
+ r.Answers = []dnsmessage.Resource{soa}
+ case qn == "shop.example.com." && q.Type == dnsmessage.TypeA:
+ r.Answers = a
+ case qn == "shop.example.com." && q.Type == dnsmessage.TypeAAAA:
+ r.Answers = aaaa
default:
r.RCode = dnsmessage.RCodeRefused
- }
- })
- recursive := fakeDNSServer(t, func(q dnsmessage.Question, r *dnsmessage.Message) {
- r.RecursionAvailable = true
- if q.Type == dnsmessage.TypeAAAA {
- r.RCode = dnsmessage.RCodeServerFailure
return
}
- r.Answers = []dnsmessage.Resource{{Header: hdr(q.Name.String(), dnsmessage.TypeA), Body: &dnsmessage.AResource{A: netip.MustParseAddr(edgeV4).As4()}}}
+ if len(r.Answers) == 0 {
+ r.Authorities = []dnsmessage.Resource{soa}
+ }
})
- res := &net.Resolver{PreferGo: true, Dial: func(ctx context.Context, _, _ string) (net.Conn, error) {
- var d net.Dialer
- return d.DialContext(ctx, "udp", recursive)
+ var mu sync.Mutex
+ var names []string
+ r = &domains.FreshResolver{
+ LookupNS: func(_ context.Context, zone string) ([]*net.NS, error) {
+ if zone == "example.com" {
+ return []*net.NS{{Host: "ns1.example.com."}}, nil
+ }
+ return nil, &net.DNSError{Err: "no such host", Name: zone, IsNotFound: true}
+ },
+ LookupHost: func(_ context.Context, host string) ([]string, error) {
+ mu.Lock()
+ names = append(names, strings.TrimSuffix(host, "."))
+ mu.Unlock()
+ if strings.TrimSuffix(host, ".") == "ns1.example.com" {
+ return []string{"192.0.2.53"}, nil
+ }
+ return []string{edgeV4}, nil // a cache that would say "ours" for anything
+ },
+ Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
+ if address != "192.0.2.53:53" {
+ return nil, fmt.Errorf("no route to %s", address)
+ }
+ var d net.Dialer
+ return d.DialContext(ctx, network, authority)
+ },
+ Backoff: warmFreshBackoff,
+ Now: clock.now,
+ }
+ return r, func() []string {
+ mu.Lock()
+ defer mu.Unlock()
+ return append([]string(nil), names...)
+ }
+}
+
+func cnameTo(target string) []dnsmessage.Resource {
+ return []dnsmessage.Resource{{
+ Header: dnsmessage.ResourceHeader{Name: dnsmessage.MustNewName("shop.example.com."), Type: dnsmessage.TypeCNAME, Class: dnsmessage.ClassINET, TTL: 60},
+ Body: &dnsmessage.CNAMEResource{CNAME: dnsmessage.MustNewName(target + ".")},
}}
- if ips, err := res.LookupHost(context.Background(), "target.other.test"); err != nil || len(ips) != 1 {
- t.Fatalf("premise: LookupHost = %v, %v; want the A record and no error", ips, err)
+}
+
+func addrRecord(name, ip string) dnsmessage.Resource {
+ a := netip.MustParseAddr(ip)
+ h := dnsmessage.ResourceHeader{Name: dnsmessage.MustNewName(name + "."), Class: dnsmessage.ClassINET, TTL: 60}
+ if a.Is4() {
+ h.Type = dnsmessage.TypeA
+ return dnsmessage.Resource{Header: h, Body: &dnsmessage.AResource{A: a.As4()}}
}
+ h.Type = dnsmessage.TypeAAAA
+ return dnsmessage.Resource{Header: h, Body: &dnsmessage.AAAAResource{AAAA: a.As16()}}
+}
+
+// zoneHarness is the production issuer warm over shop.example.com with a
+// real FreshResolver in front of zoneFresh's authority.
+func zoneHarness(t *testing.T, appsDomain string, a, aaaa []dnsmessage.Resource) (*issuerHarness, func() []string) {
+ t.Helper()
clock := &fakeClock{t: time.Unix(1_800_000_000, 0)}
- newFresh := func(lookupIP func(context.Context, string, string) ([]net.IP, error)) *domains.FreshResolver {
- return &domains.FreshResolver{
- LookupNS: func(_ context.Context, zone string) ([]*net.NS, error) {
- if zone == "example.com" {
- return []*net.NS{{Host: "ns1.example.com."}}, nil
- }
- return nil, &net.DNSError{Err: "no such host", Name: zone, IsNotFound: true}
- },
- LookupHost: func(_ context.Context, host string) ([]string, error) {
- if strings.TrimSuffix(host, ".") == "ns1.example.com" {
- return []string{"192.0.2.53"}, nil
+ fresh, asked := zoneFresh(t, clock, a, aaaa)
+ h := buildIssuerHarness(t, fresh, appsDomain, []string{"shop.example.com"})
+ h.clock = clock
+ h.w.now = clock.now
+ return h, asked
+}
+
+// #724 R2 structural fix, through newIssuerWarm and a real FreshResolver: a
+// CNAME out of the customer's zone opens the gate only when the target is
+// one of our own names, and nothing about the target is looked up (the
+// fresh answer carries no cached or out-of-zone address).
+func TestIssuerWarmFreshCNAMETargetMustBeOurs(t *testing.T) {
+ for name, tc := range map[string]struct {
+ target string
+ apps string
+ parents []string
+ order bool
+ }{
+ "our edge name": {target: "edge.apps.example", apps: harnessApps, order: true},
+ "the apps domain itself": {target: "apps.example", apps: harnessApps, order: true},
+ "under a wildcard parent": {target: "x.shops.example.net", apps: harnessApps, parents: []string{"shops.example.net"}, order: true},
+ "a third party": {target: "cdn.other.net", apps: harnessApps},
+ "not on a label boundary": {target: "edge.xapps.example", apps: harnessApps},
+ "apps domain as a substring": {target: "apps.example.evil.net", apps: harnessApps},
+ "no apps domain": {target: "edge.apps.example", apps: ""},
+ } {
+ t.Run(name, func(t *testing.T) {
+ // The reply also carries an address for the target: not this
+ // zone's to give, and never counted.
+ h, asked := zoneHarness(t, tc.apps, append(cnameTo(tc.target), addrRecord(tc.target, edgeV4)), nil)
+ h.parents = tc.parents
+ h.w.pass()
+ if got := h.orderedHost("shop.example.com"); got != tc.order {
+ t.Fatalf("ordered = %v, want %v", got, tc.order)
+ }
+ for _, n := range append(asked(), func() []string {
+ h.cached.mu.Lock()
+ defer h.cached.mu.Unlock()
+ var out []string
+ for k := range h.cached.calls {
+ out = append(out, k)
}
- return nil, &net.DNSError{Err: "no such host", Name: host, IsNotFound: true}
- },
- LookupIP: lookupIP,
- Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
- if address != "192.0.2.53:53" {
- return nil, fmt.Errorf("no route to %s", address)
+ return out
+ }()...) {
+ if n == tc.target {
+ t.Fatalf("the target %s was looked up through a cache", n)
}
- var d net.Dialer
- return d.DialContext(ctx, network, authority)
- },
- Backoff: warmFreshBackoff,
- Now: clock.now,
- }
+ }
+ })
}
- h := buildIssuerHarness(t, newFresh(res.LookupIP), []string{"shop.example.com"})
- h.clock = clock
- h.w.now = clock.now
+}
+
+// In-zone records decide by the address rule: an AAAA elsewhere refuses.
+func TestIssuerWarmFreshInZoneAAAAElsewhereRefuses(t *testing.T) {
+ h, _ := zoneHarness(t, harnessApps,
+ []dnsmessage.Resource{addrRecord("shop.example.com", edgeV4)},
+ []dnsmessage.Resource{addrRecord("shop.example.com", "2001:db8::66")})
h.w.pass()
if h.orderedHost("shop.example.com") {
- t.Fatal("ordered with the CNAME target's AAAA unresolved")
+ t.Fatal("ordered with an in-zone AAAA pointing elsewhere")
+ }
+ // Control: both families ours orders.
+ h2, _ := zoneHarness(t, harnessApps,
+ []dnsmessage.Resource{addrRecord("shop.example.com", edgeV4)},
+ []dnsmessage.Resource{addrRecord("shop.example.com", edgeV6)})
+ h2.w.pass()
+ if !h2.orderedHost("shop.example.com") {
+ t.Fatal("control: not ordered with both families ours")
}
+}
- // Control: the same fixture with the AAAA query answered empty (NODATA)
- // orders, so the refusal above is the failed family and nothing else.
- recursive2 := fakeDNSServer(t, func(q dnsmessage.Question, r *dnsmessage.Message) {
- r.RecursionAvailable = true
- if q.Type == dnsmessage.TypeA {
- r.Answers = []dnsmessage.Resource{{Header: hdr(q.Name.String(), dnsmessage.TypeA), Body: &dnsmessage.AResource{A: netip.MustParseAddr(edgeV4).As4()}}}
- }
- })
- res2 := &net.Resolver{PreferGo: true, Dial: func(ctx context.Context, _, _ string) (net.Conn, error) {
- var d net.Dialer
- return d.DialContext(ctx, "udp", recursive2)
- }}
- h2 := buildIssuerHarness(t, newFresh(res2.LookupIP), []string{"shop.example.com"})
- h2.clock = clock
- h2.w.now = clock.now
+// The gate never accepts an answer that has both a Target and addresses,
+// whatever they are.
+func TestIssuerWarmFreshTargetWithAddressesRefuses(t *testing.T) {
+ h := newIssuerHarness(t, "shop.example.com")
+ h.fresh.setAnswer("shop.example.com", domains.FreshAnswer{Target: "edge." + harnessApps, Addrs: []string{edgeV4}})
+ h.w.pass()
+ if h.orderedHost("shop.example.com") {
+ t.Fatal("ordered on an answer with both a Target and addresses")
+ }
+ h2 := newIssuerHarness(t, "shop.example.com")
+ h2.fresh.setAnswer("shop.example.com", domains.FreshAnswer{Target: "edge." + harnessApps})
h2.w.pass()
if !h2.orderedHost("shop.example.com") {
- t.Fatal("control: not ordered with the target's AAAA answered NODATA")
+ t.Fatal("control: not ordered on a bare Target that is ours")
+ }
+}
+
+func TestEdgeNamesMatchesOnLabelBoundaries(t *testing.T) {
+ ours := edgeNames("Apps.Example", func() []string { return []string{"shops.example.net", ""} })
+ for name, want := range map[string]bool{
+ "apps.example": true,
+ "edge.apps.example": true,
+ "EDGE.APPS.EXAMPLE.": true,
+ "shops.example.net": true,
+ "a.b.shops.example.net": true,
+ "xapps.example": false,
+ "apps.example.net": false,
+ "example": false,
+ "": false,
+ "other.net": false,
+ } {
+ if got := ours(name); got != want {
+ t.Errorf("ours(%q) = %v, want %v", name, got, want)
+ }
+ }
+ if edgeNames("", func() []string { return []string{"shops.example.net"} })("shops.example.net") {
+ t.Error("an empty apps domain matched a name")
}
}
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index 69d32bd28..560b47942 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -4904,6 +4904,8 @@ func RunWithActivatorReady(args []string, act Activator, cache *Cache, ready fun
func() []string { return e.warmSet(appsDomain, parents) },
perHostCert,
edgeIPs,
+ appsDomain,
+ parents,
e.issuerGate,
store,
)
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 1f4dc807d..e63c46ecf 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -142,4 +142,4 @@ plan14-root-reads-fixedbox-health-alarms.tsv 0f7153571df8c1b4b50c31f57efcfdf60c7
plan14-root-reads-fixed-host-ignore-user-data.tsv 250e3ba91e1bc5fcd6be5cc2bafce4c7d6645d2d2f0c080913b99f01b1d19129
plan14-root-reads-deploy-edge-718.tsv 250e3ba91e1bc5fcd6be5cc2bafce4c7d6645d2d2f0c080913b99f01b1d19129
plan14-root-reads-demo-slice-adopt.tsv 707018faaa1fee3b47abb78389ae7854264e76621cc316889061adb69bf13e10
-plan14-root-reads-issuer-fresh-gate-724.tsv 10cc1d3ea30180daea3755e94148e898f4e518b98fc76f1f1be62e845d365541
+plan14-root-reads-issuer-fresh-gate-724.tsv 6f67706041cbc12604a2473c755560d374a0af442933f7f55de39eda892dc2a2
diff --git a/internal/provision/testdata/plan14-root-reads-issuer-fresh-gate-724.tsv b/internal/provision/testdata/plan14-root-reads-issuer-fresh-gate-724.tsv
index c3b830231..8769efb11 100644
--- a/internal/provision/testdata/plan14-root-reads-issuer-fresh-gate-724.tsv
+++ b/internal/provision/testdata/plan14-root-reads-issuer-fresh-gate-724.tsv
@@ -1,6 +1,6 @@
# Census overlay issuer-fresh-gate-724, written by census-propose (#369). census-ruling-issuer-fresh-gate-724, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-issuer-fresh-gate-724.md.
# 1 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@legacy be159b9c8b2bda15a531ca118003a76e19c7156cc4fd4ca038625ca2da391f29 internal/edge/edge.go RunWithActivatorReady legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): the inline home-map arming (newHomeMap, one boot Refresh, Store, run) moves unchanged into the new Edge.ArmHomeMap and is called here as e.ArmHomeMap(); same refresh, same timeout, same order. The reads are moved, none added.;rev3=census-ruling-agent-start-demo-1;basis=Logs the combined explicit wildcard parents through demoWildcardDomains; no new watcher or read loop.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: invoke the local admission Close before HTTP/HTTPS draining and door shutdown in both dev and normal listeners. Preserve merged main's startup behavior and its census basis; the same five read sites, no new reads.;rev3=census-ruling-stateless-replicas-3;basis=Task 1b: defer stopping and joining the edge's replica jobs at shutdown. Existing five direct read sites unchanged; no new reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Wrap dev, HTTP and HTTPS listeners through ConfigureGroupHairpin before serving. Indirectly read protected root boot identity and group-ingress.json; kernel local/peer addresses mark local ingress, never HTTP headers. Agent edge uses verified public source for accounting; direct read sites unchanged and absent marker keeps original listeners. CI fix removes interface enumeration: local peer must match snapshot primary IPv4, an ingress IPv4 installed locally by root, or loopback; kernel destination must still be an ingress EIP on port 80/443. Merge 45cebde4 retains deferred stopReplicaProbes alongside group listener wrapping and shutdown admission closure.;rev3=census-ruling-demo-api-site-route;basis=Change the startup failure context from load routes to initialize because origin validation now runs during construction. Existing five read sites unchanged; no new read or runtime authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Invoke the agent shutdown timestamp hook synchronously at SIGTERM/SIGINT receipt before closing admission in dev and TLS paths. No read added.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5: registers the https and http servers with the connection drain (conns.serve) so a drain can close idle keep-alive connections; no read added;rev3=census-ruling-issuer-fresh-gate-724;basis=builds the cert warm through newIssuerWarm (certwarm.go) instead of newCertWarm with dnsGate(warmResolver, edgeIPs): the same cached DNS gate plus, when the cached lookup has no answer, one fresh look at the name's zone nameservers via domains.FreshResolver.ResolveAll (public nameserver addresses only, existing destination policy), bounded per pass and probe; the answer only decides whether to place an ACME order. No file or root-owned read added, same 5 sites. data-literal@129,data-literal@148,data-literal@284,data-literal@417,file:Open@1013 2cade75b3861ac808925bb7b3cef86bfe5e3a58323f53344776b719bff3f1cd4
-internal/edge/edge.go RunWithActivatorReady legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): the inline home-map arming (newHomeMap, one boot Refresh, Store, run) moves unchanged into the new Edge.ArmHomeMap and is called here as e.ArmHomeMap(); same refresh, same timeout, same order. The reads are moved, none added.;rev3=census-ruling-agent-start-demo-1;basis=Logs the combined explicit wildcard parents through demoWildcardDomains; no new watcher or read loop.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: invoke the local admission Close before HTTP/HTTPS draining and door shutdown in both dev and normal listeners. Preserve merged main's startup behavior and its census basis; the same five read sites, no new reads.;rev3=census-ruling-stateless-replicas-3;basis=Task 1b: defer stopping and joining the edge's replica jobs at shutdown. Existing five direct read sites unchanged; no new reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Wrap dev, HTTP and HTTPS listeners through ConfigureGroupHairpin before serving. Indirectly read protected root boot identity and group-ingress.json; kernel local/peer addresses mark local ingress, never HTTP headers. Agent edge uses verified public source for accounting; direct read sites unchanged and absent marker keeps original listeners. CI fix removes interface enumeration: local peer must match snapshot primary IPv4, an ingress IPv4 installed locally by root, or loopback; kernel destination must still be an ingress EIP on port 80/443. Merge 45cebde4 retains deferred stopReplicaProbes alongside group listener wrapping and shutdown admission closure.;rev3=census-ruling-demo-api-site-route;basis=Change the startup failure context from load routes to initialize because origin validation now runs during construction. Existing five read sites unchanged; no new read or runtime authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Invoke the agent shutdown timestamp hook synchronously at SIGTERM/SIGINT receipt before closing admission in dev and TLS paths. No read added.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5: registers the https and http servers with the connection drain (conns.serve) so a drain can close idle keep-alive connections; no read added;rev3=census-ruling-issuer-fresh-gate-724;basis=builds the cert warm through newIssuerWarm (certwarm.go) instead of newCertWarm with dnsGate(warmResolver, edgeIPs): the same cached DNS gate plus, when the cached lookup has no answer, one fresh look at the name's zone nameservers via domains.FreshResolver.ResolveAll (public nameserver addresses only, existing destination policy), bounded per pass and probe; the answer only decides whether to place an ACME order. No file or root-owned read added, same 5 sites. data-literal@129,data-literal@148,data-literal@284,data-literal@417,file:Open@1013 2cade75b3861ac808925bb7b3cef86bfe5e3a58323f53344776b719bff3f1cd4
-@coverage internal/domains 08d31cbe267c3b3f5d491ffe3a01b3df790f0d68301d015963670db206876371
-@coverage internal/edge 7d6979c574fecde9b26c6f6054b763fdaad111e576a8d0c4ee014f3b3d69cdb6
+@legacy 65cac0e72a4d5fdfa918fcc4c98d6b9b31b226237557a38680f60f7cfe97b233 internal/edge/edge.go RunWithActivatorReady legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): the inline home-map arming (newHomeMap, one boot Refresh, Store, run) moves unchanged into the new Edge.ArmHomeMap and is called here as e.ArmHomeMap(); same refresh, same timeout, same order. The reads are moved, none added.;rev3=census-ruling-agent-start-demo-1;basis=Logs the combined explicit wildcard parents through demoWildcardDomains; no new watcher or read loop.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: invoke the local admission Close before HTTP/HTTPS draining and door shutdown in both dev and normal listeners. Preserve merged main's startup behavior and its census basis; the same five read sites, no new reads.;rev3=census-ruling-stateless-replicas-3;basis=Task 1b: defer stopping and joining the edge's replica jobs at shutdown. Existing five direct read sites unchanged; no new reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Wrap dev, HTTP and HTTPS listeners through ConfigureGroupHairpin before serving. Indirectly read protected root boot identity and group-ingress.json; kernel local/peer addresses mark local ingress, never HTTP headers. Agent edge uses verified public source for accounting; direct read sites unchanged and absent marker keeps original listeners. CI fix removes interface enumeration: local peer must match snapshot primary IPv4, an ingress IPv4 installed locally by root, or loopback; kernel destination must still be an ingress EIP on port 80/443. Merge 45cebde4 retains deferred stopReplicaProbes alongside group listener wrapping and shutdown admission closure.;rev3=census-ruling-demo-api-site-route;basis=Change the startup failure context from load routes to initialize because origin validation now runs during construction. Existing five read sites unchanged; no new read or runtime authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Invoke the agent shutdown timestamp hook synchronously at SIGTERM/SIGINT receipt before closing admission in dev and TLS paths. No read added.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5: registers the https and http servers with the connection drain (conns.serve) so a drain can close idle keep-alive connections; no read added;rev3=census-ruling-issuer-fresh-gate-724;basis=builds the cert warm through newIssuerWarm (certwarm.go), now also passing the apps domain and the wildcard parents it already computes: the same cached DNS gate plus, when the cached lookup has no answer, one fresh look at the name's zone nameservers via domains.FreshResolver.ResolveAll (public nameserver addresses only, existing destination policy; no cached or out-of-zone address in the answer), bounded per pass and probe; an out-of-zone CNAME target opens the gate only when it is under the apps domain or a wildcard parent. The answer only decides whether to place an ACME order. No file or root-owned read added, same 5 sites. data-literal@129,data-literal@148,data-literal@284,data-literal@417,file:Open@1013 58ab034a583d5fc7980914af90bbcac2161e609326f34d4e473de2ad21a0b28e
+internal/edge/edge.go RunWithActivatorReady legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites;rev3=census-ruling-edge-held-streams;basis=the edge in the agent (carlos-edge.service, user carlos): the inline home-map arming (newHomeMap, one boot Refresh, Store, run) moves unchanged into the new Edge.ArmHomeMap and is called here as e.ArmHomeMap(); same refresh, same timeout, same order. The reads are moved, none added.;rev3=census-ruling-agent-start-demo-1;basis=Logs the combined explicit wildcard parents through demoWildcardDomains; no new watcher or read loop.;rev3=census-ruling-region-ha-p3a;basis=P3a Task 3: invoke the local admission Close before HTTP/HTTPS draining and door shutdown in both dev and normal listeners. Preserve merged main's startup behavior and its census basis; the same five read sites, no new reads.;rev3=census-ruling-stateless-replicas-3;basis=Task 1b: defer stopping and joining the edge's replica jobs at shutdown. Existing five direct read sites unchanged; no new reader or authority.;rev3=census-ruling-region-ha-p3b;basis=Wrap dev, HTTP and HTTPS listeners through ConfigureGroupHairpin before serving. Indirectly read protected root boot identity and group-ingress.json; kernel local/peer addresses mark local ingress, never HTTP headers. Agent edge uses verified public source for accounting; direct read sites unchanged and absent marker keeps original listeners. CI fix removes interface enumeration: local peer must match snapshot primary IPv4, an ingress IPv4 installed locally by root, or loopback; kernel destination must still be an ingress EIP on port 80/443. Merge 45cebde4 retains deferred stopReplicaProbes alongside group listener wrapping and shutdown admission closure.;rev3=census-ruling-demo-api-site-route;basis=Change the startup failure context from load routes to initialize because origin validation now runs during construction. Existing five read sites unchanged; no new read or runtime authority.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Invoke the agent shutdown timestamp hook synchronously at SIGTERM/SIGINT receipt before closing admission in dev and TLS paths. No read added.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5: registers the https and http servers with the connection drain (conns.serve) so a drain can close idle keep-alive connections; no read added;rev3=census-ruling-issuer-fresh-gate-724;basis=builds the cert warm through newIssuerWarm (certwarm.go), now also passing the apps domain and the wildcard parents it already computes: the same cached DNS gate plus, when the cached lookup has no answer, one fresh look at the name's zone nameservers via domains.FreshResolver.ResolveAll (public nameserver addresses only, existing destination policy; no cached or out-of-zone address in the answer), bounded per pass and probe; an out-of-zone CNAME target opens the gate only when it is under the apps domain or a wildcard parent. The answer only decides whether to place an ACME order. No file or root-owned read added, same 5 sites. data-literal@129,data-literal@148,data-literal@284,data-literal@417,file:Open@1013 58ab034a583d5fc7980914af90bbcac2161e609326f34d4e473de2ad21a0b28e
+@coverage internal/domains cedf0752d453d73bb3f3003b2a90d8c6a3139fa385c082c2e5cc7419f6a8f691
+@coverage internal/edge 9c830a5bf8a3e3e6207f0e6c47b22bae46180aad31c0332baaeb3570d46042fb