Dial TCP -L/-D forwards and bind TCP -R forwards while impersonating the
connection's user through an S4U session, instead of as LocalSystem. The
socket, connect, and bind run under the user's token, so Windows Filtering
Platform rules and any per-user bind restrictions apply to the user, as
the unix monitor's user-credential children arrange. The socket's owning
process is still tailscaled, so a connection-to-PID lookup names
tailscaled; impersonation changes the authorized identity, not process
ownership. A non-LocalSystem tailscaled already runs as the user, so it
dials and binds directly.
This replaces the earlier use of gliderssh's default handlers, which dial
and bind as the daemon. Windows now installs its own direct-tcpip and
tcpip-forward handlers, mirroring the unix ones without the monitor.
Move the identity-independent forwarding helpers (the loopback bind
policy, the gateway-ports knob, the RFC 4254 payload structs, and the
copy loop) into fwdshared.go, built on the unix and Windows platforms
that dial and bind themselves, so the Windows handlers do not copy the
loopback policy. plan9 keeps gliderssh's handlers and does not build it.
Unix socket forwarding and agent forwarding stay unsupported on Windows;
fwd_windows.go documents why and what agent forwarding would take.
Updates #4697
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Ib7d9f1e3a5c7206e4b8d0f2a6c8e1b3d5f7a9c2e
Start each caller-facing process in its own job object and keep the sole
handle on the Process rather than handing a copy to the child. Terminate
now kills the whole job, the session's descendants too, like SIGKILL to a
Unix process group. If this tailscaled dies, the OS closes the last job
handle and kill-on-close terminates the tree, so a crashed service does
not leak a user's session processes, matching the Unix monitor's
termination on RPC loss. A graceful session end clears kill-on-close
first, so processes the user backgrounded survive.
The pseudoconsole relay keeps starting its shell without its own job, so
the shell joins the caller's job as before.
Updates #4697
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Ia3c7e9f1b5d2460a8c3e7f9b2d4a6c8e0f1b3d5a
Add the Windows versions of the per-OS hooks and build the SSH server on
Windows. As LocalSystem (the service), tailscaled logs the target user on
with an S4U logon via util/winutil/s4u and runs the session process with
that user's token, with pipes or, for PTYs, the s4u pseudoconsole relay.
A non-LocalSystem tailscaled can only run sessions as itself. SFTP runs
"tailscaled be-child sftp" as the user.
There is no per-connection monitor process on Windows: the session runs
under the user's token directly, so connmonitor_windows.go and
fwd_windows.go stub out the monitor and forwarding seams. TCP port
forwarding works; Unix socket forwarding and agent forwarding are
refused.
The shell follows OpenSSH for Windows's DefaultShell registry value, else
pwsh, Windows PowerShell, or cmd.exe. OpenSSH's host keys are reused when
readable. Policy user names match Windows accounts case-insensitively;
"=" treats LocalSystem and the built-in Administrator as root.
TestTailscaleSSH in tstest/integration covers the same-user path on all
platforms and, with --run-windows-service-tests, the S4U path.
Updates #4697
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I9e3f1a7c5b2d4e6f8a0c2b4d6e8f1a3c5b7d9e2f
Move handleSSHAgentForwarding and closeAgentForwarding from process_unix.go
into tailssh.go, since they only use the platform seams (fwdListenAgent and
removeAgentForwardingDir) and have no Unix-specific code of their own. Move
the sshForwardGatewayPorts knob into fwdmonitor.go next to its only user,
and move the evalSSHPolicy and matchRule convenience wrappers into the test
file, which is the only place that calls them.
This is a no-op refactor in preparation for a port of the SSH server to
another platform, so that the port does not need its own copies of these
functions or carry unused declarations.
Updates #cleanup
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I7c3e1f0a9d2b4e6f8a1c3e5d7f9b1d3f5a7c9e1b
Whether Login swaps a UAC-filtered token for its linked full token depends
on the account: the built-in Administrator is never filtered, domain
accounts' network logons are not filtered, and other local Administrators
members are. Log which happened, and any failure to get the linked token,
so a session running with fewer rights than expected can be explained from
the log.
Updates #4697
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I2c4e6a8b0d3f5a7c9e1b3d5f7a9c1e3b5d7f9a1c
After the relayed process exited, beRelay closed the Process, which closed
the pseudoconsole's output pipe while the goroutine copying that output to
the relay's stdout might still be reading it, and then exited. Any output
still in the pseudoconsole at that point was lost. For a short command
that was all of it: "ssh -t host echo hello" against a domain controller
test node printed nothing in 10 of 10 tries.
Release the process instead, which closes the pseudoconsole and so lets
the output pipe reach EOF, wait for the copy to finish, and only then close
the pipes and exit.
Updates #4697
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I1a3c5e7f9b2d4f6a8c0e2b4d6f8a0c2e4b6d8f0a
This package has been unused since 2024. The Windows SSH server is about
to use it, which needed a few changes:
Pipe-mode children were created with DETACHED_PROCESS and so had no
console; every console program they started then allocated its own and
lost its output to it. Use CREATE_NO_WINDOW instead, as OpenSSH for
Windows does.
Add Process.Release (Close without closing the I/O pipes), upgrade
UAC-filtered admin tokens to the linked full token, start processes in
the user's profile directory, add StartCurrentUserProcess* for a
non-LocalSystem caller, make the pseudoconsole relay exit with the child's
exit code, and stop mergeEnv from upper-casing variable names.
Updates #4697
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I6d2e9a4c1f7b3058e2a1d4c6b9f0e7a3d5c8b1f4
This is needed for authenticated log uploads (see #20482).
Add a noop declaration now, so that we can call it from
client implementations on other platforms (e.g., Android or iOS).
Updates tailscale/corp#39092
Signed-off-by: Joe Tsai <[email protected]>
For kube-apiserver ProxyGroups with static endpoints, the operator sets
PORT on the k8s-proxy container to the targetPort of the NodePort
Services behind the advertised endpoints. k8s-proxy never read PORT, so
tsnet listened on a random port and traffic to the static endpoints was
forwarded to a port with nothing listening. Peers stayed on DERP.
This fixes this by parsing PORT and setting it as tsnet.Server.Port.
Thanks to @icheishvili (#18841) and @rquitales (#21716), whose changes
this is based on.
Updates #21714
Signed-off-by: chaosinthecrd <[email protected]>
policies
This adds support for reading string-list policies represented as
DWORD-backed registry subkeys. Each nonzero DWORD contributes its value
name to the resulting string list, allowing group policy settings to
expose predefined options as checkboxes instead of requiring users to
enter strings manually.
This also adds definitions for HiddenNetworkDevices.
Updates tailscale/corp#50029
Signed-off-by: kari <[email protected]>
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]>
This uses the same notification delivery logic for policy changes and regular ipn bus updates. Previously, sysPolicyChangedForSession silnetly dropped policy notifications when a watcher's channel was full, potentially leaving clients with stale policy and gui visibility state. Now lagging watchers follow the existing block, suspend, or close behavior, allowing them to recover the latest policy when they resume or reconnect.
Updates tailscale/corp#44104
Signed-off-by: kari-ts <[email protected]>
tailscale/wireguard-go#116 changed the receive loop to retry any errors
other than net.ErrClosed without a delay. magicsock entered a spin loop
if it encountered a UDP read error.
magicsock's receive funcs now return only net.ErrClosed when the socket
actually closes. Every other read error is counted, logged, and retried
after a short delay. IsUDPReadFeedback and IsUDPReadUnknown are removed
because they can be handled like any other error.
Retrying errors may hide failures which used to stop the receive func.
- There is a new metric magicsock_recv_udp_error which counts all read
errors.
- After 30s of continuous errors, the receive function marks itself as
broken. A warning is raised until a read succeeds.
Updates #22097
Change-Id: Ib9ade0ed001e413205eb7d452aa108aae574e0d1
Signed-off-by: Nick Beirne <[email protected]>
Adds a test that issueACMECert, against tstest/acmetest, retries an
order naming "replaces" once without it when the CA rejects it, and
stores the cert from the retried order. It also checks that rate limits
and server errors are not retried, and that the error from the plain
order is returned if that is rejected too.
Updates #22042
Signed-off-by: chaosinthecrd <[email protected]>
When a previous cert exists, the renewal order names it in the ARI
"replaces" field. Let's Encrypt rejects that order if the current ACME
account did not issue the cert, which is the case once the account key
has been recreated but the cert kept (for example after
acme-account.key.pem is deleted), so renewal fails until the cert
expires or is deleted. This fixes this by retrying the order once
without "replaces" when the CA rejects it, unless it was rate limited.
The new cert belongs to the current account, so later renewals use
"replaces" again.
Fixes#22042
Signed-off-by: chaosinthecrd <[email protected]>
Adds a test that checks whoIs gets the identity from the request's remote
address, and returns an error instead of using the X-Forwarded-For header
when the remote address is not a tailnet node.
Updates tailscale/corp#51000
Signed-off-by: chaosinthecrd <[email protected]>
whoIs fell back to the X-Forwarded-For header when WhoIs on the request's
remote address failed (only when serving over plain HTTP, as cmd/k8s-proxy
does). That header comes from the client, so the identity could come from
the request instead of the connection. This fixes this by removing the
fallback, so whoIs only uses the connection's remote address. It also asks
for TCP only, as the proxy only serves TCP, so a miss does not also try UDP.
Updates tailscale/corp#51000
Thank you Emilio Mendoza @a3l6 for reporting
Signed-off-by: chaosinthecrd <[email protected]>
wgengine/magicsock: retire stale TSMP disco key after peer restart
When a nonzero control key replaces an old control key equal to the
active TSMP key, updateDiscoKey clears the TSMP-active flag and
subsequent sends use the new control key, while the retired TSMP
material stays stored. A zero control key falls back to the TSMP key as
active, and a different TSMP key that is already active stays preferred.
Each compare-and-swap attempt allocates a fresh disco snapshot before
choosing the active key.
Fixes#22201
Signed-off-by: Matt Van Horn <[email protected]>
ParseDuration rewrites the digits before a d or w unit as hours, but only
looked at the digits after the decimal point, so 0.5d quietly returned
7m12s. Return an error for fractional day and week values instead.
Fixes#21552
Signed-off-by: Aniket <[email protected]>
Lets an embedder pick the dialer for non-tailnet connections, such
as to control. When control runs in the same process, the node can
then reach it in memory (e.g. memnet) instead of via loopback.
Updates tailscale/corp#27636
Signed-off-by: Kristoffer Dalby <[email protected]>
Prepare for shared socket policy for DERP, control, and log uploads.
Callers need to configure options such as TCP user timeout on the same
socket that netns configures to avoid routing loops.
Use ControlContext for dialer namespace setup and run any caller-supplied
ControlContext afterward, only if namespace setup succeeds. Reject a
non-nil Control unconditionally with a panic directing callers to
ControlContext, including when netns is disabled, rather than support
both hook types and their precedence rules. Listener Control hooks
remain unchanged.
Existing in-tree FromDialer callers supply neither hook, so no caller
migration is required. Keep socket defaults and proxy-wrapping behavior
unchanged. Test hook ordering, context and argument forwarding, errors,
legacy-hook rejection, disabled mode, and proxy delegation.
Updates tailscale/corp#50948
Change-Id: I9d778273f3257fe8a298463ef29ec2dd5d5fb7b0
Signed-off-by: James Tucker <[email protected]>
The eventbus routes events by exact type, so a subscriber of *T never
sees a T. Add a test that type-checks the module for linux, windows and
darwin and fails if any event type is used with eventbus or
eventbustest both by value and by pointer. To keep memory use down, it
drops function bodies outside the packages that import those. It skips
in race builds because of a go/types data race, golang/go#81122.
Updates #22307
Change-Id: Ia7486c43936f367f8767ad9c8750faa9b6bdf8f0
Signed-off-by: Brad Fitzpatrick <[email protected]>
Both tests passed filter funcs taking a pointer to an event type that
is published by value, so the filters never matched. The health test
passed only because Expect timed out, so make it look for the event it
means to forbid.
Updates #22307
Change-Id: I7daf64656cd9b0e9e98372cd803a6e824db96594
Signed-off-by: Brad Fitzpatrick <[email protected]>
Count DERP keepalive and ping/pong traffic, terminal read-deadline
expirations, and control map-request watchdog expirations. Count
successful pre-compression log upload bytes alongside existing upload
totals to support batch-size comparisons.
Keep timeout attribution narrow: expirations do not imply a successful
reconnect, and completed writes do not imply peer receipt. Log upload
metrics remain on the existing per-logger ExpVar surface.
Add deterministic coverage without changing heartbeat timing, socket
settings, reconnect behavior, or upload policy.
Updates tailscale/corp#50948
Change-Id: I95f7bab62c000172a4825283bb4c055dd29d8043
Signed-off-by: James Tucker <[email protected]>
Use ControlContext for production net.Dialer socket hooks:
PeerAPI and debug peer dialing, captive-portal probes, stunstamp TCP
measurements, and the test agent connection.
Update the PeerDialControlFunc callback signature and Apple extension
implementation together with both consumers. Preserve namespace binding,
socket settings, timeout values, and existing error handling. Listener
Control and RawConn.Control are separate APIs and remain unchanged.
Add coverage for platform hook forwarding and errors, debug and captive
portal dialing, cancellation, SO_REUSEADDR, and test-agent hook selection
and keepalive configuration. Cover the Apple missing-interface error and
non-Linux bypass no-op in their platform-specific tests.
Updates tailscale/corp#50948
Change-Id: I4fb162666724f307f2d3d0beba6ed1b0ed15bb4f
Signed-off-by: James Tucker <[email protected]>
https://github.com/tailscale/wireguard-go/compare/79ead109a81a8f57c75ac9e6ddee61714c82744b...9e10ef9af41578baabde0283237d5cbb6422ff25
Start off with device.WithQueueStagedGlobalLimit inheriting the same
value from the knob it replaced, device.WithPreallocatedBuffersPerPool.
Unlike WithPreallocatedBuffersPerPool, WithQueueStagedGlobalLimit is
exclusive of packet memory allocated for transport messages that are
immediately transmitted. So, one must consider
WithQueueStagedGlobalLimit alongside .Queue{In,Out}boundSize to
understand overall memory ceiling impacts.
An approximation of the configured packet memory ceiling on iOS can be
calculated with the following formula:
device.singlePacketSlabSize * ( // 1788
(2 * device.WithQueueOutboundSize) + // 128
(2 * device.WithQueueInboundSize) + // 128
device.WithQueueStagedGlobalLimit // 64
)
=
~572KB
Where previously it was:
device.singlePacketSlabSize * ( // 1788
device.WithPreallocatedBuffersPerPool // 64
)
=
~114KB
Updates tailscale/tailscale#1971
Updates tailscale/tailscale#21773
Updates tailscale/corp#46396
Signed-off-by: Jordan Whited <[email protected]>
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]>
The eventbus routes events by exact type, and these three subscribers
took a pointer to an event type that is only ever published by value,
so they never ran. logtail could not detect the network coming back up
after an upload failure, LocalBackend never recorded or announced the
latest client version, and the magicsock portmapper log limiter never
reset after a major link change.
Updates #22307
Signed-off-by: Nick Khyl <[email protected]>
Time.LoadAtomic and StoreAtomic only worked on 32-bit platforms if
the field happened to be 64-bit aligned, which tstun and magicsock
each guarded with a test. AtomicTime wraps an atomic.Int64, so the
compiler guarantees its alignment, and the tests can go. Also use it
for tstime/rate's Limiter.next, which was an atomic.Int64 holding a
mono.Time.
Updates #cleanup
Updates #22290 (where this was discovered)
Change-Id: I02807906ed9be59446456853bccece6e32e472ed
Signed-off-by: Brad Fitzpatrick <[email protected]>
wgengine/filter asks its accept-logging Limiter about every accepted
packet, so with tailscaled's TUN and UDP queues spread over CPUs
(tailscale/tailscale#22188), that Limiter's mutex took 11% of a subnet
router's CPU on a 128-CPU host, most of it contended. On a denial,
record when the next token is due, and deny before then without taking
the mutex. A denial with a backwards timestamp no longer rewinds the
bucket's last update time, which credited it with tokens it never
earned.
│ old │ new │
│ sec/op │ sec/op vs base │
AllowN 13.550n ± 0% 1.143n ± 2% -91.56% (p=0.000 n=10)
AllowN-8 108.6500n ± 4% 0.1497n ± 4% -99.86% (p=0.000 n=10)
geomean 38.37n 0.4137n -98.92%
Updates #22188
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I928f64d3df7b51c6cac0da7dafe9ef5e71acaa05
tsnet called the serve LocalAPI client and LocalBackend methods
unconditionally, so it didn't build with ts_omit_serve, which every
minimal feature set includes. Make those methods return
feature.ErrUnavailable when serve is omitted, as ListenFunnel and
ListenService now do too.
Declare tsnet's minimum feature set (netstack) as
featuretags.TSNetMin, add cmd/featuretags --tsnet to keep it, and add
a test that type-checks tsnet with it and a few other small feature
sets.
Fixes#22282
Updates #22283
Change-Id: I866fa34d052bfd437b1c9d3309063999d7ebb02c
Co-Authored-By: Fredrik Fornwall <[email protected]>
Signed-off-by: Brad Fitzpatrick <[email protected]>
This moves HiddenNetworkDvice policy out of ipnlocal and into an optional ipnext.
This adds a per-session notification hook that uses each watcher's effective policy snapshot to populate NodeGUIVisibility.
A full visibility snapshot is sent on initialization and policy changes, and on subsequent peer updates, only changed peers are evaluated.
The extension populates Notify.NodeGUIVisibility with the hidden peers
among the nodes the Notify covers: all peers when it carries Policy
(initially and on policy change), or the PeersChanged peers otherwise.
Absent means visible, so a Policy-bearing Notify replaces the client's
visibility state and a peer-change Notify updates only the changed peers.
No NodeGUIVisibilityChanges/Removed fields and no per-session node state
are needed: removed peers simply leave the client's peer set, and full
netmap updates already resend every peer alongside SelfChange.
When the feature isn't linked, the hook slice is empty and the fast path
in notifyForSessionLocked is unchanged. When the policy isn't configured,
the hook costs a snapshot lookup per session per Notify and sends nothing.
Updates tailscale/corp#44104
Signed-off-by: kari <[email protected]>
Signed-off-by: Nick Khyl <[email protected]>
Tests that the localapi cert-status/ handler checks read access and returns
the status as JSON, that LocalBackend.CertStatus goes through the hook, and
that feature/acme's hook reports the same missing, valid and expired results
as the C2N /tls-cert-status handler. Also tests that Client.CertStatus
returns ErrCertStatusUnsupported for a 404 and not for other errors.
Updates tailscale/corp#38175
Signed-off-by: chaosinthecrd <[email protected]>
The localapi cert/ endpoint fetches a cert when none is cached, so polling it
triggers issuance. feature/acme can already report a cached cert without
contacting the CA, but only over the C2N /tls-cert-status path. This moves
that check into an extension method and serves it as localapi cert-status/,
with a matching Client.CertStatus, reporting Missing on a cache miss instead
of issuing. Client.CertStatus returns ErrCertStatusUnsupported (wrapping
errors.ErrUnsupported) when tailscaled has no cert-status endpoint.
Updates tailscale/corp#38175
Signed-off-by: chaosinthecrd <[email protected]>
The cleanup returned by flowCreated decremented activeFlowCount on every
call, and its documented contract pushed the burden of calling it exactly
once onto the datapath. A caller that lost track and ran a cleanup twice
would undercount the flows still forwarding over the assignment, letting
popExpired reclaim both of its addresses back to the pools mid-connection,
or drive the count to -1, which can never again satisfy popExpired's
zero-flow test and so pins the assignment in the expiry heap and leaks
both addresses for the life of the process.
The cleanup now releases its hold at most once, guarded by a bool read and
written under c.mu alongside the decrement it protects. Repeat calls are
no-ops. The Conn25Datapath docs no longer ask callers to guarantee this.
No such double-call is reachable through FlowTable today: removeFlowLocked
deletes both cache entries, so NewFlow's second lookup misses, and the
capacity eviction takes lru.Back(), never the flow just pushed to the
front. This removes the class rather than a live bug.
Updates https://github.com/tailscale/corp/issues/50760
Change-Id: I1888f36eb8fdec9b219ccfd2d290dc4eb19c55a0
Signed-off-by: Mazdak Nasab <[email protected]>
Funnel can't be on without serve. With the HasServe check, the
compiler reduces the method to a constant and inlines it, so the
linker drops it from those builds.
Updates #22283
Change-Id: Idd5da9c1e4f8f41a828a3774f5c4d44872eb1dda
Signed-off-by: Brad Fitzpatrick <[email protected]>
setControlClientStatusLocked releases b.mu around tkaSyncIfNeeded. If
Logout replaced the control client meanwhile, the old client's netmap
was applied to the new profile, leaving it Stopped with the old IPs.
Fixes#22274
Change-Id: If4e9fdd5477db7f97b0362c5632c280dba4c18f5
Signed-off-by: Fredrik Fornwall <[email protected]>
The deb and rpm contents set no mode, so nfpm copied each file's mode
from the source file on disk and the result depended on where the build
ran. Since the release logic moved to OSS in fc4b25d9 (2023-02), corp
builds read the configs and systemd units from the read-only Go module
cache and ship them as 0444, where 1.36 shipped 0644. A checkout with
umask 002 instead gives group-writable 0664 files and 0775 binaries.
Set the modes explicitly, as the tarballs already do: 0755 for the
binaries and 0644 for the systemd units and /etc/default/tailscaled.
Configs return to 0644; binaries are unchanged.
Tested by building the amd64 deb and rpm under umask 002 and 022 and
checking the modes with dpkg-deb -c and rpm -qplv; package metadata is
otherwise unchanged.
Fixes#22202
Change-Id: I14acbd075b2f680720fdec47ce5e4e6033c363f7
Signed-off-by: Gabriel von Winckler <[email protected]>
feature/acme uses LocalBackend.ServeConfig to find hostnames needing
cert refresh, which broke builds with ts_omit_serve but not
ts_omit_acme. The serveConfig field it reads exists in all builds, so
move the method out of the serve-only file rather than making acme
depend on serve, and skip the refresh loop hook when serve is omitted
so the linker can drop it.
Updates #22283
Change-Id: I2cef6683cd6e6144306ddec95255d606f7a539ae
Signed-off-by: Brad Fitzpatrick <[email protected]>