auth

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnauthenticated is returned when authentication is required but not provided.
	// This should be mapped to HTTP 401 Unauthorized in handlers.
	ErrUnauthenticated = errors.New("unauthenticated")

	// ErrForbidden is returned when a user is authenticated but lacks permission.
	// This should be mapped to HTTP 403 Forbidden in handlers (or 404 to prevent info leakage).
	ErrForbidden = errors.New("forbidden")
)

Functions

func AuthSessionTo

func AuthSessionTo(ctx context.Context, session Session) context.Context

func AuthnMiddleware

func AuthnMiddleware(authn AuthnProvider, options ...MiddlewareOption) func(ctx huma.Context, next func(huma.Context))

func IsPublicSession added in v0.4.0

func IsPublicSession(s Session) bool

IsPublicSession checks if a session is the PublicSession type.

func IsSystemSession

func IsSystemSession(s Session) bool

IsSystemSession checks if a session is the SystemSession type.

func WithPublicContext added in v0.4.0

func WithPublicContext(ctx context.Context) context.Context

WithPublicContext creates a context carrying a PublicSession.

func WithSystemContext

func WithSystemContext(ctx context.Context) context.Context

WithSystemContext creates a context for internal system operations.

Types

type AuthnProvider

type AuthnProvider interface {
	Authenticate(ctx context.Context, reqHeaders func(name string) string, query url.Values) (Session, error)
}

type Authorizer

type Authorizer struct {
	Authz AuthzProvider
}

func (*Authorizer) Check

func (a *Authorizer) Check(ctx context.Context, verb PermissionAction, resource Resource) error

func (*Authorizer) IsRegistryAdmin

func (a *Authorizer) IsRegistryAdmin(ctx context.Context) bool

type AuthzProvider

type AuthzProvider interface {
	// Check verifies if the session can perform the action on the resource.
	// Used for single-resource operations (get, update, delete).
	Check(ctx context.Context, s Session, verb PermissionAction, resource Resource) error
	// IsRegistryAdmin checks if the session has global permissions (i.e. "*") for the registry
	// Also used by internal operations and database queries that need to bypass filtering.
	IsRegistryAdmin(ctx context.Context, s Session) bool
}

AuthzProvider defines the authorization interface.

type MiddlewareOption added in v0.2.0

type MiddlewareOption func(*middlewareConfig)

func WithPublicPaths added in v0.4.0

func WithPublicPaths(prefixes ...string) MiddlewareOption

WithPublicPaths marks path prefixes as public, bypassing credential authentication and instead carry a PublicSession, so downstream authz hooks still see a session and can scope what anonymous callers may access.

func WithSkipPaths added in v0.2.0

func WithSkipPaths(paths ...string) MiddlewareOption

WithPublicPaths marks paths that can skip authentication and require no authorization. Used for endpoints outside the authz model, such as health and metrics.

type Permission

type Permission struct {
	Action          PermissionAction `json:"action"`
	ResourcePattern string           `json:"resource"`
}

type PermissionAction

type PermissionAction string

PermissionAction represents an action that can be performed on a resource.

const (
	PermissionActionRead    PermissionAction = "read"
	PermissionActionPublish PermissionAction = "publish"
	PermissionActionEdit    PermissionAction = "edit"
	PermissionActionDelete  PermissionAction = "delete"
	PermissionActionDeploy  PermissionAction = "deploy"
)

type PermissionArtifactType

type PermissionArtifactType string

PermissionArtifactType represents the type of artifact that a permission is for.

const (
	PermissionArtifactTypeAgent   PermissionArtifactType = "agent"
	PermissionArtifactTypeSkill   PermissionArtifactType = "skill"
	PermissionArtifactTypeServer  PermissionArtifactType = "server"
	PermissionArtifactTypePrompt  PermissionArtifactType = "prompt"
	PermissionArtifactTypeRuntime PermissionArtifactType = "runtime"
)

type Principal

type Principal struct {
	User User
}

Authn

type PublicAuthzProvider

type PublicAuthzProvider struct{}

PublicAuthzProvider implements the permissive default authorization policy. Integrators can replace it through AppOptions.AuthzProvider.

func NewPublicAuthzProvider

func NewPublicAuthzProvider() *PublicAuthzProvider

NewPublicAuthzProvider creates a new public authorization provider.

func (*PublicAuthzProvider) Check

Check allows every action.

func (*PublicAuthzProvider) IsRegistryAdmin

func (*PublicAuthzProvider) IsRegistryAdmin(context.Context, Session) bool

IsRegistryAdmin returns true because the default provider applies no restrictions.

type PublicSession added in v0.4.0

type PublicSession struct{}

PublicSession is the session carried by requests on public paths (see WithPublicPaths), e.g. the read-only MCP Registry v0.1 compatibility API. A public path still carries a session, so downstream authz hooks run and decide what an anonymous caller may see.

func (*PublicSession) Principal added in v0.4.0

func (s *PublicSession) Principal() Principal

type Resource

type Resource struct {
	Name string
	Type PermissionArtifactType
}

type Session

type Session interface {
	Principal() Principal
}

func AuthSessionFrom

func AuthSessionFrom(ctx context.Context) (Session, bool)

type SystemSession

type SystemSession struct{}

SystemSession is used for internal system operations such as reconciliation.

func (*SystemSession) Principal

func (s *SystemSession) Principal() Principal

type User

type User struct {
	Permissions []Permission
}

Jump to

Keyboard shortcuts

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