Documentation
¶
Overview ¶
Package admin adds administrator operations to Canopy.
The module implements canopy.Module and canopy.RouteModule. Add it through canopy.Config.Modules. The store must implement canopy.AdminStore.
An AdminAuthorizer decides who is an admin. The default treats a user with the role "admin" as an administrator. Override it for custom rules.
The module can list and create users, set roles, ban and unban users, list and revoke sessions, and impersonate a user. A ban takes effect at once, because the module revokes the banned user's sessions and the core rejects a banned user. Impersonation records the admin on the session through ImpersonatedBy.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdminAuthorizer ¶
type AdminAuthorizer interface {
IsAdmin(ctx context.Context, data canopy.SessionData) bool
}
AdminAuthorizer decides if a session may use the admin API.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module adds admin operations: list and create users, set roles, ban and unban, list and revoke sessions, and impersonation. It implements canopy.Module and canopy.RouteModule.
type Options ¶
type Options struct {
// Authorizer decides who is an admin. The default is a RoleAuthorizer
// built from AdminRoles.
Authorizer AdminAuthorizer
// AdminRoles lists the user roles that grant admin access. The
// default is ["admin"]. It is used only when Authorizer is nil.
AdminRoles []string
// ImpersonationParentCookieName is the HttpOnly cookie that preserves
// proof of the original admin session during impersonation.
ImpersonationParentCookieName string
}
Options configures the admin module.
type RoleAuthorizer ¶
type RoleAuthorizer struct {
Roles []string
}
RoleAuthorizer treats a user as an admin when the user role is in the list.
func (RoleAuthorizer) IsAdmin ¶
func (a RoleAuthorizer) IsAdmin(ctx context.Context, data canopy.SessionData) bool