egressproxy

package
v0.53.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package egressproxy is the egress proxy of the run-controller's kubernetes network mode (v4 D6, plan PR5): a CONNECT-only forward proxy that knows a client by its source pod IP and lets it reach only the host:port pairs of its pod's maku.ogenki.io/egress annotation, which the run-controller alone writes (the run-pod policy holds it).

Index

Constants

View Source
const (
	DecisionAllow  = "allow"
	DecisionRefuse = "refuse"
	DecisionError  = "error"
)

The decisions of Proxy.Count, the bounded label of maku_egress_proxy_connections_total.

View Source
const DefaultIdleTimeout = 5 * time.Minute

DefaultIdleTimeout closes a tunnel that moved no byte either way for this long.

View Source
const EgressAnnotation = runctl.EgressAnnotation

EgressAnnotation is the run pod's allow-list.

Variables

View Source
var ErrRefused = errors.New("refused")

ErrRefused is a destination the proxy never dials: a name that resolves to a non-public or denied address.

Functions

func MustCIDRs

func MustCIDRs(cidrs ...string) []*net.IPNet

MustCIDRs parses CIDRs, panicking on a bad one (for constants and validated config).

Types

type Dialer

type Dialer struct {
	Resolver Resolver
	Deny     []*net.IPNet // beyond the non-public ranges: the chart's privateCIDRs
	Dial     func(ctx context.Context, network, addr string) (net.Conn, error)
	Timeout  time.Duration
}

Dialer resolves a name itself and dials the address it vetted, so a second lookup cannot substitute another (DNS rebinding).

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, hostport string) (net.Conn, error)

DialContext dials hostport after resolving its host. Any non-public or denied address among the answers refuses the whole name: a name that mixes them is not trusted for either.

type Entry

type Entry struct {
	RunID string
	Allow []string
}

Entry is one client's identity and allow-list.

type Index

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

Index maps a pod IP to its run, from the pods a watch feeds it.

func NewIndex

func NewIndex() *Index

NewIndex is an empty Index.

func (*Index) Delete

func (x *Index) Delete(namespace, name string)

Delete forgets a pod.

func (*Index) Lookup

func (x *Index) Lookup(ip string) (Entry, bool)

Lookup is ip's entry. It has one only when exactly one unfinished pod holds ip, and that pod is the run-controller's, not terminating, and annotated. Pending counts with Running: a pod with an IP is already running containers, and the watch can trail its phase change. A terminating pod still holds its IP, so it makes the IP ambiguous instead of freeing it.

func (*Index) Upsert

func (x *Index) Upsert(p *corev1.Pod)

Upsert records p's latest state.

type Lookuper

type Lookuper interface {
	Lookup(ip string) (Entry, bool)
}

Lookuper maps a client IP to its run.

type Proxy

type Proxy struct {
	Index       Lookuper
	Dial        func(ctx context.Context, hostport string) (net.Conn, error)
	IdleTimeout time.Duration
	Log         *slog.Logger
	Count       func(decision string) // optional
	Bytes       func(n int64)         // optional
	// MaxTunnels caps the open tunnels in all, MaxTunnelsPerClient those of one source IP; 0 is no
	// cap. A CONNECT over either is refused 429 before anything is dialled.
	MaxTunnels, MaxTunnelsPerClient int
	// contains filtered or unexported fields
}

Proxy serves CONNECT only. A client gets a tunnel to host:port when its source IP maps to a run whose allow-list holds exactly that pair, and the host is a name, never an IP literal. Each decision logs `allow run=<id> <host:port>` or `refuse run=<id|-> <host:port>`, as the harness's test proxy does.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP decides and, when allowed, splices the client to the destination.

type Resolver

type Resolver interface {
	LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
}

Resolver is net.Resolver's lookup.

Jump to

Keyboard shortcuts

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