domains: fresh lookup takes the delegation from the parent zone (#1383)
FreshResolver.resolve took the registrable domain's NS set from the cached LookupNS. A cached NS set outlives a move of the domain's DNS hosting: the registry delegates to the new host at once, the box's resolvers go on naming the old host for the old set's TTL (two days under .uk), and the old host goes on answering with authority. A name pointing here on the new host read "elsewhere", which is final for a name not yet published, so the alias was never published. Step 1 now asks the parent zone. The cached LookupNS finds the parent (the public suffix, or the closest name above it with an NS set, as far as the TLD), one of its servers is verified to hold that zone and asked, non-recursively, for the registrable domain's NS set (QNAME minimisation: the registry never sees the customer's hostname), and only a referral for exactly the registrable domain is taken, with glue for in-zone nameservers only and publicNameserver on every address. The walk below is unchanged. With no usable delegation (no NS set for the suffix, parent servers that fail or do not verify, a truncated or authoritative reply, a referral off the path, no address we may dial) the lookup falls back to the cached NS set, which is what main did. The parent step runs inside half of what is left of Timeout so silent parent servers leave the fallback its time. Resolve and ResolveUpgrade both take the new step. The only new cached queries are NS sets of the suffix's levels and the addresses of the parent's nameserver hosts; none is for the customer's name or a label below the registrable domain. Tests that pinned the exact cached queries now expect the suffix's NS query; noCachedBelow allows NS queries for the names above the registrable domain. Census: internal/domains envelope re-pinned, no unit changed.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
6 files changed,
+476
−46
docs/superpowers/notes/census-proposal-parent-delegation-1383.md+11 −0internal/domains/freshdns.go+132 −25internal/domains/freshdns_parent_test.go+302 −0internal/domains/freshdns_test.go+27 −21internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-parent-delegation-1383.tsv+3 −0
CI cancelled — superseded by a newer push — run details
CI log
=== gate === go: downloading go1.26.10 (linux/arm64) go version go1.26.10 linux/arm64 opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1 tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz tofu: downloaded, digest verified aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip aws: downloaded, digest verified archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip archive: downloaded, digest verified installed in /tmp/carlos-opentofu-MKNddS .amadan/test-gate.sh go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0 go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5 go: downloading github.com/benbjohnson/litestream v0.5.14 go: downloading github.com/aws/aws-sdk-go-v2/service/acm v1.45.0 go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0 go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2 go: downloading golang.org/x/sys v0.49.0 go: downloading github.com/aws/aws-sdk-go-v2/service/route53 v1.64.1 go: downloading github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.37.0 go: downloading github.com/superfly/ltx v0.5.1 go: downloading golang.org/x/net v0.62.0 go: downloading modernc.org/sqlite v1.55.0 go: downloading golang.org/x/crypto v0.58.0 go: downloading golang.org/x/mod v0.41.0 go: downloading github.com/pion/logging v0.2.4 go: downloading github.com/pion/stun/v3 v3.1.5 go: downloading github.com/pion/turn/v4 v4.1.4 go: downloading github.com/aws/aws-sdk-go-v2/service/sesv2 v1.66.6 go: downloading github.com/aws/aws-sdk-go-v2/service/ssm v1.74.0 go: downloading github.com/pierrec/lz4/v4 v4.1.22 go: downloading github.com/pion/dtls/v3 v3.1.4 go: downloading github.com/klauspost/compress v1.20.2 go: downloading github.com/wlynxg/anet v0.0.5 go: downloading github.com/pion/randutil v0.1.0 go: downloading golang.org/x/sync v0.24.0 go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18 go: downloading github.com/prometheus/client_golang v1.17.0 go: downloading github.com/lmittmann/tint v1.1.3 go: downloading google.golang.org/protobuf v1.36.10 go: downloading github.com/beorn7/perks v1.0.1 go: downloading github.com/prometheus/client_model v0.5.0 go: downloading github.com/prometheus/common v0.45.0 go: downloading github.com/prometheus/procfs v0.12.0 go: downloading github.com/cespare/xxhash/v2 v2.3.0 go: downloading golang.org/x/text v0.43.0 go: downloading github.com/klauspost/compress v1.20.2 go: downloading modernc.org/sqlite v1.55.0 go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0 go: downloading github.com/pierrec/lz4/v4 v4.1.22 go: downloading modernc.org/libc v1.74.1 go: downloading modernc.org/libc v1.74.1 go: downloading modernc.org/memory v1.11.0 go: downloading modernc.org/mathutil v1.7.1 go: downloading github.com/google/uuid v1.6.0 go: downloading github.com/dustin/go-humanize v1.0.1 go: downloading modernc.org/mathutil v1.7.1 amadan: job cancelled — a newer push superseded it
Intent
Attributed to this commit: 16.8 g CO₂e (2,029,927 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on parent-delegation-1383, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/notes/census-proposal-parent-delegation-1383.md b/docs/superpowers/notes/census-proposal-parent-delegation-1383.md| new file mode 100644 |
| index 000000000..62a13850c |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-parent-delegation-1383.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: parent-delegation-1383 |
| + |
| +Ruling `census-ruling-parent-delegation-1383`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +Envelopes re-pinned: `internal/domains`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Seal: `841361b89e20c3763149e8784cdebb037dcc4b828b24196a01d3e300ff319661` → `841361b89e20c3763149e8784cdebb037dcc4b828b24196a01d3e300ff319661`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-parent-delegation-1383.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/domains/freshdns.go b/internal/domains/freshdns.go| index cae8eeb3f..4ad99e9b4 100644 |
| --- a/internal/domains/freshdns.go |
| +++ b/internal/domains/freshdns.go |
| @@ -30,9 +30,11 @@ import ( |
| // zone's own nameservers is the one answer no cache can hold back. |
| // |
| // The cached resolver is still used, only for names that exist whatever |
| -// the customer has done yet: the registrable domain's NS set (LookupNS), |
| -// nameserver host addresses and a CNAME target outside the zone (in |
| -// practice the deployment's own edge name) (LookupHost). For a new name |
| +// the customer has done yet: the NS set of the registrable domain's parent |
| +// zone (its public suffix or TLD), and of the registrable domain itself |
| +// when the parent gives no delegation (LookupNS), nameserver host |
| +// addresses and a CNAME target outside the zone (in practice the |
| +// deployment's own edge name) (LookupHost). For a new name |
| // (Resolve) it is never asked about the name or any label between it and |
| // the registrable domain; see resolve. A published name (ResolveUpgrade) |
| // exists, so that look may ask it about those too. |
| @@ -359,10 +361,18 @@ func registrableDomain(name string) (string, bool) { |
| // registrable domain, without the cached resolver ever hearing about the |
| // name or any label between it and the registrable domain: |
| // |
| -// 1. zone = registrableDomain(name). Its NS set comes from the cached |
| -// LookupNS: the domain is registered, so the answer is positive and |
| -// primes nothing. This is the ONLY cached NS (or any) query on the |
| -// name's path. |
| +// 1. zone = registrableDomain(name). Its servers come from the PARENT |
| +// zone's delegation, asked for now (delegation): the cached LookupNS |
| +// finds the parent zone (the public suffix, or the closest name above |
| +// it with an NS set), one of the parent's servers is verified to hold |
| +// it and is asked, non-recursively, for the registrable domain's NS |
| +// set, and its referral names the servers. When the parent gives no |
| +// usable delegation, the registrable domain's NS set comes from the |
| +// cached LookupNS instead, as it did before #1383. The suffix, the |
| +// TLD and a registered domain all exist, so these answers are positive |
| +// and prime nothing. They are the ONLY cached NS queries on the name's |
| +// path, and none is for the name or a label below the registrable |
| +// domain. |
| // 2. Each of up to freshMaxServers public addresses of the zone's servers |
| // is verified to hold zone (verifyZone: an authoritative SOA owned by |
| // exactly zone) and then asked for name (ask). |
| @@ -393,6 +403,16 @@ func registrableDomain(name string) (string, bool) { |
| // outside this function: section 4's cached look after a second fresh |
| // failure in a row and for names past the per-pass budget. |
| // |
| +// Why the parent is asked (#1383): a cached NS set outlives a move of the |
| +// domain's DNS hosting. The registry delegates to the new host at once, |
| +// while the box's resolvers go on naming the old host for the old NS set's |
| +// TTL (two days under .uk), and the old host goes on answering, with |
| +// authority, the records it had. Read from the cached NS set, a name that |
| +// points here on the new host is "elsewhere" until that TTL runs out, and |
| +// for a new name that verdict is final. The parent's delegation is the |
| +// authority on where the zone lives, and asking the parent's own servers |
| +// is the one way to read it that no cache can hold back. |
| +// |
| // upgrade is ResolveUpgrade's walk for a published name: the same walk, |
| // except that serverAddrs may ask the cache for any nameserver host. |
| // |
| @@ -404,19 +424,34 @@ func registrableDomain(name string) (string, bool) { |
| // and then fails the AAAA exchange, the second refers); the zone the walk |
| // ends in costs at most 3 + 3 = 6. With 1 + freshMaxZones zones that is |
| // 3*5 + 6 = 21 authoritative exchanges. A hint costs what a referral does. |
| -// Cached: one LookupNS; LookupHost for at most freshMaxNSHosts nameserver |
| -// hosts per zone, 16 in all (fewer once freshMaxServers IPv4 addresses are |
| -// found; none for a zone reached by a hint); and one LookupHost per reply |
| -// that ends in an out-of-zone CNAME target, which a failed lookup repeats |
| -// on the next server: one in each zone that hands on, two in the last, 5 |
| -// in all. 22 cached calls. The two maxima need different replies from the |
| -// same servers, so no one lookup reaches both. |
| +// The parent step adds at most 2 for each of freshMaxServers parent |
| +// servers (SOA, then NS), 4, so 25 exchanges. Cached: one LookupNS per |
| +// level of the public suffix (S of them, until one has an NS set; 1 for |
| +// example.com, 1 or 2 for example.co.uk), one more for the registrable |
| +// domain when the parent step falls back, and LookupHost for at most |
| +// freshMaxNSHosts of the parent's nameserver hosts; then LookupHost for at |
| +// most freshMaxNSHosts nameserver hosts per zone (fewer once |
| +// freshMaxServers IPv4 addresses are found; none for a zone reached by a |
| +// hint), and twice that for the registrable domain when the parent's |
| +// delegation names no address we may dial and the cached NS set is used |
| +// after it, 20 in all; and one LookupHost per reply that ends in an |
| +// out-of-zone CNAME target, which a failed lookup repeats on the next |
| +// server: one in each zone that hands on, two in the last, 5 in all. |
| +// 30 + S cached calls. The maxima need different replies from the same |
| +// servers, so no one lookup reaches them all. |
| +// |
| +// Time: the parent step runs inside HALF of what is left of Timeout when |
| +// the walk starts (2 s of the default 4 s for a new name). That is enough |
| +// for one silent parent server at AttemptTimeout and a referral from the |
| +// next, and it leaves the other half to the fallback when both are silent. |
| +// Whatever the parent step does not use goes to the walk. |
| // |
| // ResolveUpgrade adds nearest's share before the walk: up to freshMaxZones |
| -// zones at 6 exchanges each, 18, so 39 exchanges; and one LookupNS per |
| +// zones at 6 exchanges each, 18, so 43 exchanges; and one LookupNS per |
| // level of the name below the registrable domain (L of them, the name |
| // included; only levels WITH an NS set are capped), plus for each of those |
| -// zones 4 nameserver hosts and 2 CNAME targets, 18, so 40 + L cached calls. |
| +// zones 4 nameserver hosts and 2 CNAME targets, 18, so 48 + S + L cached |
| +// calls. |
| // |
| // Verification is what makes a referral or an NS set safe to follow: a |
| // server only answers once it has shown, with authority, an SOA owned by |
| @@ -428,16 +463,24 @@ func (r *FreshResolver) resolve(ctx context.Context, name string, upgrade bool) |
| if !ok { |
| return nil, fmt.Errorf("%w: %s is a public suffix", errNoAuthority, name) |
| } |
| - nss, err := r.LookupNS(ctx, zone) |
| - if err != nil || len(nss) == 0 { |
| - return nil, fmt.Errorf("%w: no NS set for %s", errNoAuthority, zone) |
| + registrable := zone |
| + var servers []netip.AddrPort |
| + if ref := r.delegation(ctx, name, registrable, upgrade); ref != nil { |
| + servers = r.serverAddrs(ctx, name, registrable, zone, ref.hosts, ref.glue, upgrade) |
| } |
| - hosts := make([]string, len(nss)) |
| - for i, ns := range nss { |
| - hosts[i] = ns.Host |
| + if len(servers) == 0 { |
| + // No delegation from the parent, or one that names no address we |
| + // may dial: the cached NS set, as before #1383. |
| + nss, err := r.LookupNS(ctx, zone) |
| + if err != nil || len(nss) == 0 { |
| + return nil, fmt.Errorf("%w: no NS set for %s", errNoAuthority, zone) |
| + } |
| + hosts := make([]string, len(nss)) |
| + for i, ns := range nss { |
| + hosts[i] = ns.Host |
| + } |
| + servers = r.serverAddrs(ctx, name, registrable, zone, hosts, nil, upgrade) |
| } |
| - registrable := zone |
| - servers := r.serverAddrs(ctx, name, registrable, zone, hosts, nil, upgrade) |
| for referrals := 0; ; referrals++ { |
| ips, ref, err := r.askZone(ctx, servers, name, zone) |
| if ref == nil { |
| @@ -461,6 +504,69 @@ func (r *FreshResolver) resolve(ctx context.Context, name string, upgrade bool) |
| } |
| } |
| +// delegation is step 1 of resolve: the registrable domain's delegation as |
| +// its parent zone gives it now (#1383). nil is "no usable delegation", and |
| +// the caller falls back to the cached NS set. |
| +// |
| +// The parent zone is the closest name above registrable with an NS set in |
| +// the cached LookupNS: its public suffix when that is a zone of its own |
| +// (com; co.uk, which nic.uk serves apart from uk), else the next name up, |
| +// as far as the TLD (a multi-label suffix that is only a name inside its |
| +// TLD's zone has no NS set). Up to freshMaxServers of the parent's servers |
| +// are verified to hold that zone (verifyZone) and asked for registrable's |
| +// NS set. Only a referral for exactly registrable is taken (referralFrom, |
| +// with registrable as both the name and the one owner allowed), with glue |
| +// only for nameservers inside registrable. Everything else is no |
| +// delegation: a server that fails or does not verify, a truncated reply, |
| +// an answer with authority (a "no such name", or a server that holds both |
| +// zones), a referral to anything but registrable. |
| +// |
| +// The question is the registrable domain's NS set, not the name's A record |
| +// (QNAME minimisation, RFC 9156): the registry's servers answer both with |
| +// the same referral, and need not learn the customer's hostname. |
| +// |
| +// The cache hears only about the suffix's levels and the parent's |
| +// nameserver hosts (a.gtld-servers.net, nsa.nic.uk), which exist whatever |
| +// the customer has done. The whole step runs inside half of what is left |
| +// of ctx's deadline, so a silent parent leaves the fallback its time. |
| +func (r *FreshResolver) delegation(ctx context.Context, name, registrable string, upgrade bool) *referral { |
| + if deadline, ok := ctx.Deadline(); ok { |
| + var cancel context.CancelFunc |
| + ctx, cancel = context.WithTimeout(ctx, time.Until(deadline)/2) |
| + defer cancel() |
| + } |
| + var hosts []string |
| + parent := registrable |
| + for len(hosts) == 0 { |
| + i := strings.Index(parent, ".") |
| + if i < 0 || ctx.Err() != nil { |
| + return nil |
| + } |
| + parent = parent[i+1:] |
| + nss, err := r.LookupNS(ctx, parent) |
| + if err != nil { |
| + continue |
| + } |
| + for _, ns := range nss { |
| + hosts = append(hosts, ns.Host) |
| + } |
| + } |
| + for _, s := range r.serverAddrs(ctx, name, registrable, parent, hosts, nil, upgrade) { |
| + if r.verifyZone(ctx, s, parent) == nil { |
| + reply, err := r.query(ctx, s, registrable, dnsmessage.TypeNS) |
| + if err == nil && !reply.Truncated && !reply.Authoritative { |
| + if ref, err := referralFrom(reply, registrable, parent); err == nil && ref.zone == registrable { |
| + return ref |
| + } |
| + } |
| + } |
| + if ctx.Err() != nil { |
| + break |
| + } |
| + } |
| + return nil |
| +} |
| + |
| // nearest is ResolveUpgrade's first look for a published name. It climbs |
| // the name's levels asking the cached LookupNS at each, as main's lookup |
| // did: the immediate parent, the name itself (a delegated sub-zone, which |
| @@ -476,7 +582,8 @@ func (r *FreshResolver) resolve(ctx context.Context, name string, upgrade bool) |
| // The climb stops below the registrable domain, which is left to the |
| // top-down walk that follows and starts there: a name directly under it |
| // tries only itself here, and an apex nothing at all (its parent would be |
| -// the TLD, whose servers are never asked). The climb asks the cache about |
| +// the public suffix, whose servers this climb never asks; the walk's first |
| +// step asks them for the delegation). The climb asks the cache about |
| // the name's own levels, which is why only a name that already exists ever |
| // comes here. |
| func (r *FreshResolver) nearest(ctx context.Context, name string) ([]string, error) { |
diff --git a/internal/domains/freshdns_parent_test.go b/internal/domains/freshdns_parent_test.go| new file mode 100644 |
| index 000000000..cce719fb3 |
| --- /dev/null |
| +++ b/internal/domains/freshdns_parent_test.go |
| @@ -0,0 +1,302 @@ |
| +package domains_test |
| + |
| +import ( |
| + "context" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "golang.org/x/net/dns/dnsmessage" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| +) |
| + |
| +// #1383: a customer moved example.co.uk's DNS hosting. The registry (co.uk) |
| +// delegates to the new host, which serves an edge address; the box's cached |
| +// resolver still names the OLD host for the NS set, and the old host still |
| +// answers, with authority, the address it had. The fresh look takes the |
| +// delegation from the parent zone, so it asks the new host. |
| + |
| +const ( |
| + oldHostIP = "198.51.100.9" // what the old DNS host still answers |
| + parentAddr = "192.0.2.1" |
| + oldHostAddr = "192.0.2.2" |
| + newHostAddr = "192.0.2.3" |
| + parentNSHost = "nsa.nic.uk" |
| +) |
| + |
| +// questions records every non-SOA question a fake parent was asked. |
| +type questions struct { |
| + mu sync.Mutex |
| + got []string // "<name> <type>" |
| +} |
| + |
| +func (q *questions) all() []string { |
| + q.mu.Lock() |
| + defer q.mu.Unlock() |
| + return append([]string(nil), q.got...) |
| +} |
| + |
| +// delegating answers as a registry's server: every non-SOA query gets a |
| +// referral (no authority) naming child's nameserver nsHost, with glue when |
| +// glueIP is set. The questions are recorded in qs. |
| +func delegating(qs *questions, child, nsHost, glueIP string) func(dnsmessage.Question, *dnsmessage.Message) bool { |
| + return func(q dnsmessage.Question, r *dnsmessage.Message) bool { |
| + qs.mu.Lock() |
| + qs.got = append(qs.got, q.Name.String()+" "+q.Type.String()) |
| + qs.mu.Unlock() |
| + 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(nsHost + ".")}, |
| + }} |
| + if glueIP != "" { |
| + r.Additionals = []dnsmessage.Resource{aRecord(nsHost+".", glueIP)} |
| + } |
| + return true |
| + } |
| +} |
| + |
| +// movedWorld is the incident for name (example.co.uk or a name below it). |
| +// The cache holds example.co.uk's OLD NS set (ns.oldhost.net, whose server |
| +// answers oldHostIP); the new host's server answers edgeIP. parent is what |
| +// the server at parentAddr does, for parentZone, whose NS set the cache |
| +// knows; a nil parent with parentZone "" leaves the suffix with no NS set |
| +// at all. |
| +func movedWorld(t *testing.T, name, parentZone string, parent *fakeAuthority) (w *world, oldHost, newHost *fakeAuthority) { |
| + t.Helper() |
| + oldHost = startAuthority(t, "example.co.uk", authoritative(aRecord(name+".", oldHostIP))) |
| + newHost = startAuthority(t, "example.co.uk", authoritative(aRecord(name+".", edgeIP))) |
| + w = &world{ |
| + ns: map[string][]string{"example.co.uk": {"ns.oldhost.net."}}, |
| + hosts: map[string][]string{ |
| + parentNSHost: {parentAddr}, |
| + "ns.oldhost.net": {oldHostAddr}, |
| + "ns.newhost.net": {newHostAddr}, |
| + }, |
| + routes: map[string]*fakeAuthority{oldHostAddr + ":53": oldHost, newHostAddr + ":53": newHost}, |
| + } |
| + if parentZone != "" { |
| + w.ns[parentZone] = []string{parentNSHost + "."} |
| + w.routes[parentAddr+":53"] = parent |
| + } |
| + return w, oldHost, newHost |
| +} |
| + |
| +func TestFreshResolverTakesTheDelegationFromTheParent(t *testing.T) { |
| + for _, name := range []string{"example.co.uk", "shop.example.co.uk"} { |
| + for kind, resolve := range map[string]func(*domains.FreshResolver) func(string) ([]string, error){ |
| + "new": func(r *domains.FreshResolver) func(string) ([]string, error) { return r.Resolve }, |
| + "published": func(r *domains.FreshResolver) func(string) ([]string, error) { return r.ResolveUpgrade }, |
| + } { |
| + t.Run(kind+" "+name, func(t *testing.T) { |
| + qs := &questions{} |
| + parent := startAuthority(t, "co.uk", delegating(qs, "example.co.uk", "ns.newhost.net", "")) |
| + w, oldHost, newHost := movedWorld(t, name, "co.uk", parent) |
| + ips, err := resolve(w.resolver(clock()))(name) |
| + if err != nil || len(ips) != 1 || ips[0] != edgeIP { |
| + t.Fatalf("resolve = %v, %v; want [%s] from the host the parent delegates to", ips, err, edgeIP) |
| + } |
| + if n := oldHost.queries.Load(); n != 0 { |
| + t.Fatalf("the old DNS host got %d queries, want none", n) |
| + } |
| + if n := newHost.queries.Load(); n != 2 { |
| + t.Fatalf("the new DNS host got %d queries, want its SOA and the A", n) |
| + } |
| + // QNAME minimisation: the registry is asked for the |
| + // registrable domain's NS set, never for the customer's name. |
| + if got := strings.Join(qs.all(), ","); got != "example.co.uk. TypeNS" { |
| + t.Fatalf("parent was asked %s, want only example.co.uk. TypeNS", got) |
| + } |
| + want := "NS co.uk,HOST " + parentNSHost + ",HOST ns.newhost.net" |
| + if kind == "published" && name != "example.co.uk" { |
| + want = "NS " + name + "," + want // nearest's climb, unchanged |
| + } |
| + if got := strings.Join(w.cached, ","); got != want { |
| + t.Fatalf("cached queries = %s, want %s", got, want) |
| + } |
| + if kind == "new" { |
| + noCachedBelow(t, w, name, "example.co.uk") |
| + } |
| + }) |
| + } |
| + } |
| +} |
| + |
| +// The incident through section 4 with production wiring: the new name is |
| +// stamped "pointing" and published, and the cached resolver hears nothing |
| +// about it. |
| +func TestStampHealthMovedDNSHostIsPointing(t *testing.T) { |
| + for _, name := range []string{"example.co.uk", "shop.example.co.uk"} { |
| + t.Run(name, func(t *testing.T) { |
| + parent := startAuthority(t, "co.uk", delegating(&questions{}, "example.co.uk", "ns.newhost.net", "")) |
| + w, oldHost, _ := movedWorld(t, name, "co.uk", parent) |
| + asked := map[string]int{} |
| + cfg, _ := worldCfg(w, name, asked) |
| + reg := regWithAlias(t, name) |
| + if err := domains.StampHealth(context.Background(), reg, cfg, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := aliasStatus(t, reg, name); got != "pointing" { |
| + t.Fatalf("alias = %q, want pointing", got) |
| + } |
| + if asked[name] != 0 { |
| + t.Fatalf("cached resolver asked about %s %d times", name, asked[name]) |
| + } |
| + noCachedBelow(t, w, name, "example.co.uk") |
| + if n := oldHost.queries.Load(); n != 0 { |
| + t.Fatalf("the old DNS host got %d queries, want none", n) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// co.uk is a zone of its own, but a multi-label suffix need not be: with no |
| +// NS set for co.uk the climb goes on to uk, whose servers hold the |
| +// delegation. |
| +func TestFreshResolverParentClimbsToTheTLD(t *testing.T) { |
| + const name = "shop.example.co.uk" |
| + qs := &questions{} |
| + parent := startAuthority(t, "uk", delegating(qs, "example.co.uk", "ns.newhost.net", "")) |
| + w, oldHost, _ := movedWorld(t, name, "uk", parent) |
| + ips, err := w.resolver(clock()).Resolve(name) |
| + if err != nil || len(ips) != 1 || ips[0] != edgeIP { |
| + t.Fatalf("Resolve = %v, %v; want [%s]", ips, err, edgeIP) |
| + } |
| + if got := strings.Join(w.cached, ","); got != "NS co.uk,NS uk,HOST "+parentNSHost+",HOST ns.newhost.net" { |
| + t.Fatalf("cached queries = %s", got) |
| + } |
| + if got := strings.Join(qs.all(), ","); got != "example.co.uk. TypeNS" { |
| + t.Fatalf("parent was asked %s, want only example.co.uk. TypeNS", got) |
| + } |
| + if n := oldHost.queries.Load(); n != 0 { |
| + t.Fatalf("the old DNS host got %d queries, want none", n) |
| + } |
| + noCachedBelow(t, w, name, "example.co.uk") |
| +} |
| + |
| +// A nameserver inside the registrable domain comes from the parent's glue: |
| +// for a new name the cache is not asked for it. |
| +func TestFreshResolverParentGlue(t *testing.T) { |
| + const name = "shop.example.co.uk" |
| + parent := startAuthority(t, "co.uk", delegating(&questions{}, "example.co.uk", "ns1.example.co.uk", newHostAddr)) |
| + w, _, _ := movedWorld(t, name, "co.uk", parent) |
| + ips, err := w.resolver(clock()).Resolve(name) |
| + if err != nil || len(ips) != 1 || ips[0] != edgeIP { |
| + t.Fatalf("Resolve = %v, %v; want [%s]", ips, err, edgeIP) |
| + } |
| + if got := strings.Join(w.cached, ","); got != "NS co.uk,HOST "+parentNSHost { |
| + t.Fatalf("cached queries = %s, want only NS co.uk and HOST %s", got, parentNSHost) |
| + } |
| +} |
| + |
| +// No usable delegation from the parent: the lookup falls back to the cached |
| +// NS set and gives the answer it gave before #1383 (here the old host's). |
| +// A server the parent step does not trust is never followed: the host it |
| +// names is not dialled. |
| +func TestFreshResolverParentFallsBackToTheCachedNSSet(t *testing.T) { |
| + const name = "shop.example.co.uk" |
| + type parentOf func(t *testing.T) (zone string, fa *fakeAuthority) |
| + fake := func(zone string, answer func(dnsmessage.Question, *dnsmessage.Message) bool) parentOf { |
| + return func(t *testing.T) (string, *fakeAuthority) { return "co.uk", startAuthority(t, zone, answer) } |
| + } |
| + toNewHost := func(child string) func(dnsmessage.Question, *dnsmessage.Message) bool { |
| + return delegating(&questions{}, child, "ns.newhost.net", "") |
| + } |
| + for label, parent := range map[string]parentOf{ |
| + "no NS set for any level of the suffix": func(*testing.T) (string, *fakeAuthority) { return "", nil }, |
| + "silent parent servers": fake("co.uk", nil), |
| + "parent refuses": fake("", func(_ dnsmessage.Question, r *dnsmessage.Message) bool { |
| + r.RCode = dnsmessage.RCodeRefused |
| + return true |
| + }), |
| + // A server that does not hold the parent zone offers a referral. |
| + "parent zone not verified": fake("elsewhere.test", toNewHost("example.co.uk")), |
| + "authoritative no such name": fake("co.uk", func(_ dnsmessage.Question, r *dnsmessage.Message) bool { |
| + r.Authoritative = true |
| + r.RCode = dnsmessage.RCodeNameError |
| + r.Authorities = []dnsmessage.Resource{soaRecord("co.uk")} |
| + return true |
| + }), |
| + "authoritative empty reply": fake("co.uk", nodata("co.uk")), |
| + "truncated referral": fake("co.uk", func(q dnsmessage.Question, r *dnsmessage.Message) bool { |
| + r.Truncated = true |
| + return toNewHost("example.co.uk")(q, r) |
| + }), |
| + // Off the path: a sibling, the parent itself, below the registrable |
| + // domain, another suffix. |
| + "referral to a sibling": fake("co.uk", toNewHost("other.co.uk")), |
| + "referral to the parent itself": fake("co.uk", toNewHost("co.uk")), |
| + "referral below the registrable domain": fake("co.uk", toNewHost("eu.example.co.uk")), |
| + "referral naming two zones": fake("co.uk", func(q dnsmessage.Question, r *dnsmessage.Message) bool { |
| + toNewHost("example.co.uk")(q, r) |
| + first := r.Authorities |
| + toNewHost("other.co.uk")(q, r) |
| + r.Authorities = append(first, r.Authorities...) |
| + return true |
| + }), |
| + // A delegation that names no address we may dial. |
| + "in-zone nameserver without glue": fake("co.uk", delegating(&questions{}, "example.co.uk", "ns1.example.co.uk", "")), |
| + "non-public glue": fake("co.uk", delegating(&questions{}, "example.co.uk", "ns1.example.co.uk", "10.0.0.5")), |
| + } { |
| + t.Run(label, func(t *testing.T) { |
| + zone, fa := parent(t) |
| + w, _, newHost := movedWorld(t, name, zone, fa) |
| + r := w.resolver(clock()) |
| + start := time.Now() |
| + ips, err := r.Resolve(name) |
| + if err != nil || len(ips) != 1 || ips[0] != oldHostIP { |
| + t.Fatalf("Resolve = %v, %v; want [%s] from the cached NS set: %v", ips, err, oldHostIP, w.cached) |
| + } |
| + if took := time.Since(start); took > r.Timeout { |
| + t.Fatalf("Resolve took %s, past Timeout %s", took, r.Timeout) |
| + } |
| + if n := newHost.queries.Load(); n != 0 { |
| + t.Fatalf("the host an untrusted parent step named got %d queries", n) |
| + } |
| + for _, d := range w.dialed { |
| + if d != parentAddr+":53" && d != oldHostAddr+":53" { |
| + t.Fatalf("dialled %v, want only the parent and the cached nameserver", w.dialed) |
| + } |
| + } |
| + if w.cachedFor("example.co.uk") != 1 { |
| + t.Fatalf("cached queries = %v, want one for the registrable domain's NS set", w.cached) |
| + } |
| + noCachedBelow(t, w, name, "example.co.uk") |
| + }) |
| + } |
| +} |
| + |
| +// The parent step has half of the Timeout, so silent parent servers leave |
| +// the fallback its time: here two silent servers at a 300 ms attempt each |
| +// would eat the whole 500 ms. |
| +func TestFreshResolverSilentParentLeavesTheFallbackTime(t *testing.T) { |
| + const name = "shop.example.co.uk" |
| + w, _, _ := movedWorld(t, name, "co.uk", startAuthority(t, "co.uk", nil)) |
| + w.hosts[parentNSHost] = []string{parentAddr, "192.0.2.4"} |
| + w.routes["192.0.2.4:53"] = w.routes[parentAddr+":53"] |
| + r := w.resolver(clock()) |
| + r.Timeout, r.AttemptTimeout = 500*time.Millisecond, 300*time.Millisecond |
| + ips, err := r.Resolve(name) |
| + if err != nil || len(ips) != 1 || ips[0] != oldHostIP { |
| + t.Fatalf("Resolve = %v, %v; want [%s] from the cached NS set inside the Timeout", ips, err, oldHostIP) |
| + } |
| +} |
| + |
| +// The walk goes on below the registrable domain as before: the host the |
| +// parent names refers to a child zone, which is verified and answers. |
| +func TestFreshResolverParentThenAReferralBelow(t *testing.T) { |
| + const name = "shop.eu.example.co.uk" |
| + parent := startAuthority(t, "co.uk", delegating(&questions{}, "example.co.uk", "ns.newhost.net", "")) |
| + w, oldHost, _ := movedWorld(t, name, "co.uk", parent) |
| + w.routes[newHostAddr+":53"] = startAuthority(t, "example.co.uk", referral("eu.example.co.uk", "192.0.2.40")) |
| + w.routes["192.0.2.40:53"] = startAuthority(t, "eu.example.co.uk", authoritative(aRecord(name+".", edgeIP))) |
| + ips, err := w.resolver(clock()).Resolve(name) |
| + if err != nil || len(ips) != 1 || ips[0] != edgeIP { |
| + t.Fatalf("Resolve = %v, %v; want [%s] from the child zone", ips, err, edgeIP) |
| + } |
| + if n := oldHost.queries.Load(); n != 0 { |
| + t.Fatalf("the old DNS host got %d queries, want none", n) |
| + } |
| + noCachedBelow(t, w, name, "example.co.uk") |
| +} |
diff --git a/internal/domains/freshdns_test.go b/internal/domains/freshdns_test.go| index 9f7047404..be8becefa 100644 |
| --- a/internal/domains/freshdns_test.go |
| +++ b/internal/domains/freshdns_test.go |
| @@ -150,7 +150,8 @@ func (w *world) cachedFor(name string) int { |
| // noCachedBelow is the #724 guard: the cache heard nothing about name or |
| // any label between it and registrable, and no NS query went to anything |
| -// but registrable itself. |
| +// but registrable itself and the names above it (its public suffix and |
| +// TLD, where the parent step of #1383 looks for the parent zone). |
| func noCachedBelow(t *testing.T, w *world, name, registrable string) { |
| t.Helper() |
| for l := name; l != registrable && strings.Contains(l, "."); l = l[strings.Index(l, ".")+1:] { |
| @@ -161,8 +162,8 @@ func noCachedBelow(t *testing.T, w *world, name, registrable string) { |
| w.mu.Lock() |
| defer w.mu.Unlock() |
| for _, c := range w.cached { |
| - if strings.HasPrefix(c, "NS ") && c != "NS "+registrable { |
| - t.Fatalf("cached NS query other than for %s: %v", registrable, w.cached) |
| + if zone, ok := strings.CutPrefix(c, "NS "); ok && zone != registrable && !strings.HasSuffix(registrable, "."+zone) { |
| + t.Fatalf("cached NS query other than for %s and the names above it: %v", registrable, w.cached) |
| } |
| } |
| } |
| @@ -408,8 +409,9 @@ func TestFreshResolverBacksOffAfterAFailure(t *testing.T) { |
| } |
| func TestFreshResolverStopsAtTheTopLevel(t *testing.T) { |
| - // The registrable domain has no NS set: an error. Only the registrable |
| - // domain is asked for one; never the TLD, never a label below. |
| + // The registrable domain has no NS set, and its TLD's nameserver has no |
| + // address: an error. The TLD (the parent zone, #1383) and then the |
| + // registrable domain are asked for an NS set; never a label below. |
| var asked []string |
| r := &domains.FreshResolver{ |
| LookupNS: func(_ context.Context, name string) ([]*net.NS, error) { |
| @@ -425,8 +427,8 @@ func TestFreshResolverStopsAtTheTopLevel(t *testing.T) { |
| if _, err := r.Resolve("a.b.nowhere.org"); err == nil { |
| t.Fatal("Resolve with no zone succeeded") |
| } |
| - if len(asked) != 1 || asked[0] != "nowhere.org" { |
| - t.Fatalf("asked for NS sets %v, want only [nowhere.org]", asked) |
| + if len(asked) != 2 || asked[0] != "org" || asked[1] != "nowhere.org" { |
| + t.Fatalf("asked for NS sets %v, want [org nowhere.org]", asked) |
| } |
| } |
| @@ -569,8 +571,10 @@ func TestFreshResolverPrivateAndWildcardSuffixes(t *testing.T) { |
| } |
| } |
| -// shop.co.uk is its own registrable domain: it is asked directly, and |
| -// co.uk never is. |
| +// shop.co.uk is its own registrable domain: it is asked directly. co.uk |
| +// and uk are asked only for an NS set, where the parent zone is looked for |
| +// (#1383); here neither has one, and the cached NS set of shop.co.uk is |
| +// used. |
| func TestFreshResolverNameUnderAnICANNSuffix(t *testing.T) { |
| fa := startAuthority(t, "shop.co.uk", authoritative(aRecord("shop.co.uk.", edgeIP))) |
| w := &world{ |
| @@ -582,8 +586,8 @@ func TestFreshResolverNameUnderAnICANNSuffix(t *testing.T) { |
| if err != nil || len(ips) != 1 || ips[0] != edgeIP { |
| t.Fatalf("Resolve = %v, %v; want [%s]", ips, err, edgeIP) |
| } |
| - if w.cachedFor("co.uk") != 0 { |
| - t.Fatalf("asked the cache about co.uk: %v", w.cached) |
| + if got := strings.Join(w.cached, ","); got != "NS co.uk,NS uk,NS shop.co.uk,HOST ns.provider.net" { |
| + t.Fatalf("cached queries = %s, want the suffix's two NS sets, then NS shop.co.uk and HOST ns.provider.net", got) |
| } |
| } |
| @@ -940,16 +944,18 @@ func TestFreshResolverUpgradeAsksTheNearestZoneFirst(t *testing.T) { |
| } |
| // The nearest-zone look leaves the registrable domain to the top-down walk |
| -// (asked once, not twice) and never asks about the TLD. |
| +// (asked once, not twice) and never asks about the TLD: "NS com" is the |
| +// walk's own first step, looking for the parent zone (#1383), and comes |
| +// after the nearest zones. |
| func TestFreshResolverUpgradeNearestZones(t *testing.T) { |
| for name, want := range map[string]string{ |
| // Directly under the registrable domain: only the name itself is |
| // tried as a nearest zone, then the walk. |
| - "shop.example.com": "NS shop.example.com,NS example.com,HOST ns1.example.com", |
| - // An apex: the walk alone. Not "NS com". |
| - "example.com": "NS example.com,HOST ns1.example.com", |
| + "shop.example.com": "NS shop.example.com,NS com,NS example.com,HOST ns1.example.com", |
| + // An apex: the walk alone. |
| + "example.com": "NS com,NS example.com,HOST ns1.example.com", |
| // Deeper: parent, name, then the walk. |
| - "shop.eu.example.com": "NS eu.example.com,NS shop.eu.example.com,NS example.com,HOST ns1.example.com", |
| + "shop.eu.example.com": "NS eu.example.com,NS shop.eu.example.com,NS com,NS example.com,HOST ns1.example.com", |
| } { |
| t.Run(name, func(t *testing.T) { |
| w := oneZone(startAuthority(t, "example.com", authoritative(aRecord(name+".", edgeIP)))) |
| @@ -1075,8 +1081,8 @@ func TestFreshResolverNeverLooksUpAnOnPathNameserver(t *testing.T) { |
| if _, err := w.resolver(clock()).Resolve("shop.eu.example.com"); !isNotFoundErr(err) { |
| t.Fatalf("Resolve error = %v, want the authoritative not-found", err) |
| } |
| - if got := strings.Join(w.cached, ","); got != "NS example.com,HOST ns.provider.net" { |
| - t.Fatalf("cached queries = %s, want only NS example.com and HOST ns.provider.net", got) |
| + if got := strings.Join(w.cached, ","); got != "NS com,NS example.com,HOST ns.provider.net" { |
| + t.Fatalf("cached queries = %s, want only NS com, NS example.com and HOST ns.provider.net", got) |
| } |
| }) |
| t.Run("referral NS set", func(t *testing.T) { |
| @@ -1096,7 +1102,7 @@ func TestFreshResolverNeverLooksUpAnOnPathNameserver(t *testing.T) { |
| if _, err := w.resolver(clock()).Resolve("shop.b.a.example.com"); !isNotFoundErr(err) { |
| t.Fatalf("Resolve error = %v, want the child's not-found", err) |
| } |
| - if got := strings.Join(w.cached, ","); got != "NS example.com,HOST ns1.example.com,HOST ns.provider.net" { |
| + if got := strings.Join(w.cached, ","); got != "NS com,NS example.com,HOST ns1.example.com,HOST ns.provider.net" { |
| t.Fatalf("cached queries = %s, want no lookup of a.example.com", got) |
| } |
| }) |
| @@ -1318,7 +1324,7 @@ func TestFreshResolverUpgradeClimbIsBounded(t *testing.T) { |
| got = append(got, c) |
| } |
| } |
| - want := "NS a.b.c.d.example.com,NS " + deepName + ",NS b.c.d.example.com,NS c.d.example.com,NS example.com" |
| + want := "NS a.b.c.d.example.com,NS " + deepName + ",NS b.c.d.example.com,NS c.d.example.com,NS com,NS example.com" |
| if strings.Join(got, ",") != want { |
| t.Fatalf("cached NS queries = %s, want %s", strings.Join(got, ","), want) |
| } |
| @@ -1387,7 +1393,7 @@ func TestFreshResolverFollowsACoHostedChildZone(t *testing.T) { |
| if got := fa.queries.Load(); got != tc.queries { |
| t.Fatalf("server got %d queries, want %d", got, tc.queries) |
| } |
| - if got := strings.Join(w.cached, ","); got != "NS example.com,HOST ns1.example.com" { |
| + if got := strings.Join(w.cached, ","); got != "NS com,NS example.com,HOST ns1.example.com" { |
| t.Fatalf("cached queries = %s; the hint must cost none", got) |
| } |
| }) |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 45ea54a0b..1ad39c3fc 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -284,3 +284,4 @@ plan14-root-reads-egress-allow-cidr-console.tsv 9fb6041c2fe2f33edf7cc2a0fb6dc050 |
| plan14-root-reads-ha-departure-evidence.tsv 924ffc4037d32d7b46af1e373bad1476fc7305833fc6c06d50d5c8c3ab5ac177 |
| plan14-root-reads-stateless-scale-2-fleet-sizes.tsv 00fe607a04674579005013fae1e275cb0434ce54493b1efbe678aed59a12366b |
| plan14-root-reads-store-versioning.tsv 841361b89e20c3763149e8784cdebb037dcc4b828b24196a01d3e300ff319661 |
| +plan14-root-reads-parent-delegation-1383.tsv 841361b89e20c3763149e8784cdebb037dcc4b828b24196a01d3e300ff319661 |
diff --git a/internal/provision/testdata/plan14-root-reads-parent-delegation-1383.tsv b/internal/provision/testdata/plan14-root-reads-parent-delegation-1383.tsv| new file mode 100644 |
| index 000000000..5ddd895b7 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-parent-delegation-1383.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay parent-delegation-1383, written by census-propose (#369). census-ruling-parent-delegation-1383, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-parent-delegation-1383.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/domains ed0a4a959b24379aa5bdd9a823ddec548fc80675b463d0b9049327e6a24b7e53 |