Commit Graph
11823 Commits
Author SHA1 Message Date
Mike JensenandTom Meadows d6535a20da cmd/k8s-proxy,ipn/ipnlocal,k8s-operator/api-proxy: drop PROXY protocol (#22754) (#22766)
* cmd/k8s-proxy,ipn/ipnlocal,k8s-operator/api-proxy: drop PROXY protocol

The API server proxy in cmd/k8s-proxy took the caller's address from the
PROXY protocol header on its localhost listener, which any local process
could write. This fixes this by removing the header from both sides, and
making serve register each non-Funnel TCP forward to a loopback address
with the proxy mapper (as netstack does), so WhoIs on the connection's
real remote address returns the caller.

Updates tailscale/corp#48697

Thank you Winfunc for reporting



* ipn/ipnlocal,k8s-operator/api-proxy: add WhoIs and forged header tests

Adds a test that WhoIs on the backend side of a serve TCP forward returns
the source node while the forward is open and fails after it closes, for
IPv4, IPv6 and localhost targets, and that a Funnel flow or a backend on
a non-loopback address gets no node. Also adds a test that the API server
proxy's plain HTTP listener does not take the caller from a PROXY header
that a local client writes.

Updates tailscale/corp#48697



---------

Change-Id: I9bd203355c68eb0e9f62755dbea908d7d5435105

(cherry picked from commit 65114d4eba)

Signed-off-by: chaosinthecrd <[email protected]>
Co-authored-by: Tom Meadows <[email protected]>
2026-12-01 08:59:39 -05:00
Mike JensenandTom Meadows 8d72eeef6f k8s-operator/sessionrecording: harden recording upload end handling (#22752) (#22765)
* k8s-operator/sessionrecording: harden recording upload end handling

The session recording hijacker treated a recording upload that ended
without an error as finished, whether or not its session had ended.

This fixes this by checking that the session's connection was closed
first, and otherwise handling the end like an upload error (so the
session's recording failure policy applies), as ssh/tailssh does.

Updates tailscale/corp#51365

Change-Id: I909c6e48f43dc295b7c4b1e5762abe4e8aa6a484


* k8s-operator/sessionrecording: test recording upload end handling

This adds Test_Hijacker cases for a recording upload that ends without an
error, both after the session's connection was closed and while it is
still open, for each recording failure policy.

Updates tailscale/corp#51365

Change-Id: If021c7fa8fea52301dde058a481d84cad23fd185


---------

Change-Id: I0fda3c9138daf8b2988edb149f5044a491fb1f6f

(cherry picked from commit 6847263baf)

Signed-off-by: chaosinthecrd <[email protected]>
Co-authored-by: Tom Meadows <[email protected]>
2026-12-01 08:59:23 -05:00
Mike JensenandTom Meadows 897add6761 k8s-operator/api-proxy: reject cross-origin browser requests in auth mode (#22751) (#22764)
* k8s-operator/api-proxy: reject cross-origin browser requests in auth mode

In auth mode the API server proxy sets the caller's identity from their
tailnet address and does not check Origin. Browsers do not apply the
same-origin policy to WebSocket, so a page a tailnet user opened could
open exec, attach or watch WebSockets through the proxy and have them run
as that user.

This fixes this by rejecting cross-origin browser requests on every
route, as browsers also send simple cross-site POSTs without a
preflight. Requests with an Origin are checked on Sec-Fetch-Site first,
where same-origin and none pass and any other value is rejected, and if
the browser does not send it the Origin host must match Host. kubectl
and client-go send no Origin and the Python and fabric8 clients send one
that matches Host, so they still work, as do web UIs whose own proxy
rewrites Host, such as kubectl proxy, Headlamp and Backstage. Headlamp
desktop, whose file:// page is cross-site to its backend, now gets 403
for writes and WebSockets. noauth mode is unchanged as it has no
identity to borrow.

Updates tailscale/corp#51482



* k8s-operator/api-proxy: add test for cross-origin requests in auth mode

Adds a test that sends exec, attach and watch WebSocket upgrades and a
plain POST through the proxy with and without a foreign Origin and
Sec-Fetch-Site, and checks that in auth mode only requests with no Origin,
the proxy's own origin or Sec-Fetch-Site same-origin reach the API server.

Updates tailscale/corp#51482



---------

Change-Id: Ibd73d59912aa98b81f00d0f6c868ae1149bb5d20

(cherry picked from commit 001e91f5b4)

Signed-off-by: chaosinthecrd <[email protected]>
Co-authored-by: Tom Meadows <[email protected]>
2026-12-01 08:59:06 -05:00
Mike JensenandTom Meadows 6aea659f96 Legacy proxy ServiceAccount: narrow its Secret access (#22750) (#22763)
* cmd/k8s-operator,k8s-operator,ipn/store/kubestore: add per-proxy RBAC

Proxies for Services, Ingresses, Connectors and PeerRelays run as the
shared proxies ServiceAccount, whose Role allows every verb on every
Secret in the operator namespace, so each proxy can read and change the
Secrets of the operator and of other proxies. This fixes this by giving
each of those proxies its own ServiceAccount, Role and RoleBinding, where
the Role names only that proxy's state Secrets, and the chart no longer
installs the proxies Role. It also removes the list and watch on every
Secret from ProxyGroup Roles, and the Secret rule with no resourceNames
that ProxyGroup and Recorder Roles got at zero replicas, so kubestore
read replicas now get cert Secrets by name. Existing proxy Pods restart
once on upgrade.

Updates tailscale/corp#51011



* cmd/k8s-operator,k8s-operator,ipn/store/kubestore: test per-proxy RBAC

Adds tests for the ServiceAccount, Role and RoleBinding that each Service
proxy and PeerRelay gets, including copied imagePullSecrets, and for the
ProxyGroup Role rules, including zero replicas. Adds an e2e test that
uses SubjectAccessReviews to check that a Service proxy and a ProxyGroup
can get their own state Secret, but cannot get the operator's OAuth
Secret or each other's state Secret, and cannot list Secrets. Also adds
tests for reloading shared TLS certs by name on read replicas, including
a cert Secret that is deleted and then recreated, and removes the test
for the Secret list that read replicas no longer do.

Updates tailscale/corp#51011



* kubestore: fix test lint failure

Change-Id: Ia988256dfe611a64b46cdb81d4e1d68bd7873ca4


---------

Change-Id: I9dd176c3f171deb3d6c49b190c6f58cf72085857



(cherry picked from commit e3f1d5ccbd)

Signed-off-by: chaosinthecrd <[email protected]>
Signed-off-by: Mike Jensen <[email protected]>
Co-authored-by: Tom Meadows <[email protected]>
2026-11-30 18:58:59 -05:00
Mike Jensen 95696cbda2 feature/taildrop: prevent symlink escapes when receiving files (#22749) (#22762)
This change confines Taildrop filesystem operations to a persistent os.Root, preventing symlinks or receive-directory replacement from redirecting file access outside the intended directory. It also closes extension-owned roots during manager replacement and shutdown.

Fixes tailscale/corp#51118

Credit to Aditya @adios-404 for reporting

Change-Id: Ica39b3603221b3c7ba4460b176aae9b67eb64556

Change-Id: I37c836325eb319afd55a21a5b553175368a10783

(cherry picked from commit 6c0903552a)

Signed-off-by: Mike Jensen <[email protected]>
2026-11-30 18:58:23 -05:00
Nick Khyl 106ddfc24b util/winutil, cmd/tailscaled: log and report app sideloading state
The Windowed UI depends on the Windows App Runtime, which cannot be
installed unless app sideloading or Developer Mode is enabled.
Sideloading is disabled by default on Windows builds older than 19041,
and can be disabled by the user or by policy on newer ones.

Add winutil.GetSideloadingState to read the settings, log the result
when tailscaled starts, and add gauges for sideloading being disabled
by policy, by the user or by default. Builds older than 17763 cannot
run the Windows App Runtime at all, so they are reported as unsupported
and do not count towards any of the gauges.

Updates tailscale/corp#52316

Change-Id: I93d1975e0a54d65d7e692dbf81480d9fdb37a574
Signed-off-by: Nick Khyl <[email protected]>
(cherry picked from commit d4f3bdd0a8)
2026-11-30 15:57:25 -08:00
Nick O'Neill ca97d565da VERSION.txt: this is v1.106.1
Signed-off-by: Nick O'Neill <[email protected]>
v1.106.1
2026-11-24 10:43:30 -08:00
Nick O'Neill 9ff10465e3 VERSION.txt: this is v1.106.0
Signed-off-by: Nick O'Neill <[email protected]>
v1.106.0
2026-11-23 13:15:43 -08:00
Michael Ben-Ami 7caf9edb40 appc,feature/conn25: build split DNS routes from the parsed config
On every self node change, conn25 parsed the app connector capability
twice: once in configFromNodeView, and again in appc.AppDNSRoutes to
build the split DNS routes. Build the routes from the config we already
have instead, and move DNSAddrScheme into feature/conn25 along with it.

With appc/conn25.go gone, conn25 no longer depends on appc, so
TestOmitAppConnectors no longer needs to omit conn25 too.

Fixes tailscale/corp#51400
Fixes tailscale/corp#51402

Signed-off-by: Michael Ben-Ami <[email protected]>
2026-11-23 16:05:43 -05:00
Nick Khyl 0afa9614d3 net/dns: stage the new hosts file outside of the etc directory on Windows
atomicfile.WriteFile creates its temporary file next to the target,
and changes in System32\drivers\etc make the DNS Client service reload
the hosts file. Besides the extra reloads, the service may then have
the hosts file open just as we try to replace it.

In this PR, we create the temporary file in System32\drivers instead,
which is on the same volume, and move it into place with
atomicfile.Rename.

Updates #21001
Updates #5753
Updates #8161
Updates #21617
Updates #14327
Updates tailscale/corp#52076

Signed-off-by: Nick Khyl <[email protected]>
2026-11-23 12:48:28 -08:00
Nick Khyl 65c4e36477 net/dns: retry failed hosts file updates in the background on Windows
Replacing the hosts file fails with a sharing violation while another
process, such as the DNS Client service or antivirus software, has it
open. Previously, we retried for about 50ms and then failed SetDNS as
a whole.

In this PR, we move hosts file updates to a CoalescedOp that retries
a failed write with backoff for up to 30 seconds, picking
up newer entries if SetDNS is called again in the meantime. A failure
is logged and no longer fails SetDNS.

Close waits for the entries to be removed.

Fixes #21035
Updates #21001
Updates #5753
Updates #8161
Updates #21617
Updates #14327
Updates tailscale/corp#52076

Signed-off-by: Nick Khyl <[email protected]>
2026-11-23 12:48:28 -08:00
Nick Khyl a115745579 util/coalescedop: add Wait
Wait blocks until no execution is in progress or pending,
so a caller can make sure the requested work is done before
shutting down.

Updates tailscale/corp#52076

Signed-off-by: Nick Khyl <[email protected]>
2026-11-23 12:48:28 -08:00
Mike O'Driscoll 00183293b8 derp/derpserver: add rate limiting exemption by IP (#22610)
Allow for specified IPs to bypass the rate limiter
in derper.

Fixes #22609

Signed-off-by: Mike O'Driscoll <[email protected]>
2026-11-23 15:25:42 -05:00
Brad Fitzpatrick 01f673c426 net/dns/resolver: don't count a torn-down UDP write as an upstream error
TestForwarderRaceLoserNoReadError races an answering resolver against
a silent one 20 times and then waits for 20 losing reads to land in
dns_query_fwd_udp_read_ctx_done or dns_query_fwd_udp_error_read. That
assumed every losing sendUDP was blocked in its read when the winner
ended the query. It isn't always: if the loser's goroutine is slow,
forwardWithDestChan's teardown (cancel, then closeOnCtxDone.Close, or
closePool.Add closing a conn registered after teardown) closes the conn
before WriteToUDPAddrPort. The loser then exits through the write error
path and never reaches a read, so the test waited out its 10s and failed
with "only 19 of 20 losing reads have woken up". Instrumenting the
failure showed udp=40 wrote=39 werr=1 every time.

No losing query leaks; every loser exits. But the write path had the
same miscounting the test was added to stop for reads: it bumped
dns_query_fwd_udp_error_write before checking ctx.Err, so query teardown
showed up as an upstream write failure. Check ctx first.

In the test, the silent upstream now reads UDP without answering
(new HangUDP option), and the answering upstream holds its UDP answer
until the silent one has the query. The loser is then always past its
write when the query ends, so all 20 losers reliably reach the read.

flakestress -p 4 -taskset 0 on Linux:
before: 57 failures in 4143 runs (1.4%)
after: 0 target failures in 31219 runs. The only failures were
247 "bind: address already in use" from loopback ephemeral port
exhaustion caused by other stress jobs on the same machine.

Flakes dashboard: http://flakes/flake?name=tailscale.com%2Fnet%2Fdns%2Fresolver.TestForwarderRaceLoserNoReadError
(115 failures in 7 days, 82 on main.)

Fixes #22549

Change-Id: I9f346aa66a175e63593815dc606b88d961834b01
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 11:02:09 -08:00
chaosinthecrd 5aed346ad7 cmd/k8s-proxy,cmd/k8s-operator: test k8s-proxy /livez and /readyz
Covers /livez and /readyz with and without tailnet IPs and with the
LocalAPI failing or timing out, and the probes that a ProxyClass enables
on the kube-apiserver ProxyGroup StatefulSet, which stay on port 9002
when the ProxyClass sets TS_LOCAL_ADDR_PORT.

Updates tailscale/corp#38175

Signed-off-by: chaosinthecrd <[email protected]>
2026-11-23 18:20:10 +00:00
chaosinthecrd 0d029cb75a cmd/{k8s-proxy,k8s-operator},k8s-operator: serve k8s-proxy /livez and /readyz
k8s-proxy did not serve /livez or /readyz, so the operator skipped the
probes for the kube-apiserver ProxyGroup even when a ProxyClass set
them. This adds both to k8s-proxy (/livez passes while the LocalAPI
answers, /readyz once the node has its tailnet IPs) and drops the
exception from the operator. k8s-proxy takes its port from the config
file that the operator writes, so its probes always use port 9002 and
ignore TS_LOCAL_ADDR_PORT and TS_ENABLE_HEALTH_CHECK. The local server
now starts before Up, so /livez answers while Up runs and while waiting
for a reissued auth key.

Updates tailscale/corp#38175

Signed-off-by: chaosinthecrd <[email protected]>
2026-11-23 18:20:10 +00:00
Danni Popova b1f550ec56 wif: add identity token auto generation for Azure (#21808)
Extends the ability to auto detect Azure as the provider the client is running on and tries fetch the JWT to use with Workload Identity.

Updates https://github.com/tailscale/corp/issues/34528

Signed-off-by: Danni Popova <[email protected]>
2026-11-23 17:51:43 +00:00
Brad Fitzpatrick 940e4c2c67 ssh/tailssh: write watchdog test PID markers atomically
TestMonitorCloseWatchdogForwardChild occasionally failed on Linux CI
with `invalid helper PID marker ".../forward-pid": ""`.

The re-exec'd helper wrote its PID marker with os.WriteFile, which
creates (and truncates) the file before writing the contents. The test
polls for the marker every 20ms and treats any successful read as
final, so a poll landing between the create and the write saw an empty
file and failed. This is a test-only race; the monitor itself was
fine.

Write the marker to a temp file and rename it into place, so the poll
sees either no file or the full PID.

The natural rate is too low to measure locally (0/168 runs of the
~14s-under-race test in 5m with flakestress -race -p 8 -taskset 0-3),
so the window was widened by injecting a 100ms sleep:
before (sleep between create and write): 3/3 runs failed with the
CI error.
after (sleep between write and rename): 0/3 runs failed.
after, without injection, flakestress -race -p 4, 5m: 0/84 runs.

Fixes #22559

Change-Id: I855d18f006535140bc136ee876b311212f8884b6
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 08:54:18 -08:00
Brad Fitzpatrick 7294a69dfd tsnet: fail the test instead of panicking when a ping times out in test helpers
setupTwoClientTest and TestDialThroughExitNode used
must.Get(lc.Ping(...)) to wait for the TSMP path to come up. When that
ping timed out, must.Get panicked, killing the whole tsnet test binary.
The flakes dashboard then blamed every test that was running or paused
at the time (TestPacketFilterFromNetmap, TestListenService, TestListen*,
TestDialUDP, ...), not just the one whose ping failed.

Use t.Fatalf instead so a failed ping fails only its own test.

The underlying ping failure was the wireguard-go duplicate handshake
initiation race, fixed by the wireguard-go bump in #22537.

Updates #22551

Change-Id: I227852aaa576e500df036bb1700fe6c7589b0a25
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 08:50:06 -08:00
fQwQf 0345103edd client/systray: shut down cleanly on termination signals (#22583)
Route SIGINT and SIGTERM through systray.Quit so the native tray loop
returns and invokes the exit callback. Stop signal delivery when Run returns.

Treat watcher cancellation as normal shutdown rather than terminating the
process with log.Fatal, and interrupt the reconnect delay when canceled.
Serialize exit cleanup with menu rebuilds.

Add subprocess tests for SIGINT, SIGTERM and the Quit menu action using a
private session bus and a fake LocalAPI.

Fixes #22582

Change-Id: I2360e203d4cc9bf3f0245133e9535d353b780e2c

Signed-off-by: fQwQf <[email protected]>
2026-11-23 09:25:34 -06:00
Brad Fitzpatrick 693839367f derp/derpserver: count packets, not seqs, in writer flood test
TestWriterFloodDoesNotStarveControlFrames checked that a pong queued
during a packet flood went out within a queue's depth of packets by
requiring the highest sequence number written before the pong to be at
most seqAtPong+depth. But the flood keeps the queue full, so enqueue
drops at the head (dropReasonQueueHead), and whenever the writer is
descheduled the flooder can push hundreds of newer packets through the
ring. The next packets the writer dequeues then carry sequence numbers
far past seqAtPong+depth even though it wrote no more than depth
packets before the pong, e.g.:

    pong written after packet 4573; want no later than packet 4071 (pong queued at 4039, depth 32)

The server's actual guarantee is in packets written: writePending
sends a pending pong before its queue drain, and each drain pass is
capped at perClientSendQueueDepth packets, so at most depth packets
are written between queuePong and the pong. Measure that directly:
read sclient.packetsSent right after queuePong and have the fake conn
record the packet frame count when the first pong is written. Reading
packetsSent after queuePong means a preemption in the test goroutine
can only loosen the bound, never cause a false failure.

The test still guards the anti-starvation property: with writePending's
per-pass budget removed it fails every run ("pong written after 720
more packets; want at most 32"), and with the budget doubled to
2*depth it fails 11 of 20 runs.

flakestress -p 4 -taskset 0-1:
before: 1401 failures / 24665 runs (5.7%)
after:  0 failures / 45896 runs

Fixes #22347

Change-Id: Ia751bae9789d9eb9f36f978ef14088b955b58785
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 07:21:41 -08:00
Brad Fitzpatrick 7a47412c33 cmd/derper: remove unpublished bootstrap DNS names, validate published ones
Remove --unpublished-bootstrap-dns-names and its TXT record rollout
percentages, unused in production since September. Require every
--bootstrap-dns-names entry to be a name that clients' fallback DNS
will ask for, per the shared net/dnsfallback/fallbacknames policy, so
names can be removed but not added. Queries for names outside the
published set now count as counter_bootstrap_dns_unknown_names.

Updates #21028

Change-Id: If9b7c3f6325de63eaaa3ba5bc9143ac5539af2ab
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 07:17:55 -08:00
Brad Fitzpatrick c7b017dc17 net/dnsfallback: only resolve Tailscale's own names, and not when offline
Client logs show that most DERP bootstrap DNS attempts come from clients
with no working network, retrying Tailscale's log and control servers,
and that the rest are mostly for names that DERP servers can't answer.
Skip the fallback when netmon says no interface is up, and don't try it
at all (or log about it) for names that aren't Tailscale's, returning
the original DNS error instead via a new dnscache.ErrNoFallback. The
name policy lives in a new leaf package, net/dnsfallback/fallbacknames,
so cmd/derper can share it.

Updates #21028

Change-Id: I25a0e4cc21866837416a24090a986e1b2dd1e78a
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 07:17:55 -08:00
Brad Fitzpatrick fefe73acf6 .github/workflows: give golangci-lint its own Go build cache
The golangci-lint job's setup-go cache key collided with the CodeQL
workflow's, so PRs restored CodeQL's main-branch build cache, which
lacks the test packages and export data golangci-lint loads. Package
loading thus ran nearly cold every time (~9 of ~10 minutes), and jobs
now regularly hit the 10m timeout. Use a dedicated cache key, and run
on pushes to main so there's a cache for PRs to restore.

Updates #18366
Updates tailscale/corp#28679

Change-Id: I7a23a66dc7198c030d6a378aa2733d558c8c37d9
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 07:01:16 -08:00
Mike O'Driscoll 82cb6f8ba0 wgengine/router: add envknob to disable src_valid_mark (#22591)
Add TS_DEBUG_DISABLE_SRC_VALID_MARK to allow disabling
of net.ipv4.conf.all.src_valid_mark being set.

Updates #3310
Updates #19796

Signed-off-by: Mike O'Driscoll <[email protected]>
2026-11-23 09:59:20 -05:00
Brad Fitzpatrick c3a92572e8 tsnet: wait for control to know s2's DERP home and endpoints in delta tests
TestPingPeerLearnedViaDelta failed on Linux and Windows with

    Ping(disco): error Post ".../localapi/v0/ping?ip=100.64.0.2&size=0&type=disco": context deadline exceeded

and the same for type=TSMP. The disco variant can't be the wireguard-go
duplicate handshake race fixed by #22537, and it still failed on main
with that fix.

The test puts s1 in manual MapResponse mode, starts s2, then copies
control.Node(s2Key) into a PeersChanged delta for s1. startServer only
waits for s2's local home DERP connection, not for s2's lite map update
carrying its HomeDERP and endpoints to reach control. If the snapshot
was taken first, s1 learned an s2 with no DERP home and no endpoints,
and because s1's automatic map responses are suppressed it never got
the later update, so neither disco nor TSMP pings could reach s2.
TestPingSubnetRouteOfDeltaPeer had the same pattern.

Add controlNodeReachable, which polls control until the node has a
HomeDERP and endpoints, and use it for both snapshots.

Injecting a random 0-300ms sleep before controlclient's SendUpdate
makes the original test fail nearly every run with the exact CI
errors (8/8 subtests); with this change 0 failures in 6 runs each of both
tests under the same injection.

flakestress -p 4 -taskset 0-1 -duration 8m, no injection:

    before: 2 failures in 1128 runs (both Ping(disco) deadline)
    after:  0 failures in 1148 runs

Fixes #22562

Change-Id: Ic5f0e1498d566a89102d92c216ae892a293d5472
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 06:41:04 -08:00
Brad Fitzpatrick 66e3d823c7 tstest/integration: deflake TestClientSideJailing
TestClientSideJailing waited only for each node's netmap to show the
peer with the expected IsJailed bit, then made a single 1s DialTCP for
each direction. But a peer's endpoints, DERP home, and disco key reach
the other node via separate map updates that can land after the peer
first appears in the netmap. If the first dial's WireGuard handshake
initiation is sent before then, magicsock drops it ("Failed to send
handshake initiation: no UDP or DERP addr") and wireguard-go does not
retry for 5s, so every "should succeed" dial in that window fails.
That matches the CI failures on the race-root-integration job: both
dials in not_jailed, and sometimes the uni_jailed n2-to-n1 dial too,
failed with exactly 1s/2s subtest durations.

This is a test bug, not a jail propagation bug: the jailed state and
the data plane peer routes and jailed filter are installed under the
same LocalBackend lock as the netmap the test polls.

Retry the dials that should succeed until they connect (up to 20s).
The dials that should fail still get a single attempt, since a late
path can only make them fail more. Also drop the flakytest.Mark.

The flake didn't reproduce unaided locally (0/192 runs; 0/95 with
-race and 2 CPUs). Delaying testcontrol's processing of endpoint
updates by 200ms reproduces it deterministically:

    before: 95/95 runs failed (with 200ms injected delay)
    after:  0/136 runs failed (with 200ms injected delay)
    after:  0/71 runs failed (-race, taskset 0-1, no injection)

Fixes #17419

Change-Id: I779d173d5d6c01fe878848cdfe049e7f29d20775
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 05:19:07 -08:00
chaosinthecrd 8c3db134d8 feature/acme: add tests for cert status of invalid cached certs
Covers not-yet-valid, untrusted CA (in date and expired), name mismatch,
cert/key mismatch and bad PEM through the C2N handler and
LocalBackend.CertStatus, and checks that getCertPEM still goes on to
issue a new cert for each unusable cached cert. Also checks that each
certStore returns errCertInvalid for a name mismatch.

Updates #22304

Signed-off-by: chaosinthecrd <[email protected]>
2026-11-23 11:16:53 +00:00
chaosinthecrd f0ce5749d1 feature/acme: report Expired only when a cached cert has expired
validCertPEM returned a bool and every certStore Read turned any failure
into errCertExpired, so the C2N tls-cert-status response and the
localapi cert-status endpoint reported Expired for an in-date cert that
failed verification for another reason (unknown CA, name mismatch,
cert/key mismatch, bad PEM). This fixes this by returning errCertExpired
only when the leaf is past its NotAfter, and otherwise an error wrapping
a new errCertInvalid that carries the verification error into the status
Error field. A cert that is not yet valid now counts as invalid, not
expired. getCertPEM treats errCertInvalid like errCertExpired, so a
cached cert that fails verification is still reissued.

Fixes #22304

Signed-off-by: chaosinthecrd <[email protected]>
2026-11-23 11:16:53 +00:00
Brad Fitzpatrick f7d2828f3a wgengine: stamp Status.AsOf when endpoints are read, strictly increasing
TestTUNDNS failed on Windows CI with:

    waitForPeerReachable([uOLy9]): peer [uOLy9]: no endpoints

The peer had a HomeDERP in control but never any endpoints, for 30s.

userspaceEngine.getStatus snapshotted e.endpoints under e.mu, then
walked the wireguard-go peers (which can block on the device mutex),
and only then set AsOf: time.Now(). RequestStatus lets two goroutines
run getStatus concurrently (for example the magicsock endpoints
callback and the TUN "external route: up" event goroutine). If the
goroutine that read the old, empty endpoints finished last, its status
had the newest AsOf, so LocalBackend.setWgengineStatus's AsOf ordering
check accepted it, reset b.endpoints to empty and sent that to
control. magicsock's endpoints hadn't changed, so nothing ever resent
them. On Windows the monotonic clock is coarse, so two statuses can
also get equal AsOf values, which the strict Before check lets through
in either order.

Take AsOf in the same critical section as the endpoints read and make
it strictly increasing, so a status with older endpoints always has an
older AsOf and is discarded.

Reproduced on Linux by injecting a random 0-20ms sleep in getStatus
between the endpoints read and the wgdev peer walk:

    before: 9 failures in <=48 runs of TestTUNDNS ("no endpoints")
    after:  0 failures in 56 runs

(The natural rate on Linux is too low to measure; the one CI failure
was on Windows.) The other TestTUNDNS failure on the dashboard (Linux,
TSMP ping "context deadline exceeded") was the wireguard-go duplicate
handshake race fixed by the wireguard-go bump in #22537.

Fixes #22563

Change-Id: Id290c7422846dc390d3cd914f7b7cfabe593e739
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-22 22:12:16 -08:00
Dep Updater ceccbc303d go.mod: bump 5 modules
* github.com/gokrazy/firmware: https://github.com/gokrazy/firmware/compare/6bd1fd16a2e2...d8b761d7b4ca
* github.com/gokrazy/kernel.amd64: https://github.com/gokrazy/kernel.amd64/compare/eb0ff0075854...17ff614bf8bc
* github.com/gokrazy/kernel.arm64: https://github.com/gokrazy/kernel.arm64/compare/595ae821533a...03045c240b24
* github.com/gokrazy/kernel.rpi: https://github.com/gokrazy/kernel.rpi/compare/85ea215f0624...a4a58496f7f6
* github.com/gokrazy/rpi-eeprom: https://github.com/gokrazy/rpi-eeprom/compare/30711eb43bb5...fb3324aa4fc1
* github.com/gokrazy/breakglass: already current
* github.com/gokrazy/gokrazy: already current
* github.com/gokrazy/serial-busybox: already current

Triggered by the gokrazy-bump workflow's schedule.

Updates #1866

Signed-off-by: Dep Updater <[email protected]>
2026-11-22 21:39:11 -08:00
Brad Fitzpatrick af9bfa07c3 net/tstun, feature/conn25: make app connector hooks safe to set while running
feature/conn25 installs its tstun.Wrapper hooks from its ipnext
extension's Init, which runs from LocalBackend.Start. By then the
wireguard-go device's RoutineReadFromTUN goroutine is already reading
packets and calling filterPacketOutboundToWireGuard, which read the
plain PreFilterPacketOutboundToWireGuardAppConnectorIntercept field
with no synchronization. A packet from the OS TUN in that window was a
data race; under -race, tailscaled in tstest/integration died with
"WARNING: DATA RACE" (conn25.go installHooks write vs wrap.go:797
read), and the test then failed with "running tailscale status: ...
EOF". All six CI logs examined show this same race.

Make the three hooks conn25 sets after startup
(PreFilterPacketOutboundToWireGuardAppConnectorIntercept,
PostFilterPacketInboundFromWireGuardAppConnector and
OnUnmappedTransitIPMessage) syncs.AtomicValues.

Add TestSetAppConnectorHooksWhileRunning, which installs the hooks
while packets flow in both directions and reproduces the CI race at
the same wrap.go line.

flakestress -race TestSetAppConnectorHooksWhileRunning:
before: 12564/12564 runs failed; after: 0/1176 runs.

The integration flake was too rare to measure locally (a few failures a
week in CI). It was blamed on tstest/integration TestTUNMode,
TestMagicDNS and TestSplitDNS.

Fixes #22557

Change-Id: Iff618c18c11f84dcbae27805024e908403031a08
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-22 16:46:06 -08:00
Loz Brown 678b3be66b feature/androidbin: register Android cgo fallback
Enable the existing Android-safe interface fallback in cgo
builds. Keep androidbin out of condregister for Android cgo
applications, which provide their own interface getter; embedded
consumers can opt in by importing androidbin directly.

Updates #17311

Change-Id: Ia26706d9757525c1bc619935574797808b693034
Signed-off-by: Loz Brown <[email protected]>
2026-11-22 15:06:36 -08:00
Brad Fitzpatrick 87b3a5ff26 control/ts2021, net/netutil: fail early if net/http's HTTP/2 is disabled
The ts2021 protocol speaks HTTP/2 inside the Noise stream. With
GODEBUG=http2client=0 (or the nethttpomithttp2 build tag), net/http
can't, and http.DefaultTransport also never gets a TLSClientConfig,
which made controlhttp crash tailscaled with a nil pointer dereference.
Return a clear user-visible error from ts2021.NewClient instead, and
make netutil.NewDefaultTransport always return a non-nil
TLSClientConfig.

Fixes #22578

Change-Id: I119c6ebbd6f1bbb5c693fb44a577862b98e688f3
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-22 07:57:32 -08:00
Brad Fitzpatrick a54bdf2bf2 .github/actions/go-cache: cache the cigocacher binary
Building cigocacher took most of the ~15-27s "Set up cigocacher" step
on every Windows job. Cache the binary in actions/cache, keyed on
cmd/cigocacher, go.mod, and go.sum, and add a test that cigocacher has
no other tailscale.com dependencies so that key stays complete.

Updates tailscale/corp#34812
Updates tailscale/corp#28679

Change-Id: I2def6f28a045249b2e87331a1f42c621e161031f
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-22 07:02:10 -08:00
Brad Fitzpatrick a33097932f 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 <[email protected]>
2026-11-21 21:00:56 -08:00
Nick Khyl 1a4f4eb6ce net/netmon: don't hold mu while closing the OS monitor
On Windows, winMon.Close unregisters the route/address/interface change
callbacks and waits for in-flight ones to return. Those callbacks call
Monitor.isActive, which takes m.mu. Monitor.Close held m.mu across
om.Close, so a change notification arriving during Close deadlocked
with it, and the test binary hung until the timeout.

Release m.mu before calling om.Close. m.closed is already set under the
lock, so late callbacks see the monitor as inactive and return.

This is also the root cause of the Windows "ipnlocal: watchdog timeout"
panics that kill the ipn/ipnlocal and wgengine/netstack test binaries.

Add TestMonitorCloseWaitsForOSCallback, which uses a fake osMon whose
Close, like winipcfg's Unregister, waits for a callback that needs
m.mu. That reproduces the deadlock on any OS.

flakestress TestMonitorCloseWaitsForOSCallback, -p 4, linux:
  before: 16/16 runs deadlocked
  after:  0/135569 runs

Fixes #22228
Fixes #22548

Change-Id: Ibe7740ca23a1ab375d37c280838942f49b4a6a8f
Signed-off-by: Nick Khyl <[email protected]>
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-21 16:16:23 -08:00
Dep Updater 1cc8632af3 go.mod: bump github.com/tailscale/wireguard-go
* github.com/tailscale/wireguard-go: https://github.com/tailscale/wireguard-go/compare/330f55178f24...a8c4fbf26d6c

Triggered by @raggi via the bumpdep workflow.

Updates #22475

Signed-off-by: Dep Updater <[email protected]>
2026-11-21 15:55:16 -08:00
Brad Fitzpatrick 1db8e79a8b .github: use gomodfs for the Go module cache on Windows CI
Instead of restoring the module cache from actions/cache, the Windows
jobs now install WinFsp and mount a gomodfs remote store (on the Azure
VNet, at vars.GOMODFS_AZURE_URL, defaulting to ci-gocached-azure-1:8090)
on M:, which also provides the tsgo toolchain via ~/.cache/tsgo. gomodfs
is started via ShellExecute so it doesn't inherit the step's pipes,
which would make the runner kill it at the end of the step, and a
separate step checks that it survived before pointing GOMODCACHE at it.
If anything fails, the jobs warn and fall back to downloading modules
and the toolchain directly.

Updates tailscale/corp#34812

Change-Id: I26cea9cfa483d5fb3fd51b1d0f87a9204f792690
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-21 11:12:52 -08:00
Brad Fitzpatrick ee7324a20e ipn/ipnlocal: deflake TestServeAppCapsConcurrentStreams on Windows
The test started 400 requests at once, each proxied over a fresh
loopback connection to one httptest server. On Windows, the dials that
overflow the listen backlog are refused, the proxy returns an empty 502,
and the test reported that as "/ops: capabilities header missing". Cap
the requests in flight at 8 and report non-200 responses as such.

Reproduced on Linux in a network namespace with net.core.somaxconn=128
and tcp_abort_on_overflow=1 (12 of 200 runs failed). With the fix, 0 of
5000 failed there, and 0 of 2000 with somaxconn=8. With the original
bug fix from 566f89e0f reverted, the test still fails 50 of 50 runs.

Flakes analysis: http://flakes/analyze-test?name=tailscale.com%2Fipn%2Fipnlocal.TestServeAppCapsConcurrentStreams

Fixes tailscale/tailscale#22543

Change-Id: Ia3f74832d958744442b837d928a21aafa0445772
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-21 10:34:47 -08:00
Alex Valiushko 36780d60ef magicsock,tstun: add gauges for the number of open queues and sockets (#22535)
Updates tailscale/corp#48168
Updates tailscale/corp#37878

Change-Id: I8bedbc5043dccf0a2aecd77dfb76899c6a6a6964
Signed-off-by: Alex Valiushko <[email protected]>
2026-11-20 16:05:40 -07:00
Mazdak Nasab 8dc50105e4 feature/conn25: do not lock mu in packetFilterAllow (#22534)
packetFilterAllow holds c.mu while touching nothing it protects.
It only calls getIPSets, a func field assigned once in newConn25
that reads the config out of an atomic pointer.
Its siblings transitIPInPool and destinationInPools already call
it unlocked. Drop the acquisition, which besides being dead
was a lock-ordering hazard if getIPSets ever grows a lock of its own.

Updates https://github.com/tailscale/corp/issues/38924

Change-Id: I2942a9b0a6a57378473393c62611c557f07e71b3

Signed-off-by: Mazdak Nasab <[email protected]>
2026-11-20 15:24:05 -07:00
Mazdak Nasab 4f7439b415 feature/conn25: name lock-requiring methods Locked (#22532)
Two methods read or write state guarded by their receiver's mutex without
taking it, relying on every caller to hold it, but were not named to say
so. enqueueAddressAssignment documented the requirement in prose only;
lookupAddrBySrcIPAndTransitIP had no doc comment at all. Rename both with
the Locked suffix the package already uses for drainAddrsLocked,
transitIPRoutableLocked and removeFlowLocked, and give the connector
lookup a doc comment stating the requirement.

Fixes https://github.com/tailscale/corp/issues/38924

Change-Id: Ib8bcaf5809ae6f982a504ae554ad1304dbb53018

Signed-off-by: Mazdak Nasab <[email protected]>
2026-11-20 14:48:51 -07:00
Brad Fitzpatrick 05abd5d73e ssh/tailssh, tstest/natlab/vmtest: expand Tailscale SSH test coverage
Add Docker integration tests for TCP and Unix forwarding, pty size,
resize and modes, session env, envknobs, x11 rejection, session
teardown, SessionDuration, policy changes and RuleExpires on active
sessions, Shutdown, host keys and utmp, and run every integrationtest
test in the Dockerfile. Extend the vmtest SSH tests to use real
OpenSSH clients across the tailnet for pty, sftp/scp, agent and port
forwarding, AcceptEnv, ControlMaster, large transfers, banners, user
mapping, revocation, check mode (via a new testcontrol handler),
recording, and the tailscale ssh CLI. Fix make sshintegrationtest,
which only ever tested one image and always exited 0, and trigger the
workflow on go.mod changes and a schedule.

Updates #13038
Updates tailscale/corp#50380

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Ie4fffad7e9298b6b77c3ec3a6ae81fd784d182ce
2026-11-20 12:44:01 -08:00
Nick Khyl 262640ff4e util/syspolicy/source: notify sessions when a forced read finds a change
A Reader is shared by all effective policies that include its source.
A forced read through one of them updated the Reader's cached snapshot
and marked it up to date, but didn't notify the other sessions, so
their policies kept the old settings.

Since a89b32904, "tailscale syspolicy reload" reloads the caller's user
policy rather than the device policy used by LocalBackend. On Windows,
a registry change made without a Group Policy refresh was therefore
reported as configured by the CLI but never applied by the backend.

Updates tailscale/corp#51820

Signed-off-by: Nick Khyl <[email protected]>
2026-11-20 11:48:47 -08:00
Nick Khyl b837008974 clientupdate: don't exit tailscaled when starting the Windows installer
When an update is requested via LocalAPI, updateWindows runs inside
tailscaled, and its os.Exit(0) after launching the tailscale.exe copy
made the service restart the tailscaled child process immediately.

Exit only when running as tailscale.exe. In tailscaled.exe,
wait for the installer instead, which stops the service as part
of the upgrade. As a side effect, an install that fails before
stopping the service is now reported as a failed update.

Updates tailscale/corp#40430

Change-Id: I8af60fa12740dafceb7c9ea4f50d87c1cad27fa4
Signed-off-by: Nick Khyl <[email protected]>
2026-11-20 11:10:50 -08:00
Fran Bull b21a970437 feature/conn25: mint tokens for DNS responses
Implement the new peerapi hook and add the tokens authenticating that
the destination IP addresses were seen by this connector when forwarding
a DNS query for the given app.

Updates tailscale/corp#46169

Signed-off-by: Fran Bull <[email protected]>
2026-11-20 10:49:42 -08:00
Fran Bull 48f915b2ad feature/conn25: decompose mapDNSResponse
To allow logic to be shared between client and connector, to allow the
connector to parse a DNS response to add its tokens that authenticate it
returned a given address for a given app.

Updates tailscale/corp#46169

Signed-off-by: Fran Bull <[email protected]>
2026-11-20 10:49:42 -08:00
Brad Fitzpatrick 5c7e705edf net/memnet: don't arm deadline timers on a closed Pipe
Setting a deadline on a Pipe starts a goroutine that wakes blocked
readers or writers when it passes, and only a later SetDeadline or Close
cancels it. But Close only cancels the timers it finds, so setting a
deadline after Close started a goroutine nothing would ever cancel,
which lived until the deadline passed.

An http.Server does exactly that if it's closed between accepting a
conn and serving it: conn.serve sets the TLS handshake deadlines on the
already-closed conn, then fails the handshake. Under synctest, the
leftover goroutines make the test fail with "main bubble goroutine has
exited but blocked goroutines remain", as seen in a lansport test in
tailscale/tb on Windows CI.

A closed Pipe has no blocked readers or writers left to wake, so don't
arm a timer for it. The deadline itself is still recorded.

Updates tailscale/corp#51705

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I772ca698fc81f7389542e87d108eec0c04b98df1
2026-11-20 06:32:38 -08:00
David Bond c8ba9da543 ipn/store/kubestore: cache TLS certs briefly on write replicas (#22103)
The write replica of an HA ProxyGroup (cert share "rw") doesn't keep TLS
certs in memory, so that it notices a recreated, empty cert Secret and
issues a new cert. As a result, it read the cert Secret from the API
server on every TLS handshake, with a 30s timeout. When the API server
was slow or unavailable, handshakes on that replica waited for the read,
and feature/acme repeated the read under the per-domain lock. Clients
with a 10s handshake timeout, such as kubectl, failed.

This commit adds a small per-domain cache of the last-known-good cert
and key for write replicas. The replica serves a cached cert for 30s
before it reads the Secret again. When it has a cached cert, the read
uses a 3s timeout, and on an error other than not found or forbidden
the replica serves the cached cert and waits another 30s before the
next read. A read that finds the Secret missing, forbidden or empty
removes the cached cert and returns ipn.ErrStateNotExist as before, so
a recreated Ingress still gets a new cert, at most 30s later.
Concurrent reads of the same Secret share one GET, and a read that is
in flight when a cert is written does not replace the written cert.

A Secret watch remains the long-term fix.

Fixes #22009

Change-Id: Id107bf0a7628a1a026f94e621173d7c5d02fb451

Signed-off-by: David Bond <[email protected]>
2026-11-20 12:32:02 +00:00