Documentation
¶
Overview ¶
Package peercred says who is at the other end of a unix socket connection: the credentials the kernel recorded when the peer connected, which the peer can not choose, and what the process holding them is.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotUnix is returned for a connection that is not a unix socket // one. ErrNotUnix = errors.New("not a unix socket connection") // ErrUnknownProcess is returned for a peer whose process can not be // read: whether it runs in a container is not known. ErrUnknownProcess = errors.New("the process of the peer can not be read") )
Functions ¶
func IDs ¶
IDs returns the uid of the peer of the unix socket connection c and its groups, its primary one first, as the kernel recorded them at connect: the ids the access to the socket file was checked with then.
The supplementary groups are read with SO_PEERGROUPS, Linux 4.13 and later. An older kernel does not record them, and they are read from the process of the peer by its pid instead, which a peer ending lets another process take.
Types ¶
type T ¶
type T struct {
// UID, GID and PID are the credentials of the peer at connect
// time, as SO_PEERCRED reports them in the namespaces of the
// reader.
UID uint32
GID uint32
PID int32
// Pinned says the process was read through a pidfd the kernel
// handed with the connection (SO_PEERPIDFD, Linux 6.5 and
// later), and still ran once read: Cgroup and ForeignMountNS
// are the ones of the peer, never of a process reusing its
// pid. Without it, they are read by the pid, which a peer
// ending lets another process take.
Pinned bool
// Cgroup is the path of the peer in the systemd hierarchy, the
// "0::" line of cgroup v2 or the "name=systemd" one of v1.
Cgroup string
// ForeignMountNS says the peer runs in another mount namespace than the
// reader, as a container does.
ForeignMountNS bool
}
T is the peer of a unix socket connection, as the kernel knows it.
func FromConn ¶
FromConn returns the peer of the unix socket connection c.
The cgroup and the mount namespace of the process are read too, and a peer whose process can not be read is not returned: a peer whose namespace is unknown could be a container taken for a process of the node, so it is refused rather than returned half known. The process is read through the pidfd of the connection where the kernel gives one, and by its pid otherwise.