refcheck

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 18 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 refcheck holds the cross-row write rules a row's own Validate cannot see: a referenced row must exist, be visible to the caller, and belong to a scope the referrer may draw on; owners that mirror a spec field are re-derived from it. The control API's CRUD guards and the apply loader both call these, one function per kind, so the two write paths cannot drift.

Rows are read through Lookup, which each caller backs with its own source (CRUD: the stores; apply: stored rows plus the bundle). Out of scope: catalog-graph checks (policy model refs) and single-row validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequireAdmin

func RequireAdmin(ctx context.Context, a authz.Authorizer, what string) error

RequireAdmin refuses a non-admin caller under a scoping authorizer. Without one (single-user mode) every authenticated caller is already the operator.

func SharedOwner

func SharedOwner(kind, name string, owner, refOwner meta.Owner) error

SharedOwner requires a project-owned referrer's target to live in the same project or be shared. Visible is not enough: a read grant on another tenant's row must not become inference through its credentials and limits. Referrers owned by the catalog tiers are unconstrained.

func StampOwnerID

func StampOwnerID(ctx context.Context, o *meta.Owner) error

StampOwnerID fills Owner.ID from the acting user on a user-owned row. A caller that is no user (the admin token, a loader with no actor) creates shared infrastructure, so an id-less user owner becomes system. A supplied owner.id must be the caller's own; only the admin token may name someone else.

func Visible

func Visible(ctx context.Context, a authz.Authorizer, kind, id string, owner meta.Owner) bool

Visible reports whether the caller may see the row; true when a doesn't scope reads (the single-user default).

Types

type Checker

type Checker struct {
	Authz authz.Authorizer
	Rows  Lookup
}

Checker applies the rules for the caller in ctx. A nil Authz is a loader running as the deployment itself: visibility and grant checks pass.

func (Checker) Group

func (c Checker) Group(ctx context.Context, g *group.Group) error

Group refuses a member id that is not a user: a typo'd id would silently grant nothing.

func (Checker) HostKey

func (c Checker) HostKey(ctx context.Context, k *hostkey.HostKey) error

HostKey requires the key's tier policy to be host-owned by the key's own host; a mismatched key drops out of the snapshot and answers no_keys.

func (Checker) HostKeyRefs

func (c Checker) HostKeyRefs(ctx context.Context, keyIDs []string, refOwner meta.Owner) error

HostKeyRefs checks the host keys a policy spends. Missing ids pass: the inference path skips a key it cannot find.

func (Checker) Key

func (c Checker) Key(ctx context.Context, k *key.Key) error

Key derives the key's owner from its principal and checks the policy it carries.

func (Checker) KeyOwner

func (c Checker) KeyOwner(ctx context.Context, k *key.Key) error

KeyOwner derives the key's owner from its principal — a service account's project, or the user it names. An account the caller may not see is reported as absent.

func (Checker) Policy

func (c Checker) Policy(ctx context.Context, p *policy.Policy) error

Policy checks the host keys and rate limits a policy draws on.

func (Checker) PolicyBinding

func (c Checker) PolicyBinding(ctx context.Context, pb *policybinding.PolicyBinding) error

PolicyBinding re-derives the owner from spec.projectId, fills in the default priority, and checks the project, policy, and subjects.

func (Checker) PolicyRef

func (c Checker) PolicyRef(ctx context.Context, policyID string, refOwner meta.Owner) error

PolicyRef checks a policy named by refOwner's row.

func (Checker) Project

func (c Checker) Project(ctx context.Context, p *project.Project) error

Project re-derives the owner from spec.teamId and checks the team.

func (Checker) RateLimitRef

func (c Checker) RateLimitRef(ctx context.Context, rateLimitID string, refOwner meta.Owner) error

RateLimitRef applies the policy-ref rule to a rate limit a policy names.

func (Checker) Role

func (c Checker) Role(ctx context.Context, r *role.Role) error

Role re-checks an edited role against every scope it is already bound at: the edit changes what each binding grants, so the editor must hold the new rules there, as creating the binding would have required.

func (Checker) RoleBinding

func (c Checker) RoleBinding(ctx context.Context, rb *rolebinding.RoleBinding) error

RoleBinding re-derives the owner from spec.scope and checks the role, the scope target, and the subjects. Binding a role hands out every permission in it, so the binder must already hold each one at that scope.

func (Checker) ServiceAccount

func (c Checker) ServiceAccount(ctx context.Context, sa *serviceaccount.ServiceAccount) error

ServiceAccount re-derives the owner from spec.projectId and checks the project and policy it names.

type Error

type Error struct {
	Status int
	Msg    string
	Err    error
}

Error is a refused write with the HTTP status it answers.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Lookup

type Lookup struct {
	Policy         func(ctx context.Context, id string) *policy.Policy
	RateLimit      func(ctx context.Context, id string) *ratelimit.RateLimit
	HostKey        func(ctx context.Context, id string) *hostkey.HostKey
	Project        func(ctx context.Context, id string) *project.Project
	Team           func(ctx context.Context, id string) *team.Team
	Role           func(ctx context.Context, id string) *role.Role
	ServiceAccount func(ctx context.Context, id string) *serviceaccount.ServiceAccount
	// RoleBindingsFor returns the stored bindings naming a role.
	RoleBindingsFor func(ctx context.Context, roleID string) ([]*rolebinding.RoleBinding, error)
	// MissingUsers returns the ids that name no user.
	MissingUsers func(ctx context.Context, ids []string) ([]string, error)
}

Lookup reads referenced rows by id; nil means absent. A nil func skips every check that needs that kind.

Jump to

Keyboard shortcuts

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