domains: Astra R1 fixes for no-negative-prime (#724)
P1: section 4 services published names' upgrade looks before any fresh-first name (random order within each group, one shared budget), so a backlog of new names can no longer starve the re-check that keeps a published alias published. P2: resolve asks the name's registrable domain first (publicsuffix EffectiveTLDPlusOne, skipped when it is the name or its immediate parent), so a nonexistent intermediate label (eu.example.com under example.com) never reaches the cache when the registrable domain answers. The walk skips that level; the doc comment states the exact guarantee and the remaining priming paths. P2: final-attempt security tests: parents only refer, the name's NS set leads to a wrong-zone or SOA-mismatched server, refused and reached. P3: comments say the name-itself attempt runs unless the deadline has expired; stamp test intro no longer calls the fresh look upgrade-only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+374
−36
docs/superpowers/notes/census-proposal-no-negative-prime-724.md+2 −2internal/domains/freshdns.go+54 −22internal/domains/freshdns_stamp_test.go+54 −2internal/domains/freshdns_test.go+248 −0internal/domains/reconcile.go+12 −6internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-no-negative-prime-724.tsv+3 −3
CI passed — run details
diff --git a/docs/superpowers/notes/census-proposal-no-negative-prime-724.md b/docs/superpowers/notes/census-proposal-no-negative-prime-724.md| index 4b5c03f3f..abe5a8442 100644 |
| --- a/docs/superpowers/notes/census-proposal-no-negative-prime-724.md |
| +++ b/docs/superpowers/notes/census-proposal-no-negative-prime-724.md |
| @@ -4,7 +4,7 @@ Ruling `census-ruling-no-negative-prime-724`. The independent reviewer approves |
| | unit | change | read sites | what changed | |
| |---|---|---|---| |
| -| `internal/domains/reconcile.go` `StampHealth` | sites | -registry:Alias, +registry:DNSStatus ×2, -registry:Host, -whole:Route, -whole:RouteAlias | section 4 now hands each route and alias, with its previous stamp (the two new registry:DNSStatus reads, rt.DNSStatus and a.DNSStatus, same rows already listed), to dnsVerdicts: a name not "pointing" before this pass and eligible for a fresh lookup (public name, not under the apps domain, ResolveFresh set) is looked at uncached first within the same 64-lookup/30 s budget and stamped from it (edge address "pointing", other "elsewhere", authoritative not-found ""), falling back to the cached lookup on a fresh error or past the budget; a previously "pointing" name keeps cached-first plus the upgrade-only fresh look, so the fresh path still never unpublishes; no new file, path or command input; the dropped Alias/Host/Route/RouteAlias sites are the old indexed loops folded into the candidate build (#724) | |
| +| `internal/domains/reconcile.go` `StampHealth` | sites | -registry:Alias, +registry:DNSStatus ×2, -registry:Host, -whole:Route, -whole:RouteAlias | section 4 now hands each route and alias, with its previous stamp (the two new registry:DNSStatus reads, rt.DNSStatus and a.DNSStatus, same rows already listed), to dnsVerdicts: a name not "pointing" before this pass and eligible for a fresh lookup (public name, not under the apps domain, ResolveFresh set) is looked at uncached first within the same 64-lookup/30 s budget (shared, with previously "pointing" names' upgrade looks serviced before any fresh-first name so new names cannot starve a published one) and stamped from it (edge address "pointing", other "elsewhere", authoritative not-found ""), falling back to the cached lookup on a fresh error or past the budget; a previously "pointing" name keeps cached-first plus the upgrade-only fresh look, so the fresh path still never unpublishes; no new file, path or command input; the dropped Alias/Host/Route/RouteAlias sites are the old indexed loops folded into the candidate build (#724) | |
| Envelopes re-pinned: `internal/domains`. |
| @@ -14,6 +14,6 @@ Recorded dispositions, which each change must still satisfy: |
| - `internal/domains/reconcile.go` `StampHealth`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-dns-fresh-lookup-724;basis=section 4 now computes every cached verdict first, then freshUpgrade gives up to 64 randomly ordered names that could have a public zone (not under the apps domain, not special-use like .internal) and whose verdict is "" or "elsewhere" an uncached lookup (30 s pass budget) that may only upgrade to "pointing", then stamps; the extra sites are the indexed loops over the same rows (#724) |
| -Seal: `8924fafc5b6083858a72f45c764081abe3bcad6a6de71901470586c076c64bb6` → `f7eb15fc80af393e7da87f84e5b9bd8fe4803ffed533cfedf209a92dd53910ec`. |
| +Seal: `8924fafc5b6083858a72f45c764081abe3bcad6a6de71901470586c076c64bb6` → `1fc14572275cc3e3fc7a889f4672d867dc3982204c8909cd87a60024f0909829`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-no-negative-prime-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 ec9bf4dc2..300253e04 100644 |
| --- a/internal/domains/freshdns.go |
| +++ b/internal/domains/freshdns.go |
| @@ -12,6 +12,7 @@ import ( |
| "time" |
| "golang.org/x/net/dns/dnsmessage" |
| + "golang.org/x/net/publicsuffix" |
| ) |
| // FreshResolver answers "what does this hostname resolve to right now" |
| @@ -68,8 +69,9 @@ const ( |
| // freshMaxServers bounds the nameserver addresses tried per zone, so a |
| // zone of silent servers leaves time for the next zone up. |
| freshMaxServers = 2 |
| - // freshMaxZones bounds the parent zones tried, nearest first; the name |
| - // itself, tried last, is not counted. More than one, because a cached |
| + // freshMaxZones bounds the parent zones tried, nearest first; the |
| + // registrable domain tried before them and the name itself tried last |
| + // are not counted. More than one, because a cached |
| // CNAME at a parent level can make its NS set belong to the CNAME |
| // target's zone, which then refuses, and a delegated sub-zone's parent |
| // only refers down. |
| @@ -161,25 +163,42 @@ func isNotFound(err error) bool { |
| return errors.As(err, &dnsErr) && dnsErr.IsNotFound |
| } |
| -// resolve walks the zones ABOVE name, nearest first, and asks each zone's |
| +// resolve finds the zone that holds name WITHOUT the cached resolver ever |
| +// hearing about a level that may not exist yet, and asks that zone's |
| // nameservers until one gives a definitive authoritative answer (the |
| -// addresses, or "no such name"). It stops below the top level: a TLD's |
| -// servers only refer back down. Only when no parent zone gave a definitive |
| -// answer is the name ITSELF tried as a zone, last. |
| +// addresses, or "no such name"). In order: |
| // |
| -// Why parents first: the cached resolver (systemd-resolved, then the VPC |
| -// resolver) caches a "no such name" for the NAME, whatever type was asked |
| -// (RFC 2308 section 5), for the zone's SOA minimum. A customer attaches a |
| -// hostname before adding its record, so a cached LookupCNAME or LookupNS on |
| -// the name itself would plant exactly that negative entry, and the cert |
| -// issuer reading the same caches would wait it out. Asking the parent |
| -// zone's servers directly needs no cached query for the name at all, and |
| -// the parent is where an ordinary customer hostname lives. The name-itself |
| -// attempt covers a name that is its own zone (an apex, or a delegated |
| -// sub-zone, whose parent only refers down); such a name exists before |
| -// anyone attaches it, so asking about it primes nothing. freshMaxZones |
| -// bounds the parents only; the name-itself attempt always gets its turn, |
| -// inside the same Timeout. |
| +// 1. the name's registrable domain (example.com for shop.eu.example.com), |
| +// when it is neither the name nor its immediate parent; |
| +// 2. the zones above name, nearest first, skipping the level step 1 |
| +// tried, and stopping below the top level (a TLD's servers only refer |
| +// back down); |
| +// 3. the name ITSELF, last, only when nothing above gave a definitive |
| +// answer. |
| +// |
| +// Why: the cached resolver (systemd-resolved, then the VPC resolver) caches |
| +// a "no such name" for a NAME, whatever type was asked (RFC 2308 section |
| +// 5), for the zone's SOA minimum, and a resolver doing NXDOMAIN cuts (RFC |
| +// 8020) denies every name below it too. A customer attaches a hostname |
| +// before adding its record, so a cached LookupCNAME or LookupNS on the |
| +// name, or on a label between it and the registrable domain that does not |
| +// exist (eu.example.com), would plant exactly that negative entry, and the |
| +// cert issuer reading the same caches would wait it out. The registrable |
| +// domain exists before anyone can attach a name under it, so asking the |
| +// cache for its NS set primes nothing. |
| +// |
| +// The guarantee, precisely: for a name under a registrable domain whose |
| +// servers answer it definitively, no cached query carries the name or any |
| +// label between it and the registrable domain. What can still prime: a |
| +// delegated child zone under the registrable domain (its referral sends the |
| +// walk through the intermediate labels, one of which may not exist), |
| +// parents whose servers do not answer (the walk then reaches the name |
| +// itself), and, in section 4, names past the per-pass budget, which get the |
| +// cached look. The name-itself attempt covers a name that is its own zone |
| +// (an apex, or a delegated sub-zone whose parent only refers down); such a |
| +// name exists before anyone attaches it. freshMaxZones bounds step 2 only: |
| +// steps 1 and 3 each have their own allowance, and step 3 gets its turn |
| +// unless the overall deadline (Timeout) has already expired. |
| // |
| // A zone is only used once it is VERIFIED: the server about to be asked |
| // answers, with authority, an SOA record owned by exactly that name. The |
| @@ -205,14 +224,27 @@ func (r *FreshResolver) resolve(ctx context.Context, name string) ([]string, err |
| } |
| return ctx.Err() != nil, nil, last |
| } |
| + parent := name[strings.Index(name, ".")+1:] |
| + registrable, err := publicsuffix.EffectiveTLDPlusOne(name) |
| + if err != nil || registrable == name || registrable == parent { |
| + registrable = "" |
| + } |
| + if registrable != "" { |
| + if stop, ips, err := try(registrable, new(int)); stop { |
| + return ips, err |
| + } |
| + } |
| zones := 0 |
| - for zone := name[strings.Index(name, ".")+1:]; strings.Contains(zone, ".") && zones < freshMaxZones; zone = zone[strings.Index(zone, ".")+1:] { |
| + for zone := parent; strings.Contains(zone, ".") && zones < freshMaxZones; zone = zone[strings.Index(zone, ".")+1:] { |
| + if zone == registrable { |
| + continue |
| + } |
| if stop, ips, err := try(zone, &zones); stop { |
| return ips, err |
| } |
| } |
| - // The parent walk is over with no definitive answer. Now the name |
| - // itself, with its own allowance outside freshMaxZones. |
| + // Nothing above gave a definitive answer. Now the name itself, with |
| + // its own allowance outside freshMaxZones. |
| _, ips, err := try(name, new(int)) |
| return ips, err |
| } |
diff --git a/internal/domains/freshdns_stamp_test.go b/internal/domains/freshdns_stamp_test.go| index 10fecd242..1137c5f31 100644 |
| --- a/internal/domains/freshdns_stamp_test.go |
| +++ b/internal/domains/freshdns_stamp_test.go |
| @@ -16,8 +16,10 @@ import ( |
| // attach output tells them to. The box's caching resolver has already |
| // answered NXDOMAIN for the name and holds that for the zone's SOA minimum, |
| // so every pass inside that window reads "" and the alias stays unpublished. |
| -// ResolveFresh asks without the cache and may only UPGRADE a verdict to |
| -// "pointing"; it never makes a verdict worse. |
| +// ResolveFresh asks without the cache. For a name that was not "pointing" |
| +// before the pass it decides the verdict, so the cache is never asked about |
| +// a name that may not exist yet; for a name that was "pointing" it may only |
| +// UPGRADE the cached verdict back to "pointing", never make it worse. |
| const edgeIP = "203.0.113.7" |
| @@ -470,3 +472,53 @@ func TestStampHealthIneligibleNamesStayCached(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// Astra R1 P1 on #724 follow-up: new names must not spend the fresh budget |
| +// a published name needs. A "pointing" alias whose cache has gone stale |
| +// (NXDOMAIN) but whose record still points here is re-checked before any |
| +// fresh-first name, so it stays published; new names past the budget get |
| +// the cached look. |
| +func TestStampHealthUpgradesBeforeFreshFirst(t *testing.T) { |
| + defer domains.SetFreshPassMax(2)() |
| + newNames := []string{"a.example.com", "b.example.com", "c.example.com", "d.example.com", "e.example.com"} |
| + for pass := 0; pass < 20; pass++ { |
| + reg := regWithAlias(t, "live.example.com") |
| + stampAlias(t, reg, "live.example.com", "pointing") |
| + for _, n := range newNames { |
| + if err := reg.UpsertAlias(registry.RouteAlias{Alias: n, Host: "app.acct.oncarlos.test", Account: "acct", App: "app"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + asked := map[string]int{} |
| + var calls []string |
| + cfg := freshCfg(counted(func(h string) ([]string, error) { |
| + if h == "live.example.com" { |
| + return nxdomain(h) |
| + } |
| + return pointingAt(h) |
| + }, asked), func(h string) ([]string, error) { |
| + if h == "live.example.com" { |
| + return pointingAt(h) |
| + } |
| + return []string{"198.51.100.9"}, nil |
| + }, &calls) |
| + if err := domains.StampHealth(context.Background(), reg, cfg, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := aliasStatus(t, reg, "live.example.com"); got != "pointing" { |
| + t.Fatalf("pass %d: published alias = %q, want pointing (fresh calls %v)", pass, got, calls) |
| + } |
| + if len(calls) != 2 || calls[0] != "live.example.com" { |
| + t.Fatalf("pass %d: fresh lookups = %v, want live.example.com then one new name", pass, calls) |
| + } |
| + for _, n := range newNames { |
| + want, cached := "pointing", 1 |
| + if n == calls[1] { |
| + want, cached = "elsewhere", 0 |
| + } |
| + if got := aliasStatus(t, reg, n); got != want || asked[n] != cached { |
| + t.Fatalf("pass %d: %s = %q with %d cached queries, want %q with %d", pass, n, got, asked[n], want, cached) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/domains/freshdns_test.go b/internal/domains/freshdns_test.go| index 06dff5a54..760a796dc 100644 |
| --- a/internal/domains/freshdns_test.go |
| +++ b/internal/domains/freshdns_test.go |
| @@ -776,3 +776,251 @@ func TestFreshResolverSkipsAnAliasedParent(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// referral answers every non-SOA query like a parent that has delegated the |
| +// name away: no authority, an NS record in the authority section. |
| +func referral(child string) func(dnsmessage.Question, *dnsmessage.Message) bool { |
| + return func(_ dnsmessage.Question, r *dnsmessage.Message) bool { |
| + r.Authorities = []dnsmessage.Resource{{ |
| + Header: dnsmessage.ResourceHeader{Name: dnsmessage.MustNewName(child + "."), Type: dnsmessage.TypeNS, Class: dnsmessage.ClassINET, TTL: 300}, |
| + Body: &dnsmessage.NSResource{NS: dnsmessage.MustNewName("ns." + child + ".")}, |
| + }} |
| + return true |
| + } |
| +} |
| + |
| +// Astra R1 P2-1 on #724 follow-up: a nonexistent INTERMEDIATE label is |
| +// primed just like the name (RFC 8020 NXDOMAIN cuts deny every descendant). |
| +// The registrable domain is asked first, so neither shop.eu.example.com nor |
| +// eu.example.com reaches the cache when example.com answers. |
| +func TestFreshResolverNestedNameAsksTheRegistrableDomainFirst(t *testing.T) { |
| + cases := map[string]struct { |
| + answer func(dnsmessage.Question, *dnsmessage.Message) bool |
| + found bool |
| + }{ |
| + "record absent": {func(_ dnsmessage.Question, r *dnsmessage.Message) bool { |
| + r.Authoritative = true |
| + r.RCode = dnsmessage.RCodeNameError |
| + return true |
| + }, false}, |
| + "record present": {authoritative(cnameRecord("shop.eu.example.com.", "edge.oncarlos.test.")), true}, |
| + } |
| + for name, tc := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + fa := startAuthority(t, "example.com", tc.answer) |
| + w := oneZone(fa) |
| + ips, err := w.resolver(clock()).Resolve("shop.eu.example.com") |
| + if tc.found && (err != nil || len(ips) != 1 || ips[0] != edgeIP) { |
| + t.Fatalf("Resolve = %v, %v; want [%s]", ips, err, edgeIP) |
| + } |
| + if !tc.found && !isNotFoundErr(err) { |
| + t.Fatalf("Resolve error = %v, want the authoritative not-found", err) |
| + } |
| + for _, n := range []string{"shop.eu.example.com", "eu.example.com"} { |
| + if c := w.cachedFor(n); c != 0 { |
| + t.Fatalf("cached resolver asked about %s %d times (%v), want 0", n, c, w.cached) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// eu.example.com is a delegated child zone: the registrable domain only |
| +// refers down, and the walk finds the child. |
| +func TestFreshResolverNestedNameInADelegatedChildZone(t *testing.T) { |
| + parent := startAuthority(t, "example.com", referral("eu.example.com")) |
| + child := startAuthority(t, "eu.example.com", authoritative(aRecord("shop.eu.example.com.", edgeIP))) |
| + w := &world{ |
| + ns: map[string][]string{ |
| + "example.com": {"ns1.example.com."}, |
| + "eu.example.com": {"ns.eu.example.com."}, |
| + }, |
| + hosts: map[string][]string{ |
| + "ns1.example.com": {"192.0.2.53"}, |
| + "ns.eu.example.com": {"192.0.2.40"}, |
| + "edge.oncarlos.test": {edgeIP}, |
| + }, |
| + routes: map[string]*fakeAuthority{"192.0.2.53:53": parent, "192.0.2.40:53": child}, |
| + } |
| + ips, err := w.resolver(clock()).Resolve("shop.eu.example.com") |
| + if err != nil || len(ips) != 1 || ips[0] != edgeIP { |
| + t.Fatalf("Resolve = %v, %v; want the child zone's answer", ips, err) |
| + } |
| + if w.cachedFor("shop.eu.example.com") != 0 { |
| + t.Fatalf("cached resolver asked about the name: %v", w.cached) |
| + } |
| +} |
| + |
| +// The registrable domain's servers are silent: the lookup falls through to |
| +// the walk, which does not ask the registrable domain a second time, and |
| +// stays inside Timeout. |
| +func TestFreshResolverSilentRegistrableDomainFallsThrough(t *testing.T) { |
| + silent := startAuthority(t, "example.com", nil) |
| + child := startAuthority(t, "eu.example.com", authoritative(aRecord("shop.eu.example.com.", edgeIP))) |
| + w := &world{ |
| + ns: map[string][]string{ |
| + "example.com": {"ns1.example.com."}, |
| + "eu.example.com": {"ns.eu.example.com."}, |
| + }, |
| + hosts: map[string][]string{ |
| + "ns1.example.com": {"192.0.2.53"}, |
| + "ns.eu.example.com": {"192.0.2.40"}, |
| + }, |
| + routes: map[string]*fakeAuthority{"192.0.2.53:53": silent, "192.0.2.40:53": child}, |
| + } |
| + r := w.resolver(clock()) |
| + start := time.Now() |
| + ips, err := r.Resolve("shop.eu.example.com") |
| + if took := time.Since(start); took > r.Timeout+500*time.Millisecond { |
| + t.Fatalf("Resolve took %s, past Timeout %s", took, r.Timeout) |
| + } |
| + if err != nil || len(ips) != 1 || ips[0] != edgeIP { |
| + t.Fatalf("Resolve = %v, %v; want the child zone's answer", ips, err) |
| + } |
| + if n := silent.queries.Load(); n != 1 { |
| + t.Fatalf("the registrable domain's server got %d queries, want 1 (asked once, not again by the walk)", n) |
| + } |
| +} |
| + |
| +// Where the walk already starts at the registrable domain (the name is an |
| +// apex, a name under a public suffix like co.uk, or a direct child of its |
| +// registrable domain) there is no separate first step: each level is asked |
| +// once, nearest parent first. |
| +func TestFreshResolverRegistrableStepSkippedWhereTheWalkCoversIt(t *testing.T) { |
| + t.Run("apex", func(t *testing.T) { |
| + silent := startAuthority(t, "example.com", nil) |
| + w := oneZone(silent) |
| + if _, err := w.resolver(clock()).Resolve("example.com"); err == nil { |
| + t.Fatal("Resolve against a silent apex succeeded") |
| + } |
| + if n := silent.queries.Load(); n != 1 { |
| + t.Fatalf("apex server got %d queries, want 1", n) |
| + } |
| + }) |
| + t.Run("under a public suffix", func(t *testing.T) { |
| + suffix := startAuthority(t, "co.uk", nil) |
| + apex := startAuthority(t, "shop.co.uk", authoritative(aRecord("shop.co.uk.", edgeIP))) |
| + w := &world{ |
| + ns: map[string][]string{ |
| + "co.uk": {"ns.co.uk."}, |
| + "shop.co.uk": {"ns.shop.co.uk."}, |
| + }, |
| + hosts: map[string][]string{ |
| + "ns.co.uk": {"192.0.2.60"}, |
| + "ns.shop.co.uk": {"192.0.2.61"}, |
| + }, |
| + routes: map[string]*fakeAuthority{"192.0.2.60:53": suffix, "192.0.2.61:53": apex}, |
| + } |
| + ips, err := w.resolver(clock()).Resolve("shop.co.uk") |
| + if err != nil || len(ips) != 1 || ips[0] != edgeIP { |
| + t.Fatalf("Resolve = %v, %v; want [%s]", ips, err, edgeIP) |
| + } |
| + if len(w.dialed) == 0 || w.dialed[0] != "192.0.2.60:53" { |
| + t.Fatalf("dialled %v, want co.uk's server first", w.dialed) |
| + } |
| + nameAfterParents(t, w, "shop.co.uk") |
| + }) |
| + t.Run("direct child", func(t *testing.T) { |
| + silent := startAuthority(t, "example.com", nil) |
| + w := oneZone(silent) |
| + if _, err := w.resolver(clock()).Resolve("shop.example.com"); err == nil { |
| + t.Fatal("Resolve against a silent zone succeeded") |
| + } |
| + if n := silent.queries.Load(); n != 1 { |
| + t.Fatalf("example.com's server got %d queries, want 1", n) |
| + } |
| + }) |
| +} |
| + |
| +// finalAttemptWorld has example.com only refer down, so shop.example.com is |
| +// decided by the last, name-itself attempt, whose NS set leads to hostile. |
| +func finalAttemptWorld(t *testing.T, hostile *fakeAuthority) *world { |
| + t.Helper() |
| + parent := startAuthority(t, "example.com", referral("shop.example.com")) |
| + return &world{ |
| + ns: map[string][]string{ |
| + "example.com": {"ns1.example.com."}, |
| + "shop.example.com": {"ns.oldprovider.net."}, |
| + }, |
| + hosts: map[string][]string{ |
| + "ns1.example.com": {"192.0.2.53"}, |
| + "ns.oldprovider.net": {"192.0.2.9"}, |
| + }, |
| + routes: map[string]*fakeAuthority{"192.0.2.53:53": parent, "192.0.2.9:53": hostile}, |
| + } |
| +} |
| + |
| +// Astra R1 P2-2 on #724 follow-up: the name-itself attempt is where a |
| +// cached CNAME can hand LookupNS another zone's servers. It must verify the |
| +// zone like every other attempt: an authoritative-looking positive answer |
| +// from a server that does not hold the name is refused. |
| +func TestFreshResolverFinalAttemptNeverTrustsAWrongZoneServer(t *testing.T) { |
| + wrong := startAuthority(t, "oldprovider.net", authoritative(aRecord("shop.example.com.", edgeIP))) |
| + w := finalAttemptWorld(t, wrong) |
| + if ips, err := w.resolver(clock()).Resolve("shop.example.com"); err == nil { |
| + t.Fatalf("Resolve = %v, want a refusal of the wrong zone's answer", ips) |
| + } |
| + if wrong.queries.Load() == 0 { |
| + t.Fatal("the final attempt never reached the wrong-zone server") |
| + } |
| +} |
| + |
| +// The same, for a server whose SOA is owned by another name. |
| +func TestFreshResolverFinalAttemptVerifiesTheSOAOwner(t *testing.T) { |
| + sloppy := startAuthority(t, "", func(q dnsmessage.Question, r *dnsmessage.Message) bool { |
| + r.Authoritative = true |
| + if q.Type == dnsmessage.TypeSOA { |
| + r.Answers = []dnsmessage.Resource{soaRecord("example.com")} |
| + return true |
| + } |
| + r.Answers = []dnsmessage.Resource{aRecord("shop.example.com.", edgeIP)} |
| + return true |
| + }) |
| + w := finalAttemptWorld(t, sloppy) |
| + if ips, err := w.resolver(clock()).Resolve("shop.example.com"); err == nil { |
| + t.Fatalf("Resolve = %v, want a refusal: the SOA is not shop.example.com's", ips) |
| + } |
| + if sloppy.queries.Load() == 0 { |
| + t.Fatal("the final attempt never reached the sloppy server") |
| + } |
| +} |
| + |
| +// A name the cache knows to be an alias is not a zone, on the final attempt |
| +// too: its servers are never dialled. |
| +func TestFreshResolverFinalAttemptSkipsAnAliasedName(t *testing.T) { |
| + hostile := startAuthority(t, "oldprovider.net", authoritative(aRecord("shop.example.com.", edgeIP))) |
| + w := finalAttemptWorld(t, hostile) |
| + w.cnames = map[string]string{"shop.example.com": "old-provider.net."} |
| + if ips, err := w.resolver(clock()).Resolve("shop.example.com"); err == nil { |
| + t.Fatalf("Resolve = %v, want an error", ips) |
| + } |
| + if hostile.queries.Load() != 0 { |
| + t.Fatalf("dialled the aliased name's servers: %v", w.dialed) |
| + } |
| +} |
| + |
| +// The registrable domain is silent and the intermediate label is not a |
| +// zone: the walk passes over the registrable domain rather than spend the |
| +// deadline asking it again, and the name's own zone answers. |
| +func TestFreshResolverWalkDoesNotReaskTheRegistrableDomain(t *testing.T) { |
| + silent := startAuthority(t, "example.com", nil) |
| + apex := startAuthority(t, "shop.eu.example.com", authoritative(aRecord("shop.eu.example.com.", edgeIP))) |
| + w := &world{ |
| + ns: map[string][]string{ |
| + "example.com": {"ns1.example.com."}, |
| + "shop.eu.example.com": {"ns.shop.example.net."}, |
| + }, |
| + hosts: map[string][]string{ |
| + "ns1.example.com": {"192.0.2.53"}, |
| + "ns.shop.example.net": {"192.0.2.41"}, |
| + }, |
| + routes: map[string]*fakeAuthority{"192.0.2.53:53": silent, "192.0.2.41:53": apex}, |
| + } |
| + ips, err := w.resolver(clock()).Resolve("shop.eu.example.com") |
| + if err != nil || len(ips) != 1 || ips[0] != edgeIP { |
| + t.Fatalf("Resolve = %v, %v; want the name's own zone's answer", ips, err) |
| + } |
| + if n := silent.queries.Load(); n != 1 { |
| + t.Fatalf("the registrable domain's server got %d queries, want 1", n) |
| + } |
| +} |
diff --git a/internal/domains/reconcile.go b/internal/domains/reconcile.go| index 09fad0293..b11a9b879 100644 |
| --- a/internal/domains/reconcile.go |
| +++ b/internal/domains/reconcile.go |
| @@ -632,7 +632,9 @@ var ( |
| // no possible public zone (sidecar hosts under .internal) have nothing to |
| // ask; neither is eligible, so neither takes a share of the budget, and |
| // both are stamped by the cached path alone. Eligible names share one |
| -// budget, visited in a random order: the pass stops looking fresh after |
| +// budget, published names' upgrades first, each group in a random order |
| +// (Astra R1 on the #724 follow-up: new names must not starve a published |
| +// name's re-check and so unpublish it). The pass stops looking fresh after |
| // freshPassMax lookups or freshPassTime, so a large backlog is worked |
| // through across passes instead of stretching any one of them. A |
| // not-pointing name past the budget gets the cached look, as before #724. |
| @@ -645,8 +647,10 @@ func dnsVerdicts(cfg Config, edge map[string]bool, candidates []freshCandidate) |
| } |
| // Fresh-first names wait for the budget loop; everything else gets its |
| // cached verdict now, and a published name the cache does not read as |
| - // pointing joins the loop for an upgrade. |
| - var pending []freshCandidate |
| + // pointing joins the loop for an upgrade. Upgrades go FIRST: a backlog |
| + // of new names must never spend the budget a published name needs to |
| + // stay published. Random order within each group. |
| + var upgrades, firsts []freshCandidate |
| for _, c := range candidates { |
| if !eligible(c.host) { |
| *c.status = dnsStatus(cfg.Resolve, c.host, edge) |
| @@ -654,15 +658,17 @@ func dnsVerdicts(cfg Config, edge map[string]bool, candidates []freshCandidate) |
| } |
| if c.prev != "pointing" { |
| *c.status = unresolvedDNS |
| - pending = append(pending, c) |
| + firsts = append(firsts, c) |
| continue |
| } |
| *c.status = dnsStatus(cfg.Resolve, c.host, edge) |
| if *c.status == "" || *c.status == "elsewhere" { |
| - pending = append(pending, c) |
| + upgrades = append(upgrades, c) |
| } |
| } |
| - rand.Shuffle(len(pending), func(i, j int) { pending[i], pending[j] = pending[j], pending[i] }) |
| + rand.Shuffle(len(upgrades), func(i, j int) { upgrades[i], upgrades[j] = upgrades[j], upgrades[i] }) |
| + rand.Shuffle(len(firsts), func(i, j int) { firsts[i], firsts[j] = firsts[j], firsts[i] }) |
| + pending := append(upgrades, firsts...) |
| start := time.Now() |
| for n, c := range pending { |
| if n >= freshPassMax || time.Since(start) >= freshPassTime { |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 8706a8e04..87b325dbf 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -144,4 +144,4 @@ plan14-root-reads-deploy-edge-718.tsv 250e3ba91e1bc5fcd6be5cc2bafce4c7d6645d2d2f |
| plan14-root-reads-demo-slice-adopt.tsv 707018faaa1fee3b47abb78389ae7854264e76621cc316889061adb69bf13e10 |
| plan14-root-reads-security-review-mitigations.tsv a6f3f9eec4aac5ea88f20d0e52eaa0651fce80c0d49b60883ff61ceade33d288 |
| plan14-root-reads-cli-registry-words.tsv 8924fafc5b6083858a72f45c764081abe3bcad6a6de71901470586c076c64bb6 |
| -plan14-root-reads-no-negative-prime-724.tsv f7eb15fc80af393e7da87f84e5b9bd8fe4803ffed533cfedf209a92dd53910ec |
| +plan14-root-reads-no-negative-prime-724.tsv 1fc14572275cc3e3fc7a889f4672d867dc3982204c8909cd87a60024f0909829 |
diff --git a/internal/provision/testdata/plan14-root-reads-no-negative-prime-724.tsv b/internal/provision/testdata/plan14-root-reads-no-negative-prime-724.tsv| index 5f5e32de3..bb3b5cd0b 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-no-negative-prime-724.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-no-negative-prime-724.tsv |
| @@ -1,5 +1,5 @@ |
| # Census overlay no-negative-prime-724, written by census-propose (#369). census-ruling-no-negative-prime-724, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-no-negative-prime-724.md. |
| # 0 body, 1 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| -@legacy f632b5dfb6bece081019d31d35a6268a227e0d4289455a9266b0f996f6392bf2 internal/domains/reconcile.go StampHealth legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-dns-fresh-lookup-724;basis=section 4 now computes every cached verdict first, then freshUpgrade gives up to 64 randomly ordered names that could have a public zone (not under the apps domain, not special-use like .internal) and whose verdict is "" or "elsewhere" an uncached lookup (30 s pass budget) that may only upgrade to "pointing", then stamps; the extra sites are the indexed loops over the same rows (#724);rev3=census-ruling-no-negative-prime-724;basis=section 4 now hands each route and alias, with its previous stamp (the two new registry:DNSStatus reads, rt.DNSStatus and a.DNSStatus, same rows already listed), to dnsVerdicts: a name not "pointing" before this pass and eligible for a fresh lookup (public name, not under the apps domain, ResolveFresh set) is looked at uncached first within the same 64-lookup/30 s budget and stamped from it (edge address "pointing", other "elsewhere", authoritative not-found ""), falling back to the cached lookup on a fresh error or past the budget; a previously "pointing" name keeps cached-first plus the upgrade-only fresh look, so the fresh path still never unpublishes; no new file, path or command input; the dropped Alias/Host/Route/RouteAlias sites are the old indexed loops folded into the candidate build (#724) registry:Alias@3172,registry:Alias@3700,registry:Alias@3790,registry:Alias@4224,registry:Alias@4288,registry:Alias@4376,registry:DNSStatus@3053,registry:DNSStatus@3181,registry:DNSStatus@3349,registry:DNSStatus@3624,registry:Host@3044,registry:Host@3421,registry:Host@3505,registry:Host@3993,registry:Host@4052,registry:Host@4134,whole:Route@199,whole:Route@236,whole:Route@2871,whole:Route@2984,whole:Route@3277,whole:Route@3947,whole:RouteAlias@2917,whole:RouteAlias@3111,whole:RouteAlias@3551,whole:RouteAlias@4177,whole:RouteAlias@780 8a40c0797f5e0dd2598359a130eeea4e7770fc4208d1b20d501143dd9925549f |
| -internal/domains/reconcile.go StampHealth legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-dns-fresh-lookup-724;basis=section 4 now computes every cached verdict first, then freshUpgrade gives up to 64 randomly ordered names that could have a public zone (not under the apps domain, not special-use like .internal) and whose verdict is "" or "elsewhere" an uncached lookup (30 s pass budget) that may only upgrade to "pointing", then stamps; the extra sites are the indexed loops over the same rows (#724);rev3=census-ruling-no-negative-prime-724;basis=section 4 now hands each route and alias, with its previous stamp (the two new registry:DNSStatus reads, rt.DNSStatus and a.DNSStatus, same rows already listed), to dnsVerdicts: a name not "pointing" before this pass and eligible for a fresh lookup (public name, not under the apps domain, ResolveFresh set) is looked at uncached first within the same 64-lookup/30 s budget and stamped from it (edge address "pointing", other "elsewhere", authoritative not-found ""), falling back to the cached lookup on a fresh error or past the budget; a previously "pointing" name keeps cached-first plus the upgrade-only fresh look, so the fresh path still never unpublishes; no new file, path or command input; the dropped Alias/Host/Route/RouteAlias sites are the old indexed loops folded into the candidate build (#724) registry:Alias@3172,registry:Alias@3700,registry:Alias@3790,registry:Alias@4224,registry:Alias@4288,registry:Alias@4376,registry:DNSStatus@3053,registry:DNSStatus@3181,registry:DNSStatus@3349,registry:DNSStatus@3624,registry:Host@3044,registry:Host@3421,registry:Host@3505,registry:Host@3993,registry:Host@4052,registry:Host@4134,whole:Route@199,whole:Route@236,whole:Route@2871,whole:Route@2984,whole:Route@3277,whole:Route@3947,whole:RouteAlias@2917,whole:RouteAlias@3111,whole:RouteAlias@3551,whole:RouteAlias@4177,whole:RouteAlias@780 8a40c0797f5e0dd2598359a130eeea4e7770fc4208d1b20d501143dd9925549f |
| -@coverage internal/domains 168f90d4623a3ac1863b7241f49e28272f4a05cd0cab6b14699101c6a88dc83a |
| +@legacy 67e3f48ab223547023032d72333a170328d9127bd9c26afd6f8c360cfcf5f6e8 internal/domains/reconcile.go StampHealth legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-dns-fresh-lookup-724;basis=section 4 now computes every cached verdict first, then freshUpgrade gives up to 64 randomly ordered names that could have a public zone (not under the apps domain, not special-use like .internal) and whose verdict is "" or "elsewhere" an uncached lookup (30 s pass budget) that may only upgrade to "pointing", then stamps; the extra sites are the indexed loops over the same rows (#724);rev3=census-ruling-no-negative-prime-724;basis=section 4 now hands each route and alias, with its previous stamp (the two new registry:DNSStatus reads, rt.DNSStatus and a.DNSStatus, same rows already listed), to dnsVerdicts: a name not "pointing" before this pass and eligible for a fresh lookup (public name, not under the apps domain, ResolveFresh set) is looked at uncached first within the same 64-lookup/30 s budget (shared, with previously "pointing" names' upgrade looks serviced before any fresh-first name so new names cannot starve a published one) and stamped from it (edge address "pointing", other "elsewhere", authoritative not-found ""), falling back to the cached lookup on a fresh error or past the budget; a previously "pointing" name keeps cached-first plus the upgrade-only fresh look, so the fresh path still never unpublishes; no new file, path or command input; the dropped Alias/Host/Route/RouteAlias sites are the old indexed loops folded into the candidate build (#724) registry:Alias@3172,registry:Alias@3700,registry:Alias@3790,registry:Alias@4224,registry:Alias@4288,registry:Alias@4376,registry:DNSStatus@3053,registry:DNSStatus@3181,registry:DNSStatus@3349,registry:DNSStatus@3624,registry:Host@3044,registry:Host@3421,registry:Host@3505,registry:Host@3993,registry:Host@4052,registry:Host@4134,whole:Route@199,whole:Route@236,whole:Route@2871,whole:Route@2984,whole:Route@3277,whole:Route@3947,whole:RouteAlias@2917,whole:RouteAlias@3111,whole:RouteAlias@3551,whole:RouteAlias@4177,whole:RouteAlias@780 8a40c0797f5e0dd2598359a130eeea4e7770fc4208d1b20d501143dd9925549f |
| +internal/domains/reconcile.go StampHealth legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-dns-fresh-lookup-724;basis=section 4 now computes every cached verdict first, then freshUpgrade gives up to 64 randomly ordered names that could have a public zone (not under the apps domain, not special-use like .internal) and whose verdict is "" or "elsewhere" an uncached lookup (30 s pass budget) that may only upgrade to "pointing", then stamps; the extra sites are the indexed loops over the same rows (#724);rev3=census-ruling-no-negative-prime-724;basis=section 4 now hands each route and alias, with its previous stamp (the two new registry:DNSStatus reads, rt.DNSStatus and a.DNSStatus, same rows already listed), to dnsVerdicts: a name not "pointing" before this pass and eligible for a fresh lookup (public name, not under the apps domain, ResolveFresh set) is looked at uncached first within the same 64-lookup/30 s budget (shared, with previously "pointing" names' upgrade looks serviced before any fresh-first name so new names cannot starve a published one) and stamped from it (edge address "pointing", other "elsewhere", authoritative not-found ""), falling back to the cached lookup on a fresh error or past the budget; a previously "pointing" name keeps cached-first plus the upgrade-only fresh look, so the fresh path still never unpublishes; no new file, path or command input; the dropped Alias/Host/Route/RouteAlias sites are the old indexed loops folded into the candidate build (#724) registry:Alias@3172,registry:Alias@3700,registry:Alias@3790,registry:Alias@4224,registry:Alias@4288,registry:Alias@4376,registry:DNSStatus@3053,registry:DNSStatus@3181,registry:DNSStatus@3349,registry:DNSStatus@3624,registry:Host@3044,registry:Host@3421,registry:Host@3505,registry:Host@3993,registry:Host@4052,registry:Host@4134,whole:Route@199,whole:Route@236,whole:Route@2871,whole:Route@2984,whole:Route@3277,whole:Route@3947,whole:RouteAlias@2917,whole:RouteAlias@3111,whole:RouteAlias@3551,whole:RouteAlias@4177,whole:RouteAlias@780 8a40c0797f5e0dd2598359a130eeea4e7770fc4208d1b20d501143dd9925549f |
| +@coverage internal/domains 465f93499339830fad65dce7feacc563fb7f6df3c3591f297d48e55e6877ad8c |