From 79ca330494aade9349359cffd63ea9f52306f77e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 22 Nov 2026 03:25:09 +0000 Subject: [PATCH] net/dnsfallback, net/captivedetection: drop decommissioned DERP 6a, make test hermetic The static fallback DERP map embedded in net/dnsfallback still lists node 6a at 68.183.90.120 (an old Bangalore DigitalOcean IP). That IP is no longer a Tailscale DERP server: it now belongs to an unrelated nginx host that either times out or answers /generate_204 with "404 Not Found". Captive portal detection treats any 404 as a captive portal. This is a production bug, not just a test bug: a client without a DERP map yet (fresh start, no on-disk cache) falls back to this static map, so a detection that picks 6a wrongly warns the user about a captive portal. It also made TestDetectCaptivePortalReturnsFalse, which probed five random nodes from that map, flaky whenever 6a was picked and nginx happened to answer. Region 6's only node, 6a, is dead, so remove region 6 entirely. The DERP server at that IP was retired when region 6 moved from DigitalOcean Bangalore to Linode Mumbai (tailscale/corp#50435, tailscale/corp#51314). Region 6 still exists in the control-sent DERP map, but its new nodes are deliberately not added here: the list is not regenerated or grown, as we're moving away from DERP servers acting as bootstrap DNS servers (#21028). If a cached DERP map from control has a region 6, GetDERPMap still merges it in whole, as it does for any region missing from the static map. Also make the test hermetic. It now runs Detect against five local derpserver.ServeNoContent servers on 127.0.0.1. Five is enough that the controlplane/login.tailscale.com endpoints sorted after them are never tried. The servers listen on tcp4 explicitly, because when httptest falls back to [::1] the challenge "ts_[::1]:port" is rejected by isChallengeChar. Add TestDetectCaptivePortalReturnsTrue, where one server answers 404 like the stale node did. Both tests skip if no local server got a request (no usable non-loopback interface). TestEndpointsAreUpAndReturnExpectedResponse still covers the real endpoints. Failures were seen on Linux and Windows, on main and many branches (37 on the flakes dashboard since 2026-11-13): http://flakes/flake?name=tailscale.com%2Fnet%2Fcaptivedetection.TestDetectCaptivePortalReturnsFalse flakestress -p 4, before: 48/418 runs failed (11.5%), all with "want=204, got=404". After: 0/4250 runs of TestDetectCaptivePortal* (throttled to 2 workers with 100ms pauses; unthrottled stress of a 10ms test uses up local ephemeral ports in TIME_WAIT and fails in bind instead). Fixes #22550 Updates #21028 Change-Id: I2a45e7fb3e21b887bfd0952a846c98d68b03f89c Signed-off-by: Brad Fitzpatrick Signed-off-by: Guy J Grigsby --- net/captivedetection/captivedetection_test.go | 60 ++++++++++++++++++- net/dnsfallback/dns-fallback-servers.json | 15 ----- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/net/captivedetection/captivedetection_test.go b/net/captivedetection/captivedetection_test.go index 6b09ca0cc..7ba5f4b34 100644 --- a/net/captivedetection/captivedetection_test.go +++ b/net/captivedetection/captivedetection_test.go @@ -5,6 +5,8 @@ package captivedetection import ( "context" + "fmt" + "net" "net/http" "net/http/httptest" "net/url" @@ -18,6 +20,7 @@ import ( "tailscale.com/derp/derpserver" "tailscale.com/net/netmon" "tailscale.com/syncs" + "tailscale.com/tailcfg" "tailscale.com/tstest/nettest" "tailscale.com/util/must" ) @@ -37,12 +40,67 @@ func TestAvailableEndpointsAlwaysAtLeastTwo(t *testing.T) { } } +// localDERPMap returns a DERPMap whose nodes are local HTTP servers using +// the given handlers, and a counter of requests they received. +// Callers pass at least five handlers so that detectOnInterface never +// reaches the non-hermetic Tailscale endpoints sorted after DERP nodes. +func localDERPMap(t *testing.T, handlers ...http.HandlerFunc) (*tailcfg.DERPMap, *atomic.Int64) { + if len(handlers) < 5 { + t.Fatalf("got %d handlers; want at least 5", len(handlers)) + } + var hits atomic.Int64 + dm := &tailcfg.DERPMap{Regions: map[tailcfg.DERPRegionID]*tailcfg.DERPRegion{}} + for i, h := range handlers { + s := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + hits.Add(1) + h(w, r) + })) + // Endpoints are IPv4-only, so don't let httptest fall back to [::1]. + s.Listener.Close() + s.Listener = must.Get(net.Listen("tcp4", "127.0.0.1:0")) + s.Start() + t.Cleanup(s.Close) + rid := tailcfg.DERPRegionID(i + 1) + dm.Regions[rid] = &tailcfg.DERPRegion{ + RegionID: rid, + Nodes: []*tailcfg.DERPNode{{ + Name: fmt.Sprintf("%da", rid), + RegionID: rid, + IPv4: s.Listener.Addr().String(), + CanPort80: true, + }}, + } + } + return dm, &hits +} + func TestDetectCaptivePortalReturnsFalse(t *testing.T) { + ok := derpserver.ServeNoContent + dm, hits := localDERPMap(t, ok, ok, ok, ok, ok) d := NewDetector(t.Logf) - found := d.Detect(context.Background(), netmon.NewStatic(), nil, 0) + found := d.Detect(t.Context(), netmon.NewStatic(), dm, 0) if found { t.Errorf("DetectCaptivePortal returned true, expected false.") } + if hits.Load() == 0 { + t.Skip("no endpoint was reached; no usable non-loopback interface?") + } +} + +func TestDetectCaptivePortalReturnsTrue(t *testing.T) { + notFound := func(w http.ResponseWriter, r *http.Request) { + http.Error(w, "404 Not Found", http.StatusNotFound) + } + ok := derpserver.ServeNoContent + dm, hits := localDERPMap(t, ok, ok, ok, ok, notFound) + d := NewDetector(t.Logf) + found := d.Detect(t.Context(), netmon.NewStatic(), dm, 0) + if hits.Load() == 0 { + t.Skip("no endpoint was reached; no usable non-loopback interface?") + } + if !found { + t.Errorf("DetectCaptivePortal returned false, expected true.") + } } func TestEndpointsAreUpAndReturnExpectedResponse(t *testing.T) { diff --git a/net/dnsfallback/dns-fallback-servers.json b/net/dnsfallback/dns-fallback-servers.json index 42dd0713b..923fc6a7e 100644 --- a/net/dnsfallback/dns-fallback-servers.json +++ b/net/dnsfallback/dns-fallback-servers.json @@ -184,21 +184,6 @@ } ] }, - "6": { - "RegionID": 6, - "RegionCode": "r6", - "RegionName": "r6", - "Nodes": [ - { - "Name": "6a", - "RegionID": 6, - "HostName": "derp6.tailscale.com", - "IPv4": "68.183.90.120", - "IPv6": "2400:6180:100:d0::982:d001", - "CanPort80": true - } - ] - }, "7": { "RegionID": 7, "RegionCode": "r7",