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
- Variables
- func IsBuiltin(name string) bool
- func SeedBuiltins(ctx context.Context, s *Store, log *slog.Logger, lock Locker) error
- type Locker
- type Role
- type Rule
- type Spec
- type Store
- func (s *Store) Delete(ctx context.Context, id string) error
- func (s *Store) Directory() directory.Store[directory.Role]
- func (s *Store) Get(ctx context.Context, id string) (*Role, error)
- func (s *Store) List(ctx context.Context) ([]*Role, error)
- func (s *Store) Upsert(ctx context.Context, r *Role) error
Constants ¶
const Wildcard = rbac.Wildcard
Wildcard matches any kind or verb inside a rule.
Variables ¶
var Kinds = []string{
"*", "audit", "debug", "groups", "host-bindings", "host-keys", "hosts",
"keys", "license", "logs", "master-key", "models", "policies",
"policy-bindings", "pricings", "projects", "providers", "rate-limits",
"role-bindings", "roles", "scim-clients", "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.
var Verbs = []string{
"*", "apply", "attach", "create", "delete", "detach", "generate", "get",
"health", "list", "mint", "read", "reload", "revoke", "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 ¶
IsBuiltin reports whether name belongs to a built-in role. Built-in names are reserved: a custom Role may not claim one.
func SeedBuiltins ¶
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 ¶
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 user for custom roles.
func Builtins ¶
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
FromDirectory is a directory row as a Role.
func (*Role) Allows ¶
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) ToDirectory ¶ added in v0.10.8
ToDirectory is r as the directory stores it.
type Rule ¶
type Rule struct {
Kinds []string `json:"kinds" yaml:"kinds" validate:"required,min=1,dive,rbackind"`
Verbs []string `json:"verbs" yaml:"verbs" validate:"required,min=1,dive,rbacverb"`
}
Rule grants every verb in Verbs on every kind in Kinds.
type Spec ¶
type Spec struct {
Rules []Rule `json:"rules" yaml:"rules" validate:"required,min=1,dive"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
}
Spec carries the rules and the enabled flag.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) Directory ¶ added in v0.10.8
Directory is the auth module's store under this one, for writes that run through the directory.