authlib

module
v0.0.0-...-4ef879c Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0

README

authlib — Shared Auth Building Blocks

A pure Go library providing reusable building blocks for JWT validation, OAuth 2.0 token exchange, and SPIFFE-based authentication. No protocol dependencies (no gRPC, no Envoy).

Packages

Shared building blocks (used by ≥2 plugins or the framework):

Package Purpose
contracts/ Tiny, stable vocabulary plugins depend on without importing each other — role constants (RoleUser, RoleAssistant, …), the ContentSource / Fragment shape for guardrail-parser interop, and claim constants (ClaimAuthorizationHeader, …) for PluginCapabilities.Claims mutex declarations.
bypass/ Path pattern matcher for public endpoints (health, agent card). Any inbound gate plugin (jwt-validation, SAML, mTLS) can use it.
routing/ Host-to-audience router with glob pattern matching. Used by token-exchange; future routed plugins are expected to reuse it.
auth/ Composition layer: HandleInbound + HandleOutbound — used internally by the jwt-validation and token-exchange plugins. Lingering in authlib/ for now; plugin-internal in practice.
config/ YAML config loader, mode presets, credential-file waiters, top-level validation
pipeline/ Plugin pipeline + lifecycle (Configurable, Initializer, Shutdowner) — see docs/framework-architecture.md
session/ In-memory session store + SessionSummary aggregation, backing the :9094 API
sessionapi/ HTTP API (/v1/sessions, /v1/events SSE, /v1/pipeline) exposing the session store
reloader/ fsnotify-based config hot-reload — atomic pipeline swap on ConfigMap change
observe/ /stats, /config, /reload/status HTTP server

Plugins and their internals:

Package Purpose
plugins/ Registry + parser plugins (a2a-parser, mcp-parser, inference-parser) + shared Build + StatsSource contract
plugins/jwtvalidation/ The jwt-validation plugin. Owns plugins/jwtvalidation/validation/ (JWKS-backed JWT verifier).
plugins/tokenexchange/ The token-exchange plugin. Owns plugins/tokenexchange/exchange/ (RFC 8693 client) and plugins/tokenexchange/cache/ (token TTL cache). Its JWT-SVID source is the framework's spiffe/, not a plugin-internal copy.
plugins/plugintesting/ Test helpers — stubs of jwt-validation / token-exchange that skip file IO, for listener-level tests.

Packages that used to live at authlib/validation, authlib/exchange, authlib/cache moved under their owning plugin. They had no reuse outside that plugin; keeping them at authlib/ top-level implied wider usefulness than reality. New plugins should follow the same pattern: if the package is plugin-internal, colocate it under plugins/<plugin>/.

Usage

Plugins own their own configuration and construct any auth.Auth they need internally from their per-plugin config (see docs/plugin-reference.md). Host processes (cmd/authbridge) just load the YAML, call plugins.Build, run the pipelines, and let each plugin handle its own dependencies.

import (
    "github.com/rossoctl/cortex/authbridge/authlib/config"
    "github.com/rossoctl/cortex/authbridge/authlib/plugins"
)

cfg, _ := config.Load("config.yaml")
config.ApplyPreset(cfg)
_ = config.Validate(cfg) // mode + listener combo only; plugins self-validate

inbound,  _ := plugins.Build(cfg.Pipeline.Inbound.Plugins)
outbound, _ := plugins.Build(cfg.Pipeline.Outbound.Plugins)

_ = inbound.Start(ctx)   // invokes Init on plugins that implement pipeline.Initializer
_ = outbound.Start(ctx)

// Listeners drive the pipelines — see cmd/authbridge/listener/*

For direct use of the auth/ composition layer (outside of plugins), see auth/auth.go — auth.New(cfg) takes an auth.Config containing the specific building blocks a caller needs.

Go Module

module github.com/rossoctl/cortex/authbridge/authlib

Direct dependencies: lestrrat-go/jwx/v2, gobwas/glob, gopkg.in/yaml.v3. No gRPC or Envoy deps.

Directories

Path Synopsis
Package auth composes authlib building blocks into HandleInbound and HandleOutbound — the two functions that all listeners call.
Package auth composes authlib building blocks into HandleInbound and HandleOutbound — the two functions that all listeners call.
Package bypass provides path pattern matching for skipping JWT validation on public endpoints (e.g., health probes, agent card discovery).
Package bypass provides path pattern matching for skipping JWT validation on public endpoints (e.g., health probes, agent card discovery).
Package clientstate owns the on-disk record abctl writes when it points an agent at Cortex, and which authbridge-proxy reads back to check the agent is still pointed at the CA in force.
Package clientstate owns the on-disk record abctl writes when it points an agent at Cortex, and which authbridge-proxy reads back to check the agent is still pointed at the CA in force.
Package config provides YAML-based configuration with mode presets and startup validation for the AuthBridge auth layer.
Package config provides YAML-based configuration with mode presets and startup validation for the AuthBridge auth layer.
Package contracts defines capability interfaces that protocol extensions implement to participate in framework services like content inspection, session bucketing, and summarization.
Package contracts defines capability interfaces that protocol extensions implement to participate in framework services like content inspection, session bucketing, and summarization.
Package costevent is the canonical wire shape of the per-request cost that litellm-budget-track publishes onto a session event.
Package costevent is the canonical wire shape of the per-request cost that litellm-budget-track publishes onto a session event.
Package costing turns one response's facts into one settled cost.
Package costing turns one response's facts into one settled cost.
Package costledger persists per-minute cost and token totals to disk so "what did today cost" survives a restart.
Package costledger persists per-minute cost and token totals to disk so "what did today cost" survives a restart.
internal
hostglob
Package hostglob is the one place cortex turns an operator-supplied host pattern into a matcher, and the one place that decides what counts as a dangerously broad pattern.
Package hostglob is the one place cortex turns an operator-supplied host pattern into a matcher, and the one place that decides what counts as a dangerously broad pattern.
listener
extproc
Package extproc implements an Envoy ext_proc gRPC streaming listener.
Package extproc implements an Envoy ext_proc gRPC streaming listener.
forwardproxy
Package forwardproxy implements an HTTP forward proxy listener.
Package forwardproxy implements an HTTP forward proxy listener.
httpx
Package httpx contains HTTP-listener helpers shared between the forwardproxy and reverseproxy listeners.
Package httpx contains HTTP-listener helpers shared between the forwardproxy and reverseproxy listeners.
internal/bodyread
Package bodyread reports why buffering a request body failed.
Package bodyread reports why buffering a request body failed.
internal/sseframe
Package sseframe reads complete Server-Sent Event frames off a streaming HTTP response body.
Package sseframe reads complete Server-Sent Event frames off a streaming HTTP response body.
internal/tlssniff
Package tlssniff provides a net.Listener wrapper that detects whether each accepted connection is a TLS handshake or a plain HTTP request, and dispatches accordingly.
Package tlssniff provides a net.Listener wrapper that detects whether each accepted connection is a TLS handshake or a plain HTTP request, and dispatches accordingly.
reverseproxy
Package reverseproxy implements an HTTP reverse proxy listener.
Package reverseproxy implements an HTTP reverse proxy listener.
skiphost
Package skiphost matches an outbound destination Host against an operator-configured pattern list to decide whether the listener should short-circuit — bypassing the plugin pipeline and session recording — and forward the request as a transparent proxy.
Package skiphost matches an outbound destination Host against an operator-configured pattern list to decide whether the listener should short-circuit — bypassing the plugin pipeline and session recording — and forward the request as a transparent proxy.
transparentproxy
Package transparentproxy implements transparent (iptables-REDIRECTed) proxy listeners for proxy-sidecar mode.
Package transparentproxy implements transparent (iptables-REDIRECTed) proxy listeners for proxy-sidecar mode.
Package llmclient is a small helper for calling OpenAI-compatible chat-completions endpoints from authbridge plugins.
Package llmclient is a small helper for calling OpenAI-compatible chat-completions endpoints from authbridge plugins.
claude
Package claude owns the Claude Code session-metadata contract: the shape abctl's harvester writes to ~/.cortex/session-metadata.json, the path it lives at, and the harvest that produces it.
Package claude owns the Claude Code session-metadata contract: the shape abctl's harvester writes to ~/.cortex/session-metadata.json, the path it lives at, and the harvest that produces it.
Package placeholder defines the convention for opaque credential handles: a random "abph_" token the agent receives in place of the real Authorization value, plus the namespaced key used to store the real token in a shared store.
Package placeholder defines the convention for opaque credential handles: a random "abph_" token the agent receives in place of the real Authorization value, plus the namespaced key used to store the real token in a shared store.
contextguru
Package contextguru is an outbound AuthBridge plugin that compacts an agent's LLM request context before it is forwarded upstream, using the embedded github.com/rossoctl/context-guru engine.
Package contextguru is an outbound AuthBridge plugin that compacts an agent's LLM request context before it is forwarded upstream, using the embedded github.com/rossoctl/context-guru engine.
cpex
Package cpex bridges AuthBridge requests through the CPEX (Context Plugin Execution) framework so operators can drive policy with CPEX's APL (Attribute Policy Language) DSL — or any of the pre-built CPEX plugins (Cedar PDP, PII scanner, audit logger, JWT identity, OAuth delegation) — without writing Go code.
Package cpex bridges AuthBridge requests through the CPEX (Context Plugin Execution) framework so operators can drive policy with CPEX's APL (Attribute Policy Language) DSL — or any of the pre-built CPEX plugins (Cedar PDP, PII scanner, audit logger, JWT identity, OAuth delegation) — without writing Go code.
ibac
Package ibac implements an Intent-Based Access Control plugin for authbridge.
Package ibac implements an Intent-Based Access Control plugin for authbridge.
internal/parsercommon
Package parsercommon holds small helpers shared by the in-tree protocol parser plugins (a2a-parser, mcp-parser, inference-parser).
Package parsercommon holds small helpers shared by the in-tree protocol parser plugins (a2a-parser, mcp-parser, inference-parser).
jwtvalidation/validation
Package validation provides JWT verification with JWKS-based key resolution.
Package validation provides JWT verification with JWKS-based key resolution.
lineage
Package lineage provides the lineage-telemetry authbridge plugin.
Package lineage provides the lineage-telemetry authbridge plugin.
litellm_budgettrack
Package litellm_budgettrack provides a pipeline plugin that tracks per-request cost and enforces a daily spending budget, rejecting requests with HTTP 429 when the budget is exceeded.
Package litellm_budgettrack provides a pipeline plugin that tracks per-request cost and enforces a daily spending budget, rejecting requests with HTTP 429 when the budget is exceeded.
opa
plugintesting
Package plugintesting exposes stub plugin adapters for listener tests that need to inject pre-built *auth.Auth instances (for example, with a mock verifier or a mock exchanger) without going through the real plugins' Configure path.
Package plugintesting exposes stub plugin adapters for listener tests that need to inject pre-built *auth.Auth instances (for example, with a mock verifier or a mock exchanger) without going through the real plugins' Configure path.
sessionbudget
Package sessionbudget enforces per-session lifetime budgets on tokens, inference calls, and wall-clock duration.
Package sessionbudget enforces per-session lifetime budgets on tokens, inference calls, and wall-clock duration.
sparc
Package sparc implements a pre-tool reflection plugin for authbridge.
Package sparc implements a pre-tool reflection plugin for authbridge.
staticinject
Package staticinject implements the static-inject outbound AuthBridge plugin: it swaps a placeholder credential on the outbound Authorization header for a real static credential, so a model-influenced workload never holds the real secret.
Package staticinject implements the static-inject outbound AuthBridge plugin: it swaps a placeholder credential on the outbound Authorization header for a real static credential, so a model-influenced workload never holds the real secret.
tokenbroker/client
Package client provides an HTTP client for the Token Broker service.
Package client provides an HTTP client for the Token Broker service.
tokenexchange/cache
Package cache provides a SHA-256 keyed token cache with TTL-based eviction.
Package cache provides a SHA-256 keyed token cache with TTL-based eviction.
tokenexchange/exchange
Package exchange implements RFC 8693 OAuth 2.0 Token Exchange and client credentials grant.
Package exchange implements RFC 8693 OAuth 2.0 Token Exchange and client credentials grant.
toolprune
Package toolprune removes unused tool definitions from outbound inference requests.
Package toolprune removes unused tool definitions from outbound inference requests.
Package praxis converts an AuthBridge config.Config into a Praxis proxy configuration (https://github.com/praxis-proxy/praxis).
Package praxis converts an AuthBridge config.Config into a Praxis proxy configuration (https://github.com/praxis-proxy/praxis).
Package pricing owns model rates and the arithmetic that turns tokens into dollars.
Package pricing owns model rates and the arithmetic that turns tokens into dollars.
internal/gen command
Command gen regenerates the bundled price table from LiteLLM's public price map.
Command gen regenerates the bundled price table from LiteLLM's public price map.
internal/pricegen
Package pricegen turns LiteLLM's public model_prices_and_context_window.json into pricing.Entry rows and renders them as Go source.
Package pricegen turns LiteLLM's public model_prices_and_context_window.json into pricing.Entry rows and renders them as Go source.
Package redact provides best-effort stripping of sensitive values from JSON config payloads served by unauthenticated diagnostic endpoints.
Package redact provides best-effort stripping of sensitive values from JSON config payloads served by unauthenticated diagnostic endpoints.
Package reloader watches a config file and atomically swaps the inbound / outbound plugin pipelines when the file changes.
Package reloader watches a config file and atomically swaps the inbound / outbound plugin pipelines when the file changes.
Package routing provides host-to-audience routing for token exchange.
Package routing provides host-to-audience routing for token exchange.
Package runtimeutil holds process-level helpers shared by the authbridge binaries (authbridge-proxy, authbridge-cpex, authbridge-envoy).
Package runtimeutil holds process-level helpers shared by the authbridge binaries (authbridge-proxy, authbridge-cpex, authbridge-envoy).
Package session provides an in-memory session store for correlating inbound user intents with outbound tool calls across request boundaries.
Package session provides an in-memory session store for correlating inbound user intents with outbound tool calls across request boundaries.
Package sessionapi exposes AuthBridge's in-memory session store over HTTP: JSON snapshots plus an SSE stream of live events.
Package sessionapi exposes AuthBridge's in-memory session store over HTTP: JSON snapshots plus an SSE stream of live events.
Package shared provides a generic, process-scoped, TTL key→value store that plugins reach via pipeline.Context.Shared.
Package shared provides a generic, process-scoped, TTL key→value store that plugins reach via pipeline.Context.Shared.
authlib/spiffe/consumer.go
authlib/spiffe/consumer.go
Package tls builds *crypto/tls.Config values for authbridge's reverse-proxy and forward-proxy listeners using a SPIRE X.509 SVID source.
Package tls builds *crypto/tls.Config values for authbridge's reverse-proxy and forward-proxy listeners using a SPIRE X.509 SVID source.
Package tlsbridge implements AuthBridge's outbound TLS bridge: it forges a per-origin leaf so the agent's egress TLS terminates at AuthBridge, the existing outbound pipeline runs on the decrypted request, and the call is relayed over a separately-verified upstream TLS connection.
Package tlsbridge implements AuthBridge's outbound TLS bridge: it forges a per-origin leaf so the agent's egress TLS terminates at AuthBridge, the existing outbound pipeline runs on the decrypted request, and the call is relayed over a separately-verified upstream TLS connection.
Package usage aggregates session events into fixed-width time buckets so a client can chart volume, errors, latency and cost over wall-clock time.
Package usage aggregates session events into fixed-width time buckets so a client can chart volume, errors, latency and cost over wall-clock time.

Jump to

Keyboard shortcuts

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