roles

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package roles adds a host-defined role hierarchy to Auth-All.

The host names the roles from the lowest to the highest. A check compares the rank of the effective role with the rank of a minimum role, so a route asks for "at least operator" and not for a list of permissions.

r := roles.New(roles.Hierarchy("viewer", "operator", "editor", "admin"),
    roles.Default("viewer"))
auth, err := authall.New(authall.WithStore(s), authall.WithPlugins(r))
mux.Handle("/deploy", r.Require("operator", deployHandler))

Index

Constants

View Source
const ID = "roles"

ID is the stable plugin identifier.

Variables

This section is empty.

Functions

func AtLeast

func AtLeast(ctx context.Context, min string) bool

AtLeast reports whether the effective role of the context ranks equal to or above min. A handler uses it for a decision inside one route.

It returns false when no role check ran, which is default deny.

func From

func From(ctx context.Context) string

From returns the effective role of the request context. It returns an empty value when no role check ran.

Types

type Option

type Option func(*Plugin)

Option configures the plugin.

func Default

func Default(name string) Option

Default names the role of a user whose role is empty. The default is the lowest role of the hierarchy.

func Hierarchy

func Hierarchy(names ...string) Option

Hierarchy names the roles from the lowest to the highest.

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin is the roles plugin.

func New

func New(opts ...Option) *Plugin

New returns the roles plugin. Registration fails when the hierarchy is empty, holds a duplicate, or does not hold the default role.

func (*Plugin) ID

func (p *Plugin) ID() string

ID implements plugin.Plugin.

func (*Plugin) Names

func (p *Plugin) Names() []string

Names returns the configured roles from the lowest to the highest.

func (*Plugin) Register

func (p *Plugin) Register(r *plugin.Registry) error

Register implements plugin.Plugin.

func (*Plugin) Require

func (p *Plugin) Require(min string, next http.Handler) http.Handler

Require protects a handler with a minimum role.

A request with no principal gets 401 UNAUTHORIZED. A principal whose role ranks below min gets 403 INSUFFICIENT_ROLE. Require panics when min is not a configured role, because a route with an unknown minimum can never pass.

func (*Plugin) RequireFunc

func (p *Plugin) RequireFunc(min string, next http.HandlerFunc) http.Handler

RequireFunc is the http.HandlerFunc form of Require.

Jump to

Keyboard shortcuts

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