egress

package
v0.0.0-...-6463c6a Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36"

Variables

This section is empty.

Functions

func AccountFromContext

func AccountFromContext(ctx context.Context) string

AccountFromContext exposes the non-sensitive sticky account identity to provider transports while keeping the context key private.

func BuildSSOCookie

func BuildSSOCookie(token, cloudflareCookies string) string

func EgressNodeFromContext

func EgressNodeFromContext(ctx context.Context) uint64

EgressNodeFromContext exposes a non-sensitive binding identifier to the Build transport without exposing the context key itself.

func QualityProbeFromContext

func QualityProbeFromContext(ctx context.Context) bool

QualityProbeFromContext reports whether the request is an internal administrator quality probe. Gateway retry policy uses this signal to keep ambiguous egress failures from changing credential health.

func RecordDirectPhysicalCall

func RecordDirectPhysicalCall(ctx context.Context, response *http.Response, err error)

RecordDirectPhysicalCall records a transport call that intentionally bypasses the managed egress lease because no Build node is configured.

func WithAccount

func WithAccount(ctx context.Context, provider string, accountID uint64) context.Context

WithAccount passes a stable Provider account identity to the egress layer. It is used only to render authentication usernames for sticky proxies such as Resin and is never written to upstream headers or audit.

func WithAccountIdentity

func WithAccountIdentity(ctx context.Context, identity string) context.Context

WithAccountIdentity attaches the stable, non-sensitive identity used by account-bound proxy templates such as Resin. Providers that represent the same upstream login (for example Web and Console sharing one SSO token) can deliberately pass the same identity so their proxy and clearance lease is not split by the internal provider name.

func WithCredential

func WithCredential(ctx context.Context, credential accountdomain.Credential) context.Context

WithCredential passes the stable egress identity of a weakly linked account to Build transport; unlinked accounts retain the existing Provider+ID identity.

func WithEgressNode

func WithEgressNode(ctx context.Context, nodeID uint64) context.Context

WithEgressNode attaches the explicitly assigned node ID for transports that only receive a request context (notably Grok Build's RoundTripper).

func WithPhysicalCallPlane

func WithPhysicalCallPlane(ctx context.Context, plane string) context.Context

WithPhysicalCallPlane annotates a bounded upstream plane while preserving the request-wide ordinal and current stage.

func WithPhysicalCallStage

func WithPhysicalCallStage(ctx context.Context, stage string) context.Context

WithPhysicalCallStage annotates an internal retry or preparation stage while preserving the request-wide ordinal and upstream plane.

func WithPhysicalCallTrace

func WithPhysicalCallTrace(ctx context.Context, provider, operation string) context.Context

WithPhysicalCallTrace starts observe-only physical-call accounting for one downstream request. It does not impose a retry budget or alter transport.

func WithQualityProbe

func WithQualityProbe(ctx context.Context) context.Context

WithQualityProbe marks an administrator-initiated probe. It permits the selected fixed node to be tested while disabled or cooling without making that node eligible for ordinary inference traffic.

Types

type ClearanceConfig

type ClearanceConfig struct {
	Mode            string
	FlareSolverrURL string
	TargetURL       string
	Timeout         time.Duration
	RefreshInterval time.Duration
}

type FailureProber

type FailureProber func(context.Context, uint64) (domain.ProbeResult, error)

type Lease

type Lease struct {
	NodeID    uint64
	NodeName  string
	Scope     domain.Scope
	ProxyURL  string
	UserAgent string
	CFCookies string
	// contains filtered or unexported fields
}

func (*Lease) DialWebSocket

func (l *Lease) DialWebSocket(ctx context.Context, endpoint string, headers fhttp.Header, handshakeTimeout time.Duration) (*websocket.Conn, *fhttp.Response, error)

func (*Lease) DialWebSocketDeferredForbidden

func (l *Lease) DialWebSocketDeferredForbidden(ctx context.Context, endpoint string, headers fhttp.Header, handshakeTimeout time.Duration) (*websocket.Conn, *fhttp.Response, error)

DialWebSocketDeferredForbidden leaves a 403 handshake response for the caller to classify before invalidating the browser-session Clearance.

func (*Lease) Do

func (l *Lease) Do(request *http.Request) (*http.Response, error)

func (*Lease) DoDeferredForbidden

func (l *Lease) DoDeferredForbidden(request *http.Request) (*http.Response, error)

DoDeferredForbidden executes an HTTP request while leaving 403 clearance invalidation to the caller after it has classified the response body.

func (*Lease) DoPinnedHTTPS

func (l *Lease) DoPinnedHTTPS(request *http.Request, serverName string) (*http.Response, error)

DoPinnedHTTPS sends a request whose URL host is an already validated IP address while preserving serverName for TLS verification. Keeping this transport separate from the shared browser client prevents a later DNS lookup or a pooled connection from reopening an SSRF validation gap.

func (*Lease) InvalidateClearance

func (l *Lease) InvalidateClearance()

InvalidateClearance invalidates the exact browser-session binding used by this lease after a 403 has been classified as egress-related.

func (*Lease) Release

func (l *Lease) Release()

type Manager

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

func NewManager

func NewManager(repository repository.EgressRepository, cipher *security.Cipher) *Manager

func (*Manager) AccountIsolatedConnections

func (m *Manager) AccountIsolatedConnections() bool

AccountIsolatedConnections reports whether upstream clients are partitioned by account.

func (*Manager) Acquire

func (m *Manager) Acquire(ctx context.Context, scope domain.Scope, affinity string) (*Lease, error)

func (*Manager) AcquireBuildEnvironmentDirectIfIsolated

func (m *Manager) AcquireBuildEnvironmentDirectIfIsolated(ctx context.Context, affinity string) (*Lease, bool, error)

AcquireBuildEnvironmentDirectIfIsolated creates an account-partitioned direct Build lease while preserving the legacy direct transport's environment-proxy semantics. The bool is false when isolation was disabled before the lease was acquired, allowing the caller to retain its original fallback transport.

func (*Manager) AcquireCredential

func (m *Manager) AcquireCredential(ctx context.Context, scope domain.Scope, credential accountdomain.Credential) (*Lease, error)

AcquireCredential binds the outbound proxy identity to one persisted Provider credential. Resin templates use this identity as their Account.

func (*Manager) AcquireIfConfigured

func (m *Manager) AcquireIfConfigured(ctx context.Context, scope domain.Scope, affinity string) (*Lease, bool, error)

func (*Manager) BuildStreamIdleTimeout

func (m *Manager) BuildStreamIdleTimeout() time.Duration

BuildStreamIdleTimeout returns the configured stream idle deadline for Grok Build responses. Returns zero when idle enforcement is disabled.

func (*Manager) Feedback

func (m *Manager) Feedback(ctx context.Context, nodeID uint64, status int, transportErr error)

func (*Manager) FeedbackForScope

func (m *Manager) FeedbackForScope(ctx context.Context, scope domain.Scope, nodeID uint64, status int, transportErr error)

func (*Manager) ForgetClearance

func (m *Manager) ForgetClearance(nodeID uint64)

ForgetClearance evicts runtime state after an administrator changes or removes a node. Unlike a 403 rejection, it does not mark the persisted last-known-good cookie as invalid; ensureClearance will still verify its binding before using it as a solver-failure fallback.

func (*Manager) ForgetClearances

func (m *Manager) ForgetClearances(nodeIDs []uint64)

ForgetClearances evicts a batch of node-scoped runtime state with one cache scan and one lock acquisition. Administrative bulk updates can contain thousands of nodes, so repeating the global snapshot invalidation per ID would add avoidable lock contention and CPU work.

func (*Manager) InvalidateClearance

func (m *Manager) InvalidateClearance(nodeID uint64)

func (*Manager) InvalidateOperationsConfig

func (m *Manager) InvalidateOperationsConfig()

func (*Manager) ProbeEgressNode

func (m *Manager) ProbeEgressNode(ctx context.Context, node domain.Node) (domain.ProbeResult, error)

ProbeEgressNode verifies IPv4 and IPv6 independently through fixed provider endpoints. Both requests share one immutable node snapshot so a concurrent administrator edit cannot mix results from different proxy configurations.

func (*Manager) RefreshClearance

func (m *Manager) RefreshClearance(ctx context.Context, nodeID uint64) error

func (*Manager) RefreshDueClearances

func (m *Manager) RefreshDueClearances(ctx context.Context, force bool) error

func (*Manager) SetClearanceLock

func (m *Manager) SetClearanceLock(value repository.DistributedLock)

SetClearanceLock enables cross-instance coordination for shared, fixed egress nodes. Account-bound Resin clearances remain process-local because they must never be persisted into the node-wide cookie fields.

func (*Manager) SetFailureProber

func (m *Manager) SetFailureProber(value FailureProber)

SetFailureProber enables an immediate, deduplicated connectivity probe after a fixed proxy reports a transport failure. The callback persists the probe result; it must not depend on the failed request context.

func (*Manager) SetLogger

func (m *Manager) SetLogger(logger *slog.Logger)

func (*Manager) UpdateAccountIsolatedConnections

func (m *Manager) UpdateAccountIsolatedConnections(enabled bool)

UpdateAccountIsolatedConnections toggles per-account upstream connection pools. When enabled, different accounts do not share TCP/HTTP clients so upstream egress load balancers can spread traffic by connection; the same account still reuses its own pool. Changing the setting rebuilds cached clients without interrupting in-flight requests.

func (*Manager) UpdateBuildResponseHeaderTimeout

func (m *Manager) UpdateBuildResponseHeaderTimeout(value time.Duration)

UpdateBuildResponseHeaderTimeout rebuilds only cached Build clients. Active requests keep their current transport and are not interrupted.

func (*Manager) UpdateBuildStreamIdleTimeout

func (m *Manager) UpdateBuildStreamIdleTimeout(value time.Duration)

UpdateBuildStreamIdleTimeout affects subsequent Build streams. Active response bodies retain the deadline captured by their existing wrapper and are not interrupted; the underlying HTTP connection pool is unchanged.

func (*Manager) UpdateClearanceConfig

func (m *Manager) UpdateClearanceConfig(value ClearanceConfig)

type Selection

type Selection struct {
	NodeID   uint64
	NodeName string
	Scope    domain.Scope
	Proxied  bool
}

Selection is the egress snapshot actually selected for an upstream request. It contains only metadata safe for audit and excludes proxy URLs, credentials, User-Agent, and Cookies.

type Trace

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

Trace retains the most recent actual egress selection per scope. When a request retries egress, audit records the final attempt. Web asset archival uses an independent scope and does not overwrite the primary Grok Web inference egress.

func TraceFromContext

func TraceFromContext(ctx context.Context) *Trace

TraceFromContext returns the egress trace from context, or nil when none is configured.

func WithTrace

func WithTrace(ctx context.Context) (context.Context, *Trace)

WithTrace creates or reuses a concurrency-safe egress selection trace for one gateway request.

func (*Trace) Selection

func (t *Trace) Selection(scope domain.Scope) (Selection, bool)

Selection returns a safe snapshot of the most recent actual egress selection for a scope.

Jump to

Keyboard shortcuts

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