mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 21:15:39 +00:00
5611f290eb
This partially revertsd6e9fb1df0
, which modified the permissions on the tailscaled Unix socket and thus required "sudo tailscale" even for "tailscale status". Instead, open the permissions back up (on Linux only) but have the server look at the peer creds and only permit read-only actions unless you're root. In the future we'll also have a group that can do mutable actions. On OpenBSD and FreeBSD, the permissions on the socket remain locked down to 0600 fromd6e9fb1df0
. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
50 lines
1001 B
Go
50 lines
1001 B
Go
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build linux
|
|
|
|
package ipnserver
|
|
|
|
import (
|
|
"net"
|
|
|
|
"golang.org/x/sys/unix"
|
|
"tailscale.com/types/logger"
|
|
)
|
|
|
|
func isReadonlyConn(c net.Conn, logf logger.Logf) (ro bool) {
|
|
ro = true // conservative default for naked returns below
|
|
uc, ok := c.(*net.UnixConn)
|
|
if !ok {
|
|
logf("unexpected connection type %T", c)
|
|
return
|
|
}
|
|
raw, err := uc.SyscallConn()
|
|
if err != nil {
|
|
logf("SyscallConn: %v", err)
|
|
return
|
|
}
|
|
|
|
var cred *unix.Ucred
|
|
cerr := raw.Control(func(fd uintptr) {
|
|
cred, err = unix.GetsockoptUcred(int(fd),
|
|
unix.SOL_SOCKET,
|
|
unix.SO_PEERCRED)
|
|
})
|
|
if cerr != nil {
|
|
logf("raw.Control: %v", err)
|
|
return
|
|
}
|
|
if err != nil {
|
|
logf("raw.Control: %v", err)
|
|
return
|
|
}
|
|
if cred.Uid == 0 {
|
|
// root is not read-only.
|
|
return false
|
|
}
|
|
logf("non-root connection from %v (read-only)", cred.Uid)
|
|
return true
|
|
}
|