mirror of
https://github.com/tailscale/tailscale.git
synced 2026-10-09 11:52:00 -04:00
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 <bradfitz@tailscale.com> Change-Id: I8a1c3e5f7b9d2e4a6c8b0d2f4e6a8c0b2d4f6a8c
82 lines
1.4 KiB
Go
82 lines
1.4 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package safesocket
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
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).
|
|
dir := t.TempDir()
|
|
var sock string
|
|
if runtime.GOOS != "windows" {
|
|
sock = filepath.Join(dir, "test")
|
|
} else {
|
|
sock = fmt.Sprintf(`\\.\pipe\tailscale-test`)
|
|
}
|
|
|
|
ln, err := Listen(sock)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
errs := make(chan error, 2)
|
|
|
|
go func() {
|
|
s, err := ln.Accept()
|
|
if err != nil {
|
|
errs <- err
|
|
return
|
|
}
|
|
ln.Close()
|
|
s.Write([]byte("hello"))
|
|
|
|
b := make([]byte, 1024)
|
|
n, err := s.Read(b)
|
|
if err != nil {
|
|
errs <- err
|
|
return
|
|
}
|
|
t.Logf("server read %d bytes.", n)
|
|
if string(b[:n]) != "world" {
|
|
errs <- fmt.Errorf("got %#v, expected %#v\n", string(b[:n]), "world")
|
|
return
|
|
}
|
|
s.Close()
|
|
errs <- nil
|
|
}()
|
|
|
|
go func() {
|
|
c, err := ConnectContext(context.Background(), sock)
|
|
if err != nil {
|
|
errs <- err
|
|
return
|
|
}
|
|
c.Write([]byte("world"))
|
|
b := make([]byte, 1024)
|
|
n, err := c.Read(b)
|
|
if err != nil {
|
|
errs <- err
|
|
return
|
|
}
|
|
if string(b[:n]) != "hello" {
|
|
errs <- fmt.Errorf("got %#v, expected %#v\n", string(b[:n]), "hello")
|
|
}
|
|
c.Close()
|
|
errs <- nil
|
|
}()
|
|
|
|
for range 2 {
|
|
if err := <-errs; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|