auth

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: 14 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 auth composes core building blocks into HandleInbound and HandleOutbound — the two functions that all listeners call.

Index

Constants

View Source
const (
	ActionAllow = "allow"
	ActionDeny  = "deny"
)

Inbound actions.

View Source
const (
	NoTokenPolicyClientCredentials = "client-credentials"
	NoTokenPolicyAllow             = "allow"
	NoTokenPolicyDeny              = "deny"
)

No-token outbound policies (set by mode preset).

View Source
const (
	ActionReplaceToken = "replace_token"
)

Outbound actions.

Variables

This section is empty.

Functions

func ExtractBearer

func ExtractBearer(authHeader string) string

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 core/auth (the home of the bearer/JWT composition layer) rather than being duplicated per listener.

Types

type AudienceDeriver

type AudienceDeriver func(host string) string

AudienceDeriver derives a target audience from a request host, for the per-host audience modes (token-exchange's audience_from_host) that name the audience after the destination service instead of configuring it statically. Outbound only: jwt-validation's inbound audience_mode:per-host was removed — a client-controlled Host must not pick the inbound audience. 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 core building blocks into inbound validation and outbound exchange.

func New

func New(cfg Config) *Auth

New creates an Auth instance from resolved configuration.

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

func (a *Auth) InboundAudiences() []string

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) Ready

func (a *Auth) Ready() bool

Ready returns true if inbound expected audiences have been loaded.

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
	OUTBOUND_NO_AUDIENCE
)

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

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

func MergeStats(srcs ...*Stats) *Stats

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.

func NewStats

func NewStats() *Stats

func (*Stats) MarshalJSON

func (s *Stats) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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