Documentation
¶
Index ¶
- func GetCurrentSessionIDFromContext(ctx context.Context) (string, bool)
- func GetCurrentUserFromContext(ctx context.Context) (*models.User, bool)
- func GetRemoteAddrFromContext(ctx context.Context) string
- func GetUserIDFromContext(ctx context.Context) (string, bool)
- func NewActivityBatchID() func(ctx huma.Context, next func(huma.Context))
- func NewAuthBridge(api huma.API, authService *services.AuthService, ...) func(ctx huma.Context, next func(huma.Context))
- func PermissionsFromContext(ctx context.Context) (*authz.PermissionSet, bool)
- func RegisterWithPermission[I, O any](api huma.API, op huma.Operation, perm string, ...)
- func RequireGlobalAdmin(api huma.API) huma.Middlewares
- func RequirePermission(api huma.API, perm string) huma.Middlewares
- func RequireSudo(api huma.API) huma.Middlewares
- type ContextKey
- type PermissionResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCurrentSessionIDFromContext ¶
GetCurrentSessionIDFromContext retrieves the current session ID from the context.
func GetCurrentUserFromContext ¶
GetCurrentUserFromContext retrieves the current user from the context.
func GetRemoteAddrFromContext ¶
GetRemoteAddrFromContext retrieves the request remote address from context.
func GetUserIDFromContext ¶
GetUserIDFromContext retrieves the user ID from the context.
func NewActivityBatchID ¶ added in v2.5.0
NewActivityBatchID lifts the client-supplied activity batch ID header into the request context so activities spawned by one logical bulk action can be grouped without threading the ID through every handler. Invalid values are ignored by utils.WithActivityBatchID.
func NewAuthBridge ¶
func NewAuthBridge(api huma.API, authService *services.AuthService, apiKeyService *services.ApiKeyService, permResolver PermissionResolver, envTokenResolver environmentAccessTokenResolver, cfg *config.Config) func(ctx huma.Context, next func(huma.Context))
NewAuthBridge creates a Huma middleware that validates credentials and enforces security requirements defined on operations. It also resolves the caller's effective PermissionSet via permResolver and stashes it on the request context for downstream RequirePermission checks.
func PermissionsFromContext ¶
func PermissionsFromContext(ctx context.Context) (*authz.PermissionSet, bool)
PermissionsFromContext retrieves the caller's resolved PermissionSet. Returns nil, false on unauthenticated paths.
func RegisterWithPermission ¶ added in v2.1.0
func RegisterWithPermission[I, O any](api huma.API, op huma.Operation, perm string, handler func(context.Context, *I) (*O, error))
RegisterWithPermission registers a Huma operation that requires perm. It attaches the RequirePermission middleware AND records perm in the operation metadata (authz.MetaRequiredPermission) so the remote environment proxy can enforce the same permission for environment-scoped operations before forwarding a request to an agent.
Use this instead of huma.Register with an inline RequirePermission middleware for every operation served under /environments/{id}/..., so the required permission stays the single source of truth for both local enforcement and remote-proxy enforcement. It is safe to use for org-level operations too; the recorded metadata is simply unused by the proxy for non-environment paths.
func RequireGlobalAdmin ¶
func RequireGlobalAdmin(api huma.API) huma.Middlewares
RequireGlobalAdmin returns a per-operation Huma middleware that rejects any caller who is not a global admin (or sudo). Used for operations that are intentionally not exposed as delegated permissions — role creation/edits, user role assignment, and OIDC mapping management. Keeping these admin-only avoids the meta-escalation surface where a holder of `roles:assign` could promote themselves via a custom role.
func RequirePermission ¶
func RequirePermission(api huma.API, perm string) huma.Middlewares
RequirePermission returns a per-operation Huma middleware that rejects callers lacking `perm`. For env-scoped permissions, the env ID is extracted from the request path (/environments/{id}/...). For org-level permissions, the env ID segment, if any, is ignored.
Attach via Operation.Middlewares:
huma.Register(api, huma.Operation{..., Middlewares: middleware.RequirePermission(api, authz.PermContainersStart)}, h.Handler)
func RequireSudo ¶ added in v2.6.0
func RequireSudo(api huma.API) huma.Middlewares
RequireSudo restricts infrastructure-only operations to callers authenticated through the agent-token path. Holding every user-facing permission is not sufficient because these operations may expose materialized secret values.
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is a type for context keys used by Huma handlers.
const ( // ContextKeyUserID is the context key for the authenticated user's ID. ContextKeyUserID ContextKey = "userID" // ContextKeyCurrentSessionID is the context key for the authenticated session ID. ContextKeyCurrentSessionID ContextKey = "currentSessionID" // ContextKeyUserPermissions is the context key for the caller's resolved // PermissionSet, attached by the auth bridge. ContextKeyUserPermissions ContextKey = "userPermissions" // ContextKeyRemoteAddr is the context key for the request remote address. ContextKeyRemoteAddr ContextKey = "remoteAddr" )
type PermissionResolver ¶
type PermissionResolver interface {
ResolvePermissions(ctx context.Context, user *models.User) (*authz.PermissionSet, error)
ResolveApiKeyPermissions(ctx context.Context, apiKeyID string) (*authz.PermissionSet, error)
}
PermissionResolver resolves a caller's effective permission set. Implemented by services.RoleService; kept as an interface so tests can stub it.