Documentation
¶
Overview ¶
Package auth composes authlib building blocks into HandleInbound and HandleOutbound — the two functions that all listeners call.
Index ¶
- Constants
- func ExtractBearer(authHeader string) string
- type AudienceDeriver
- type Auth
- func (a *Auth) HandleInbound(ctx context.Context, authHeader, path, audience string) *InboundResult
- func (a *Auth) HandleOutbound(ctx context.Context, authHeader, host string) *OutboundResult
- func (a *Auth) InboundAudiences() []string
- func (a *Auth) IncInboundApprove(reason InboundApprovalReason)
- func (a *Auth) IncInboundDeny(reason InboundDenialReason)
- func (a *Auth) IncOutboundApprove(reason OutboundApprovalReason)
- func (a *Auth) IncOutboundDeny(reason OutboundDenialReason)
- func (a *Auth) IncOutboundReplaceToken(reason OutboundReplaceTokenReason)
- func (a *Auth) Ready() bool
- func (a *Auth) UpdateIdentity(id IdentityConfig, clientAuth exchange.ClientAuth)
- type Config
- type IdentityConfig
- type InboundApprovalReason
- type InboundDenialReason
- type InboundResult
- type OutboundApprovalReason
- type OutboundDenialReason
- type OutboundReplaceTokenReason
- type OutboundResult
- type Stats
Constants ¶
const ( ActionAllow = "allow" ActionDeny = "deny" )
Inbound actions.
const ( NoTokenPolicyClientCredentials = "client-credentials" NoTokenPolicyAllow = "allow" NoTokenPolicyDeny = "deny" )
No-token outbound policies (set by mode preset).
const (
ActionReplaceToken = "replace_token"
)
Outbound actions.
Variables ¶
This section is empty.
Functions ¶
func ExtractBearer ¶
ExtractBearer pulls the token out of an HTTP `Authorization` header value. Returns the token (no "Bearer " prefix) on a well-formed bearer header, "" otherwise. The "Bearer" scheme match is case-insensitive per RFC 6750 §2.1.
Used by every listener that touches request headers — extproc, forwardproxy, reverseproxy — so it lives here in authlib/auth (the home of the bearer/JWT composition layer) rather than being duplicated per listener.
Types ¶
type AudienceDeriver ¶
AudienceDeriver derives a target audience from a request host, for the per-host audience modes (jwt-validation's audience_mode: per-host and token-exchange's audience_from_host) that name the audience after the destination service instead of configuring it statically. Returns "" if no derivation is possible (falls back to route config).
type Auth ¶
type Auth struct {
Stats *Stats
// contains filtered or unexported fields
}
Auth composes authlib building blocks into inbound validation and outbound exchange.
func (*Auth) HandleInbound ¶
func (a *Auth) HandleInbound(ctx context.Context, authHeader, path, audience string) *InboundResult
HandleInbound validates an inbound request's JWT token. audience overrides the default expected audience when non-empty. This supports the per-host audience mode, where the audience is derived per request from the destination host. Pass "" to use the configured default.
func (*Auth) HandleOutbound ¶
func (a *Auth) HandleOutbound(ctx context.Context, authHeader, host string) *OutboundResult
HandleOutbound processes an outbound request, performing token exchange if needed.
func (*Auth) InboundAudiences ¶
InboundAudiences returns a copy of the configured expected audiences for inbound JWT validation (may be empty before credentials load).
func (*Auth) IncInboundApprove ¶
func (a *Auth) IncInboundApprove(reason InboundApprovalReason)
IncInboundApprove records a new approval (for statistics)
func (*Auth) IncInboundDeny ¶
func (a *Auth) IncInboundDeny(reason InboundDenialReason)
IncInboundDeny records a new denial (for statistics)
func (*Auth) IncOutboundApprove ¶
func (a *Auth) IncOutboundApprove(reason OutboundApprovalReason)
IncOutboundApprove records a new approval (for statistics)
func (*Auth) IncOutboundDeny ¶
func (a *Auth) IncOutboundDeny(reason OutboundDenialReason)
IncOutboundDeny records a new denial (for statistics)
func (*Auth) IncOutboundReplaceToken ¶
func (a *Auth) IncOutboundReplaceToken(reason OutboundReplaceTokenReason)
func (*Auth) UpdateIdentity ¶
func (a *Auth) UpdateIdentity(id IdentityConfig, clientAuth exchange.ClientAuth)
UpdateIdentity updates the agent's identity and exchanger credentials after credential files have been resolved. This is called from a background goroutine after the gRPC listener has started.
type Config ¶
type Config struct {
Verifier validation.Verifier
Exchanger *exchange.Client
Cache *cache.Cache
Bypass *bypass.Matcher
Router *routing.Router
Identity IdentityConfig
NoTokenPolicy string // NoTokenClientCredentials, NoTokenAllow, or NoTokenDeny
AudienceDeriver AudienceDeriver // optional, derives audience from host (per-host audience modes)
Logger *slog.Logger
}
Config holds the resolved dependencies for the auth layer.
type IdentityConfig ¶
type IdentityConfig struct {
ClientID string // agent's OAuth client ID (used by token-exchange)
Audiences []string // expected inbound JWT audiences (jwt-validation); at least one required for static inbound validation
Issuer string // expected JWT iss (jwt-validation); inbound debug logging only
}
IdentityConfig holds the agent's identity for audience validation and token exchange.
type InboundApprovalReason ¶
type InboundApprovalReason int
InboundApprovalReason enumerates the rationale for inbound validation success.
const ( APPROVE_PASSTHROUGH InboundApprovalReason = iota APPROVE_AUTHORIZED )
func (InboundApprovalReason) String ¶
func (r InboundApprovalReason) String() string
type InboundDenialReason ¶
type InboundDenialReason int
InboundDenialReason enumerates the reasons for inbound validation failure.
const ( DENY_NO_HEADER InboundDenialReason = iota DENY_MALFORMED_HEADER DENY_VALIDATOR_MISSING DENY_JWT_FAILED )
func (InboundDenialReason) String ¶
func (r InboundDenialReason) String() string
type InboundResult ¶
type InboundResult struct {
Action string // ActionAllow or ActionDeny
Claims *validation.Claims // non-nil when a valid JWT was present
DenyStatus int // HTTP status code (e.g., 401)
DenyReason string // human-readable error — safe for logs, response bodies
DenyReasonCode InboundDenialReason // machine-stable enum paired with the /stats counter; use for filtering / indexing session events
}
InboundResult is the outcome of inbound JWT validation.
type OutboundApprovalReason ¶
type OutboundApprovalReason int
OutboundApprovalReason enumerates the rationale for outbound validation success.
const ( OUTBOUND_NO_MATCHING_ROUTE OutboundApprovalReason = iota OUTBOUND_NO_EXCHANGER OUTBOUND_PASSTHROUGH OUTBOUND_NO_TOKEN_POLICY )
func (OutboundApprovalReason) String ¶
func (r OutboundApprovalReason) String() string
type OutboundDenialReason ¶
type OutboundDenialReason int
OutboundDenialReason enumerates the reasons for outbound denial.
const ( OUTBOUND_CREDS_REQUESTED_NO_EXCHANGER OutboundDenialReason = iota OUTBOUND_CREDENTIALS_GRANT_FAILURE OUTBOUND_NO_TOKEN OUTBOUND_TOKEN_EXCHANGE_FAILED )
func (OutboundDenialReason) String ¶
func (r OutboundDenialReason) String() string
type OutboundReplaceTokenReason ¶
type OutboundReplaceTokenReason int
OutboundReplaceTokenReason enumerates the reasons for outbound token exchange.
const ( OUTBOUND_ACTION_REPLACE_TOKEN OutboundReplaceTokenReason = iota OUTBOUND_ACTION_CACHE_HIT )
func (OutboundReplaceTokenReason) String ¶
func (r OutboundReplaceTokenReason) String() string
type OutboundResult ¶
type OutboundResult struct {
Action string // ActionAllow, ActionReplaceToken, or ActionDeny
Token string // replacement token (when Action == ActionReplaceToken)
DenyStatus int // HTTP status code (e.g., 503)
DenyReason string // human-readable error
DenyReasonCode OutboundDenialReason // machine-stable enum paired with the /stats counter
CacheHit bool // true when Token was served from the exchange cache; safe to read on any Action
// Route context populated when the router matched the request. Gives
// observability callers (token-exchange plugin writing a SessionEvent)
// a way to surface which route was chosen without reaching into
// routing.ResolvedRoute directly. RouteMatched=false means the
// request passed through because no route fired.
RouteMatched bool // true when Router.Resolve returned a non-nil route (regardless of action)
TargetAudience string // resolved route's audience (or deriver's output); empty on passthrough
RequestedScopes string // resolved route's scopes, raw space-separated; empty on passthrough
}
OutboundResult is the outcome of outbound token exchange.
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
Stats holds statistics for validation and exchange. The current implementation keeps approvals/denials/exchange as counters.
func MergeStats ¶
MergeStats returns a new Stats whose counters are the sum of all srcs. Each src's mutex is taken independently; the returned Stats has its own storage and no relationship to the sources. Safe to call concurrently — sources are only read under their own locks.
Used by the /stats aggregator to fold per-plugin counters into a single response per HTTP request without leaking plugin-local Stats instances into the presentation layer.