Files
tailscale/ssh/tailssh/c2n_windows.go
Brad Fitzpatrick f4bf658006 ssh/tailssh, feature/ssh, cmd/tailscaled: run the Tailscale SSH server on Windows
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
2026-11-13 02:56:53 +00:00

65 lines
1.5 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package tailssh
import (
"unsafe"
"golang.org/x/sys/windows"
)
func init() {
hookLocalUsernames = windowsLocalUsernames
}
// userInfo1 is the Win32 USER_INFO_1 structure returned by NetUserEnum at
// level 1.
type userInfo1 struct {
Name *uint16
Password *uint16
PasswordAge uint32
Priv uint32
HomeDir *uint16
Comment *uint16
Flags uint32
ScriptPath *uint16
}
const (
// filterNormalAccount is NetUserEnum's FILTER_NORMAL_ACCOUNT: ordinary
// user accounts, excluding machine and trust accounts.
filterNormalAccount = 0x0002
// ufAccountDisable is the UF_ACCOUNTDISABLE user flag.
ufAccountDisable = 0x0002
// maxPreferredLength asks NetUserEnum to allocate as much as it needs.
maxPreferredLength = 0xFFFFFFFF
)
// windowsLocalUsernames returns the names of the enabled local user accounts
// on this machine.
func windowsLocalUsernames() ([]string, error) {
var names []string
var resume uint32
for {
var buf *byte
var read, total uint32
err := windows.NetUserEnum(nil, 1, filterNormalAccount, &buf, maxPreferredLength, &read, &total, &resume)
if err != nil && err != windows.ERROR_MORE_DATA {
return names, err
}
if buf != nil {
for _, ui := range unsafe.Slice((*userInfo1)(unsafe.Pointer(buf)), read) {
if ui.Flags&ufAccountDisable != 0 {
continue
}
names = append(names, windows.UTF16PtrToString(ui.Name))
}
windows.NetApiBufferFree(buf)
}
if err == nil {
return names, nil
}
}
}