policybinding

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 10 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 policybinding is the domain layer for the PolicyBinding entity — it points a set of subjects inside one Project at one Policy. Several bindings may match a principal; the lowest priority wins, so a principal always resolves to exactly one Policy.

Authorization is app/authz's concern; this package validates shape only.

Index

Constants

View Source
const DefaultPriority = 100

DefaultPriority is applied to a binding that declares none. Lower wins.

Variables

This section is empty.

Functions

This section is empty.

Types

type PolicyBinding

type PolicyBinding struct {
	Meta meta.Metadata `json:"metadata" yaml:"metadata"`
	Spec Spec          `json:"spec"     yaml:"spec"`

	// SubjectKeys is Spec.Subjects rendered as match keys. Derived, so it
	// stays off the wire and out of manifests; the snapshot builder fills
	// it so the request path compares strings instead of building them.
	SubjectKeys []string `json:"-" yaml:"-"`
}

PolicyBinding attaches Spec.PolicyID to Spec.Subjects inside a Project.

func (*PolicyBinding) EffectivePriority

func (b *PolicyBinding) EffectivePriority() int

EffectivePriority reads an unset priority as the default, so a binding authored without one still orders against explicit values. The field is a pointer because 0 is a valid, highest-winning priority and must not read as absent.

func (*PolicyBinding) IndexSubjects

func (b *PolicyBinding) IndexSubjects()

IndexSubjects recomputes SubjectKeys. Called wherever a binding enters the snapshot; cheap, and never on the request path.

func (*PolicyBinding) IsEnabled

func (b *PolicyBinding) IsEnabled() bool

IsEnabled returns true when Enabled is unset or explicitly true.

func (*PolicyBinding) StampOwner

func (b *PolicyBinding) StampOwner()

StampOwner sets Meta.Owner to the binding's Project. Called by every write path so Owner never drifts from ProjectID.

func (*PolicyBinding) Validate

func (b *PolicyBinding) Validate() error

Validate runs intra-row rules via the shared meta.Validator and enforces:

  • Owner.Kind is project; Owner.ID, when set, equals Spec.ProjectID.
  • the subject rules shared with RoleBinding.

type Spec

type Spec struct {
	ProjectID string                `json:"projectId" yaml:"projectId" validate:"required,uuid"`
	PolicyID  string                `json:"policyId"  yaml:"policyId"  validate:"required,uuid"`
	Priority  *int                  `json:"priority,omitempty" yaml:"priority,omitempty" validate:"omitempty,gte=0,lte=10000"`
	Subjects  []rolebinding.Subject `json:"subjects"  yaml:"subjects"  validate:"required,min=1,dive"`
	Enabled   *bool                 `json:"enabled,omitempty" yaml:"enabled,omitempty"`
}

Spec carries the project, the policy, the tie-break priority, the subjects, and the enabled flag.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds a DB rather than Queries so Upsert can run a multi-table transaction.

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) Get

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

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

func (*Store) List

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

func (*Store) Upsert

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

Upsert re-derives Owner from ProjectID.

Jump to

Keyboard shortcuts

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