middleware

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware for the MCP Kubernetes server. These middleware functions handle security headers, CORS, and other cross-cutting concerns.

Index

Constants

View Source
const EventTokenMissingIdentity = "token_missing_identity"

EventTokenMissingIdentity is the audit event type emitted when a structurally valid bearer token reaches /mcp without an email claim, so Kubernetes impersonation cannot proceed.

Variables

This section is empty.

Functions

func CORS

func CORS(allowedOrigins []string) func(http.Handler) http.Handler

CORS adds CORS headers for OAuth endpoints with validated origins

func HTTPMetrics added in v0.0.139

func HTTPMetrics(provider *instrumentation.Provider) func(http.Handler) http.Handler

HTTPMetrics creates middleware that records HTTP request metrics. It records the total number of requests and request duration for each method/path/status combination.

The middleware normalizes paths to prevent high cardinality: - /mcp/{session_id} -> /mcp/:session (for session-based endpoints) - UUID patterns are replaced with :uuid - Numeric IDs are replaced with :id

The provider parameter can be nil, in which case the middleware is a no-op that just passes through to the next handler.

func RequireIdentity added in v0.2.1

func RequireIdentity(auditor *security.Auditor, logger *slog.Logger) func(http.Handler) http.Handler

RequireIdentity rejects requests whose validated UserInfo carries no email claim. Without an email there is no Impersonate-User to send to the Kubernetes API; the request would otherwise pass through and fail later with a misleading "unknown resource type" error from the discovery client.

Must be wired after the OAuth ValidateToken middleware so UserInfo is on the context. Requests without UserInfo are passed through unchanged (ValidateToken already handled those).

func SecurityHeaders

func SecurityHeaders(hstsEnabled bool) func(http.Handler) http.Handler

SecurityHeaders adds comprehensive security headers to all HTTP responses

func ValidateAllowedOrigins

func ValidateAllowedOrigins(originsEnv string) ([]string, error)

ValidateAllowedOrigins validates and normalizes allowed CORS origins

Types

This section is empty.

Jump to

Keyboard shortcuts

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