peer

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 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 RequireRoutes added in v0.7.0

func RequireRoutes(policy Policy, log *slog.Logger, mux *http.ServeMux) http.Handler

RequireRoutes is Require for a mux, and lets the users of Policy.Routes through to their own routes.

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
	// Routes holds users that may use some routes only, by the pattern the
	// route was registered with, such as "GET /v1/host". A user in UIDs may
	// use every route, whatever is listed here.
	Routes map[uint32][]string
}

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