peercred

package
v0.31.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package peercred is gRPC transport credentials for a unix socket that say WHO is at the other end: the uid, gid and pid the kernel recorded for the peer when it connected (SO_PEERCRED on Linux, LOCAL_PEERCRED on macOS).

⛔ grpc-go's credentials/local does not do this. It tells a unix socket from a TCP one and reports a security level, and the uid is not in its AuthInfo -- so a server built on it can say "somebody local" and never "fileshare". The provisioner must say the second: it answers one uid, and the socket's mode alone is a file permission any root process can widen.

Nothing is encrypted and nothing needs to be: the bytes never leave the kernel. What these credentials add is the identity, read once at the handshake. The kernel records it at connect(2), so a peer cannot change it afterwards by changing its own uid, nor pass the connection to another process and have the new holder's uid reported.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotUnix = errors.New("peercred: not a unix socket connection")

ErrNotUnix is returned for a connection that is not a unix socket: only a unix socket has a peer the kernel can name.

Functions

func New

New returns credentials that read the peer's identity and accept any. A server checks the uid it needs per call; a client made with New accepts whatever answers.

func RequireServer

func RequireServer(uid uint32) credentials.TransportCredentials

RequireServer returns client credentials that refuse the connection unless the process answering on the socket runs as uid.

Types

type AuthInfo

type AuthInfo struct {
	credentials.CommonAuthInfo
	UID uint32
	GID uint32
	// PID is the peer's process id, or -1 where the system does not report
	// one. It is for logs only: a pid can be reused once its process exits.
	PID int32
	// contains filtered or unexported fields
}

AuthInfo is what the handshake learned about the peer. The server finds it in a call's peer.Peer (FromContext).

func FromContext

func FromContext(ctx context.Context) (AuthInfo, bool)

FromContext returns the peer credentials of a call's connection.

func (AuthInfo) AuthType

func (AuthInfo) AuthType() string

AuthType is "peercred".

func (AuthInfo) CloseConn

func (a AuthInfo) CloseConn() error

CloseConn closes the connection this AuthInfo was read from -- the whole transport, not one call. It is how a server that keeps a closed set of verbs answers anything outside it: there is no reply, the peer just loses its connection.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL