Documentation
¶
Overview ¶
Package factory provides factory functions for creating vMCP authentication components.
Index ¶
- func BuildAuthzConfig(authzCfg *config.AuthzConfig) (*authz.Config, error)
- func IncomingBearerChallenge(cfg *config.IncomingAuthConfig) auth.BearerChallenge
- func NewIncomingAuthMiddleware(ctx context.Context, cfg *config.IncomingAuthConfig, serverName string, ...) (authMw func(http.Handler) http.Handler, ...)
- func NewOutgoingAuthRegistry(_ context.Context, envReader env.Reader) (auth.OutgoingAuthRegistry, error)
- type IncomingAuthOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAuthzConfig ¶ added in v0.30.1
func BuildAuthzConfig(authzCfg *config.AuthzConfig) (*authz.Config, error)
BuildAuthzConfig builds the authorizer-agnostic *authz.Config that the vMCP core admission seam (core.Config.Authz) consumes from the incoming-auth config, or (nil, nil) when no Cedar policies are configured.
It is the SAME config newCedarAuthzMiddleware builds the HTTP authz middleware from, surfaced so the composition root can feed it to core.New via server.Config.Authz once server.New routes through Serve. The nil return mirrors that middleware's nil result for the no-policies case, preserving allow-all parity (a nil core Authz is allow-all).
func IncomingBearerChallenge ¶ added in v0.70.0
func IncomingBearerChallenge(cfg *config.IncomingAuthConfig) auth.BearerChallenge
IncomingBearerChallenge returns the parameters of the WWW-Authenticate challenges the incoming token validator sends: its issuer as realm, its resource URL for the RFC 9728 metadata, and its scopes. Another vMCP component that refuses a token with 401, such as call binding, sends them too. It returns the zero value for incoming auth without OIDC.
func NewIncomingAuthMiddleware ¶
func NewIncomingAuthMiddleware( ctx context.Context, cfg *config.IncomingAuthConfig, serverName string, passThroughTools map[string]struct{}, upstreamReader upstreamtoken.TokenReader, keyProvider keys.PublicKeyProvider, embeddedAuthServerIssuer string, opts ...IncomingAuthOption, ) ( authMw func(http.Handler) http.Handler, authzMw func(http.Handler) http.Handler, authInfoHandler http.Handler, err error, )
NewIncomingAuthMiddleware creates HTTP middleware for incoming authentication and authorization based on the vMCP configuration.
This factory handles all incoming auth types:
- "oidc": OIDC token validation
- "local": Local OS user authentication
- "anonymous": Anonymous user (no authentication required)
Authentication and authorization are returned as separate middleware to allow the caller to insert discovery and annotation-enrichment middleware between them. This ensures the authz middleware can access tool annotations populated by the discovery pipeline.
All middleware types now directly create and inject Identity into the context, eliminating the need for a separate conversion layer.
The serverName parameter is the VirtualMCPServer name and is used as the Cedar resource entity name in authorization policy evaluation. It must match the resource name used when compiling Cedar policies for this server.
The passThroughTools parameter is optional (pass nil for none). Tool names in this set bypass the response filter's policy check in tools/list responses. This is used when the optimizer is enabled: its meta-tools (find_tool, call_tool) would otherwise be rejected by Cedar default-deny since no policy references them by name. Authorization for the underlying backend tools is enforced by the middleware's call_tool interception.
Returns:
- authMw: Composed auth + MCP parser middleware (auth runs first, then parser)
- authzMw: Authorization middleware (nil if authz is not configured)
- authInfoHandler: Handler for /.well-known/oauth-protected-resource endpoint (may be nil)
- err: Error if middleware creation fails
func NewOutgoingAuthRegistry ¶
func NewOutgoingAuthRegistry( _ context.Context, envReader env.Reader, ) (auth.OutgoingAuthRegistry, error)
NewOutgoingAuthRegistry creates an OutgoingAuthRegistry with all available strategies.
All strategies are registered upfront. Most are stateless; token_exchange and aws_sts maintain an internal per-config cache initialized on first use. This simplifies the factory and eliminates on-demand strategy registration.
Registered Strategies:
- "unauthenticated": Default fallback for backends without auth
- "header_injection": Custom HTTP header injection
- "token_exchange": RFC-8693 OAuth 2.0 token exchange
- "upstream_inject": Per-upstream token injection from stored credentials
- "aws_sts": AWS STS AssumeRoleWithWebIdentity + SigV4 request signing
- "obo": Microsoft Entra on-behalf-of (OBO) token exchange
- "xaa": Cross-Application Access (two-step ID-JAG exchange per draft-ietf-oauth-identity-assertion-authz-grant)
Parameters:
- ctx: Context for any initialization that requires it
- envReader: Environment variable reader for dependency injection
Returns:
- auth.OutgoingAuthRegistry: Registry with all strategies registered
- error: Any error during strategy initialization or registration
Types ¶
type IncomingAuthOption ¶ added in v0.70.0
type IncomingAuthOption func(*incomingAuthOptions)
IncomingAuthOption configures NewIncomingAuthMiddleware.
func WithCallBinding ¶ added in v0.70.0
func WithCallBinding(binding *callbinding.Binding) IncomingAuthOption
WithCallBinding gives the OIDC token validator the call binding that the vMCP server enforces, so it accepts the messages that belong to a call that outlives its token (callbinding.Binding.TokenValidatorOption). Pass the same Binding as the server's CallBinding. It has no effect on local or anonymous incoming auth, whose identities never carry an expiring call-bound token.