proxy

package
v0.6.13 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package proxy is the egress gateway's transparent SNI/Host proxy (plans/egress-domain-filtering.md §5.5). nft redirects a gateway-mode sandbox's TCP 80/443 here; the proxy decides on the outer SNI (443) or each request's Host (80), dials the name itself through the shared dial guard, and splices bytes without terminating TLS.

Index

Constants

View Source
const (
	// ReasonInspectUnavailable: the gateway has no CA yet (sandboxd sends it
	// after every gateway start), so the connection is refused, never
	// passed through unchecked.
	ReasonInspectUnavailable = "inspect_unavailable"
	// ReasonHostMismatch: an inspected request's Host is not the TLS server
	// name, the domain-fronting shape (EF-53).
	ReasonHostMismatch = "host_mismatch"
	// ReasonBodyTooLarge: an inspected request body is over the cap.
	ReasonBodyTooLarge = "body_too_large"
	// ReasonSecretMissing: an inject rule's value hasn't reached the gateway
	// (P3-2), so the request is refused rather than sent with the
	// placeholder.
	ReasonSecretMissing = "secret_missing"
)

Inspection denial reasons.

View Source
const (
	DefaultMaxConns           = 16384
	DefaultMaxConnsPerSandbox = 512
	DefaultIdleTimeout        = 30 * time.Minute
)

Defaults (SB_EGRESS_PROXY_MAX_CONNS[_PER_SANDBOX] and timeouts).

View Source
const (
	ReasonSNINotAllowed  = "sni_not_allowed"
	ReasonHostNotAllowed = "host_not_allowed"
	ReasonNoSNI          = "no_sni"
	ReasonBlockedIP      = "blocked_ip"
	ReasonBlocked        = "blocked"
	ReasonConnCap        = "conn_cap"
	ReasonUpstreamProxy  = "upstream_proxy_unavailable"
	ReasonUnknownSource  = "unknown_source"
	ReasonDialFailed     = "dial_failed"
	ReasonBadRequest     = "bad_request"
	// ReasonBinaryNotAllowed: a per-binary rule covers the destination and
	// the connection's executable isn't listed (P3-3).
	ReasonBinaryNotAllowed = "binary_not_allowed"
	// ReasonBinaryUnknown: the connection couldn't be traced to an
	// executable, so a per-binary rule can't admit it.
	ReasonBinaryUnknown = "binary_unknown"
	// ReasonRuleDenied: a ruled host's request matched no rule (P3-1).
	ReasonRuleDenied = "rule_denied"
	// ReasonPathNotCanonical: a ruled host's request path could be read two
	// ways (dot segments, encoded slashes), so no rule can vouch for it.
	ReasonPathNotCanonical = "path_not_canonical"
)

Denial reasons (audit and explainable denials, CEO D4/D10).

View Source
const DefaultInspectMaxBody = 256 << 20

DefaultInspectMaxBody caps an inspected request body (SB_EGRESS_INSPECT_MAX_BODY_BYTES).

Variables

This section is empty.

Functions

func OriginalDst

func OriginalDst(c net.Conn) (netip.AddrPort, error)

OriginalDst returns the destination a REDIRECTed connection was originally addressed to. The kernel returns a sockaddr_in; IPv6Mreq is the 20-byte getsockopt shape that fits it.

Types

type Config

type Config struct {
	MaxConns           int
	MaxConnsPerSandbox int
	IdleTimeout        time.Duration
	DialTimeout        time.Duration
	HelloTimeout       time.Duration
	Guard              egresspolicy.DialGuard
	// OriginalDst returns the pre-REDIRECT destination (SO_ORIGINAL_DST).
	OriginalDst func(net.Conn) (netip.AddrPort, error)
	Dialer      Dialer
	Logger      *slog.Logger
	// Upstream chains allowed names through the operator's proxy
	// (§5.10 PC-4); nil dials direct.
	Upstream *egresspolicy.Upstream
	// UpstreamRoots verifies the real host behind an inspected connection;
	// nil is the gateway host's system roots.
	UpstreamRoots *x509.CertPool
	// InspectMaxBody caps an inspected request body (P3-1).
	InspectMaxBody int64
	// Identify traces connections for per-binary rules (P3-3); nil refuses
	// every connection a per-binary rule covers.
	Identify Identifier
}

Config tunes a Proxy.

type Decision

type Decision struct {
	SandboxID string
	Host      string
	Port      uint16
	Allowed   bool
	Reason    string
	Rule      string
	Mode      egress.Mode
}

Decision is one decided connection or request, for audit and learn mode.

type Dialer

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

Dialer opens the upstream connection. The default dials directly through the host resolver; the private-cloud upstream proxy chain (§5.10 PC-4) plugs in here.

type Identifier

type Identifier func(sandboxID string, pid int, local, remote netip.AddrPort, paths []string) (is func(path string) bool, err error)

Identifier traces a sandbox connection local→remote to its executable (P3-3): is(path) reports whether the connection's process is the binary at path inside the sandbox, for the paths its rules list. In production sandboxd answers it (procid.Client): the gateway can't read the sandbox's /proc itself (review finding 16).

type Inspector

type Inspector interface {
	Leaf(host string) (*tls.Certificate, error)
}

Inspector issues the certificate the proxy presents for an inspected name (*inspect.Authority).

type Observer

type Observer func(Decision)

Observer receives decisions. It must not block.

type Proxy

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

Proxy serves redirected connections.

func New

func New(src Sources, observe Observer, cfg Config) *Proxy

New builds a Proxy.

func (*Proxy) Active

func (p *Proxy) Active() int

Active returns the number of connections being proxied.

func (*Proxy) InspectorForTest added in v0.6.9

func (p *Proxy) InspectorForTest() Inspector

InspectorForTest is the installed inspector, for tests of the code that installs and removes it.

func (*Proxy) Serve

func (p *Proxy) Serve(ln net.Listener) error

Serve accepts redirected connections until ln closes.

func (*Proxy) SetInspector

func (p *Proxy) SetInspector(i Inspector)

SetInspector installs the node CA's issuer; nil removes it.

func (*Proxy) SetOperator

func (p *Proxy) SetOperator(g egresspolicy.DialGuard, up *egresspolicy.Upstream)

SetOperator replaces the dial guard and upstream chain from a reloaded operator file; dials after it use the new ones. Connections already open are revalidated by the gateway (Gateway.RevalidateConns).

type Sources

type Sources interface {
	Source(netip.Addr) (egress.Source, bool)
	Track(id, host string, port uint16, conn net.Conn) *egress.TrackedConn
	// BinName names the host a redirected per-binary flow is for (P3-3).
	BinName(id string, dst netip.AddrPort) (string, bool)
}

Sources resolves a peer IP to its sandbox and registers live connections (*egress.Gateway).

Jump to

Keyboard shortcuts

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