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.
Subjects live in the role_binding_subjects junction, where a subject with an id also fills the matching FK column so deleting a user or service account drops it from every binding.
Index ¶
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 (*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) 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
}
Store holds a pool rather than Queries so Upsert can run a multi-table transaction.
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" )