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 ¶
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 ¶
func New() credentials.TransportCredentials
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 ¶
FromContext returns the peer credentials of a call's connection.