l7

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package l7 provides an HTTP CONNECT forward proxy for name-based egress.

Product intent: clients direct listed app domains to an egress gateway over the mesh (WireGuard underlay). The gateway runs this server, matches CONNECT targets against a domain policy, and dials the internet by hostname — avoiding brittle domain→IP→route collection used for L3 egress ranges.

This package does not own Netmaker control-plane config, PAC generation, or WireGuard. See docs/PROXY_L7_EGRESS.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServerClosed = errors.New("l7: server closed")
	ErrForbidden    = errors.New("l7: destination not allowed")
	ErrBadRequest   = errors.New("l7: bad CONNECT request")
)

Common errors returned by the L7 proxy.

Functions

This section is empty.

Types

type AllowAll

type AllowAll struct{}

AllowAll permits any non-empty host (useful for tests; not for production egress).

func (AllowAll) Allow

func (AllowAll) Allow(host, port string) error

Allow implements DomainMatcher.

type Allowlist

type Allowlist struct {
	// Domains are exact names (example.com) or wildcards (*.example.com).
	Domains []string
}

Allowlist matches exact hostnames and optional "*.suffix" wildcards (one or more labels). Matching is case-insensitive. Empty Allowlist denies all hosts.

func (Allowlist) Allow

func (a Allowlist) Allow(host, port string) error

Allow implements DomainMatcher.

type ConnectTarget

type ConnectTarget struct {
	Host string
	Port string // e.g. "443"
}

ConnectTarget is the host:port from an HTTP CONNECT request.

func (ConnectTarget) HostPort

func (t ConnectTarget) HostPort() string

HostPort returns host:port for dialing.

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

Dialer dials TCP destinations for CONNECT tunnels.

type DomainMatcher

type DomainMatcher interface {
	// Allow returns nil if host (and optional port) may be dialed; otherwise a reason error.
	Allow(host, port string) error
}

DomainMatcher decides whether a CONNECT destination is allowed. Implementations are supplied by the integrator (e.g. netclient from control-plane lists).

type Logger

type Logger interface {
	Debug(msg string, kv ...any)
	Info(msg string, kv ...any)
	Warn(msg string, kv ...any)
	Error(msg string, kv ...any)
}

Logger is a minimal structured logging facade.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an HTTP CONNECT forward proxy intended to listen on a mesh address of an egress gateway.

func NewServer

func NewServer(opts ServerOptions) (*Server, error)

NewServer validates options and returns a Server. Does not listen until Start.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the bound address, or "" if not listening.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start binds ListenAddr and serves HTTP CONNECT.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop closes the listener and waits for in-flight handlers to finish (bounded by ctx).

type ServerOptions

type ServerOptions struct {
	// ListenAddr is the TCP address to bind (typically a mesh IP:port on the egress GW).
	ListenAddr string
	// Matcher decides whether a CONNECT target is allowed (required).
	Matcher DomainMatcher
	// Dialer is optional; nil uses net.Dialer with DialTimeout.
	Dialer Dialer
	// Logger is optional; nil uses a no-op logger.
	Logger Logger
	// DialTimeout bounds outbound dials and CONNECT header read (default 15s).
	DialTimeout time.Duration
	// IdleTimeout is the max lifetime of an established tunnel (default 5m).
	IdleTimeout time.Duration
}

ServerOptions configures the CONNECT forward proxy.

Jump to

Keyboard shortcuts

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