Commit Graph
201 Commits
Author SHA1 Message Date
Francois Marier 019902a601 tstest/natlab: Fix typo in README sample command
The current command fails with:

    invalid value "15" for flag -timeout: parse error

because the timeout flag wants a time.Duration value.

Updates #cleanup

Change-Id: I645974078ce60c42b9d5d7bd227226de5fff26ad
Signed-off-by: Francois Marier <[email protected]>
2026-11-18 14:47:44 -07:00
Claus Lensbøl f1b5e51369 tstest/natlab/vmtest: make ssh tests run across Linux test matrix (#22491)
Updates #21817

Signed-off-by: Claus Lensbøl <[email protected]>
2026-11-18 11:17:00 -05:00
François Marier 3631dae2d8 tstest/natlab/vnet: check PCP nonces in renewals and deletes (#22370)
PCP requests with an incorrect nonce are ignored by PCP servers
which follow the simple threat model defined in RFC 6887. Doing
it in natlab will ensure we detect client regressions.

Updates #21127

Change-Id: Ifefcda278800f642c161df90e76babeb089da5a3
Signed-off-by: Francois Marier <[email protected]>
2026-11-12 14:22:14 -07:00
François Marier 1ebf217e93 tstest/natlab/vnet: implement portmap deletions (#22302)
Add basic support for the deletion of port mappings in natlab.
NAT-PMP clients are supposed to set the external port to 0 in their
requests, but we test with a bogus port since servers are supposed
to ignore this value.

Note that passing a lifetime of 0 to a UPnP mapping will delete
that mapping (like it's supposed to in PCP/NAT-PMP) instead of
following the spec and turning that into 604800s.

Updates #21713

Change-Id: I487cc0cae1247dff69484658f86a45d278bcdea7
Signed-off-by: Francois Marier <[email protected]>
2026-11-10 15:58:59 -07:00
François Marier 3ac0005aa2 tstest/natlab/vnet: add portmapping test for renewals (#22182)
This includes vmtests to test that the tailscale client
renews PCP and NAT-PMP portmaps correctly, and unit
tests for the natlab server implementation. UPnP will
require a different approach since the client doesn't
currently have a way to notice that its requested
lifetime was capped.

It also makes TestPortmapCreate parallel. Both
portmapping tests run within 2.5min on my laptop.
TestPortmapRenew is gated behind `--run-slow-tests`.

Updates #21713

Change-Id: Ie2a5f5e906c1f4eda8d10f5d4eff28b159b455cc
Signed-off-by: Francois Marier <[email protected]>
2026-11-09 09:03:22 -07:00
Brendan Creane b7c3386649 net/dns,tstest/natlab/vmtest: accept a silent openresolv listing as no snippets (#22211)
openresolv before 3.13 exits 1 from "resolvconf -i" when its interface
directory holds no snippets. FreeBSD ships openresolv 3.9.2 in its base
system, so on FreeBSD hosts with static network configuration that status
aborted every DNS reconfiguration. A listing that prints nothing on stdout
or stderr now yields an empty base config whatever its exit status, which
also covers the exit status 2 that openresolv 3.17 returns.

The natlab DNSOpenresolv mode now provisions FreeBSD guests as well, by
deregistering the snippets dhclient added, and the openresolv VM tests run
on FreeBSD too. Without the net/dns change, the new FreeBSD test fails with
the health error reported in #11907.

Updates #11907
Updates #11129

Signed-off-by: Brendan Creane <[email protected]>
2026-11-06 14:15:57 -08:00
François Marier ca4e1972fa tstest/natlab/vnet: move PCP/NAT-PMP code to portmapper.go (#22145)
portmapper.go was introduced for UPnP in commit
8ed43f1f2a.

This also adds a unit test which exercises the incomplete
natlab server implementation of these portmapping protocols.

Updates #21713

Change-Id: I33b61ccbe8c1d8d99d56aa357ae24777be3f5739
Signed-off-by: Francois Marier <[email protected]>
2026-11-03 14:51:11 -07:00
François Marier 1b68f62be8 tstest/natlab: add a new portmapper VM test (#22071)
This test encodes the current behaviour of the Tailscale client.
It only covers the creation of new mappings.

Updates #21713

Change-Id: Ia44877036569660f4129484d5059ed22ffbf9cda
Signed-off-by: Francois Marier <[email protected]>
2026-10-30 10:19:14 -07:00
François Marier 8ed43f1f2a tstest/natlab: add basic SSDP and UPnP support (#21823)
This bare-bones implementation of a UPnP server covers only what
the Tailscale client needs in order to successfully create a
new mapping.

A new flag is introduced for the test control server so that UPnP
can continue to be disabled in all tests except natlab.

Updates #21713

Change-Id: I57779e07c6a628a12bb30dccabd94f7bb21270c4
Signed-off-by: Francois Marier <[email protected]>
2026-10-28 11:58:07 -07:00
Claus Lensbøl 41d25e0c8f cmd/natlab-test-matrix,tstest/natlab/vmtest: add test matrix tool (#21818)
Add experimental tool for generating a matrix of tests to be run by CI.
This tool will parse the test files in the vmtest folder, and find
candidates that can be with with a set of variations. For now that is
expressed as different flavours of Linux, but it can be expanded across
OS'es but also other things like NAT configurations and portmapper
extensions available.

Updates #21817

Signed-off-by: Claus Lensbøl <[email protected]>
2026-10-28 14:05:30 -04:00
Francois Marier 2b62983a4a tstest/natlab/vnet: fix TCPConn leak
Explicitly close the other end of the losing connection.

This is a follow-up to 31baee90c0.

Updates #cleanup

Change-Id: I5bf36a7451da05545e7242ee5c1bff02fa44b362
Signed-off-by: Francois Marier <[email protected]>
2026-10-26 21:49:04 -07:00
Francois Marier 48ac67151e tstest/natlab/vnet: send "unsupported version" NAT-PMP/PCP responses
When receiving a PCP request, a NAT-PMP-only server must reply with
an unsupported version response. Same for a PCP-only server
receiving a NAT-PMP request.

The tailscale client sends both a NAT-PMP and a PCP request when
probing for portmapping support and it correctly handle any
unsupported version response it receives.

Updates #21713

Change-Id: I0ec8b4a6c1de14bcc64b82f1988cde7fc01f5747
Signed-off-by: Francois Marier <[email protected]>
2026-10-16 10:13:52 -07:00
Brendan Creane a0a79982d4 feature/acme,tstest/acmetest: report the authorization error when an ACME order fails (#21790)
When validation fails, WaitOrder returns only the order's status, so
tailscale cert printed "acme: order ... status: invalid" with no reason.
The CA's reason is on the authorization's challenge. Wait on each
authorization before the order and return that error instead.

To test this, move natlab's fake ACME CA to tstest/acmetest, where unit
tests can import it, and teach it tls-alpn-01, a validation hook, and
the "invalid" state a CA reports when validation fails.

Updates #21759

Signed-off-by: Brendan Creane <[email protected]>
2026-10-15 07:45:30 -07:00
François Marier 53c3957233 tstest/natlab/{vmtest,vnet}: add basic PCP support (#21730)
This implements enough of PCP to establish direct connections
with a node behind a hard NAT.

Updates #21713

Change-Id: I44b955e9b8ecce80ddc49afdfb01eb49c8d56f8c
Signed-off-by: Francois Marier <[email protected]>
2026-10-13 08:51:12 -07:00
Francois Marier 87ec06810d tstest/natlab/vmtest: give LANPing attempts more than 5s
TTA's /ping runs four pings, taking 3-4s. The 5s timeout wasn't
enough for slow VMs using TCG.

Updates #cleanup

Change-Id: I70006f4c07b776d58619e0ef75c91d0d65b13fff
Signed-off-by: Francois Marier <[email protected]>
2026-10-09 17:02:41 -07:00
Brad Fitzpatrick 0a1eb8c4da ipn/ipnlocal: don't answer single-label names from quad-100
Since 7e609b258 (v1.102), quad-100 looks up MagicDNS names in
nodeBackend.nodeByName, which also holds short-name keys for in-process
dials. So a query for "foo." matched peer "foo.tail-scale.ts.net" and
was answered with its Tailscale IP. 1ec348784 fixed that for MagicDNS
off; this fixes it for MagicDNS on, too, matching pre-1.102 behavior.
The OS applies the search domain to short names before they reach
quad-100, so a single-label query is a root zone name, not a tailnet
name, and must be forwarded (e.g. to LAN mDNS/LLMNR or a global
nameserver). Short names still work for in-process dials via
NodeByName.

Updates #20789

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Ic8199a96cf79178210c9a85e0cebfb46567a894a
2026-10-09 11:01:40 -07:00
François Marier f5e7486c17 tstest/natlab/vnet: refactor NAT-PMP support (#21715)
This will make the addition of PCP support easier.

No changes to NAT-PMP support or tests.

Updates #21713

Change-Id: I7ac58badbd4e8680c0e50d8dd5d78d6d0abb4aa0
Signed-off-by: Francois Marier <[email protected]>
2026-10-09 11:00:06 -07:00
Claus Lensbøl 1e3097c9f2 tstest/natlab/{vnet,vmtest},cmd/tta: add roaming test to natlab (#21695)
To faciliate roaming a few things had to happen as tta communicated over
the same links as tailscaled communicates over, meaning that the
connection to tta gets cut when cutting the interface.

 - Whenever we have connected to the client after waiting for it to come
   up, clean up idle connections.
 - Have tta use keepalives to reconnect.
 - Delete default route on just via, not the interface.
 - Add capabilities to QMP for setting the interface state.
 - Implement the test.

Fixes tailscale/corp#49639

Signed-off-by: Claus Lensbøl <[email protected]>
2026-10-09 13:05:45 -04:00
Francois Marier 8bdb4283de tstest/natlab/vmtest: use -icount for gokrazy VMs under TCG
On hosts without hardware virtualization, gokrazy VMs can hang at
boot with no console output. Timing jitter under software emulation
breaks the kernel's early boot timer calibration, causing it to spin
waiting for timer interrupts that never arrive.

Passing -icount shift=auto ties virtual clocks to instruction execution,
making timer calibration deterministic and preventing the boot hang.

Updates #cleanup

Change-Id: I7c0aa96e5344041af9a7246f7d50bed1da47ab95
Signed-off-by: Francois Marier <[email protected]>
2026-10-07 18:54:33 -07:00
Brendan Creane 4862f5f466 tstest/natlab/vmtest: add a dhcpcd DHCP client option for Ubuntu guests (#21672)
WithDHCPClient(DHCPClientDhcpcd) makes systemd-networkd leave the vnet NIC
unmanaged and runs the dhcpcd that the Ubuntu 24.04 image ships on it.
dhcpcd is the DHCP client on Raspberry Pi OS and other distributions, and
unlike networkd it configures the interface first and runs its resolvconf
hook afterwards. TestDhcpcdOpenresolvDNS checks that dhcpcd holds the
lease, its hook registered the lease's nameserver with openresolv, and
tailscaled forwards through it.

Updates #21607

Signed-off-by: Brendan Creane <[email protected]>
2026-10-06 17:09:47 -07:00
Brendan Creane b62885dd02 net/dns/resolver: don't retry an upstream REFUSED or SERVFAIL over TCP (#20829)
A TCP retry to the server that just answered can only return the same
rcode, and when that server accepted the connection and never answered,
the query ran the full 10s dnsQueryTimeout and the client got nothing.
An upstream rcode now ends the UDP/TCP race when it arrives, and the
client gets it once every resolver has had udpRaceTimeout to answer
instead of waiting for all of them to report. tcpQueryTimeout is also
set on the conn, since a context cannot interrupt a blocked read, and a
new dns_query_fwd_udp_read_ctx_done counter separates query teardown
from upstream read errors.

Fixes #20826

Signed-off-by: Brendan Creane <[email protected]>
2026-10-06 16:19:28 -07:00
Francois Marier 2d34ce3bbf tstest/natlab/vnet: stop agent dials from outliving their Server
While a VM reboots, tests poll its agent roughly every 5s. Each
request that times out leaves behind a goroutine blocked in
Server.takeAgentConn, waiting for TTA to connect back. Several can
pile up before a request succeeds and the test ends, and the rest
wait forever.

Making takeAgentConn return at Server shutdown unblocks any goroutine
still waiting when the test ends.

In a full vmtest run, the two dials stranded by the reboot in
TestGokrazyUpdatesItselfToSameImage logged until the package exited
10 minutes later. With this change, "still waiting" log lines in the
same run drop from 267 to 72, and the longest wait goes from 10m10s
to 40s.

Updates #cleanup

Change-Id: Ib4c1d2ce8f2a7b73d3f0c1e6a9e5b2d8f4a1c7e3
Signed-off-by: Francois Marier <[email protected]>
2026-10-06 11:48:17 -07:00
Brendan Creane 284ca9991d tstest/natlab: upload tailscaled logs from cloud-image guests (#21664)
Only gokrazy builds trust the fake log catcher's TLS certificate, so
Ubuntu, Debian, Fedora and FreeBSD guests failed every upload and the
failure dump of their tailscaled logs was always empty. vnet now also
serves the log catcher over plain HTTP on port 80, and the harness points
those guests at it with TS_LOG_TARGET. Env.NodeLogs returns what a node
has uploaded.

macOS guests still do not upload: tailmac does not pass TailscaledEnv to
tailscaled, so the setting would not reach it.

Updates #13038

Signed-off-by: Brendan Creane <[email protected]>
2026-10-06 07:54:31 -07:00
Francois Marier 31baee90c0 tstest/natlab/vnet: don't hand out idle agent conns the agent already closed
TestSelfSignedDERPHashPinning occasionally fails on a slow vm with:

    tailscale up (limit 1m30s): Get "http://unused/up?accept-routes=true": EOF

Because this endpoint has both IPv4 and IPv6 addresses, TTA will fall
back to the second address when running on a slow host and race both
connections. The losing connection will get closed by net.Dialer and
never produce a response.

By keeping the gVisor endpoint with the conn, we can avoid returning
closed connections in takeAgentConnOne().

This fix uncovered a bug in Env.Tailscale(): calling "tailscale
update" via a GET request may be replayed by net.http.Transport and
that will trigger a second update undoing the first. Using POST
disables all such retries.

Update #cleanup

Change-Id: I2f8b7c4d9e1a3b5c7d0e2f4a6b8c1d3e5f7a9b0c
Signed-off-by: Francois Marier <[email protected]>
2026-10-05 11:26:11 -07:00
François Marier d33279d752 tstest/natlab/vmtest: wait for tailscaled to break race with tta (#21472)
The agent and tailscaled are started concurrently by gokrazy and
tta can win that race, in which case it answers 502 Bad Gateway
because tailscaled.sock does not exist yet.

This is most likely to be seen on slower machines using TCG.

Updates #cleanup

Change-Id: I4012bd189adfb2565470c814204fcf18545f1017
Signed-off-by: Francois Marier <[email protected]>
2026-10-01 11:35:16 -07:00
Brad Fitzpatrick 654c105f8b tstest/natlab/vmtest, gokrazy, cmd/tailscale/cli: add minimal-build vmtests
Add vmtests that boot pairs of gokrazy VMs whose tailscale and tailscaled
are minimal builds and check that IP traffic flows between them over
WireGuard, so we notice if a minimal build stops doing its one job:
build_dist.sh --extra-small (direct path through NATs), that minus NAT
traversal (DERP across NATs, direct on a shared LAN), and DERP-only.

They found that "tailscale up" built with ts_omit_ipnbus returned before
calling Start or EditPrefs, making it a no-op. Fix that, and have it wait
for the Running state by polling tailscaled's status instead of watching
the IPN bus, so scripts can rely on it as with normal builds.

The extra-small feature list moves to featuretags.ExtraSmall so
build_dist.sh (via a new "featuretags --extra-small") and vmtest share
it. The gokrazy builder gains --output and --go-build-tags flags to build
the variant images, and natlabprep --gokrazy prebuilds them all for CI.

Updates #13038
Updates #12614

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I0caa2c7b3adf2399da09b6d07a942f1dc34e8486
2026-09-30 15:53:47 -07:00
Claus Lensbøl b31be2cd1e tstest/natlab/{vnet,vmtest}: clean up natlab inconsitencies (#21483)
There were a handful of inconsitencies in natlab with the biggest being.
 - Pair and grid tests living under tstest/integration and using the old
   test style.
 - Inconsistent use of e vs env.
 - Methods for actions on node living on the vnet.Node rather than being
   a method on vmtest.Env

Clean up these inconsitencies.

Updates #cleanup

Signed-off-by: Claus Lensbøl <[email protected]>
2026-09-29 14:57:10 -04:00
Francois Marier eb79f3e33e tstest/natlab/vmtest: fix test flake
It's possible for multiple direct connections to be counted and
these tests are successful as long as it's more than one.

Fixes #21578

Change-Id: I979efc92a43f78d0e51d602d96e61828e6fabdff
Signed-off-by: Francois Marier <[email protected]>
2026-09-29 10:56:17 -07:00
Brendan Creane 2d4379386a net/dns: don't take over DNS when the OS has no upstream resolvers (#20794)
On backends that can't do OS-level split DNS, Tailscale forwards the default
route to the system's own resolvers, which it reads out of the OS config. At
boot that config may not be populated yet, because NetworkManager or
systemd-resolved haven't run, and Tailscale took over regardless: it pointed
the OS at 100.100.100.100 but compiled an empty "." route, so every
non-Tailscale name failed to resolve for the rest of the process's life.

Fail compileConfig instead, which leaves the OS resolvers in place, and
retry the last config with a bounded backoff until resolvers appear. A
health warning explains why MagicDNS is inactive in the meantime.

Sandboxed macOS and iOS are exempt. There the network extension reapplies
the config itself when the OS nameservers change, and quad-100 as the
primary resolver is what keeps tailnet names resolving while the base config
is still empty. Dropping the exemption is tracked in tailscale/corp#48962.

This also changes the outcome on an openresolv host with no snippets
registered. Since the fix for #20825, openresolv reports an empty base config
there and tailscaled took over with no upstream, so every public name got
SERVFAIL. Such a host now keeps its resolv.conf and shows the health warning
instead. TestOpenresolvDNS checks that outcome.

TestSplitDNSEmptyBaseConfig covers the boot race end to end in natlab: it
empties resolv.conf on a guest using the "direct" backend, checks that
tailscaled leaves it alone, then adds a resolver and checks that both tailnet
and public names resolve.

Fixes #20341

Signed-off-by: Brendan Creane <[email protected]>
2026-09-27 10:20:42 -07:00
Martin Minkus 27b2a7d1a1 wgengine/router/osrouter: leave pf and forwarding alone in FreeBSD netstack mode
FreeBSD handles subnet routes in netstack by default, but the router
still installed its pf NAT rules whenever SNATSubnetRoutes was set,
which is the default. Every FreeBSD node, subnet router or not, loaded
and enabled pf, inserted anchor references into the host's main
ruleset and loaded NAT rules that netstack never needed, since
netstack dials subnet destinations from the host's own addresses.
It also flipped the forwarding sysctls for any advertised route.

Only do either when the kernel path is opted into with
TS_DEBUG_NETSTACK_SUBNETS=false and routes are advertised.

TestSubnetRouterFreeBSDManyFlows ran in netstack mode since the default
changed, so it no longer exercised pf at all. Opt it into the kernel
path and assert the anchor holds NAT rules, and have
TestSubnetRouterFreeBSD assert the default mode leaves pf untouched.

Also drop the stale claim in handleSubnetsInNetstack that the pf NAT
rule never matches; that was the (self) pool bug, since fixed.

Updates #21450

Change-Id: Ibf91a676a026cebb29f64e39a64fe8e75488360b
Signed-off-by: Martin Minkus <[email protected]>
2026-09-25 12:10:53 -07:00
Brad Fitzpatrick d4f2bb4cff ipn/ipnlocal: skip the kernel peerapi listener on FreeBSD when netstack is present
FreeBSD is a weak-host stack like Linux, so a LAN-adjacent machine can
send a SYN for a node's Tailscale IP to the node's NIC and get the
kernel's SYN-ACK from the peerapi port, confirming which tailnet
identity that MAC address belongs to. Linux closes this with
SO_BINDTODEVICE and macOS/iOS with IP_BOUND_IF, but FreeBSD has no
per-socket interface bind (only IP_RECVIF and SO_SETFIB).

Instead, treat FreeBSD like Android: when netstack is present, don't
create a kernel-level peerapi listener at all and use the fake listener,
since netstack already intercepts peerapi connections from peers in
userspace and the kernel socket only ever served the local host. When
netstack is compiled out (ts_omit_netstack), the kernel listener is the
only way to serve peers, so keep it and log that it must be restricted
with pf.

Along the way, tailscaled's own pf source NAT rule on FreeBSD turned out
to rewrite the source of such a SYN-ACK to the LAN IP and a random port,
so a plain connect() from the LAN never completes. The SYN-ACK still
leaks, though, so the natlab test now watches for SYN-ACKs on the
attacker's NIC with tcpdump instead of checking for a completed
handshake, and gains a FreeBSD variant. With the fix disabled, that
variant fails on the leaked SYN-ACK from the peerapi port.

Fixes #21419
Updates tailscale/corp#48248

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I0d2de4ebc9bae28450d500bd7b6ddbfa70f9052f
2026-09-25 12:10:40 -07:00
Francois Marier ef50433800 tstest/natlab/vnet: tear down gVisor network stacks at Server shutdown
Resolves #21442

Change-Id: I98f220d1a0ddc1a15cd9ebe7a8aaa745d17a43b2
Signed-off-by: Francois Marier <[email protected]>
2026-09-25 09:39:50 -07:00
Francois Marier 8d43ba6737 tstest/natlab/vmtest: close unused pipe read FD to avoid leak
There are two copies of the read file descriptor (parent & child).
Since the parent copy is unused, we can close it after fork.

Updates #cleanup

Change-Id: Id789e0a04970c9fb8eaeed1f299aa25f29fcf48c
Signed-off-by: Francois Marier <[email protected]>
2026-09-23 13:04:11 -07:00
François Marier 02de76ba62 tstest/natlab: ignore transport errors during gokrazy update (#21441)
In my testing using TCG, I hit non-EOF network errors that made
this test fail. Since we already poll and check the image version
later, we can treat this response as best-effort.

Resolves #21440

Change-Id: Ia923fc2c199aae7a543d00e06d25a375512daa01
Signed-off-by: Francois Marier <[email protected]>
2026-09-23 10:50:34 -07:00
Francois Marier a35aff2895 tstest/natlab: move running instructions to a README
Updates #cleanup

Change-Id: I9580fbfeeef2edf0c678c8ab1ec70131fd20f0b5
Signed-off-by: Francois Marier <[email protected]>
2026-09-23 10:19:34 -07:00
Brad Fitzpatrick b3de3b2217 ipn/ipnlocal, net/netns: bind Linux peerapi listener to the tun device
Linux is a weak-host stack, so a LAN-adjacent machine can complete a
TCP handshake with a node's peerapi listener by sending a packet to
the node's Tailscale IP, with no credentials and no tailnet
membership.

macOS and iOS already bind the listener to the tunnel interface, and
Windows is protected by its strong host model, so Linux tun mode was
the only platform that leaked.

Bind the Linux listener to the tunnel interface as well, so the
kernel only answers connections that arrive from the tunnel or from
the local host. A natlab VM test verifies that a same-LAN machine can
no longer complete the handshake, while local and peer peerapi keep
working.

FreeBSD has the same weak-host exposure but no per-socket equivalent,
so handling it there with pf is a TODO (#21419).

Updates tailscale/corp#48248

Reported-By: Samuel Keeley (@keeleysam)
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I5f8501b0938c9f7aa39c4c12ebddd988c72e89bf
2026-09-22 14:10:30 -07:00
Brad Fitzpatrick 3014ad828e tstest/natlab/{vmtest,vnet}: bound "tailscale up", dump tailscaled logs on failure
When a natlab node's "tailscale up" hung (TestEasyEasy on CI, twice on
main), the only bound was the 10 minute test context, so the failure
arrived as go test's timeout panic. The VM console logs weren't dumped
(t.Cleanup doesn't run on a panic), and they wouldn't have helped
anyway: on gokrazy the console holds only kernel and init output, while
tailscaled's stdout/stderr goes to a remote syslog that vnet discards
unless the node has VerboseSyslog set. There was no way to see what the
stuck node was doing.

Bound each node's "tailscale up" in Env.Start to 90 seconds (it takes
about a second against the in-process control server), so a stuck node
becomes a normal test failure. On failure, dump the tail of each node's
tailscaled logs from vnet's fake log.tailscale.com log catcher, which
already buffered them per node but exposed them to nothing; add
Server.NodeLogs for that. Also add VMTEST_VERBOSE_SYSLOG=1 to stream
the guests' syslog into the test output live, the vmtest equivalent of
tstest/integration/nat's --log-tailscaled flag.

With this, the CI hang reproduced locally under CPU pressure (2 CPUs
shared with busy loops) in 1 of 22 runs, and the dumped logs showed
tailscaled's control client stuck at "awaiting unpause", which is fixed
separately.

Updates #deflake

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Icfd3a2cdc66d924388a722f3a3cd19f86e116921
2026-09-20 11:02:04 -07:00
James Tucker 3ec674bc86 go.mod,wgengine/netstack,tstest/natlab/vnet: enable RACK and cubic with gVisor clock fix
Update gVisor to include its fix for RACK loss detection with coarse
monotonic clocks. Configure netstack with the 500 microsecond clock
resolution used on Windows so RACK accounts for timestamp quantization.

Remove the TCP recovery override that disabled RACK, enabling gVisor's
default RACK behavior on all platforms.

Switch netstack to cubic congestion control. The int overflow in CUBIC
sender cwnd arithmetic that required pinning reno has since been reworked
upstream into float arithmetic with RFC 9438 target clamping.

Align the natlab vnet stack with netstack: enable cubic, and drop the
now-redundant explicit SACK and receive-buffer moderation sets, both of
which are gVisor defaults.

Fixes #9707

Signed-off-by: James Tucker <[email protected]>
2026-09-15 17:15:35 -07:00
Brendan Creane 3ea665b113 tstest/natlab/vmtest: cover openresolv with a second snippet registered (#21003)
TestOpenresolvDNS pins the case where Tailscale owns the only resolvconf
snippet, so on its own it would also pass if tailscaled never read an OS
base config at all. Register a snippet the way a DHCP client would, then
toggle accept-dns to force a reapply, and assert its nameserver becomes
quad-100's upstream.

SetAcceptDNS is the toggle: tailscaled has no reason to re-read the OS
config on its own, and this avoids rebooting the guest to change what the
OS resolver looks like mid-test.

Updates #20825
Updates tailscale/corp#44793

Signed-off-by: Brendan Creane <[email protected]>
2026-09-15 10:24:47 -06:00
Brendan Creane 970cc199fe tstest/natlab/vmtest: add VM coverage for openresolv DNS backend (#20999)
* net/dns: export OSConfigurationReadWarnable

A natlab vmtest checks that a node is not reporting this warning. Exporting
the Warnable lets the test take the warning's text from it, instead of
keeping a copy of the wording that could stop matching without failing.

Updates #20825
Updates tailscale/corp#44793

Signed-off-by: Brendan Creane <[email protected]>

* tstest/natlab/vmtest: add VM coverage for the openresolv DNS backend

dnsMode() picks one of five Linux DNS backends, and natlab could provision
only systemd-resolved and direct. Add a DNSOpenresolv mode and a VM test for
it, so the backend behind #20825 is covered.

No cloud image ships openresolv and a guest cannot download it, so its two
source files are vendored under testdata and installed with cloud-init's
write_files. openresolv's build is a set of sed substitutions with nothing to
compile, so resolvconf.go does the substitutions in process.

Updates #20825
Updates tailscale/corp#44793

Signed-off-by: Brendan Creane <[email protected]>

---------

Signed-off-by: Brendan Creane <[email protected]>
2026-09-10 09:12:12 -07:00
Martin Minkus b25459ab1f tstest/natlab/vmtest: add multi-flow FreeBSD SNAT test
The existing TestSubnetRouterFreeBSD makes a single HTTP request, which
cannot catch a NAT rule whose translation address is wrong on average
but right occasionally: with a PF "-> (self)" rule, pf round-robins new
states across every address on the machine, so one request has decent
odds of drawing the working address while most flows hang at SYN. That
made the single-flow test an unreproducible coin flip rather than a
regression gate.

Open several fresh flows and require that all of them complete and that
the backend sees exactly one source address. PF rule counters and the
state table are dumped along the way, so a failure shows which address
each flow was translated to.

Fails 4/8 (alternating) against a "-> (self)" NAT rule, with the state
table showing the dead flows translated to the QEMU debug NIC's address
and to tailscale0's own address. Passes 8/8 with per-egress-interface
rules, and under netstack subnet routing.

Updates #5573

Change-Id: I1739ceefbab7764f1db8d07424832947b1d962a3
Signed-off-by: Martin Minkus <[email protected]>
2026-08-31 20:31:01 -07:00
Brad Fitzpatrick 1293b4f67b wgengine/router/osrouter: add native FreeBSD routing, no-snat support
And add site-to-site natlab vmtests for Linux + FreeBSD.

Fixes #5573
Updates #18897

Change-Id: I9629f46fdd99137f0ae96431487d3a7410e2a4cc
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-08-31 20:31:01 -07:00
Simon Law 0e84b4a3a0 tailcfg: replace int with DERPRegionID for additional type safety (#20646)
Historically, when DERP regions were switched away from strings to
numeric identifiers in PR #14641, tailcfg.Node.HomeDERP was declared
as an int instead of its own type.

This PR declares a new tailcfg.DERPRegionID type, represented by an
int64, and converts the following fields to use this type:

- netcheck.Report.PreferredDERP
- netcheck.Report.RegionLatency
- netcheck.Report.RegionV4Latency
- netcheck.Report.RegionV6Latency
- tailcfg.DERPHomeParams.RegionScore
- tailcfg.DERPMap.Regions
- tailcfg.DERPNode.RegionID
- tailcfg.DERPRegion.RegionID
- tailcfg.NetInfo.PreferredDERP
- tailcfg.Node.HomeDERP
- tailcfg.PeerChange.DERPRegion
- tailcfg.PingResponse.DERPRegionID

Note that the original field was an int, while the new field is backed
by an int64. This change makes DERPRegionID the same size on both
32-bit and 64-bit architectures.

Fixes: #20165

Change-Id: Ic6f795a6d791dd16f756f246d5a02085443e212f

Signed-off-by: Simon Law <[email protected]>
2026-08-19 16:25:50 -07:00
Brendan Creane efae57a58c tstest/natlab: test that a peer's name doesn't shadow a bare upstream name (#20804)
* tstest/natlab: test that a peer's name doesn't shadow a bare upstream name

With MagicDNS off, only suffixed names should be answered locally, but
since 1.102 quad-100 also answers a bare, unqualified name whenever a
tailnet device shares that name. It returns the device's Tailscale IP
instead of forwarding to the tailnet's global nameserver, leaving the
upstream record unreachable.

TestBareNameNotHijackedByPeer configures a global nameserver owning a
single-label name, adds a peer named to collide with it, and asserts the
client's lookup returns the upstream address. It queries via "tailscale
dns query" so the name stays a single label; a search domain completing
it would resolve a different name and pass regardless.

Add SplitDNSBareName to vnet's split-DNS zone to serve that name, and a
packet-level case asserting the fake server answers it.

Updates #20789

Signed-off-by: Brendan Creane <[email protected]>

* tstest/natlab: check short names resolve via quad-100 when MagicDNS is on

TestMagicDNS asserted a peer's short name resolves, but through getent
with a search domain configured: libc completed it to the FQDN, so the
lookup never asked quad-100 for a single label. The bare-name path the
resolver takes when MagicDNS is enabled was untested.

Query the short name with "tailscale dns query" too, which asks for
exactly the name given. This is the enabled-MagicDNS mirror of
TestBareNameNotHijackedByPeer, and pins the other side of the condition
added in 1ec348784: a fix that dropped short names unconditionally,
rather than only when MagicDNS is disabled, now fails here.

Updates #20789

Signed-off-by: Brendan Creane <[email protected]>

---------

Signed-off-by: Brendan Creane <[email protected]>
2026-08-10 18:23:44 -07:00
Simon Law 00699abdfb tailcfg,tailcfg/{nodecap,selfcap}: split capability constants to their own packages (#20639)
Package tailcfg defines the types and constants used by the Tailscale
protocol, but since everything is all in one package, it’s difficult
to sift through the docs: https://pkg.go.dev/tailscale.com/tailcfg

We define and enumerate capabilities as string constants for
tailcfg.NodeCapability and tailcfg.PeerCapability. This PR extracts
them into their own packages:

- tailcfg.CapabilityFileSharing becomes nodecap.FileSharing
- tailcfg.NodeAttrOnlyTCP443 becomes nodecap.OnlyTCP443
- tailcfg.PeerCapabilityTaildrive becomes peercap.Taildrive

We originally intended for CapabilityFoo to grant an entitlement or
permission for Foo, and for NodeAttrBar to configure Bar in the
nodeAttrs section of the policy file. However, there was no technical
enforcement of this convention, so new capabilities have used the
NodeAttr prefix regardless of meaning. Therefore, this PR unifies
tailcfg.CapabilityFoo and tailcfg.NodeAttrBar into a single package as
nodecap.Foo and nodecap.Bar.

Ran `go fix -inline ./...` and committed the changes that replaced
uses of the tailcfg aliases with the authoritative ones.

Updates #20259

Change-Id: Ieb7e7e6c8247c39faf42fdf15c68cdc7c621c730
Signed-off-by: Simon Law <[email protected]>
2026-08-07 16:30:35 -07:00
Brendan CreaneandClaude Opus 5 a265908a72 tstest/natlab: add a second fake DNS server and split-DNS tests (#20553)
Add a second fake DNS server (4.11.4.12) serving a zone the default one
doesn't, so a split-DNS route can be verified: resolving that name proves the
query was forwarded there.

Tailscale implements a split-DNS route two ways, and a test covers each. When
the OS resolver supports split DNS and every route shares one resolver set,
tailscaled hands the OS that resolver directly and quad-100 stays out of the
query path; TestSplitDNSOSForwarded covers this, reaching the split resolver
over a subnet route as a real deployment would. Otherwise the OS is pointed at
quad-100, which forwards per-domain itself; TestSplitDNS covers this against
both the systemd-resolved and direct backends, along with the other ways a
lookup resolves -- answered locally by quad-100 from an extra record or from the
netmap, and unrouted names still going to the machine's normal resolver.

TestSplitDNSNoMagicDNS covers split DNS on a tailnet with MagicDNS off, which
the two above leave out: one has mixed resolver sets but MagicDNS on, the other
MagicDNS off but a single resolver set. Together those conditions take a
distinct path through compileConfig, where tailscaled reads the OS base
resolver config rather than scoping quad-100 to a match domain.

Both arrangements produce the same answers, so each test also asserts the
guest's resolver state to prove which one it exercised.

Fixes tailscale/corp#44798

Signed-off-by: Brendan Creane <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
2026-08-06 17:05:51 -07:00
Claus Lensbøl 3799eaf264 ipn/ipnlocal,wgengine: implement wg-go SetPriorityMessageOnEstablishmentFunc (#20606)
Implements a way to send TSMPDiscoAdverts based on a trigger from
wireguard-go when a rekey happens. This lets us distribute disco keys
consistently, but also sets us up for a minimal message that can be
distributed to other clients.

A benchmark is implemented to make it easier to keep the call cheap and
to avoid locking up anything in wireguard-go.

Updates #20081

Signed-off-by: Claus Lensbøl <[email protected]>
2026-07-30 09:20:43 -04:00
Brad Fitzpatrick c0c453334a ipn/ipnlocal: evict stale node indexes when a delta upsert replaces a peer
When a node is renamed in the admin console, control sends peers a
single MapResponse delta: a PeersChanged entry carrying the full
updated node with its new Name, and no new DNSConfig (MagicDNS
records are computed client-side from peer names). That arrives as a
NodeMutationUpsert, but nodeBackend's upsert path only added the new
node's index entries and never removed the replaced node's, so
nodeByName retained the old name, and nodeByAddr, nodeByKey, and
nodeByStableID could likewise go stale if those fields changed.

Since 7e609b258 the quad-100 resolver serves MagicDNS answers on
demand from those live indexes, so a renamed peer's old name kept
resolving until something rebuilt the indexes from a full netmap,
such as toggling Tailscale off and on.

Evict the replaced node's index entries before adding the new ones.
Also consolidate the natlab DNS coverage into a single TestMagicDNS
that boots one VM and exercises extra records, search domains, and
peer add/rename/remove end to end, injecting the same MapResponse
shapes that production control sends.

Updates tailscale/corp#45631

Change-Id: I8a418317d930ec8ce112f7bd19bfd5778117a65e
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-07-27 19:43:11 -07:00
Mario Minardi e48e7b730a ssh/tailssh: check if user matching autogroup:nonroot is root
Add a check to ensure that the user being matched to an
autogroup:nonroot rule is in fact a non-root user on the system.

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

Signed-off-by: Mario Minardi <[email protected]>
2026-07-27 17:18:34 -06:00
Brad Fitzpatrick 420a8e5a1a drive/driveimpl: handle Unicode normalization mismatches in filenames
Files whose names contain characters with Unicode decompositions (such
as umlauts or voiced kana) could not be opened or written over
Taildrive.

Background: keyboards and IMEs emit NFC (precomposed) characters on
every platform, so filenames on Linux (ext4 etc) and Windows (NTFS)
disks are usually NFC bytes. NFD (decomposed) names mostly come from
Apple software: HFS+ forced a variant of NFD on write, and Apple's
frameworks still decompose paths via fileSystemRepresentation. APFS
preserves whatever bytes it is given but does normalization-insensitive
lookups (it stores a hash of the normalized name), so canonically
equivalent names find the same file. ext4 and NTFS lookups, by
contrast, are byte-exact.

On the wire, the macOS WebDAV client sends paths in NFD form (they
pass through the decomposing file system representation, and unlike
Apple's NFS client there is no "nfc" mount option). Windows and Linux
WebDAV clients pass names through as the application provided them,
typically NFC. WebDAV itself mandates no normalization, and PROPFIND
hrefs reflect the server's on-disk bytes.

The two forms are canonically equivalent but byte-wise different, so a
macOS client requesting the NFD form of an NFC-named file on a Linux
or Windows host got a 404 from the exact-byte lookup. Even against an
APFS host, where the filesystem absorbs the mismatch, the client-side
StatCache could still infer a 404: a cached directory listing in one
form caused depth 0 PROPFINDs in the other form to be treated as not
found without ever reaching the server. The inverse direction (NFD
bytes on a Linux disk, copied there from a Mac, requested in NFC form
by a Windows or Linux client) was broken too.

Alternative regimes considered: normalizing names at storage time (as
Nextcloud and Syncthing's autoNormalize do) would rename user files in
shared directories as a side effect of serving them; normalizing
request paths to a fixed form on the wire is unsound because the
on-disk form is unknowable a priori (ext4 can hold either form, or
both). Instead, adopt the APFS model: preserve bytes, but make lookups
normalization-insensitive.

Concretely, wrap the remote file server's webdav.Dir in a
normalizingFS that, when an exact path lookup fails, rescans the
parent directory for an entry whose name is canonically equivalent,
comparing the NFC form of both sides (which also sidesteps Apple's
nonstandard decomposition tables). Exact matches always win, and newly
created files keep the exact bytes the client sent. Also NFC-normalize
StatCache keys so canonically equivalent names share a cache entry.

The change is covered at three levels: unit tests for the StatCache,
an in-process two-node test in drive/driveimpl, and a new TestTaildrive
VM integration test in tstest/natlab/vmtest that shares a directory
between two Ubuntu VMs and exercises the NFC/NFD cases over the real
stack with curl playing the part of a macOS WebDAV client.

Fixes #15020

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I9c2f157e604efc629828581e08d5b3191dbb7d4e
2026-07-27 06:35:54 -07:00