diff --git a/safesocket/basic_test.go b/safesocket/basic_test.go index 9cef30049..05ed98a93 100644 --- a/safesocket/basic_test.go +++ b/safesocket/basic_test.go @@ -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) diff --git a/safesocket/pipe_windows.go b/safesocket/pipe_windows.go index 0ffee762f..a15fe0aa3 100644 --- a/safesocket/pipe_windows.go +++ b/safesocket/pipe_windows.go @@ -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 diff --git a/safesocket/pipe_windows_test.go b/safesocket/pipe_windows_test.go index 5d4e68cc2..ef04ab087 100644 --- a/safesocket/pipe_windows_test.go +++ b/safesocket/pipe_windows_test.go @@ -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 {