Documentation
¶
Overview ¶
Package broker is the egress credential broker's engine: a reconciler-less reverse proxy that agent pods address directly (base-URL env overrides in the pod point the claude CLI at it) and that injects or signs the model credential outbound. It is what makes agent pods fully credential-less — the pod authenticates to the broker with an audience-bound projected ServiceAccount token (an identity document, not a capability), and the broker alone holds the Anthropic API key or the cloud workload identity that signs Bedrock/Vertex/Foundry traffic.
One route per upstream, keyed by path prefix (anthropic, bedrock, vertex, foundry). The route set is the extension seam for future brokered upstreams (forge-minted GitHub tokens, package registries). Every request is authenticated via TokenReview before any upstream contact, audited as a single slog line (never bodies or headers), and streamed through with immediate flushing so SSE responses survive multi-minute runs.
Index ¶
- Constants
- func ParseTarget(raw string) (*url.URL, error)
- type Config
- type CredentialFunc
- type Server
- type Upstream
- func Anthropic(target *url.URL, keyFile string, bearer bool) Upstream
- func Bedrock(ctx context.Context, target *url.URL, region string) (Upstream, error)
- func FoundryEntra(target *url.URL) (Upstream, error)
- func FoundryKey(target *url.URL, keyFile string) Upstream
- func Vertex(ctx context.Context, target *url.URL) (Upstream, error)
Constants ¶
const ( // DefaultAudience is the projected-token audience callers must present. DefaultAudience = "patchy-egress-broker" // DefaultVerdictTTL bounds TokenReview QPS: one review per caller token // per TTL, not one per request. DefaultVerdictTTL = time.Minute // DefaultPingInterval is the SSE idle keep-alive period. DefaultPingInterval = 30 * time.Second // DefaultMaxRequestBytes caps a buffered (SigV4-signed) request body. DefaultMaxRequestBytes = 10 << 20 )
Default knob values, applied by Config.withDefaults.
const TokenHeader = provider.BrokerTokenHeader
TokenHeader carries the caller's projected ServiceAccount token. It is stripped before any byte is forwarded upstream: the token authenticates the caller to the broker and must never travel further.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Audience is the projected-token audience callers must present.
Audience string
// AgentNamespace/AgentServiceAccount pin the only identity the broker
// answers to: system:serviceaccount:<AgentNamespace>:<AgentServiceAccount>.
AgentNamespace string
AgentServiceAccount string
// VerdictTTL is how long one token's TokenReview verdict is cached.
VerdictTTL time.Duration
// PingInterval is the SSE idle keep-alive period; 0 takes the default,
// negative disables ping injection (pure passthrough).
PingInterval time.Duration
// MaxRequestBytes caps a buffered request body (BufferBody routes).
MaxRequestBytes int64
// Upstreams is the route table, keyed by path prefix
// ("anthropic"/"bedrock"/"vertex"/"foundry").
Upstreams map[string]Upstream
}
Config configures the broker engine.
type CredentialFunc ¶
CredentialFunc attaches the upstream credential to one outbound request: inject an API key header, attach an OAuth bearer, or SigV4-sign. It runs on the rewritten outbound request, after the caller's broker token and any inbound authorization headers have been stripped.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the broker engine: authenticated, audited reverse proxies for the configured upstream routes.
func New ¶
New builds a Server. cs performs the TokenReviews; the broker needs no other Kubernetes access of any kind.
func (*Server) Handler ¶
Handler is the proxy surface: one subtree per configured route, everything under it requiring a valid caller token — plus the (unauthenticated) probe endpoints, so controllers can check readiness over the same Service URL agent pods proxy through.
func (*Server) HealthHandler ¶
HealthHandler serves the probe endpoints on the health listener: healthz is liveness, readyz additionally requires every configured route's credential source to be usable — which is what replaces controller-side Secret probing as "is the model credential present". Neither touches the API server: TokenReview being down must fail requests, not probes.
type Upstream ¶
type Upstream struct {
// Target is the upstream base URL the route prefix maps onto.
Target *url.URL
// Credential attaches the upstream credential; nil forwards unmodified.
Credential CredentialFunc
// BufferBody buffers the request body in memory (bounded by
// Config.MaxRequestBytes) before forwarding — required when Credential
// hashes the payload, as SigV4 does.
BufferBody bool
// Ready reports whether the route's credential source is usable; readyz
// fails while any configured route's is not. Nil means always ready.
Ready func(ctx context.Context) error
}
Upstream is one brokered route: where it forwards and how it credentials.
func Anthropic ¶
Anthropic is the first-party route: inject the credential from a mounted Secret file and forward otherwise unchanged — the anthropic-version and anthropic-beta headers the CLI sends pass through, so prompt caching and beta features survive the hop. An API key rides x-api-key; bearer=true sends Authorization: Bearer instead, which is how a `claude setup-token` OAuth token authenticates. Either way the file is read per request, so a rotated Secret propagates without a restart.
func Bedrock ¶
Bedrock is the Amazon Bedrock route: SigV4-sign each request with the broker's ambient AWS identity (IRSA / EKS Pod Identity / env credentials — whatever config.LoadDefaultConfig resolves) and forward. The route buffers bodies: SigV4 signs a hash of the payload, so the whole body must be in hand before the request leaves.
func FoundryEntra ¶
FoundryEntra is the Foundry route in Entra mode: attach a bearer token from the broker's ambient Azure identity (Workload Identity in-cluster), cached and refreshed broker-side — which is what fixes a static bearer expiring mid-run on long evaluation jobs.
func FoundryKey ¶
FoundryKey is the Microsoft Foundry route in API-key mode: inject the key from a mounted Secret file, same rotation posture as the Anthropic route.