refcheck

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: 27 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

View Source
const (
	// CodeLaneRequired refuses a key with no account while its user's personal account, the one it would default to, is off.
	CodeLaneRequired = "lane_required"
	// CodePersonalAccountOff refuses a write that would put something in, or share something with, a user whose personal account is off.
	CodePersonalAccountOff = "personal_account_off"
)

Codes of the refusals a turned-off personal account answers with.

View Source
const (
	// CodeAccountShared refuses a host key on a shared account: keys live on the real account.
	CodeAccountShared = "account_shared"
	// CodeReshare refuses sharing a shared account: only the real account's owner shares it.
	CodeReshare = "reshare_refused"
	// CodeShareExists refuses a second share of one account with one receiver.
	CodeShareExists = "share_exists"
	// CodeAlreadyReachable refuses sharing with a scope that already reaches the account through ownership.
	CodeAlreadyReachable = "already_reachable"
)

Codes of refused share writes.

View Source
const CodeAccountNotHeld = "account_not_held"

CodeAccountNotHeld is the error code of a key naming an account it may not run in.

View Source
const CodeAccountRequired = "account_required"

CodeAccountRequired refuses a host key that names no provider account.

View Source
const CodeDuplicateBinding = "duplicate_binding"

CodeDuplicateBinding is the error code of a binding naming an account another binding already holds.

View Source
const CodeInUse = "resource_in_use"

CodeInUse is the error code of a write refused because other rows still name the row, as a refused delete of a referenced row answers.

Variables

This section is empty.

Functions

func Principal added in v0.10.8

Principal is the caller in ctx as the auth module's directory sees it. Admin is RequireAdmin's rule (the admin role or token, any caller in single-user mode, or a loader with no authorizer), so the directory's admin-only paths open exactly where relay's do.

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) Account added in v0.20.0

func (c Checker) Account(ctx context.Context, a *account.Account) error

Account checks the host a provider account is held at and, for a shared account, its real account and receiver. Caller accounts are made with their team, project, user, service account or membership, never written as new rows.

func (Checker) AccountPayloadLogging added in v0.20.0

func (c Checker) AccountPayloadLogging(ctx context.Context, existing, incoming *account.Account) error

AccountPayloadLogging refuses a change to a caller account's payloadLogging by the user it constrains, since it decides whether their request bodies are kept. A personal account's is an admin's to set; a team, project, member or service account's is its scope admin's (the caller already passed accounts.update there), never the member account's own holder.

func (Checker) AccountRef added in v0.20.0

func (c Checker) AccountRef(ctx context.Context, id string, refOwner meta.Owner) error

AccountRef checks that a host key owned by refOwner may name the account.

func (Checker) BindablePolicy added in v0.20.0

func (c Checker) BindablePolicy(ctx context.Context, policyID string, scope meta.Owner) error

BindablePolicy checks the policy a binding owned by scope uses. A host's tier preset is shared like a system policy (a team binds the provider's tier to its own account). A personal policy is bound by its owner: to their own accounts, or from a team or project where its owner may manage policy bindings.

func (Checker) BudgetRefs added in v0.20.0

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

BudgetRefs checks budgets a policy owned by refOwner links.

func (Checker) CredentialRefs added in v0.20.0

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

CredentialRefs checks host keys a policy owned by refOwner links.

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) GroupRename added in v0.11.9

func (c Checker) GroupRename(ctx context.Context, oldName, newName string) error

GroupRename refuses changing a group's name while a role binding names the old one. Group subjects match by name, so the rename would silently detach every such binding from the group's members.

func (Checker) HostKey

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

HostKey checks the host the key authenticates to and its account, which the key must name and which must be held at that host.

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 its default lane.

func (Checker) KeyAccount added in v0.20.0

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

KeyAccount checks the key's default lane against account.TakesKeysOf, and refuses a closed one. An empty accountId takes the principal's own account (Rows.DefaultAccount), made on first use.

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) MayShare added in v0.20.0

func (c Checker) MayShare(ctx context.Context, src *account.Account) error

MayShare refuses a caller who is not src's owner: sharing gives src's keys away. A personal account is shared by its user alone, never by an admin; a team's, project's or the system's by an admin of that scope (who may edit its accounts). A loader without an authorizer runs as the deployment.

func (Checker) PersonalProviderAccount added in v0.20.0

func (c Checker) PersonalProviderAccount(ctx context.Context, a *account.Account) error

PersonalProviderAccount refuses a provider account owned by a user whose personal account is turned off: it would serve nothing.

func (Checker) Policy

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

Policy checks the pools, rate limits and budgets a policy draws on, and that every binding using it may use its pools.

func (Checker) PolicyBinding

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

PolicyBinding checks the owning scope, the policy, and the accounts, each of which must sit inside that scope and be held by no other binding.

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) Pool added in v0.20.0

func (c Checker) Pool(ctx context.Context, p *pool.Pool) error

Pool checks the pool's host and requires every key and account in it to be at that host.

func (Checker) PoolAccountRefs added in v0.20.0

func (c Checker) PoolAccountRefs(ctx context.Context, ids []string, refOwner meta.Owner, hostID string) error

PoolAccountRefs checks that a pool owned by refOwner at hostID may draw on the accounts.

func (Checker) PoolRefs added in v0.20.0

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

PoolRefs checks pools a policy owned by refOwner links.

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.

func (Checker) Share added in v0.20.0

func (c Checker) Share(ctx context.Context, src, share *account.Account) error

Share checks a new share of src: who shares it, the row itself, and what only a new share must meet.

func (Checker) ShareExists added in v0.20.0

func (c Checker) ShareExists(ctx context.Context, src *account.Account, r account.Receiver) error

ShareExists is the refusal of a second share of src with r.

func (Checker) UsableAccount added in v0.20.0

func (c Checker) UsableAccount(ctx context.Context, a *account.Account, by meta.Owner) error

UsableAccount checks the account for a new policy binding owned by by: in its scope and held by no other binding. A host key joins only an account of its own owner, which the list's owner filters already express.

func (Checker) UsableBudget added in v0.20.0

func (c Checker) UsableBudget(ctx context.Context, b *budget.Budget, by meta.Owner) error

UsableBudget checks the budget for a policy owned by by.

func (Checker) UsableHostKey added in v0.20.0

func (c Checker) UsableHostKey(ctx context.Context, k *hostkey.HostKey, by meta.Owner) error

UsableHostKey checks the host key for a pool owned by by at the key's own host; the pool's host is the list's host_id filter.

func (Checker) UsablePolicy added in v0.20.0

func (c Checker) UsablePolicy(ctx context.Context, p *policy.Policy, by meta.Owner) error

UsablePolicy checks the policy, and the pools and keys it links, for a new policy binding owned by by.

func (Checker) UsablePool added in v0.20.0

func (c Checker) UsablePool(ctx context.Context, p *pool.Pool, by meta.Owner) error

UsablePool checks the pool for a policy owned by by.

func (Checker) UsablePoolAccount added in v0.20.0

func (c Checker) UsablePoolAccount(ctx context.Context, a *account.Account, by meta.Owner) error

UsablePoolAccount checks the account for a pool owned by by at the account's own host: its own and reachable provider accounts and the shares made with by; the pool's host is the list's host_id filter.

func (Checker) UsableRateLimit added in v0.20.0

func (c Checker) UsableRateLimit(ctx context.Context, rl *ratelimit.RateLimit, by meta.Owner) error

UsableRateLimit checks the rate limit for a policy owned by by.

func (Checker) UsableScope added in v0.20.0

func (c Checker) UsableScope(ctx context.Context, by meta.Owner) error

UsableScope checks the scope a picker asks for exists: a team or project must exist (400) and be visible (404), and a user scope must name a user (400). Whether the caller may write in it is the authorizer's decision, taken by the caller of this check.

type Error

type Error struct {
	Status int
	// Code is the machine-readable error code, when the refusal has one.
	Code string
	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 Grants added in v0.10.8

type Grants struct{ Authz authz.Authorizer }

Grants is the directory's grant check in relay: authz.CheckGrant, which expands wildcards over relay's closed vocabulary and probes through Authz. An admin passes without probing.

func (Grants) CheckGrant added in v0.10.8

func (g Grants) CheckGrant(ctx context.Context, p *principal.Principal, r rbac.Role, scope rbac.Scope, _, _ []string) 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
	Host           func(ctx context.Context, id string) *host.Host
	Account        func(ctx context.Context, id string) *account.Account
	Pool           func(ctx context.Context, id string) *pool.Pool
	Budget         func(ctx context.Context, id string) *budget.Budget
	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)
	// RoleBindings and PolicyBindings return every stored binding.
	RoleBindings   func(ctx context.Context) ([]*rolebinding.RoleBinding, error)
	PolicyBindings func(ctx context.Context) ([]*policybinding.PolicyBinding, error)
	// PolicyBindingsFor returns the bindings using a policy.
	PolicyBindingsFor func(ctx context.Context, policyID string) ([]*policybinding.PolicyBinding, error)
	// MissingUsers returns the ids that name no user.
	MissingUsers func(ctx context.Context, ids []string) ([]string, error)
	// UserVisible reports whether the caller may see the user, for a share with one; nil sees every user.
	UserVisible func(ctx context.Context, id string) bool
	// DefaultAccount returns the id of a principal's own account (a service account's account, a user's personal account), making it on first use.
	DefaultAccount func(ctx context.Context, p key.Principal) (string, error)
	// UserMayBindIn reports whether a user may manage policy bindings in a team or project scope.
	UserMayBindIn func(ctx context.Context, userID string, scope meta.Owner) (bool, error)
	// UserName returns a user's username for refusal wording, empty when unknown.
	UserName func(ctx context.Context, userID string) string
	// PersonalAccountOff reports whether a user's personal account is turned off, with the username for refusal wording; nil treats every user's as on.
	PersonalAccountOff func(ctx context.Context, userID string) (off bool, username string)
}

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

func (Lookup) Memoized added in v0.20.0

func (l Lookup) Memoized() Lookup

Memoized returns l with every read cached for the life of the returned value; nil funcs stay nil. DefaultAccount stays uncached: it may create the account it returns. PersonalAccountOff reads the published plans in memory, so it is passed on as is.

Jump to

Keyboard shortcuts

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