config

package
v0.0.0-...-53bd38a Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 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 config provides YAML-based configuration with mode presets and startup validation for the AuthBridge auth layer.

Package config's resolve.go previously constructed a shared auth.Config + auth.Auth for all plugins to share. With per-plugin configuration, that responsibility moved into each plugin's Configure (see docs/plugin-reference.md), and this file is now just the shared credential-file waiters that multiple plugins need when they share a file path (e.g. /shared/client-id.txt used by both jwt-validation's audience_file and token-exchange's client_id_file).

Index

Constants

View Source
const (
	AccountingAuto  = "auto"
	AccountingTrue  = "true"
	AccountingFalse = "false"
)

The values AccountingConfig.Enabled takes.

View Source
const (
	DefaultPraxisListen = "127.0.0.1:47605"
	DefaultPraxisEgress = "127.0.0.1:47606"
)

Default loopback addresses of the praxis-mode listeners.

View Source
const (
	DefaultUpdateWait       = 6 * time.Hour
	DefaultUpdateCheckEvery = 3 * time.Hour
)

The defaults for update.wait and update.check_every.

View Source
const (
	ProcessAttributionAuto = "auto"
	ProcessAttributionOn   = "on"
	ProcessAttributionOff  = "off"
)

The values of session.process_attribution.

View Source
const (
	ExtProcBodyModeBuffered   = "buffered"
	ExtProcBodyModeFullDuplex = "full_duplex"
)

Values of ListenerConfig.ExtProcBodyMode.

View Source
const (
	// ResponsesWebSocketsParse carries the WebSocket and parses every turn on it the
	// way an HTTPS Responses request is parsed. Where the proxy cannot do that — the
	// request was not decrypted, or a plugin rewrites response bodies or redirects
	// requests — it falls back to ResponsesWebSocketsDecline for that socket.
	ResponsesWebSocketsParse = "parse"
	// ResponsesWebSocketsDecline answers the upgrade with 426 Upgrade Required and
	// contacts no origin; Codex reads that as "use HTTPS" and switches at once.
	ResponsesWebSocketsDecline = "decline"
	// ResponsesWebSocketsForward forwards the upgrade and splices the origin's 101, as
	// the proxy does for every other WebSocket (#1488). The socket works, but its
	// frames are opaque: no turn is parsed, priced or recorded, only the handshake's
	// request row and a 101 row when the socket ends.
	ResponsesWebSocketsForward = "forward"
)

Valid ListenerConfig.ResponsesWebSockets values.

View Source
const (
	RoleReverse = "reverse" // inbound reverse proxy
	RoleForward = "forward" // outbound forward proxy
)

Proxy roles selectable via ListenerConfig.Roles in proxy-sidecar mode.

View Source
const (
	InboundInterceptionReverseProxy = "reverse-proxy" // fixed backend (default)
	InboundInterceptionTransparent  = "transparent"   // SO_ORIGINAL_DST per connection
)

Valid ListenerConfig.InboundInterception values. Interception is two independent axes (inbound, outbound), so the inbound mechanism is a field on the reverse role rather than a role of its own — matching the outbound transparent listener, which likewise rides inside the forward role instead of being separately selectable.

View Source
const (
	ModeEnvoySidecar = "envoy-sidecar"
	ModeProxySidecar = "proxy-sidecar"
)

Valid mode strings.

View Source
const (
	// MetricsPushSendsLine says what the push sends.
	MetricsPushSendsLine = "" /* 160-byte string literal not displayed */
	// MetricsPushStopLine says how to stop it.
	MetricsPushStopLine = "To stop it, set metrics_push.enabled: false, or METRICS_PUSH=false in the proxy's environment."
)
View Source
const DefaultLocalMemoryLimitMB = 2048

DefaultLocalMemoryLimitMB is the soft memory limit a local install uses when the config carries no memory block. The default must be COMPUTED (MemoryLimitBytes), never written into a stored *Config: the reloader compares the active config against a fresh disk load on every reload, so a boot-time cfg.Memory assignment would refuse every reload on a local install. Same shape as ArchiveRunsOnLocalInstall — a method, not state.

View Source
const DefaultMetricsPushInterval = 60 * time.Second

DefaultMetricsPushInterval is metrics_push.interval when the block and the environment leave it unset.

Variables

This section is empty.

Functions

func ApplyPreset

func ApplyPreset(cfg *Config)

ApplyPreset fills in mode-specific defaults for listener addresses. Plugin-specific defaults live inside each plugin's Configure (see docs/plugin-reference.md); the runtime config no longer shapes plugin behavior.

func BodyReaderPlugins

func BodyReaderPlugins() []string

BodyReaderPlugins returns the outbound plugins that must come before every request-body writer (pipeline.validateCapabilities), sorted. The slice is a new copy. A test in core/plugins/all keeps the list in step with the registry.

func HasContextOperator

func HasContextOperator(c *Config) bool

HasContextOperator reports whether c's outbound pipeline has a context operator that runs. Outbound only: inference requests leave through it. An entry turned off with on_error: off is not built, so it does not count; one under observe still reports its ops, as dry runs.

func MetricsPushOnNotice

func MetricsPushOnNotice(url, goos string) []string

MetricsPushOnNotice is what a fresh config with the push on is announced with: a first line naming where the counters go, then the sends, stop and restart lines.

func MetricsPushRestartLine

func MetricsPushRestartLine(goos string) string

MetricsPushRestartLine says how to make a change to metrics_push take effect on goos (a runtime.GOOS value). The block is restart-only: until the proxy restarts, the reloader refuses the edited file, the rest of the save with it.

There is no `agentop service` on Windows (#1520): the proxy is the cortex --local a user started in a terminal.

func PraxisOffSafe

func PraxisOffSafe() []string

PraxisOffSafe returns the praxisOffSafe names, sorted.

func ReadCredentialFile

func ReadCredentialFile(path string) (string, error)

ReadCredentialFile performs a one-shot read of a credential file, returning its whitespace-trimmed contents. Used by plugins from Configure to opportunistically pick up values the operator has already mounted from a Secret; when it returns an error, the plugin should fall back to WaitForCredentialFile from Init to wait for the file.

func SafeURL

func SafeURL(raw string) string

SafeURL is u with no user info, query or fragment: scheme, host and path at most, the only parts of a metrics_push.url that may reach an error or a log. A credential can hide in the user info ("https://user:pass@host") or the query ("?token=..."). An unparseable URL gives a placeholder, never the input.

func Validate

func Validate(cfg *Config) error

Validate checks the top-level runtime config: mode and listener combo. Plugin-specific validation (issuer, token URL, identity type, jwt_audience) lives inside each plugin's Configure and runs at pipeline build time.

Empty pipelines are permitted: AuthBridge will run as a pass-through on any stage with no plugins. This supports testing scenarios and asymmetric deployments (e.g. inbound auth only, no outbound token exchange). Operators get a startup WARN per empty stage from WarnEmptyPipelines so the open-proxy condition is visible in logs.

func WaitForCredentialFile

func WaitForCredentialFile(ctx context.Context, path string) (string, error)

WaitForCredentialFile blocks until the file is readable with non-zero length, or until ctx is cancelled. Plugins call this from Init (via a goroutine) to wait out the race with the operator's Secret-mount propagation.

Polls at 2s intervals — fast enough for human-observable boot times, slow enough that a pod full of plugins isn't hammering the kubelet. Emits a WARN every heartbeatInterval while the file is still absent so operators can spot wrong paths / missing volume mounts in `kubectl logs` during an incident, rather than discovering them after chasing silent 503s from traffic.

func WaitForCredentialFileTicks

func WaitForCredentialFileTicks(ctx context.Context, path string, ticks <-chan time.Time) (string, error)

WaitForCredentialFileTicks is WaitForCredentialFile with the poll interval supplied by the caller: it reads the file again after each value on ticks. Tests pass an unbuffered channel to step the loop.

func WarnEmptyPipelines

func WarnEmptyPipelines(cfg *Config, logger *slog.Logger)

WarnEmptyPipelines emits a startup WARN for every pipeline stage that has no plugins. An empty stage is a supported configuration (pass-through), not an error, but it means traffic on that direction flows without authentication, JWT validation, or token exchange. Surfacing this once at startup makes the open-proxy condition visible in logs without blocking deployments that intentionally run without plugins (e.g. testing, asymmetric deployments).

Call this from each cmd entry point AFTER Validate succeeds and BEFORE the pipelines are built. Pass slog.Default() unless you need a scoped logger.

Types

type AccountingConfig

type AccountingConfig struct {
	// Enabled is "auto" (the default, also spelled ""), "true" or "false". A string, not a
	// *bool, because it has three values; YAML's true and false decode into it as "true" and
	// "false".
	Enabled string `yaml:"enabled" json:"enabled"`

	// SubscriptionWeights value a saving on a subscription login in usage-limit units: tokens
	// times these weights. Nil means DefaultSubscriptionWeights. Read once, when the accountant
	// host is built, so a reload that changes them is refused (reloader.validateReloadable).
	SubscriptionWeights *SubscriptionWeights `yaml:"subscription_weights,omitempty" json:"subscription_weights,omitempty"`
}

AccountingConfig is the top-level `accounting:` block: whether the process hosts the accountant (core/accounting), which prices what the context operators saved with the same rules as the context-guru proxy (design §5.3).

accounting:
  enabled: auto   # auto | true | false
  subscription_weights:   # optional; defaults shown (design §5.7a)
    input: 1
    cache_write_5m: 1.25
    cache_write_1h: 2
    cache_read: 0.1
    output: 5

The block is the same in a cluster and on a laptop; only the Tracker snapshot is laptop-only.

NOT HOT-RELOADABLE from off to on: the host is built once at boot, so a reload that would turn accounting on when the process booted with it off is refused (reloader.validateAccounting). Turning it off is accepted on purpose, as a kill-switch for on_error: off, and the host goes idle. An edit that resolves the same is accepted either way.

func (*AccountingConfig) On

func (a *AccountingConfig) On(hasOperator bool) bool

On reports whether accounting runs. hasOperator is whether the outbound pipeline has a context operator (HasContextOperator). Under auto, accounting is on exactly when there is one: a pipeline with no operator has nothing to account for, so it pays nothing — no client body is kept and no buffering changes. "true" forces it on, for the cache figures alone. A nil receiver is auto. A value Validate refuses reads as auto.

func (*AccountingConfig) Validate

func (a *AccountingConfig) Validate() error

Validate refuses a value of Enabled other than "", "auto", "true" and "false", in any case: YAML's own boolean spellings (True, TRUE, False, FALSE) decode into this string field verbatim (unlike a *bool field, which yaml.v3 already folds them into), so this compares case- insensitively to accept every spelling a YAML user might write for the same value. It also refuses a negative subscription weight. Safe on a nil receiver.

func (*AccountingConfig) Weights

Weights returns the configured subscription weights, or the defaults. Safe on a nil receiver.

type Config

type Config struct {
	Mode     string         `yaml:"mode" json:"mode"` // "envoy-sidecar", "proxy-sidecar"
	Listener ListenerConfig `yaml:"listener" json:"listener"`
	Pipeline PipelineConfig `yaml:"pipeline" json:"pipeline"`
	Session  SessionConfig  `yaml:"session" json:"session"`
	Stats    StatsConfig    `yaml:"stats" json:"stats"`
	// MTLS, when non-nil, enables transport-level mTLS using SPIRE
	// X.509 SVIDs. Applies symmetrically to inbound (reverse-proxy)
	// and outbound (forward-proxy) traffic in proxy-sidecar mode;
	// envoy-sidecar mode is unaffected (Envoy handles its own TLS via
	// SDS). Pointer so absent block = today's plaintext behavior.
	MTLS *MTLSConfig `yaml:"mtls,omitempty" json:"mtls,omitempty"`
	// SPIFFE, when non-nil, configures the in-process Provider that
	// supplies X.509-SVIDs to the mTLS listeners and a JWT-SVID to the
	// token-exchange plugin (when configured). Pointer so absent block
	// = no Provider and no mirrored SVID files (until the chart/operator
	// follow-ups land and start populating the block).
	SPIFFE *SPIFFEConfig `yaml:"spiffe,omitempty" json:"spiffe,omitempty"`
	// TLSBridge, when non-nil and Enabled, terminates agent outbound TLS so the
	// outbound pipeline sees decrypted HTTPS. See docs/.../tlsbridge-design.md.
	TLSBridge *TLSBridgeConfig `yaml:"tls_bridge,omitempty" json:"tls_bridge,omitempty"`
	// Memory, when set, applies a Go runtime soft memory limit
	// (debug.SetMemoryLimit) at boot. See MemoryConfig.
	Memory *MemoryConfig `yaml:"memory,omitempty" json:"memory,omitempty"`
	// Praxis, when Enabled, turns on praxis mode: cortex-gateway forwards the
	// traffic and Cortex ingests its rows. Absent means direct mode.
	Praxis *PraxisConfig `yaml:"praxis,omitempty" json:"praxis,omitempty"`
	// Update configures automatic updates. agentop reads auto and wait on each run.
	// The proxy reads check_every at boot.
	Update *UpdateConfig `yaml:"update,omitempty" json:"update,omitempty"`
	// Pricing configures model rates for the whole process — one section rather
	// than a knob per plugin, so cost is consistent wherever it is reported.
	//
	// Absent means the bundled price table alone, which is deliberate: covering
	// internal usage with no manual setup is the point. Set `pricing.bundled:
	// false` to price only what you configure. See core/cost/pricing.
	Pricing *pricing.Config `yaml:"pricing,omitempty" json:"pricing,omitempty"`
	// CostLedger configures the durable per-minute cost ledger (core/cost/ledger),
	// which persists closed minutes so "what did today cost" survives a restart.
	//
	// Absent means the caller's default, and the callers differ deliberately: a local
	// install turns it ON (a laptop has a home directory and a developer who wants
	// yesterday's number), Kubernetes leaves it OFF (writing files in a pod is the
	// wrong sink; a central collector is the right one). Set `cost_ledger.enabled:
	// false` to turn it off locally.
	CostLedger *CostLedgerConfig `yaml:"cost_ledger,omitempty" json:"cost_ledger,omitempty"`
	// Accounting says whether the process hosts the accountant, which prices what the context
	// operators saved. Absent means auto: on when the outbound pipeline has a context
	// operator. See AccountingConfig.
	Accounting *AccountingConfig `yaml:"accounting,omitempty" json:"accounting,omitempty"`
	// MetricsPush says where the accountant's llm.savings.* counters are pushed. Absent, or
	// with no URL, nothing is pushed. See MetricsPushConfig.
	MetricsPush *MetricsPushConfig `yaml:"metrics_push,omitempty" json:"metrics_push,omitempty"`
}

Config is the top-level AuthBridge configuration.

Plugin-specific settings (inbound JWT validation, outbound token exchange, identity, bypass paths, routes) live inside their respective entries under Pipeline.* now — see the plugin reference at docs/plugin-reference.md for how each plugin declares its own config schema and defaults.

func Load

func Load(path string) (*Config, error)

Load reads and parses a YAML config file with environment variable expansion. Defined env vars are expanded; undefined references like ${UNDEFINED} are left as-is to avoid silent empty-string substitution.

func Parse

func Parse(data []byte) (*Config, error)

Parse is Load for a config already in memory: the same expansion, defaults and validation.

func (*Config) AccountingOn

func (c *Config) AccountingOn() bool

AccountingOn is c.Accounting.On(HasContextOperator(c)): whether a process started from c hosts the accountant.

func (*Config) ArchiveRunsOnLocalInstall

func (c *Config) ArchiveRunsOnLocalInstall() (bool, string)

ArchiveRunsOnLocalInstall reports whether the session archive runs for c when it is started from a local install — a config inside ~/.cortex — or with session.archive.dir set, and why. Otherwise it never runs. That half is the caller's to decide, since only the caller knows where the config lives.

ON BY DEFAULT ONLY WHERE A CLEAR REACHES IT: bound to loopback only, the one shape whose DELETE /v1/sessions answers. Elsewhere the history it wrote could only be removed by hand, so an unset block leaves it off there, and an explicit true opts in knowing that.

func (*Config) MemoryLimitBytes

func (c *Config) MemoryLimitBytes(localInstall bool) int64

MemoryLimitBytes reports the configured soft limit in bytes, or 0 for off. A nil memory block on a local install defaults to DefaultLocalMemoryLimitMB; anywhere else it is off. localInstall is a parameter because the binary, not the file, knows it.

func (*Config) PraxisEnabled

func (c *Config) PraxisEnabled() bool

PraxisEnabled reports whether praxis mode is on. False on a nil block.

func (*Config) UpdateAutoEnabled

func (c *Config) UpdateAutoEnabled() bool

UpdateAutoEnabled is true unless update.auto is set to false. Nil-safe on c.

type CostLedgerConfig

type CostLedgerConfig struct {
	// Enabled is a POINTER so "unset" and "explicitly false" are different states.
	// The local default is on, and an operator has to be able to turn it off; with a
	// plain bool an absent block and `enabled: false` would be the same value, so the
	// only way to disable it would be to delete the whole block — which also discards
	// the retention setting beside it.
	//
	// Takes effect on restart. See the type doc.
	Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	// Dir is where day files are written. Empty means the caller's default, which for
	// a local install is ~/.cortex/cost — kept out of this struct so the config does
	// not pin a $HOME-derived absolute path into a file that may be copied between
	// machines.
	Dir string `yaml:"dir,omitempty" json:"dir,omitempty"`
	// RetentionDays is how many day files survive. Zero means the package default of
	// 31, which is roughly 10 MB.
	//
	// THIRTY-ONE because that is what window=month needs: a month-to-date total on the 31st
	// of a 31-day month opens 31 day files, and cost/ledger's prune keeps exactly
	// retention_days distinct dates. See ledger.defaultRetentionDays, which is pinned to
	// usage.WindowMonthLocalDays.
	//
	// A non-zero value must be at least minCostLedgerRetentionDays; see there. Note that the
	// FLOOR is lower than the default: a deployment may legitimately keep less history than
	// window=month needs, and one that does will answer that window short.
	//
	// THE SHORTFALL IS DISCLOSED, which an earlier version of this comment denied: a pruned day
	// file is absent rather than unreadable, so it produces no Caveats entry — but
	// usage.Snapshot.DaysOutsideRetention counts the days a REQUEST asks for beyond this setting,
	// and the band marks such a total as a floor while `agentop cost` prints a coverage line. What
	// is still silent is a day pruned INSIDE the current horizon, from a setting that used to be
	// shorter; see that field. The default covers the longest shipped window so that the ordinary
	// case needs no disclosure at all.
	RetentionDays int `yaml:"retention_days,omitempty" json:"retention_days,omitempty"`
}

CostLedgerConfig configures the durable cost ledger.

NOT HOT-RELOADABLE, unlike most of this file. The reloader swaps the plugin pipeline and per-plugin config in place, but the ledger is constructed once at startup and handed to the session store as a recorder, so a running proxy holds whichever writer it opened. Editing anything here — enabled, dir, retention_days — takes effect on RESTART.

The edit is REFUSED rather than ignored: reloader.validateReloadable compares this block the way it compares mode and listener.*, so a live edit fails the reload, leaves LastError naming cost_ledger on /reload/status, and asks for a pod restart.

It did not always. This doc used to warn that "an operator who edits this to stop writing cost history has every reason to believe it stopped" — and they did, because the edit was ACCEPTED: ReloadsOK incremented, ActiveConfigSHA256 moved, and /config served the new values while the startup writer kept appending under the old retention. Documenting that was the weaker of the two options available; the guard is three lines and the precedent for it was already in the same function. Pinned by reloader.TestReloader_RefusesCostLedgerChange.

func (*CostLedgerConfig) DirSet

func (c *CostLedgerConfig) DirSet() bool

DirSet reports whether an operator named a directory for the ledger.

IT IS THE STRONGEST AVAILABLE SIGNAL THAT THE LEDGER CAN DELIVER, which is why the caller uses it to pick the default. The ledger's whole purpose is surviving a restart; writing to a path nobody chose achieves the opposite in a container, where the only place left is the image's writable layer — wiped on every restart and counted against the pod's ephemeral-storage limit, which is an eviction rather than a lost figure. An operator who names a path has mounted something to put it on, and that is a fact this package can see where "is there a volume here" is not.

A method rather than a field read, and nil-safe, because the block is absent in the common Kubernetes case and every caller would otherwise repeat the same check.

func (*CostLedgerConfig) LedgerEnabled

func (c *CostLedgerConfig) LedgerEnabled(defaultOn bool) bool

LedgerEnabled reports whether the ledger should run, given the default for this deployment shape.

WHAT defaultOn USED TO MEAN, AND WHY IT CHANGED. It was localMode — true under --local, false otherwise — and that made the default a property of WHICH FLAG STARTED THE BINARY rather than of whether the ledger could do its job. Every service install runs --config, so the documented "on by default" was false for every installed laptop. The caller now derives defaultOn from whether a durable location exists at all (see DirSet), so the answer no longer depends on the command line.

A method on the pointer receiver so a nil block — the common case in Kubernetes — answers without every caller writing the same nil check and one of them getting it backwards.

func (*CostLedgerConfig) Validate

func (c *CostLedgerConfig) Validate() error

Validate is called from the loader when CostLedger != nil.

type EgressGuardConfig

type EgressGuardConfig struct {
	// Enabled arms the guard. False (or an absent egress_guard block) keeps
	// the dial behavior unchanged.
	Enabled bool `yaml:"enabled" json:"enabled"`

	// PermitCIDRs lists CIDR prefixes within the refused space that remain
	// dialable — e.g. ["127.0.0.1/32"] for a laptop proxy whose upstream is a
	// local model, or ["10.0.0.0/8"] for an in-cluster deployment. Never has
	// any effect on link-local, unspecified, multicast or the AWS IPv6
	// metadata address (fd00:ec2::254).
	PermitCIDRs []string `yaml:"permit_cidrs,omitempty" json:"permit_cidrs,omitempty"`
}

EgressGuardConfig configures the forward proxy's SSRF dial guard.

type ListenerConfig

type ListenerConfig struct {
	ExtProcAddr         string `yaml:"ext_proc_addr" json:"ext_proc_addr"`
	ForwardProxyAddr    string `yaml:"forward_proxy_addr" json:"forward_proxy_addr"`
	ReverseProxyAddr    string `yaml:"reverse_proxy_addr" json:"reverse_proxy_addr"`
	ReverseProxyBackend string `yaml:"reverse_proxy_backend" json:"reverse_proxy_backend"`

	// Roles selects which proxies run in proxy-sidecar mode. Empty (the
	// default) runs BOTH the reverse proxy (inbound) and the forward proxy
	// (outbound) — the full pod deployment, so existing configs are unchanged.
	// Set a subset to run a single shape:
	//   roles: [forward]   # egress-only (e.g. a laptop TLS-bridge demo)
	//   roles: [reverse]   # inbound-only JWT validation
	// Valid values: "reverse", "forward". The preset fills an addr default
	// only for an active role, and reverse_proxy_backend is required only when
	// the reverse role is active. Ignored outside proxy-sidecar mode.
	Roles []string `yaml:"roles" json:"roles"`

	// InboundInterception selects HOW inbound traffic reaches the reverse
	// proxy's pipeline, in proxy-sidecar mode with the reverse role active:
	//
	//   reverse-proxy (default) — the operator binds AuthBridge on the agent's
	//                 original port and relocates the agent to a free one
	//                 ("port stealing"), so the Service needs no patching.
	//                 Forwards to the single reverse_proxy_backend URL.
	//   transparent — proxy-init PREROUTING-REDIRECTs inbound TCP to
	//                 transparent_inbound_addr; the listener recovers the port
	//                 the client actually addressed via SO_ORIGINAL_DST and
	//                 forwards there over loopback. The agent keeps its own
	//                 port, so no PORT env var is imposed on it and every port
	//                 it listens on is covered — not just the first declared
	//                 one. Requires proxy-init (NET_ADMIN) and is Linux-only.
	//
	// Defaults to reverse-proxy: transparent adds a privileged init container,
	// so it is opt-in, and leaving it unset keeps existing deployments
	// byte-identical.
	InboundInterception string `yaml:"inbound_interception" json:"inbound_interception"`

	// TransparentInboundAddr is the bind address for the inbound transparent
	// listener (inbound_interception: transparent). The proxy-sidecar preset
	// defaults it to ":8083" when that mode is selected — 8080 (reverse), 8081
	// (forward) and 8082 (transparent egress) are already taken. It MUST match
	// proxy-init's INBOUND_TRANSPARENT_PORT, or PREROUTING will REDIRECT to a
	// dead port and inbound traffic will break outright.
	TransparentInboundAddr string `yaml:"transparent_inbound_addr" json:"transparent_inbound_addr"`

	// TransparentProxyAddr is the bind address for the outbound transparent
	// listener used by proxy-sidecar enforce-redirect mode: iptables REDIRECTs
	// the agent's bypass egress here, and the listener recovers the original
	// destination via SO_ORIGINAL_DST and tunnels it through the same outbound
	// pipeline as the forward proxy. The proxy-sidecar / lite presets default it
	// to ":8082", so for those shapes the listener is effectively always on —
	// binding is harmless when nothing is redirected to it (cooperative
	// HTTP_PROXY deployments simply never receive connections on it). An empty
	// value only disables the listener for modes that have no preset default for
	// this field (envoy-sidecar); under proxy-sidecar / lite the
	// preset refills it, matching the always-on enforce-redirect design.
	TransparentProxyAddr string `yaml:"transparent_proxy_addr" json:"transparent_proxy_addr"`

	// SessionAPIAddr is the bind address for the session events HTTP server
	// (JSON snapshots + SSE stream consumed by agentop or curl). Default per
	// mode preset is ":9094". Set to empty string to disable the endpoint.
	SessionAPIAddr string `yaml:"session_api_addr" json:"session_api_addr"`

	// HealthAddr is the bind address for the liveness/readiness server
	// (/healthz, /readyz). Every mode preset defaults it to ":9091", which is
	// what Kubernetes probes expect. It is configurable because the literal was
	// previously hardcoded, and two proxies on one host could therefore never
	// coexist: the second died on a bind conflict. Local setups can pin it to
	// loopback on another port; leaving it empty keeps the preset default.
	HealthAddr string `yaml:"health_addr" json:"health_addr"`

	// BindLoopbackOnly rewrites EVERY listener address in this config (and the
	// stats address) to 127.0.0.1, keeping each port. Off by default, which
	// preserves Kubernetes behaviour exactly.
	//
	// Why a flag and not the default: in a pod, a wildcard bind is correct and
	// necessary — the network namespace is the boundary, and kubelet probes health
	// from outside the container's loopback, so forcing 127.0.0.1 there would fail
	// every liveness probe. On a laptop there is no namespace, and the same default
	// publishes the listener on Wi-Fi.
	//
	// Why a flag and not a per-listener pin: pinning each address protects only the
	// listeners someone remembered to name. A config written before a pin existed
	// never receives it (writeBuiltinConfig never overwrites, so hand edits
	// survive), and a listener added later starts wide with nothing to catch it.
	// This was not hypothetical: a laptop config predating the health and
	// transparent pins was serving *:9091 and *:8082 on every interface. One rule
	// covers listeners that do not exist yet.
	BindLoopbackOnly bool `yaml:"bind_loopback_only" json:"bind_loopback_only"`

	// SkipHosts lists outbound destination host patterns whose traffic
	// bypasses the plugin pipeline AND session recording entirely. The
	// listener forwards matched requests as a transparent proxy without
	// running plugins or appending events to any session bucket.
	//
	// Intended for high-volume infrastructure traffic that competes
	// with agent-meaningful events for session-buffer slots. The
	// canonical example: an OpenTelemetry collector sidecar that emits
	// dozens of exports per agent turn — without this gate, those
	// exports occupy the session buffer's FIFO eviction window and
	// silently push out the inbound A2A user intent that IBAC needs
	// to align tool calls against, causing IBAC to fall through to
	// the no_intent skip path on every call after the first.
	//
	// Patterns use `.`-delimited glob semantics (same library as
	// `authproxy-routes`): "otel-collector*" matches the short
	// service name, "otel-collector.rossoctl-system.svc.cluster.local"
	// matches the FQDN, "*-collector" matches any single-label name
	// ending in -collector. Port is stripped before matching, so
	// patterns must NOT include `:port`.
	//
	// Empty list (default) preserves current behavior: every outbound
	// host runs the pipeline and is eligible for session recording.
	//
	// Trust model — the value matched against SkipHosts is the
	// destination Host as observed at the listener boundary, which is
	// agent-influenceable in two of the three deployment shapes:
	//
	//   - ext_proc / envoy-sidecar: matches Envoy's `:authority`
	//     (fallback `host` header). The agent sets these; Envoy may
	//     rewrite them per its config, but ultimately the value is
	//     "what the agent told Envoy it wanted to talk to."
	//   - HTTP forward-proxy / proxy-sidecar: matches `r.Host` from
	//     the HTTP request. The request is then dialed against
	//     `r.URL`, so a forged Host that diverges from the real URL
	//     host would skip-match yet send to the actual upstream.
	//   - CONNECT-tunnel / proxy-sidecar: safer-by-construction —
	//     `r.Host` IS the dial target. A forged Host cannot
	//     skip-match while dialing elsewhere.
	//
	// Implication: do NOT list a destination here that you'd want
	// IBAC / token-exchange to deny on. Skip means "the operator
	// trusts every flow to this host enough to bypass the entire
	// outbound enforcement pipeline." Limit entries to infrastructure
	// destinations the agent should not be making policy decisions
	// against in the first place (collector sidecars, log shippers).
	//
	// Each skip is logged at INFO with the matched host and pattern
	// so an operator reviewing logs can see when a pattern fired and
	// catch unexpected matches early. The `transparentproxy` listener
	// (proxy-sidecar enforce-redirect mode) intentionally does NOT
	// consult SkipHosts — that is the hard egress guard and must not
	// be self-exemptable via the agent's outbound destination.
	//
	// When EgressAllowHosts (or MOCA_EGRESS_ALLOW) is non-empty, the
	// allowlist is checked FIRST and a skip pattern cannot exempt an
	// off-list host: the allowlist is the outer boundary.
	//
	// Match-all patterns ("*", "**", whitespace-only) and patterns
	// containing ":port" are rejected at startup so a single
	// misconfigured entry can't silently disable all outbound
	// enforcement. Mirrors the bypass-pattern guard added to ibac
	// in #496.
	SkipHosts []string `yaml:"skip_hosts" json:"skip_hosts"`

	// ResponsesWebSockets is what the forward proxy does with a WebSocket upgrade on
	// an OpenAI Responses API path (a GET with Upgrade: websocket on a path ending
	// /responses — Codex's transport): one of the ResponsesWebSockets* values below.
	// Empty means the default, ResponsesWebSocketsParse. See
	// ResponsesWebSocketsMode.
	ResponsesWebSockets string `yaml:"responses_websockets,omitempty" json:"responses_websockets,omitempty"`

	// EgressAllowHosts is the forward proxy's deny-by-default destination
	// allow list (#1483, MOCA MI1 §8.5): when non-empty, an outbound
	// destination not on the list is refused with 403 destination_denied
	// naming the host — header X-Moca-Egress-Error, text/plain body
	// "destination_denied: <host>\n", the moca egress conformance
	// contract's refusal shape — before the plugin pipeline, before DNS
	// resolution and before any dial, so an off-list host is answered by
	// name rather than left to time out. Applies to CONNECT targets,
	// absolute-form http:// hosts, and the target a plugin's redirect
	// moved a request to.
	//
	// Entries are "host:port", exact match (no globs — a wildcard in a
	// security boundary is one typo from "allow everything", so the shapes
	// that would widen it are rejected at startup). Hosts compare
	// lowercased without a trailing dot; a destination naming no port
	// defaults to its scheme's (80 http, 443 otherwise).
	//
	// Checked BEFORE skip_hosts: when the list is on it is the outer
	// boundary, and a skip_hosts entry for an off-list host is refused,
	// not honored — bypass must not become an egress bypass.
	//
	// When this field is empty, the binary falls back to the
	// MOCA_EGRESS_ALLOW environment variable (comma-separated host:port
	// entries) — the channel the MOCA conformance harness drives the
	// target with. Both empty means the feature is off and outbound
	// behavior is unchanged.
	//
	// SCOPE — this gates the FORWARD PROXY's paths only, and "outer
	// boundary" above means outer with respect to skip_hosts, not with
	// respect to every way a byte can leave the pod. Not covered:
	//
	//   - the transparent listener (listener.transparent_proxy_addr,
	//     proxy-sidecar enforce-redirect mode): egress that iptables
	//     REDIRECTs there is NOT filtered by this list.
	//     HandleTransparentConn runs the shared pipeline but dials the
	//     recovered destination without consulting it. Note the contrast
	//     with SkipHosts above, which that listener also does not consult
	//     — there the omission hardens the boundary, here it leaves a way
	//     around this one.
	//   - the extproc listener (envoy-sidecar mode): no wiring at all —
	//     only cmd/cortex builds a Matcher, and only onto the forward
	//     proxy server.
	//
	// MOCA shape A is the proxy-sidecar forward proxy and #1483 names
	// CONNECT plus absolute-form only, so that is the scope this field
	// claims. A deployment that also captures traffic by iptables
	// REDIRECT, or runs envoy-sidecar, needs its egress held somewhere
	// else too — deny-by-default here is not deny-by-default for the pod.
	//
	// A listener.* field: changing it requires a restart, like every other
	// listener knob.
	EgressAllowHosts []string `yaml:"egress_allow_hosts,omitempty" json:"egress_allow_hosts,omitempty"`

	// DeclineResponsesWebSockets is the boolean responses_websockets replaced. v0.9.4
	// shipped it, so a config that sets it keeps working: when responses_websockets is
	// unset, true reads as decline and false as forward — under #1488 a forwarded
	// upgrade is a real one, which is what false asked for — and Validate warns,
	// naming the new key. Setting both is refused, since they can disagree.
	//
	// Deprecated: use ResponsesWebSockets.
	DeclineResponsesWebSockets *bool `yaml:"decline_responses_websockets,omitempty" json:"decline_responses_websockets,omitempty"`

	// EgressGuard arms the SSRF dial guard on the forward proxy's every
	// outbound dial (#1484): each destination is resolved once, refused with
	// 403 destination_private when it lands in loopback, link-local (cloud
	// metadata, 169.254.169.254), RFC 1918 / unique-local space, RFC 6598
	// CGNAT (100.64.0.0/10), or one of this host's own interface addresses —
	// the addresses themselves, not their on-link subnets — and dialed at the
	// checked address, so DNS rebinding cannot re-answer between check and
	// connect. CONNECT tunnels, plain and bridged requests, transparent
	// redirects and skip_hosts traffic are all covered: a bypass must not
	// become an SSRF bypass.
	//
	// OFF BY DEFAULT, deliberately: a sidecar's ordinary upstreams — Keycloak,
	// in-cluster services, a laptop's local model — live in exactly the
	// refused space, so defaulting this on would break every existing
	// deployment. An operator who wants the hard boundary (or runs the MOCA
	// shape, where the sandbox's egress is meant to be public-only) enables it
	// and lists the private prefixes still allowed in permit_cidrs.
	//
	// permit_cidrs covers prefixes within the refused space only; link-local,
	// unspecified, multicast and the AWS IPv6 metadata address
	// (fd00:ec2::254) are NEVER permitted, whatever the list says — the
	// metadata ranges are what this guard exists among other things to
	// protect.
	//
	// A pointer so "absent" (off) stays distinguishable from an explicit
	// enabled: false, as SessionConfig.Enabled is. Listener.* field:
	// changing it requires a restart, like every other listener knob.
	EgressGuard *EgressGuardConfig `yaml:"egress_guard,omitempty" json:"egress_guard,omitempty"`

	// UpstreamProxy is the parent proxy that the forward proxy sends its own egress
	// through: an http://host:port URL, for a forward proxy in an agent VM whose only
	// way out is an egress gateway. Empty (the default) dials every destination
	// directly. It is explicit, and HTTPS_PROXY is never read in its place, because on
	// a laptop HTTPS_PROXY points at Cortex itself. Restart-only.
	UpstreamProxy string `yaml:"upstream_proxy,omitempty" json:"upstream_proxy,omitempty"`

	// StampAttribution makes the forward proxy add the X-Cortex-* attribution headers
	// to the requests it sends upstream, so that a Cortex at an egress gateway files
	// them under the session this proxy resolved. Off by default: no X-Cortex-* header
	// leaves the proxy. Restart-only.
	StampAttribution bool `yaml:"stamp_attribution,omitempty" json:"stamp_attribution,omitempty"`

	// ExtProcOutboundOnly makes the ext_proc listener run the outbound pipeline for
	// every request and ignore x-authbridge-direction, for an ext_proc that sees only
	// egress (a gateway pod). It is refused with inbound plugins configured, which
	// would never run. Restart-only.
	ExtProcOutboundOnly bool `yaml:"ext_proc_outbound_only,omitempty" json:"ext_proc_outbound_only,omitempty"`

	// ExtProcRecordAll makes the ext_proc listener record every outbound request and its
	// response, as the forward proxy does: also one that no parser or plugin marked, such
	// as a tool's curl or git at an egress gateway. Off by default: such a request leaves
	// no row. Each row takes memory and, with session.archive, disk. skip_hosts still
	// records nothing. Restart-only.
	ExtProcRecordAll bool `yaml:"ext_proc_record_all,omitempty" json:"ext_proc_record_all,omitempty"`

	// ExtProcIdentityHeader names the request header from which the ext_proc listener
	// takes the requester's identity (the subject) on the outbound path. The listener
	// removes the header before the request goes upstream. Set it only when an
	// authorizer before ext_proc always overwrites or removes the client's copy.
	// Cortex cannot check who set the header. Restart-only.
	ExtProcIdentityHeader string `yaml:"ext_proc_identity_header,omitempty" json:"ext_proc_identity_header,omitempty"`

	// ExtProcBodyMode sets how the ext_proc listener gets request and response
	// bodies from Envoy: "buffered" (the default, also when empty) asks Envoy for
	// BUFFERED bodies through mode_override, and Envoy's buffer limit applies.
	// "full_duplex" expects FULL_DUPLEX_STREAMED in the Envoy filter config: the
	// listener sends no mode_override and collects the body chunks itself, up to
	// ExtProcMaxBodyBytes. Cortex refuses any other value. Restart-only.
	ExtProcBodyMode string `yaml:"ext_proc_body_mode,omitempty" json:"ext_proc_body_mode,omitempty"`

	// ExtProcMaxBodyBytes is the largest body that the ext_proc listener collects
	// in full_duplex mode. 0 means 32 MiB. It applies only with ext_proc_body_mode:
	// full_duplex; Cortex refuses it with buffered, and refuses a negative value.
	// Restart-only.
	ExtProcMaxBodyBytes int `yaml:"ext_proc_max_body_bytes,omitempty" json:"ext_proc_max_body_bytes,omitempty"`
}

ListenerConfig holds per-mode listener addresses.

func (ListenerConfig) ActiveRoles

func (l ListenerConfig) ActiveRoles() map[string]bool

ActiveRoles returns the set of proxy roles to run in proxy-sidecar mode. An empty Roles list defaults to BOTH roles (the full pod deployment), so existing configs and the operator path are unchanged; a non-empty list runs exactly the roles named. Unknown values are surfaced by Validate, not here.

func (ListenerConfig) InboundTransparent

func (l ListenerConfig) InboundTransparent() bool

InboundTransparent reports whether the inbound transparent listener should run instead of the fixed-backend reverse proxy. Empty means the default (reverse-proxy), so callers need no separate zero-value check.

func (ListenerConfig) ResponsesWebSocketsMode

func (l ListenerConfig) ResponsesWebSocketsMode() string

ResponsesWebSocketsMode is ListenerConfig.ResponsesWebSockets with the default applied: parse, in every deployment.

Parse is the default because it is the transport Codex asks for and the one it performs best on: one socket for a whole session, with later turns sending only new input instead of the whole conversation. Every turn on it is still parsed — model, tokens, cost, tool calls — so carrying it costs Cortex no visibility, and where it cannot be carried the socket is declined rather than broken. Decline and forward are the escape hatches: decline keeps Codex on HTTPS without delay, and forward hands the socket across as every other WebSocket is, working but opaque.

A config that still sets the deprecated decline_responses_websockets, and not this key, gets the mode that boolean meant (see DeclineResponsesWebSockets).

type MTLSConfig

type MTLSConfig struct {
	// Mode controls the inbound + outbound TLS posture. Defaults to
	// permissive when empty.
	Mode MTLSMode `yaml:"mode" json:"mode"`
}

MTLSConfig is the top-level mTLS schema. One mode applies to both directions; if asymmetric needs surface later, this can split into separate Inbound / Outbound sub-blocks without breaking the existing flat shape.

X.509-SVID material is supplied by the in-process Provider (see SPIFFEConfig) and no longer configured here. Legacy chart configs may still ship cert_file / key_file / bundle_file keys; the YAML loader silently drops them (pinned by TestLoad_UnknownMTLSFields_Ignored).

func (*MTLSConfig) ResolvedMode

func (m *MTLSConfig) ResolvedMode() MTLSMode

ResolvedMode returns Mode with the empty-string default applied.

func (*MTLSConfig) Validate

func (m *MTLSConfig) Validate() error

Validate rejects unknown mode values at startup. SVID material is supplied by the SPIFFE Provider (see SPIFFEConfig); validation of that material is the Provider's responsibility, not this struct's.

type MTLSMode

type MTLSMode string

MTLSMode names the inbound + outbound TLS posture. Vocabulary borrows from Istio's PeerAuthentication.mtls.mode for familiarity.

const (
	// MTLSModePermissive accepts both TLS and plaintext on the
	// inbound side (byte-peek listener) and tries TLS on the outbound
	// side, falling back to plain TCP on handshake failure. The
	// rollout-friendly default; when an operator omits the mode
	// field, this is what they get.
	MTLSModePermissive MTLSMode = "permissive"
	// MTLSModeStrict accepts only TLS on the inbound side (byte-peek
	// closes non-TLS connections) and treats outbound TLS handshake
	// failures as hard errors with no fallback. Production posture
	// once the cluster is fully mTLS-capable.
	MTLSModeStrict MTLSMode = "strict"
)

type MemoryConfig

type MemoryConfig struct {
	// LimitMB is the soft limit in megabytes. Zero disables the limit (an
	// explicitly-set zero is kept as "off"); the block absent entirely leaves
	// the defaulting to the binary — cmd/cortex applies
	// DefaultLocalMemoryLimitMB for a local install, none anywhere else.
	LimitMB int `yaml:"limit_mb" json:"limit_mb"`
}

MemoryConfig applies a Go runtime soft memory limit at boot. The limit is SOFT by the runtime's contract: near it the GC runs more often (trading CPU for memory — that is where the savings come from), and a live heap that genuinely exceeds it is allowed to grow past it rather than fail any allocation. The failure mode of setting it too low is slowness near the limit, never a crash. It counts Go-managed memory (heap, stacks, runtime structures); cgo allocations, the CPEX build's FFI included, sit outside it.

It exists because nothing in cmd/ or core/ bounded the runtime's appetite: with GOGC at its default the heap is sized to ~2x live, and session-API reads leave the memory they expand from the store's sharing as idle RSS — measured, a live heap of ~1.4GB carried 2.9GB of RSS (#1541). A limit caps both.

Boot-only, like mtls: apply it where the process starts, not per reload.

type MetricsPushConfig

type MetricsPushConfig struct {
	// Enabled is nil for the default, true.
	Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	// URL is the collector's base URL; the exporter posts to <url>/v1/metrics. https, or http
	// to a loopback address only.
	URL string `yaml:"url,omitempty" json:"url,omitempty"`
	// Token is the collector's bearer token. Empty sends no Authorization header.
	Token string `yaml:"token,omitempty" json:"token,omitempty"`
	// Interval is how often the counters are pushed. Zero means DefaultMetricsPushInterval.
	Interval time.Duration `yaml:"interval,omitempty" json:"interval,omitempty"`
}

MetricsPushConfig is the top-level `metrics_push:` block: where Cortex pushes the accountant's llm.savings.* counters, over OTLP/HTTP, to the central collector (design §5.10).

metrics_push:
  enabled: true     # default true, but with no URL nothing is sent
  url: ""           # no default; METRICS_PUSH_URL overrides
  token: ""         # METRICS_PUSH_TOKEN; sent as Authorization: Bearer <token>
  interval: 60s     # METRICS_PUSH_INTERVAL

There is no default URL in code: with no URL nothing leaves the machine. The built-in ~/.cortex/config.yaml (cmd/cortex/local.go) writes the central collector's URL. The block is the same in a cluster and on a laptop.

NOT HOT-RELOADABLE: the push is started once at boot, so a reload that changes the block is refused (reloader.validateReloadable), as for listener.*. The token is never logged; /config serves it redacted (core/redact matches the key "token").

func (MetricsPushConfig) IsEnabled

func (m MetricsPushConfig) IsEnabled() bool

IsEnabled is Enabled with its default, true.

func (MetricsPushConfig) On

func (m MetricsPushConfig) On() bool

On reports whether anything is pushed: enabled, and a URL to push to.

func (*MetricsPushConfig) Resolve

func (m *MetricsPushConfig) Resolve(env func(string) string) MetricsPushConfig

Resolve returns the block with the environment applied: METRICS_PUSH (a boolean), METRICS_PUSH_URL, METRICS_PUSH_TOKEN and METRICS_PUSH_INTERVAL (a Go duration) override the file, and an unset interval becomes DefaultMetricsPushInterval. Safe on a nil receiver; the receiver is not changed.

A METRICS_PUSH that is not a boolean turns the push off, so a typo never sends anything. A METRICS_PUSH_INTERVAL that is not a positive duration keeps the configured interval.

func (MetricsPushConfig) Validate

func (m MetricsPushConfig) Validate() error

Validate refuses a URL that is not https, other than http to a loopback address, a URL with user info or a query string (neither is sent: the credential belongs in Token), and a negative interval. An empty URL is valid: nothing is pushed. The error never quotes the token, and quotes the URL only as SafeURL gives it.

WHERE A BAD BLOCK IS CAUGHT: the block as written in the YAML is checked by config.Validate, so a bad one fails config.Load like any other block. The METRICS_PUSH_* environment is applied at runtime (Resolve) and checked again by push.Start; a bad METRICS_PUSH_URL only WARNs and turns the push off, and the proxy runs (accounting fails open).

type PipelineConfig

type PipelineConfig struct {
	Inbound  PipelineStageConfig `yaml:"inbound" json:"inbound"`
	Outbound PipelineStageConfig `yaml:"outbound" json:"outbound"`
}

PipelineConfig holds the plugin pipeline composition. Required: the runtime YAML must populate both inbound and outbound lists, or plugins.Build will produce empty pipelines and the listener will have nothing to invoke. There are no implicit defaults.

type PipelineStageConfig

type PipelineStageConfig struct {
	Plugins []PluginEntry `yaml:"plugins" json:"plugins"`
}

PipelineStageConfig lists the plugins for a pipeline stage in execution order.

type PlannedListener

type PlannedListener struct {
	Name string
	Addr string
}

PlannedListener is one socket the proxy serves: Name is how callers ask for it and how an error names it, Addr as configured.

func ListenerPlan

func ListenerPlan(cfg *Config, local bool) ([]PlannedListener, error)

ListenerPlan lists every socket the proxy serves, under the same conditions it serves them — the one list both the proxy (cmd/cortex's reserveListeners binds it, and take and claimed make a disagreement with what main serves fatal at boot) and anything that wants those sockets free before it starts (agentop setup's port preflight) work from.

local is the local-install flag: a config under ~/.cortex, whichever flag started it. A local install has no iptables to REDIRECT to the transparent listeners, so it never binds them.

type PluginEntry

type PluginEntry struct {
	Name    string               `yaml:"name" json:"name"`
	ID      string               `yaml:"id,omitempty" json:"id,omitempty"`
	OnError pipeline.ErrorPolicy `yaml:"on_error,omitempty" json:"on_error,omitempty"`
	Config  json.RawMessage      `yaml:"-" json:"config,omitempty"`
}

PluginEntry names a plugin and optionally carries per-instance config.

The YAML accepts both the bare-name form ("jwt-validation") and the full form ({name, id, on_error, config}). The short form keeps existing pipeline configs parsing unchanged; the long form is what plugins that implement pipeline.Configurable actually need. See docs/plugin-reference.md for the convention plugins follow when decoding Config.

Config is captured as a raw subtree via json.RawMessage so the plugin can do its own DisallowUnknownFields decode against a typed struct — the framework does not interpret it.

OnError is the framework-owned wrapper policy (see ErrorPolicy). Plugin authors do not consume it — it lives outside the plugin's own config block so all plugins get the same rollout story without each one re-implementing shadow mode.

func (*PluginEntry) UnmarshalYAML

func (p *PluginEntry) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML accepts either a bare string or a map. The string form is equivalent to {name: <string>} with no config.

type PraxisConfig

type PraxisConfig struct {
	Enabled bool                `yaml:"enabled" json:"enabled"`
	Listen  string              `yaml:"listen,omitempty" json:"listen,omitempty"`
	Egress  string              `yaml:"egress,omitempty" json:"egress,omitempty"`
	Policy  *PraxisPolicyConfig `yaml:"policy,omitempty" json:"policy,omitempty"`
}

PraxisConfig is the top-level `praxis:` block. Listen is cortex-gateway's listener, where the forward proxy's hop sends each recorded request. Egress is Cortex's egress listener, where the gateway sends each request on to its origin.

func (*PraxisConfig) EgressAddr

func (p *PraxisConfig) EgressAddr() string

EgressAddr returns praxis.egress, or DefaultPraxisEgress when it is empty or the block is nil.

func (*PraxisConfig) ListenAddr

func (p *PraxisConfig) ListenAddr() string

ListenAddr returns praxis.listen, or DefaultPraxisListen when it is empty or the block is nil.

type PraxisPolicyConfig

type PraxisPolicyConfig struct {
	ConfigPath string `yaml:"config_path" json:"config_path"`
}

PraxisPolicyConfig is `praxis.policy:`, the Praxis policy filter that cortex-gateway runs.

type SPIFFEConfig

type SPIFFEConfig struct {
	// Socket is the SPIRE agent socket URL. Defaults to
	// "unix:///spiffe-workload-api/spire-agent.sock" — the same path
	// spiffe-helper used to talk to.
	Socket string `yaml:"socket" json:"socket"`

	// MirrorFiles, when true, runs an in-process goroutine that writes
	// /opt/svid.pem, /opt/svid_key.pem, /opt/svid_bundle.pem, and
	// /opt/jwt_svid.token on every rotation — preserving today's
	// external-reader contract (Envoy filesystem SDS, e2e probes,
	// debugging shells). Pointer so we can distinguish unset
	// ("apply default true") from explicit false ("operator opted out").
	MirrorFiles *bool `yaml:"mirror_files" json:"mirror_files"`

	// MirrorDir is the directory where mirror files are written.
	// Defaults to "/opt". Only used when MirrorFiles is true.
	MirrorDir string `yaml:"mirror_dir" json:"mirror_dir"`
}

SPIFFEConfig is the top-level SPIFFE provider configuration. One block drives the in-process Provider that supplies X.509-SVIDs to the mTLS listeners and a JWT-SVID to the token-exchange plugin (when configured).

Defaults match the file layout spiffe-helper used to write. They apply only when this block is present: Load() gates them on non-nil, and an absent block constructs no Provider at all.

The audience for the JWT-SVID used by token-exchange as a client assertion is per-plugin (tokenexchange.identity.jwt_audience) and is no longer carried here — only the tokenexchange plugin's spiffe identity path consumes it, so it lives in that plugin's config.

func (*SPIFFEConfig) Validate

func (s *SPIFFEConfig) Validate() error

Validate rejects sockets that aren't unix:// URLs. The Workload API only speaks over a unix domain socket in our deployment model; a tcp:// or http:// scheme is almost certainly an operator typo and should fail at startup rather than at first dial.

type SessionArchiveConfig

type SessionArchiveConfig struct {
	// Enabled is a pointer so unset can follow the default; see ArchiveRunsOnLocalInstall.
	// false always wins.
	Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	// RetentionDays is how long a segment is kept after its last write. 0 means the default,
	// 30.
	RetentionDays int `yaml:"retention_days,omitempty" json:"retention_days,omitempty"`
	// MaxBytes bounds the archive's size; the oldest segments go first past it. 0 means the
	// default, 2 GiB.
	MaxBytes int64 `yaml:"max_bytes,omitempty" json:"max_bytes,omitempty"`
	// Dir is where the archive writes. Empty means ~/.cortex/sessions, which only a local install
	// uses. Must be absolute, for the reason cost_ledger.dir must be. The archive owns everything
	// under it: a clear deletes Dir/data whole, so Dir must be a directory nothing else uses.
	Dir string `yaml:"dir,omitempty" json:"dir,omitempty"`
}

SessionArchiveConfig is `session.archive`: the session archive, which persists every session to disk so it survives a restart and the store's own eviction (core/session/archive).

A LAPTOP FEATURE. The cortex binary runs it from a config inside ~/.cortex, where it writes to ~/.cortex/sessions, or from any config that sets Dir. A cluster cannot start it by mounting a volume over ~/.cortex: someone must write Dir. And off loopback, where DELETE /v1/sessions cannot clear it, someone must also write enabled: true. See ArchiveRunsOnLocalInstall.

Nested under `session` rather than top-level like cost_ledger, because it records through the session store: the dependency is structural. And because reloader.validateReloadable refuses any live change under `session`, changing this needs a restart with no code of its own.

func (*SessionArchiveConfig) ArchiveEnabled

func (c *SessionArchiveConfig) ArchiveEnabled(defaultOn bool) bool

ArchiveEnabled reports whether the archive should run, given the caller's default for an unset block. Safe on a nil receiver.

func (*SessionArchiveConfig) DirSet

func (c *SessionArchiveConfig) DirSet() bool

DirSet reports whether the config names a directory for the archive. Safe on a nil receiver.

func (*SessionArchiveConfig) Validate

func (c *SessionArchiveConfig) Validate() error

Validate is called from the loader when session.archive is present.

type SessionConfig

type SessionConfig struct {
	// Enabled: nil means "unset → default on". Explicit `false` opts out.
	// Do not change to a plain bool — losing the nil sentinel would collapse
	// "user didn't say" with "user said false" and silently flip the default.
	Enabled *bool `yaml:"enabled" json:"enabled"`
	// TTL bounds how long an IDLE session is kept. Empty or "0" means never, which is
	// the default: time-based expiry read as data loss — traffic vanished because
	// someone stepped away, not because anything overflowed. Set it to a duration
	// ("30m") where limiting how long raw prompts sit in memory is worth the surprise,
	// or where one long-lived session would otherwise grow without limit — with
	// MaxEvents unset, a ttl is the only thing that bounds that shape. See Limits for
	// how the three resolve together and why the default is what it is.
	TTL string `yaml:"ttl" json:"ttl"` // duration string; default: never

	// MaxEvents bounds how many events ONE session keeps, oldest evicted first.
	// Unset (0) means unlimited, which is the default: a trimmed store is lossy on
	// exactly the sessions worth reading, and the trim point is invisible from the
	// timeline. Set it where one long-lived chatty session would otherwise grow
	// without limit — MaxSessions bounds how MANY sessions are kept, not how big any
	// one of them gets, so it is no help against a single session that never ends.
	MaxEvents int `yaml:"max_events" json:"max_events"` // max events per session; default: unlimited
	// MaxSessions bounds how many sessions are kept at once, least-recently-updated
	// evicted first. Unset means 100.
	//
	// NOT "0 = unlimited", which is what this said and what the store would do with a
	// zero it was handed: Limits substitutes 100 for any value <= 0, so the documented
	// unlimited was unreachable through every binary. It cannot be honoured either,
	// because MaxSessions is a plain int — an operator who never mentions max_sessions
	// yields the same 0 as one who writes it, so honouring 0 would delete the default
	// for everyone who left it alone, and with MaxEvents now unset that is the last
	// default bound standing. Distinguishing the two would take a *int, the way Enabled
	// above uses a *bool for exactly this reason. Not worth it for a value nobody has
	// asked for: to lift the cap, set it high.
	MaxSessions int `yaml:"max_sessions" json:"max_sessions"` // max concurrent sessions; default: 100 (<= 0 means default)

	// IDHeaders names the request headers consulted, in order, for a
	// client-supplied session id to bucket events under. Unset means the built-in
	// list of supported-agent headers (see SessionIDHeaders); an explicit list
	// REPLACES that default rather than extending it, and an explicit empty list
	// turns header bucketing off and puts every session back in one shared bucket.
	// The unset default also reads X-Session-Id on a loopback-only install (see
	// SessionIDHeadersFor).
	// Like Enabled above, the nil-versus-empty distinction is load-bearing — do
	// not collapse it by assigning a default at load time.
	//
	// The ids these headers carry are client-asserted and unauthenticated: a
	// client can name any bucket, including another session's. The store is
	// in-process, so the reach of that is every client that can reach this proxy
	// — one workload for a sidecar, but all of them for a shared or standalone
	// forward proxy, which binds a wildcard address by default. Set this to an
	// empty list in any deployment where telemetry attribution is a trust
	// boundary rather than a convenience. See session.IDFromHeaders for the full
	// reasoning.
	IDHeaders []string `yaml:"id_headers" json:"id_headers"`

	// ClientAffinity files a request that carries NO session header under the newest
	// session of the same coding agent (by User-Agent), rather than under the single
	// most-recently-updated session. nil means "unset → default on"; explicit `false`
	// opts out. Read it through ClientAffinityEnabled.
	//
	// It matters where more than one coding agent shares this proxy — Claude Code and
	// Bob Shell on one laptop. Without it each agent's header-less calls (Bob's startup
	// probes and task classifier, Claude Code's WebFetch) land in whichever session spoke
	// last, which is the other agent's half the time. With it, a known agent's calls
	// before its first header collect in a pending:<agent> bucket that its first
	// session adopts, and traffic from no known agent goes to the default bucket while
	// two agents have both sent traffic in the last five minutes; tunnel rows keep
	// ActiveSession(). Anything else resolves exactly as before, which is what keeps
	// in-cluster A2A correlation intact. Needs id_headers non-empty; see
	// session.Store.SessionForClient.
	//
	// ON BY DEFAULT because the template is not enough. Only the --local built-in config
	// used to turn it on, and that file is written once and never regenerated, so every
	// laptop installed before the key existed kept filing Bob's classifier completions —
	// real inference, priced in Bob's own unit — under a concurrent Claude Code session.
	// A pointer, like Enabled above, so the default can flip without taking away the
	// off switch.
	ClientAffinity *bool `yaml:"client_affinity" json:"client_affinity"`

	// ProcessAttribution files a request that carries no session header under the session
	// of the process that sent it, or of its nearest ancestor that named one, looked up
	// from the kernel by core/peerproc — so a tool an agent's shell runs, its gh and git
	// tunnels and its WebFetch land in the agent's session, and a process of no agent in
	// none. "auto", the default (and what an empty value means), turns it on exactly when
	// listener.bind_loopback_only is set: only there is every client a process on this
	// host. "on" and "off" force it. Needs id_headers non-empty, like client_affinity. Only
	// the cortex binary acts on it. Not hot-reloadable. See session.Store.SessionForProcess.
	ProcessAttribution string `yaml:"process_attribution" json:"process_attribution"`

	// Archive is the session archive, which persists sessions to disk on a laptop install. Nil
	// means the binary's default. See SessionArchiveConfig.
	Archive *SessionArchiveConfig `yaml:"archive,omitempty" json:"archive,omitempty"`

	// StampMaxNewPerMinute caps how many new sessions X-Cortex-Session stamps can
	// create per minute in the ext_proc listener. Over the cap, a stamp is ignored and
	// the request files as if it carried none. 0 means the default, 30 (see
	// StampNewPerMinute). Below 0 is refused. Restart-only.
	StampMaxNewPerMinute int `yaml:"stamp_max_new_per_minute,omitempty" json:"stamp_max_new_per_minute,omitempty"`
}

SessionConfig controls in-memory session tracking for cross-request correlation. When enabled, the framework records inbound intents and outbound tool calls so that guardrail plugins can evaluate sequences across request boundaries.

Enabled is a pointer so the loader can distinguish "unset" (apply default) from "explicitly false" (user opted out). Default when unset: enabled.

func (SessionConfig) ClientAffinityEnabled

func (s SessionConfig) ClientAffinityEnabled() bool

ClientAffinityEnabled reports whether header-less requests are filed by coding agent. Defaults to true when ClientAffinity is unset, so operators need to explicitly opt out.

func (SessionConfig) Limits

func (s SessionConfig) Limits() (SessionLimits, error)

Limits resolves the session store's parameters from config.

One home for what used to be the same twenty lines in three main packages, kept in step by review alone. It is also the only way to assert the part that matters most and is easiest to get wrong in one copy: MaxEvents passes through UNMODIFIED, so an operator who has not set session.max_events gets a store that never evicts an event from a live session.

The defaults, and why they are not symmetrical:

  • TTL 0 (never expire on time). Time-based expiry read as data loss — traffic vanished because someone stepped away, not because anything overflowed. Note what this does NOT rest on any more: it used to be justified by "the size caps still bound memory", and with MaxEvents unset by default that is no longer true for a single long-lived session. TTL stays 0 because a clock is the wrong tool for bounding memory, not because something else is bounding it.
  • MaxEvents 0 (unlimited). A trimmed store is lossy on exactly the sessions worth reading, and FIFO eviction takes the BEGINNING of a session — on a long agent run, the inbound request that started it — with no mark left in the timeline.
  • MaxSessions 100, for any configured value <= 0 including unset. This one keeps a default because it bounds how MANY sessions are kept, which is the dimension that grows without an operator doing anything unusual, and evicting a whole idle session costs less than truncating a live one. So the resolved MaxSessions is always positive, which is why LogAttrs does not render an "unlimited" for it the way it does for MaxEvents.

So on a single session that never ends, nothing here is a ceiling: set max_events or a ttl for that shape. A negative max_events means unlimited, the same as unset — it used to fall back to 500, and the startup log reports the resolved value either way.

A malformed session.ttl yields the zero TTL and is returned as an error for the caller to log; resolution stays here, logging stays at the edge.

func (SessionConfig) ProcessAttributionEnabled

func (s SessionConfig) ProcessAttributionEnabled(loopbackOnly bool) bool

ProcessAttributionEnabled reports whether header-less requests are filed by the process that sent them, given whether every listener binds loopback only.

func (SessionConfig) SessionEnabled

func (s SessionConfig) SessionEnabled() bool

SessionEnabled returns true when session tracking should run. Defaults to true when Enabled is unset, so operators need to explicitly opt out.

func (SessionConfig) SessionIDHeaders

func (s SessionConfig) SessionIDHeaders() []string

SessionIDHeaders returns the headers to consult for a client-supplied session id, defaulting to the known coding-agent session headers when unset: bucketing per coding-agent session is the point of running this on a laptop, and an operator should not have to learn a header name to get it. An explicit empty list disables the lookup.

The order is a precedence rule over clients, not a ranking — a request carrying both headers buckets under the Claude Code id. See session.IDFromHeaders.

Whatever this returns, a request that carries none of the named headers buckets exactly as it did before this option existed.

func (SessionConfig) SessionIDHeadersFor

func (s SessionConfig) SessionIDHeadersFor(loopbackOnly bool) []string

SessionIDHeadersFor is SessionIDHeaders for a deployment that knows whether every listener binds loopback only. On a laptop install (loopbackOnly) the unset default also reads session.SessionIDHeader — X-Session-Id, which OpenCode, Pi (with its Cortex extension) and similar frameworks send — and session.CodexSessionHeader, the bare Session-Id Codex sends. Everywhere else the default is SessionIDHeaders' own: both are generic names, and an in-cluster agent that sends one for its own reasons (the IBAC demo's does, with an id it minted) would otherwise have its calls filed away from the session that holds its user's intent. An explicit list is used as it is, either way.

CodexSessionHeader goes LAST, and the order is the point rather than an accident: it is the least namespaced of the four, so every client sending a dedicated header still wins the bucket. See session.IDFromHeaders for what the precedence means.

func (SessionConfig) StampNewPerMinute

func (s SessionConfig) StampNewPerMinute() int

StampNewPerMinute is StampMaxNewPerMinute with the default applied: 30 when unset.

type SessionLimits

type SessionLimits struct {
	TTL         time.Duration
	MaxEvents   int
	MaxSessions int
}

SessionLimits is the resolved form of the three store parameters: what session.New should be called with, after defaults.

func (SessionLimits) LogAttrs

func (l SessionLimits) LogAttrs() []any

LogAttrs renders the resolved limits for a startup line, spelling out the two zeros that would otherwise read as misconfiguration: "ttl=0s" as if sessions expired instantly, "maxEvents=0" as if the store kept nothing. Takes limits as Limits produces them, where MaxSessions is always positive.

type StatsConfig

type StatsConfig struct {
	StatsAddress string `yaml:"address" json:"address"` // for example, ":9093"
}

StatsConfig represents the configuration for reporting config and statistics

type SubscriptionWeights

type SubscriptionWeights struct {
	Input        float64 `yaml:"input" json:"input"`
	CacheWrite5m float64 `yaml:"cache_write_5m" json:"cache_write_5m"`
	CacheWrite1h float64 `yaml:"cache_write_1h" json:"cache_write_1h"`
	CacheRead    float64 `yaml:"cache_read" json:"cache_read"`
	Output       float64 `yaml:"output" json:"output"`
}

SubscriptionWeights are the usage-limit weight of one token in each tier (accountant design §7.1). A subscription bills no dollars per token; it draws down a usage limit, and the weights say how much of it a token of each tier uses. The defaults are the API rate ratios.

func DefaultSubscriptionWeights

func DefaultSubscriptionWeights() SubscriptionWeights

DefaultSubscriptionWeights are the API rate ratios: input 1, cache write 5m 1.25, cache write 1h 2, cache read 0.1, output 5 (design §5.7a).

func (*SubscriptionWeights) UnmarshalYAML

func (w *SubscriptionWeights) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML starts from the defaults, so a key the block leaves out keeps its default weight and an explicit 0 stays 0.

type TLSBridgeConfig

type TLSBridgeConfig struct {
	// Mode is the bridge posture: "disabled" (off) or "enabled" (intercept all
	// eligible egress on the configured Ports). Empty == disabled.
	Mode string `yaml:"mode" json:"mode"` // disabled | enabled
	// CADir holds the per-agent signing CA, mounted from the operator's
	// cert-manager Secret. The bridge reads tls.crt + tls.key (to sign leaves);
	// ca.crt is the trust cert handed to the agent. cert-manager Secret key
	// conventions, so only the directory is configured.
	CADir string `yaml:"ca_dir" json:"ca_dir"`
	// GenerateCA, when true, makes the bridge mint and persist a self-signed CA
	// into CADir (tls.crt/tls.key/ca.crt) if those files are absent, instead of
	// failing at startup. For standalone / demo use only — in-cluster the CA is
	// a mounted cert-manager Secret and this stays false so a missing Secret
	// fails loudly rather than silently forging leaves under an untrusted CA.
	// CADir should persist across restarts: on ephemeral storage (e.g. an
	// emptyDir) a fresh CA is minted each boot, so clients must re-trust the
	// new ca.crt.
	GenerateCA bool `yaml:"generate_ca" json:"generate_ca"`
	// UpstreamCABundle is an extra-roots PEM file for re-origination (private-CA
	// origins the agent trusts); empty == system roots only.
	UpstreamCABundle string `yaml:"upstream_ca_bundle" json:"upstream_ca_bundle"`
	// UpstreamInsecure disables origin cert verification on re-origination
	// (InsecureSkipVerify). For internal/self-signed upstreams when the origin CA
	// is unavailable. Prefer UpstreamCABundle when possible.
	UpstreamInsecure bool `yaml:"upstream_insecure" json:"upstream_insecure"`
	// PassthroughHosts are hosts to tunnel (never intercept). Distinct from
	// listener.skip_hosts, which bypasses the whole pipeline; these still run the
	// egress gate, they just aren't TLS-terminated. Set, it replaces the built-in default
	// list; `passthrough_hosts: []` intercepts every host but PassthroughHostsExtra.
	PassthroughHosts []string `yaml:"passthrough_hosts" json:"passthrough_hosts"`
	// PassthroughHostsExtra are more hosts to tunnel, added to whichever list applies:
	// PassthroughHosts when set, the built-in default list otherwise (none under
	// fail_closed). So passing one more host through, such as a GitHub Enterprise server
	// or an internal registry, does not mean copying the default list into
	// PassthroughHosts and keeping the copy current by hand (#2149).
	PassthroughHostsExtra []string `yaml:"passthrough_hosts_extra" json:"passthrough_hosts_extra"`
	// Ports is the set of TCP ports to intercept as TLS. Empty => {443, 8443}.
	// Only HTTP(S)-bearing ports belong here: the bridge serves the decrypted
	// stream as HTTP/1.1 or h2, so terminating a non-HTTP TLS protocol (LDAPS,
	// SMTPS, DB-over-TLS, …) would break it.
	Ports []int `yaml:"ports" json:"ports"`
	// FailClosed makes interception a requirement rather than a best effort, for a
	// shared host where an opaque tunnel is a policy bypass. A host the bridge
	// intercepts is always intercepted, or refused: no skip memory, no fallback
	// tunnel, an SNI that must name the CONNECT host, and an unverified origin
	// answered 502 upstream_unverified. The default passthrough list does not
	// apply; an explicit passthrough_hosts still tunnels.
	FailClosed bool `yaml:"fail_closed" json:"fail_closed"`
}

TLSBridgeConfig configures the outbound TLS bridge (TLS termination of agent egress — formerly "MITM" — so the outbound plugin pipeline sees decrypted HTTPS).

func (*TLSBridgeConfig) Validate

func (b *TLSBridgeConfig) Validate() error

Validate is called from the loader when TLSBridge != nil.

type UpdateConfig

type UpdateConfig struct {
	Auto *bool `yaml:"auto,omitempty" json:"auto,omitempty"`
	// Wait is how long after its publication agentop update --auto waits before it
	// installs a release. A duration string. Default DefaultUpdateWait. "0" installs at once.
	Wait string `yaml:"wait,omitempty" json:"wait,omitempty"`
	// CheckEvery is how often the proxy starts the updater. A duration string from
	// 1h to 24h. Default DefaultUpdateCheckEvery. A change needs a restart.
	CheckEvery string `yaml:"check_every,omitempty" json:"check_every,omitempty"`
}

UpdateConfig is the top-level `update:` block.

func (*UpdateConfig) Times

func (u *UpdateConfig) Times() (wait, checkEvery time.Duration, err error)

Times resolves update.wait and update.check_every. Nil-safe on u. On an error it returns the defaults with the error.

check_every is at least 1h, so the updater does not run too often. It is at most 24h, because agentop reports "no update check" after 72h.

Jump to

Keyboard shortcuts

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