authz

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package authz decides what an operator may do, once auth has decided who they are.

Permissions are closed: each one names something the code actually checks, so one that nothing enforces cannot be invented. Roles are open: a role is a name for a set of permissions, and that is configuration.

Index

Constants

View Source
const (
	Viewer   = "viewer"
	Operator = "operator"
	Admin    = "admin"
	Owner    = "owner"
)

The roles a new tenant starts with. They are seeded, not enforced: a deployment is free to change or remove any of them.

View Source
const Least = "viewer"

Least is what somebody holds in a tenant when their membership states no role: belonging without a role stated is belonging as a viewer.

Variables

View Source
var (
	// ErrDenied is what a handler turns into a refusal.
	ErrDenied = errors.New("the role does not allow that")
	// ErrUnknownPermission guards against storing a permission nothing checks,
	// which would look granted and do nothing.
	ErrUnknownPermission = errors.New("no such permission")
)

Functions

func Described

func Described() map[Permission]string

Described is every permission with what granting it allows, so a role can be built without reading the code.

func Known

func Known(permission Permission) bool

func TenantFrom

func TenantFrom(ctx context.Context) (uuid.UUID, bool)

func WithTenant

func WithTenant(ctx context.Context, tenant uuid.UUID) context.Context

WithTenant marks a context as acting for one tenant. Everything done under it is confined to that tenant, and storage is expected to enforce it rather than trust the caller to filter.

Types

type Group

type Group struct {
	Area        string
	Permissions []Permission
}

Group is one area with everything it allows.

func Grouped

func Grouped() []Group

Grouped is the closed set arranged by area, in the order the areas first appear, so the panel can show it as something readable.

type Permission

type Permission string
const (
	EventsRead        Permission = "events.read"
	EventsReplay      Permission = "events.replay"
	EventsForce       Permission = "events.force"
	RoutesRead        Permission = "routes.read"
	RoutesWrite       Permission = "routes.write"
	VerificationRead  Permission = "verification.read"
	VerificationWrite Permission = "verification.write"
	OperatorsRead     Permission = "operators.read"
	OperatorsWrite    Permission = "operators.write"
	RolesWrite        Permission = "roles.write"
	TenantsWrite      Permission = "tenants.write"
)

func All

func All() []Permission

func (Permission) Action

func (p Permission) Action() string

func (Permission) Area

func (p Permission) Area() string

Area is the part of Charon a permission is about, and Action is what it allows there. Splitting the name is how the panel groups them instead of listing ten strings in a row.

type Role

type Role struct {
	Name        string
	Description string
	// BuiltIn marks the roles shipped with the project. They are editable like
	// any other; the flag only lets the panel say so.
	BuiltIn bool
	Grants  []Permission
}

Role is a name and what it allows. It is data: a deployment defines its own.

func BuiltIn

func BuiltIn() []Role

func Everything

func Everything() Role

Everything is what a system administrator holds: not a role stored anywhere, because a role belongs to a tenant and this deliberately does not.

func (Role) Allows

func (r Role) Allows(permission Permission) bool

func (Role) Authorize

func (r Role) Authorize(permission Permission) error

func (Role) Validate

func (r Role) Validate() error

Validate rejects a role that grants something nothing enforces.

Jump to

Keyboard shortcuts

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