safesocket: let a non-administrator listen on the Windows named pipe

The pipe's security descriptor named the Administrators group as the
pipe's owner (O:BA) and primary group (G:BA). Only administrators may
assign that SID as an owner, so a tailscaled run by a regular user (in
userspace-networking mode with its own --socket) died at startup with
"This security ID may not be assigned as the owner of this object". The
tests already had to swap in an empty descriptor to run unelevated.

Neither part did anything for us. The primary group is never consulted by
Windows access checks; it exists only for POSIX and NFS compatibility. The
owner grants exactly one thing beyond the DACL: the right to read and
rewrite the pipe's DACL. Whoever creates the pipe already has that in
practice. For the default pipe name under ProtectedPrefix\Administrators,
the creator must be an administrator (only administrators may create pipes
with that prefix), so naming Administrators as owner gave them nothing
new. A regular user creating a pipe of some other name runs the process
that owns it and controls its DACL anyway. Who may connect is decided only
by the DACL, which is unchanged: read and write for Users and LocalSystem.

So drop the owner and group and let the creator own the pipe. While here,
drop the AI, OI, and CI flags too: they concern inheritance to child
objects, which a named pipe doesn't have, and were copied from a file
system descriptor. The tests now use the real descriptor. Also give a
pointer when listening on the default ProtectedPrefix\Administrators pipe
fails with access denied.

Updates #2791

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I8a1c3e5f7b9d2e4a6c8b0d2f4e6a8c0b2d4f6a8c
This commit is contained in:
Brad Fitzpatrick authored and Brad Fitzpatrick committed 2026-09-28 13:26:52 -07:00
1 parent a40d145b21
commit 48ec6284d3
3 files changed
+13 -25

No files matched your search

-4
View File
@@ -11,9 +11,6 @@ import (
"testing"
)
// downgradeSDDL is a no-op test helper on non-Windows systems.
var downgradeSDDL = func() func() { return func() {} }
func TestBasics(t *testing.T) {
// Make the socket in a temp dir rather than the cwd
// so that the test can be run from a mounted filesystem (#2367).
@@ -23,7 +20,6 @@ func TestBasics(t *testing.T) {
sock = filepath.Join(dir, "test")
} else {
sock = fmt.Sprintf(`\\.\pipe\tailscale-test`)
t.Cleanup(downgradeSDDL())
}
ln, err := Listen(sock)
+13 -2
View File
@@ -7,9 +7,11 @@ package safesocket
import (
"context"
"errors"
"fmt"
"net"
"runtime"
"strings"
"sync"
"time"
@@ -27,8 +29,12 @@ func connect(ctx context.Context, path string) (net.Conn, error) {
// windowsSDDL is the Security Descriptor set on the namedpipe.
// It provides read/write access to all users and the local system.
// It is a var for testing, do not change this value.
var windowsSDDL = "O:BAG:BAD:PAI(A;OICI;GWGR;;;BU)(A;OICI;GWGR;;;SY)"
//
// It deliberately sets no owner or group: the creator becomes the owner.
// Naming the Administrators group as the owner, as this once did, made
// listening fail for a tailscaled run by a non-administrator, since only
// administrators may assign that SID as an owner.
const windowsSDDL = "D:P(A;;GWGR;;;BU)(A;;GWGR;;;SY)"
func listen(path string) (net.Listener, error) {
lc, err := winio.ListenPipe(
@@ -40,6 +46,11 @@ func listen(path string) (net.Listener, error) {
},
)
if err != nil {
if errors.Is(err, windows.ERROR_ACCESS_DENIED) && strings.HasPrefix(strings.ToLower(path), `\\.\pipe\protectedprefix\administrators\`) {
// Only administrators may create pipes under that prefix,
// which is where tailscaled listens by default.
return nil, fmt.Errorf("namedpipe.Listen: %w; creating a pipe under \\\\.\\pipe\\ProtectedPrefix\\Administrators requires running as an administrator; run elevated or pass --socket with another pipe name", err)
}
return nil, fmt.Errorf("namedpipe.Listen: %w", err)
}
return &winIOPipeListener{Listener: lc}, nil
-19
View File
@@ -6,30 +6,11 @@ package safesocket
import (
"fmt"
"testing"
"tailscale.com/util/winutil"
)
func init() {
// downgradeSDDL is a test helper that downgrades the windowsSDDL variable if
// the currently running user does not have sufficient priviliges to set the
// SDDL.
downgradeSDDL = func() (cleanup func()) {
// The current default descriptor can not be set by mere mortal users,
// so we need to undo that for executing tests as a regular user.
if !winutil.IsCurrentProcessElevated() {
var orig string
orig, windowsSDDL = windowsSDDL, ""
return func() { windowsSDDL = orig }
}
return func() {}
}
}
// TestExpectedWindowsTypes is a copy of TestBasics specialized for Windows with
// type assertions about the types of listeners and conns we expect.
func TestExpectedWindowsTypes(t *testing.T) {
t.Cleanup(downgradeSDDL())
const sock = `\\.\pipe\tailscale-test`
ln, err := Listen(sock)
if err != nil {