Help us shape the future of Go! Take the 2026 Go Developer Survey

peer

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package peer checks who is on the other end of a local Unix socket. The kernel reports the peer's user, so a process cannot claim to be someone else the way it could with a token or a header.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnContext

func ConnContext(ctx context.Context, c net.Conn) context.Context

ConnContext is meant for http.Server.ConnContext. It records the peer when a connection is accepted. If the credentials cannot be read no peer is stored, and every request on that connection is refused.

func Require

func Require(policy Policy, log *slog.Logger, next http.Handler) http.Handler

Require refuses requests from anyone the policy does not allow.

func WithPeer

func WithPeer(ctx context.Context, p Peer) context.Context

WithPeer returns a context carrying p. Tests use it to stand in for a real connection.

Types

type Peer

type Peer struct {
	UID uint32
	PID int32
}

Peer is the process on the other end of the socket.

func From

func From(ctx context.Context) (Peer, bool)

type Policy

type Policy struct {
	UIDs []uint32
}

Policy lists the users allowed in. Root is always allowed.

func (Policy) Allows

func (p Policy) Allows(peer Peer) bool

Jump to

Keyboard shortcuts

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