Files
privatae-bastion/client-go/contextsock_linux.go
T
Privatae e4c9b69b46
ci / personal-data (push) Successful in 5s
ci / test (push) Successful in 3m4s
ci / fuzz (push) Successful in 3m45s
bastion 0.53.2
2026-10-20 04:42:14 +00:00

16 lines
396 B
Go

//go:build linux
package main
import "golang.org/x/sys/unix"
// SO_PEERCRED: the kernel stamps the peer's credentials onto the socket at
// connect() and they are never re-read, so this is who connected.
func contextPeerUID(fd uintptr) (uint32, error) {
cred, err := unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED)
if err != nil {
return 0, err
}
return cred.Uid, nil
}