rolebinding

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 7 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 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateSubjects

func ValidateSubjects(name string, subjects []Subject) error

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" doc:"Id of the granted role."`
	Scope    meta.Owner `` /* 200-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: {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 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 junction rows.

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.

func (*Store) Get

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

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

func (*Store) List

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

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, b *RoleBinding) error

Upsert re-derives Owner from Spec.Scope.

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.

func (*Subject) Key

func (s *Subject) Key() string

Key renders the subject as the string the snapshot indexes it under: "<kind>:<id-or-name>".

type SubjectKind

type SubjectKind string

SubjectKind enumerates what a binding can name.

const (
	SubjectUser           SubjectKind = "user"
	SubjectGroup          SubjectKind = "group"
	SubjectServiceAccount SubjectKind = "serviceaccount"
)

Jump to

Keyboard shortcuts

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