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 ¶
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.