Documentation
¶
Overview ¶
Package authz implements per-action authorization (ADR-0009).
Every API route declares the action it performs by wrapping its handler with Guard.Protect, or explicitly opts out with Public. Verify walks the router and rejects routes that did neither, so a forgotten check fails at startup instead of silently allowing access (default deny).
The package does not depend on the authentication implementation: the guard obtains the caller through a SubjectFunc supplied by the server.
Index ¶
Constants ¶
const RoleAdmin = "admin"
RoleAdmin is the only role in MVP.
Variables ¶
var ErrForbidden = errors.New("forbidden")
ErrForbidden is returned when a subject may not perform an action.
Functions ¶
Types ¶
type Action ¶
type Action string
Action is a permission name in the form "<area>:<verb>".
const ( SessionSelf Action = "session:self" // own session: me, logout // JobsRead lists background jobs (#126); each job is shown only to callers allowed the // action that started it, which is also required to cancel it. JobsRead Action = "jobs:read" ContainersRead Action = "containers:read" // list, inspect, logs, stats ContainersOperate Action = "containers:operate" // start, stop, restart, kill, pause ContainersWrite Action = "containers:write" // create, recreate, remove ContainersExec Action = "containers:exec" // web terminal (kept separate for #102) ImagesRead Action = "images:read" ImagesWrite Action = "images:write" // pull, tag, push, remove VolumesRead Action = "volumes:read" VolumesWrite Action = "volumes:write" NetworksRead Action = "networks:read" NetworksWrite Action = "networks:write" StacksRead Action = "stacks:read" StacksWrite Action = "stacks:write" // edit files, adopt, remove StacksDeploy Action = "stacks:deploy" // up, down, restart, pull NamespacesRead Action = "namespaces:read" NamespacesWrite Action = "namespaces:write" // create, remove (#195) SystemRead Action = "system:read" // info, events, df, runtime versions SystemPrune Action = "system:prune" RegistriesRead Action = "registries:read" RegistriesWrite Action = "registries:write" UsersRead Action = "users:read" UsersWrite Action = "users:write" SettingsRead Action = "settings:read" SettingsWrite Action = "settings:write" )
Action catalog (ADR-0009). Add new actions here; the catalog doubles as the permission list for the future roles UI (#78).
type AdminOnly ¶
type AdminOnly struct{}
AdminOnly is the MVP authorizer: the admin role may do everything, nobody else anything. Unknown actions are always denied.
type Authorizer ¶
Authorizer decides whether a subject may perform an action on a resource.
type Guard ¶
type Guard struct {
// contains filtered or unexported fields
}
Guard wraps handlers with authorization checks.
func NewGuard ¶
func NewGuard(authorizer Authorizer, subject SubjectFunc, logger *slog.Logger) *Guard
NewGuard returns a guard using authorizer and subject.
type Protected ¶
type Protected struct {
Action Action
// contains filtered or unexported fields
}
Protected is a handler with a declared action.
type PublicHandler ¶
type PublicHandler struct {
// contains filtered or unexported fields
}
PublicHandler is a handler explicitly marked as not requiring authorization.
func Public ¶
func Public(h http.HandlerFunc) *PublicHandler
Public marks h as reachable without authorization (setup, login, version, health).
func (*PublicHandler) ServeHTTP ¶
func (p *PublicHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
type Resource ¶
Resource identifies what an action applies to. Fields are empty when not applicable; they allow resource-level rules later (e.g. #97 is out of scope, but namespaces may be).
func ResourceFromRequest ¶
ResourceFromRequest builds the resource from the conventional route parameters ({env}, {id}) and the namespace query parameter (ADR-0006).
type Route ¶
type Route struct {
Method string
Path string
Action Action // empty for public routes
Public bool
}
Route describes a registered route and its declared access.