refcheck

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 25 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 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 PolicyLinks(p *policy.Policy) map[string]bool

PolicyLinks is the ids of the pools, rate limits and budgets p links, for Checker.Held.

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 the organization. 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
	// Held is the ids of the links a save keeps rather than makes: the ones
	// the stored row already holds under the same owner, or a copy takes over
	// from a source the caller reads. They skip the visibility check only, so
	// a tenant can still save a row an admin linked to rows the tenant may not
	// see; the owner rules still apply.
	Held map[string]bool
}

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. The policy the account names is AccountPolicy's.

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, and that of a service account a user owns, whose lane's value comes before the 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) AccountPolicy added in v0.31.0

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

AccountPolicy checks the policy a names, in the scope of a's owner.

func (Checker) AccountPolicyChange added in v0.31.0

func (c Checker) AccountPolicyChange(ctx context.Context, prev, next *account.Account) error

AccountPolicyChange checks the policy next names when the write picks it: on create (prev nil), or when the policy or the owner changes. An edit that keeps both leaves the policy as it was.

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 an account owned by scope names. A host's tier preset is shared like an organization policy (a team puts the provider's tier on its own account). A personal policy goes on its owner's own accounts, or on accounts of a team or project where its owner may update accounts.

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. A key of a user's service account is refused while that user's personal account is off, as a key in the personal account is: the service account's lane is closed then.

func (Checker) KeyOwnedByPrincipal added in v0.31.0

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

KeyOwnedByPrincipal refuses a key whose owner is not the one KeyOwner gives its principal: a write that would move a key's row out of its principal's scope while it keeps running in the principal's lane.

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 owner, 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 account naming it may use its pools.

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) Reaches added in v0.31.0

func (c Checker) Reaches(ctx context.Context, owner, refOwner meta.Owner) bool

Reaches reports whether a row owned by refOwner may draw on a row owned by owner by ownership alone, before the caller's visibility; see reaches.

func (Checker) ReachesByOwnership added in v0.31.0

func (c Checker) ReachesByOwnership(ctx context.Context, owner, receiver meta.Owner) bool

ReachesByOwnership reports whether a share owned by receiver, of an account owned by owner, would be refused as already_reachable: receiver is owner or a scope inside it.

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 stamps the owner (metadata.owner, or the project spec.projectId names) and checks the project, team or user it names.

func (Checker) ServiceAccountOwnerOn added in v0.31.0

func (c Checker) ServiceAccountOwnerOn(ctx context.Context, owner meta.Owner) error

ServiceAccountOwnerOn refuses owner as a service account's owner while it is a user whose personal account is turned off: the service account's lane is closed then, as KeyAccount and a share with it find.

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) 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) UsableHostKeyAccount added in v0.31.0

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

UsableHostKeyAccount checks the account for a host key owned by by: a provider account of by's own, not a share, which holds no keys.

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 an account 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.

func (Checker) UserServiceAccountKey added in v0.31.0

func (c Checker) UserServiceAccountKey(ctx context.Context, owner meta.Owner) error

UserServiceAccountKey refuses minting a credential of a service account owned by owner, a user, to anyone but that user and an admin: the key runs under the user's personal account and reaches what the user owns, as a key of the user's own, which no one else may create either.

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 returns every stored role binding.
	RoleBindings func(ctx context.Context) ([]*rolebinding.RoleBinding, error)
	// AccountsWithPolicy returns the accounts naming a policy.
	AccountsWithPolicy func(ctx context.Context, policyID string) ([]*account.Account, 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)
	// UserMayUpdateAccountsIn reports whether a user may update accounts in a team or project scope.
	UserMayUpdateAccountsIn 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