egressproxy

package
v0.60.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 15 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). A check-enabled run also reaches its install set (maku.ogenki.io/egress-install) until its harness closes it or its deadline passes, whichever comes first; the close is one-way.

Index

Constants

View Source
const (
	EgressAnnotation        = runctl.EgressAnnotation
	InstallAnnotation       = runctl.EgressInstallAnnotation
	InstallUntilAnnotation  = runctl.EgressInstallUntilAnnotation
	InstallClosedAnnotation = runctl.EgressInstallClosedAnnotation
)

The run pod's annotations the proxy reads.

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 (
	ReasonBadRequest    = "bad_request"
	ReasonUnknownClient = "unknown_client"
	ReasonNotAllowed    = "not_allowed"
	ReasonInstallClosed = "install_closed"
	ReasonTooMany       = "too_many"
	ReasonDeniedAddress = "denied_address"
	ReasonInstallCheck  = "install_check"
)

The reasons of a refusal, the bounded label of maku_egress_proxy_refusals_total. install_closed is a host of the run's install set after the set closed: the signature of a download the toolchain install did not make.

View Source
const ClosePath = "/v1/close-install"

ClosePath is where a run pod closes its own install set: POST {"podUID": "<its UID>"}.

View Source
const DefaultIdleTimeout = 5 * time.Minute

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

View Source
const InstallCheckHost = "install-check.maku.invalid:443"

InstallCheckHost is the harness's self-check after a close: a CONNECT to it answers 409 while the client's install set is open and 403 once it is closed. It is never dialled, and its refusal is install_check, not install_closed: the alert on install_closed stays for real downloads.

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.

Reasons are every refusal reason, for a metric that exports each from the start.

Functions

func MustCIDRs

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

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

Types

type Closer added in v0.57.0

type Closer interface {
	CloseInstall(ctx context.Context, namespace, name, uid string) error
}

Closer persists a pod's closed install set where every replica reads it: the pod itself. uid is a precondition, so a pod recreated under the same name is never closed by its predecessor.

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
	// Install is the install set; InstallUntil its deadline, zero when the pod names none or an
	// unreadable one, which reads as closed; InstallClosed that the set was closed.
	Install       []string
	InstallUntil  time.Time
	InstallClosed bool
	// The pod's identity, which a close names.
	Namespace, Name, UID string
}

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

func (Entry) InstallOpen added in v0.57.0

func (e Entry) InstallOpen(now time.Time) bool

InstallOpen is whether the install set admits a CONNECT at now.

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) MarkClosed added in v0.57.0

func (x *Index) MarkClosed(uid string)

MarkClosed records that the pod with uid had its install set closed. It only narrows: nothing reopens a set.

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)
	MarkClosed(uid string)
}

Lookuper maps a client IP to its run, and records a closed install set.

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
	Refused     func(reason string)   // optional
	// Closer writes a close; nil, every close fails, and the harness fails its run closed.
	Closer Closer
	// Now is the clock the install deadline is read against; nil is time.Now.
	Now func() time.Time
	// 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, and the close of a run pod's install set at ClosePath. A client gets a tunnel to host:port when its source IP maps to a run whose allow-list holds exactly that pair, or whose install set holds it while the set is open, 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, with phase=install|agent (install while the run's install set is open) and, on a refusal, a bounded reason.

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