The records send the operator to "the controller's terminal", and nothing reaches it (hq issue 343). mesh-cli holds no credential: it asks the engine on its own machine over a socket. The engine reads the asking account from the kernel (SO_PEERCRED), never from the program, and asks the controller on mesh.control.<node>.cli, its own node's subject, so the bus server says which node asked. The controller decides what the line may do; nothing received on the socket is run or applied here, and the socket has no network address (ADR 0004 stands). The local protocol is the SDK's go/cli package, at a pseudo-version of its branch until that merges and is tagged go/v0.1.8.
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
//go:build linux
|
|
|
|
package meshcli
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
// peerCredentials is the user id of the process at the other end, as the kernel recorded it when it connected
|
|
// (SO_PEERCRED). Nothing the process says is read.
|
|
func peerCredentials(conn *net.UnixConn) (uint32, error) {
|
|
raw, err := conn.SyscallConn()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
var cred *syscall.Ucred
|
|
var inner error
|
|
if err := raw.Control(func(fd uintptr) {
|
|
cred, inner = syscall.GetsockoptUcred(int(fd), syscall.SOL_SOCKET, syscall.SO_PEERCRED)
|
|
}); err != nil {
|
|
return 0, err
|
|
}
|
|
if inner != nil {
|
|
return 0, inner
|
|
}
|
|
if cred == nil {
|
|
return 0, errors.New("the kernel gave no credentials")
|
|
}
|
|
return cred.Uid, nil
|
|
}
|
|
|
|
// notOwnDirectory says what is wrong with the socket's directory, or nothing: it must be a directory, not a
|
|
// link, owned by the account the engine runs as.
|
|
func notOwnDirectory(dir string) string {
|
|
info, err := os.Lstat(dir)
|
|
if err != nil {
|
|
return err.Error()
|
|
}
|
|
if info.Mode()&os.ModeSymlink != 0 || !info.IsDir() {
|
|
return dir + " is not a directory the engine made"
|
|
}
|
|
if st, ok := info.Sys().(*syscall.Stat_t); ok && int(st.Uid) != os.Geteuid() {
|
|
return fmt.Sprintf("%s belongs to user id %d, not to the engine's account", dir, st.Uid)
|
|
}
|
|
return ""
|
|
}
|