mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 08:41:19 -08:00
The pipe's security descriptor named the Administrators group as owner and group. 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. Drop the owner and group so the creator owns the pipe; the DACL granting users and LocalSystem access is unchanged, and it is the DACL that matters. The tests now use the real descriptor. Also give a pointer when listening on the default ProtectedPrefix\Administrators pipe fails with access denied, since that prefix does need an administrator. Updates #2791 Signed-off-by: Brad Fitzpatrick <[email protected]> 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)
|
|
}
|
|
}
|
|
}
|