Documentation
¶
Overview ¶
Package rolebinding is the domain layer for the RoleBinding entity — it grants one Role to a set of subjects at one scope (global, a Team, or a Project). A binding at scope S applies to every resource whose scope chain contains S.
Authorization is app/authz's concern; this package validates shape only.
Index ¶
- func ValidateSubjects(name string, subjects []Subject) error
- type RoleBinding
- type Spec
- type Store
- func (s *Store) Delete(ctx context.Context, id string) error
- func (s *Store) Directory() directory.Store[directory.RoleBinding]
- func (s *Store) Get(ctx context.Context, id string) (*RoleBinding, error)
- func (s *Store) List(ctx context.Context) ([]*RoleBinding, error)
- func (s *Store) Upsert(ctx context.Context, b *RoleBinding) error
- type Subject
- type SubjectKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateSubjects ¶
ValidateSubjects enforces the subject rules shared by RoleBinding and PolicyBinding: exactly one identifier per subject, keyed by kind, and no duplicates within the list.
Types ¶
type RoleBinding ¶
type RoleBinding struct {
Meta meta.Metadata `json:"metadata" yaml:"metadata"`
Spec Spec `json:"spec" yaml:"spec"`
}
RoleBinding grants Spec.RoleID to Spec.Subjects at Spec.Scope.
func FromDirectory ¶ added in v0.10.8
func FromDirectory(r *directory.RoleBinding) *RoleBinding
FromDirectory is a directory row as a RoleBinding.
func (*RoleBinding) IsEnabled ¶
func (b *RoleBinding) IsEnabled() bool
IsEnabled returns true when Enabled is unset or explicitly true.
func (*RoleBinding) StampOwner ¶
func (b *RoleBinding) StampOwner()
StampOwner sets Meta.Owner to the binding's scope. Called by every write path so Owner never drifts from Spec.Scope.
func (*RoleBinding) ToDirectory ¶ added in v0.10.8
func (b *RoleBinding) ToDirectory() *directory.RoleBinding
ToDirectory is b as the directory stores it.
func (*RoleBinding) Validate ¶
func (b *RoleBinding) Validate() error
Validate runs intra-row rules via the shared meta.Validator and enforces:
- Scope.Kind is system, team, or project; a non-system scope carries an id and a system scope carries none.
- Meta.Owner equals Spec.Scope.
- subjects are distinct, group subjects carry a name and the others an id.
type Spec ¶
type Spec struct {
RoleID string `json:"roleId" yaml:"roleId" validate:"required,uuid"`
Scope meta.Owner `json:"scope" yaml:"scope" validate:"required"`
Subjects []Subject `json:"subjects" yaml:"subjects" validate:"required,min=1,dive"`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
}
Spec carries the role, the scope, the subjects, and the enabled flag. Scope is a meta.Owner: {system} is global, {team,id} and {project,id} name a tenancy row. Meta.Owner mirrors it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) Directory ¶ added in v0.10.8
func (s *Store) Directory() directory.Store[directory.RoleBinding]
Directory is the auth module's store under this one, for writes that run through the directory.
type Subject ¶
type Subject struct {
Kind SubjectKind `json:"kind" yaml:"kind" validate:"required,oneof=user group serviceaccount"`
ID string `json:"id,omitempty" yaml:"id,omitempty" validate:"omitempty,uuid"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
}
Subject is one grantee. User and service-account subjects carry an id; group subjects carry a name, because an IdP group has no row to point at and a local group of the same name unions with it.
type SubjectKind ¶
type SubjectKind string
SubjectKind enumerates what a binding can name.
const ( SubjectUser SubjectKind = "user" SubjectGroup SubjectKind = "group" SubjectServiceAccount SubjectKind = "serviceaccount" )