auth

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 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 provides authentication middleware for the registry API server.

Index

Constants

This section is empty.

Variables

View Source
var DefaultValidatorFactory validatorFactory = func(
	ctx context.Context,
	cfg auth.TokenValidatorConfig,
) (tokenValidatorInterface, error) {
	return auth.NewTokenValidator(ctx, cfg)
}

DefaultValidatorFactory uses the real ToolHive token validator.

Functions

func IsPublicPath

func IsPublicPath(requestPath string, publicPaths []string) bool

IsPublicPath checks if a path should bypass authentication. It performs secure path matching by: 1. Rejecting paths with encoded path separators to prevent double-encoding attacks 2. Normalizing the path to prevent traversal attacks (e.g., /health/../registry/v0.1/servers) 3. Using segment-aware matching so /health matches /health and /health/check but NOT /healthcheck

func NewAuthMiddleware

func NewAuthMiddleware(
	ctx context.Context,
	cfg *config.AuthConfig,
	factory validatorFactory,
) (func(http.Handler) http.Handler, http.Handler, error)

NewAuthMiddleware creates authentication middleware based on config. Returns: (middleware, authInfoHandler, error)

By default, authentication is ENABLED and requires OAuth configuration. To disable authentication for development, either:

  • Use --auth-mode=anonymous flag
  • Set auth.mode: anonymous in the config file

This function validates the auth configuration before creating the middleware.

func WrapWithPublicPaths

func WrapWithPublicPaths(
	authMw func(http.Handler) http.Handler,
	publicPaths []string,
) func(http.Handler) http.Handler

WrapWithPublicPaths wraps an auth middleware to bypass authentication for public paths. It checks each request path against the provided list of public paths using IsPublicPath. Requests to public paths are passed directly to the next handler without authentication, while all other requests go through the provided auth middleware.

Types

This section is empty.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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