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 ¶
const ( EgressAnnotation = runctl.EgressAnnotation InstallAnnotation = runctl.EgressInstallAnnotation InstallUntilAnnotation = runctl.EgressInstallUntilAnnotation InstallClosedAnnotation = runctl.EgressInstallClosedAnnotation )
The run pod's annotations the proxy reads.
const ( DecisionAllow = "allow" DecisionRefuse = "refuse" DecisionError = "error" )
The decisions of Proxy.Count, the bounded label of maku_egress_proxy_connections_total.
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.
const ClosePath = "/v1/close-install"
ClosePath is where a run pod closes its own install set: POST {"podUID": "<its UID>"}.
const DefaultIdleTimeout = 5 * time.Minute
DefaultIdleTimeout closes a tunnel that moved no byte either way for this long.
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 ¶
var ErrRefused = errors.New("refused")
ErrRefused is a destination the proxy never dials: a name that resolves to a non-public or denied address.
var Reasons = []string{ReasonBadRequest, ReasonUnknownClient, ReasonNotAllowed, ReasonInstallClosed, ReasonTooMany, ReasonDeniedAddress, ReasonInstallCheck}
Reasons are every refusal reason, for a metric that exports each from the start.
Functions ¶
Types ¶
type Closer ¶ added in v0.57.0
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).
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.
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 (*Index) Lookup ¶
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
MarkClosed records that the pod with uid had its install set closed. It only narrows: nothing reopens a 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.