protected

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: CC0-1.0 Imports: 9 Imported by: 0

Documentation

Overview

Package protected wraps listeners with best-effort peer-owner checks.

A protected listener accepts only connections whose peer owner matches at least one configured rule. Connections that do not match, or whose owner cannot be resolved, are closed internally and the listener continues waiting for the next connection.

The owner lookup is performed by sockowner pkg. That lookup is intentionally best-effort and race-prone: sockets can close, be reused, or be shared by multiple processes while ownership information is being resolved.

Username rules are resolved twice. Each username is resolved once when the protected listener is created, and again for every accepted connection. A username rule matches only when both resolutions return the same UID and the connection owner has that UID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen(network, address string, rules Rules) (net.Listener, error)

Listen announces on the local network address and returns a protected listener. Its network and address arguments match net.Listen.

func ListenCtx

func ListenCtx(
	ctx context.Context,
	network, address string,
	rules Rules,
) (net.Listener, error)

ListenCtx announces on the local network address and returns a protected listener. Its network and address arguments match net.Listen.

func NewListener

func NewListener(l net.Listener, rules Rules) (net.Listener, error)

NewListener wraps l with owner-based connection filtering.

func NewTCPListener

func NewTCPListener(
	l gonnect.TCPListener,
	rules Rules,
) (gonnect.TCPListener, error)

NewTCPListener wraps l with owner-based TCP connection filtering.

Types

type Listener

type Listener struct {
	net.Listener
	// contains filtered or unexported fields
}

Listener is a protected net.Listener wrapper.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept accepts the next connection whose owner matches the listener rules.

func (*Listener) GetWrapped

func (l *Listener) GetWrapped() any

GetWrapped returns the wrapped listener.

type Rules

type Rules struct {
	UIDs      []uint32
	GIDs      []uint32
	Usernames []string
}

Rules controls which peer owners may connect to a protected listener.

A connection is accepted when at least one UID, GID, or username rule matches its resolved owner. Empty rules match nothing.

type TCPListener

type TCPListener struct {
	gonnect.TCPListener
	// contains filtered or unexported fields
}

TCPListener is a protected gonnect.TCPListener wrapper.

func (*TCPListener) Accept

func (l *TCPListener) Accept() (net.Conn, error)

Accept accepts the next TCP connection as a net.Conn.

func (*TCPListener) AcceptTCP

func (l *TCPListener) AcceptTCP() (gonnect.TCPConn, error)

AcceptTCP accepts the next TCP connection whose owner matches the listener rules.

func (*TCPListener) GetWrapped

func (l *TCPListener) GetWrapped() any

GetWrapped returns the wrapped TCP listener.

func (*TCPListener) SetDeadline

func (l *TCPListener) SetDeadline(t time.Time) error

SetDeadline sets the deadline associated with the wrapped listener.

Jump to

Keyboard shortcuts

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