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, reading a system scope as the global one. Called by every read and 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 organization (the global scope, no id), team or project (with an id).
- 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" doc:"Id of the granted role."`
Scope meta.Owner `` /* 251-byte string literal not displayed */
Subjects []Subject `json:"subjects" yaml:"subjects" validate:"required,min=1,dive" doc:"Users, groups and service accounts granted the role."`
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty" doc:"False suspends the grant. Omitted means true."`
}
Spec carries the role, the scope, the subjects, and the enabled flag. Scope is a meta.Owner: {organization} 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 `` /* 135-byte string literal not displayed */
ID string `` /* 136-byte string literal not displayed */
Name string `` /* 150-byte string literal not displayed */
}
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" )