role

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package role is the domain layer for the Role entity — a named set of (kinds, verbs) rules. A Role carries no scope: the scope comes from the RoleBinding that names it, so one Role is reusable at every level.

Authorization is app/authz's concern; this package validates shape only and answers the pure Allows question the evaluator will ask.

Index

Constants

View Source
const (
	BuiltinAdmin        = "admin"
	BuiltinTeamAdmin    = "team-admin"
	BuiltinProjectAdmin = "project-admin"
)

Names of the built-in roles that administer the deployment, one team or one project.

View Source
const Wildcard = rbac.Wildcard

Wildcard matches any kind or verb inside a rule.

Variables

View Source
var Kinds = []string{
	"*", "accounts", "audit", "budgets", "debug", "groups", "host-bindings", "host-keys", "hosts",
	"keys", "license", "logs", "master-key", "models", "policies",
	"policy-bindings", "pools", "pricings", "projects", "providers", "rate-limits",
	"role-bindings", "roles", "scim-clients", "secret-keys", "service-accounts", "settings",
	"system", "teams", "tokens", "usage", "users",
}

Kinds is the closed set a rule may name: the control-API plurals plus the wildcard. Sorted — membership is a binary search.

View Source
var Verbs = []string{
	"*", "apply", "attach", "create", "delete", "destroy", "detach", "generate",
	"get", "health", "list", "mint", "read", "reload", "revoke", "rewrap", "rotate",
	"snapshot", "update",
}

Verbs is the closed set a rule may name. Wider than CRUD because the special endpoints (rotate, health, mint, …) need names of their own.

Functions

func IsBuiltin

func IsBuiltin(name string) bool

IsBuiltin reports whether name belongs to a built-in role. Built-in names are reserved: a custom Role may not claim one.

func SeedBuiltins

func SeedBuiltins(ctx context.Context, s *Store, log *slog.Logger, lock Locker) error

SeedBuiltins writes the built-in Roles, by name. A row whose rules already match the embedded file is left untouched; one whose rules differ is rewritten, so a rule added in a release reaches an upgraded deployment instead of only new ones. Ids and display fields of an existing row are preserved — bindings name the id.

The read-then-write is not atomic, so pods booting together would each mint an id for the same missing role: lock serializes them. A nil Locker runs the seed unserialized, which is only safe for a single process.

Types

type Locker

type Locker func(ctx context.Context, fn func(context.Context) error) error

Locker runs fn while holding a lock shared by every pod. internal/storage.WithAdvisoryLock bound to a pool and a key satisfies it.

type Role

type Role struct {
	Meta meta.Metadata `json:"metadata" yaml:"metadata"`
	Spec Spec          `json:"spec"     yaml:"spec"`
}

Role is a named rule set. Owner is system for the built-ins, and the organization or a user for custom roles.

func Builtins

func Builtins() ([]*Role, error)

Builtins returns the built-in system Roles, freshly parsed with no ids set. Order follows the embedded file.

func FromDirectory added in v0.10.8

func FromDirectory(r *directory.Role) *Role

FromDirectory is a directory row as a Role.

func (*Role) Allows

func (r *Role) Allows(kind, verb string) bool

Allows reports whether any rule covers (kind, verb). A rule matches when its kinds hold kind or "*" and its verbs hold verb or "*".

func (*Role) IsEnabled

func (r *Role) IsEnabled() bool

IsEnabled returns true when Enabled is unset or explicitly true.

func (*Role) ToDirectory added in v0.10.8

func (r *Role) ToDirectory() *directory.Role

ToDirectory is r as the directory stores it.

func (*Role) Validate

func (r *Role) Validate() error

Validate runs intra-row rules via the shared meta.Validator and enforces:

  • Owner.Kind is system (built-in), organization or user (custom).

type Rule

type Rule struct {
	Kinds []string `` /* 168-byte string literal not displayed */
	Verbs []string `` /* 181-byte string literal not displayed */
}

Rule grants every verb in Verbs on every kind in Kinds.

type Spec

type Spec struct {
	Rules   []Rule `` /* 170-byte string literal not displayed */
	Enabled *bool  `json:"enabled,omitempty" yaml:"enabled,omitempty" doc:"False makes bindings of this role grant nothing. Omitted means true."`
}

Spec carries the rules and the enabled flag.

type Store

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

func NewStore

func NewStore(db storage.DB) *Store

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete relies on the FK to cascade the role's bindings.

func (*Store) Directory added in v0.10.8

func (s *Store) Directory() directory.Store[directory.Role]

Directory is the auth module's store under this one, for writes that run through the directory.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*Role, error)

Get returns (nil, nil) when no row has id.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*Role, error)

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, r *Role) error

Upsert expects Meta.ID set by the caller.

Jump to

Keyboard shortcuts

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