Documentation
¶
Index ¶
- Variables
- func AuthSessionTo(ctx context.Context, session Session) context.Context
- func AuthnMiddleware(authn AuthnProvider, options ...MiddlewareOption) func(ctx huma.Context, next func(huma.Context))
- func IsPublicSession(s Session) bool
- func IsSystemSession(s Session) bool
- func WithPublicContext(ctx context.Context) context.Context
- func WithSystemContext(ctx context.Context) context.Context
- type AuthnProvider
- type Authorizer
- type AuthzProvider
- type MiddlewareOption
- type Permission
- type PermissionAction
- type PermissionArtifactType
- type Principal
- type PublicAuthzProvider
- type PublicSession
- type Resource
- type Session
- type SystemSession
- type User
Constants ¶
This section is empty.
Variables ¶
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 AuthnMiddleware ¶
func AuthnMiddleware(authn AuthnProvider, options ...MiddlewareOption) func(ctx huma.Context, next func(huma.Context))
func IsPublicSession ¶ added in v0.4.0
IsPublicSession checks if a session is the PublicSession type.
func IsSystemSession ¶
IsSystemSession checks if a session is the SystemSession type.
func WithPublicContext ¶ added in v0.4.0
WithPublicContext creates a context carrying a PublicSession.
Types ¶
type AuthnProvider ¶
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 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 ¶
func (*PublicAuthzProvider) Check(context.Context, Session, PermissionAction, Resource) error
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 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
}