network

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAddressDenied = errors.New("sandbox: resolved network address denied")

ErrAddressDenied reports that a target resolved to an address outside the public destination space a route is permitted to reach.

View Source
var ErrClosed = errors.New("sandbox: executor closed")

ErrClosed reports that a proxy refused an authorization because the executor that owns it is shutting down. It is the same sentinel the executor layer exposes as ErrExecutorClosed: one value, so errors.Is answers the same way whichever side of the boundary raised it.

View Source
var ErrRouteDenied = errors.New("sandbox: egress route denied")
View Source
var ErrTargetDenied = errors.New("sandbox: network target denied")
View Source
var UnparseableTarget = Target{/* contains filtered or unexported fields */}

UnparseableTarget is the placeholder recorded against an execution when a proxied request carried a target that could not be parsed at all. It is deliberately a value no real target can equal, so a denial is still audited without inventing a plausible-looking host.

Functions

This section is empty.

Types

type DialFunc

type DialFunc func(ctx context.Context, transport, address string) (net.Conn, error)

DialFunc opens a connection to an already-resolved address.

type LookupFunc

type LookupFunc func(ctx context.Context, host string) ([]net.IP, error)

LookupFunc resolves a host to the addresses a route may connect to.

type Proxy

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

func NewProxy

func NewProxy(route Route) (*Proxy, error)

func NewProxyWithListener

func NewProxyWithListener(route Route, listener net.Listener) (*Proxy, error)

NewProxyWithListener starts an authenticated enforcement proxy on an already-bound loopback TCP listener. The caller retains ownership when validation fails; after a successful return, Proxy.Close owns the listener.

This seam lets a platform reserve every permitted loopback port before sandbox construction and then make a one-way transition of exactly one reservation into the proxy endpoint. It never falls back to another port.

func (*Proxy) Addr

func (proxy *Proxy) Addr() string

func (*Proxy) Authorize

func (proxy *Proxy) Authorize(executionID string, targets []Target) (string, error)

func (*Proxy) AuthorizeAll

func (proxy *Proxy) AuthorizeAll(executionID string) (string, error)

AuthorizeAll authorizes an execution for every target the route permits. It backs a profile whose network access is Allow, where the executor holds no per-target list to enumerate.

func (*Proxy) Close

func (proxy *Proxy) Close() error

func (*Proxy) Denial

func (proxy *Proxy) Denial(executionID string) error

func (*Proxy) Release

func (proxy *Proxy) Release(executionID string)

func (*Proxy) Route

func (proxy *Proxy) Route() Route

Route returns the egress route this proxy was constructed with.

func (*Proxy) ServeHTTP

func (proxy *Proxy) ServeHTTP(writer http.ResponseWriter, request *http.Request)

func (*Proxy) URL

func (proxy *Proxy) URL(executionID, credential string) string

type Route

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

Route is a validated, immutable route description. Secret upstream credentials are kept only in the private URL and excluded from identity.

func NewDirectRoute

func NewDirectRoute() (Route, error)

NewDirectRoute creates an explicit direct route with local DNS and address-class validation.

func NewUpstreamRoute

func NewUpstreamRoute(rawURL string, trustedAddressGuarantee bool) (Route, error)

NewUpstreamRoute creates an explicit HTTP or HTTPS organization proxy route. trustedAddressGuarantee is asserted only when the upstream contract guarantees resolved-address filtering.

func (Route) AddressGuarantee

func (route Route) AddressGuarantee() bool

func (Route) DialTarget

func (route Route) DialTarget(ctx context.Context, target Target) (net.Conn, error)

DialTarget resolves target through the route's resolver and connects to the first address that answers. Every resolved address must be a public destination: if any one of them is not, the whole dial fails with ErrAddressDenied rather than silently trying the remaining addresses, so a DNS answer that mixes public and private records cannot reach the private one.

func (Route) DialUpstream

func (route Route) DialUpstream(ctx context.Context) (net.Conn, error)

DialUpstream connects to the route's upstream proxy, wrapping the connection in TLS when the endpoint is https.

func (Route) Fingerprint

func (route Route) Fingerprint() string

func (Route) IsDirect

func (route Route) IsDirect() bool

IsDirect reports whether the route dials targets itself rather than handing them to an upstream proxy.

func (Route) String

func (route Route) String() string

func (Route) TargetGuarantee

func (route Route) TargetGuarantee() bool

func (Route) Upstream

func (route Route) Upstream() *url.URL

Upstream returns the upstream proxy endpoint, or nil for a direct route. The returned URL is the route's own; callers must not mutate it.

func (Route) Validate

func (route Route) Validate() error

func (Route) WithDialer

func (route Route) WithDialer(lookup LookupFunc, dial DialFunc) Route

WithDialer returns a copy of route that resolves and dials through the supplied collaborators; a nil argument leaves that collaborator unchanged.

This narrows nothing and widens nothing: DialTarget still rejects any resolved address outside the public destination space, so a substituted resolver cannot be used to reach loopback, link-local, or metadata addresses. The route's fingerprint is deliberately unchanged, because a fingerprint identifies the route's authority — its kind, endpoint, and guarantees — and not the machinery it uses to reach the network.

type RouteResolver

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

RouteResolver confines a consumer selector to prevalidated routes.

func NewRouteResolver

func NewRouteResolver(routes []Route, selector func(context.Context, Target) string) (*RouteResolver, error)

func (*RouteResolver) Resolve

func (resolver *RouteResolver) Resolve(ctx context.Context, target Target) (Route, error)

type Target

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

Target is a normalized transport, hostname, and port tuple.

func ParseTarget

func ParseTarget(raw string) (Target, error)

ParseTarget accepts the v1 tcp:<host>:<port> grant target.

func (Target) Address

func (target Target) Address() string

func (Target) Hostname

func (target Target) Hostname() string

func (Target) Port

func (target Target) Port() uint16

func (Target) String

func (target Target) String() string

func (Target) Transport

func (target Target) Transport() string

type TargetDeniedError

type TargetDeniedError struct {
	ExitCode     int
	ProcessError error
	// contains filtered or unexported fields
}

TargetDeniedError preserves the completed process result while making an authenticated proxy denial the primary typed error.

func NewTargetDeniedError

func NewTargetDeniedError(exitCode int, processErr, denial error) *TargetDeniedError

NewTargetDeniedError builds the typed error an executor returns when a spawn ran to completion but the proxy denied one of its network targets. The denial itself stays unexported so it can only be read through Error(), which keeps the denied host out of any caller that merely formats the wrapped sentinel.

func (*TargetDeniedError) Error

func (err *TargetDeniedError) Error() string

func (*TargetDeniedError) Unwrap

func (err *TargetDeniedError) Unwrap() error

Jump to

Keyboard shortcuts

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