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
- func PolicyLinks(p *policy.Policy) map[string]bool
- func Principal(ctx context.Context, a authz.Authorizer) *principal.Principal
- func RequireAdmin(ctx context.Context, a authz.Authorizer, what string) error
- func SharedOwner(kind, name string, owner, refOwner meta.Owner) error
- func StampOwnerID(ctx context.Context, o *meta.Owner) error
- func Visible(ctx context.Context, a authz.Authorizer, kind, id string, owner meta.Owner) bool
- type Checker
- func (c Checker) Account(ctx context.Context, a *account.Account) error
- func (c Checker) AccountPayloadLogging(ctx context.Context, existing, incoming *account.Account) error
- func (c Checker) AccountRef(ctx context.Context, id string, refOwner meta.Owner) error
- func (c Checker) BindablePolicy(ctx context.Context, policyID string, scope meta.Owner) error
- func (c Checker) BudgetRefs(ctx context.Context, ids []string, refOwner meta.Owner) error
- func (c Checker) CredentialRefs(ctx context.Context, ids []string, refOwner meta.Owner) error
- func (c Checker) Group(ctx context.Context, g *group.Group) error
- func (c Checker) GroupRename(ctx context.Context, oldName, newName string) error
- func (c Checker) HostKey(ctx context.Context, k *hostkey.HostKey) error
- func (c Checker) Key(ctx context.Context, k *key.Key) error
- func (c Checker) KeyAccount(ctx context.Context, k *key.Key) error
- func (c Checker) KeyOwner(ctx context.Context, k *key.Key) error
- func (c Checker) MayShare(ctx context.Context, src *account.Account) error
- func (c Checker) PersonalProviderAccount(ctx context.Context, a *account.Account) error
- func (c Checker) Policy(ctx context.Context, p *policy.Policy) error
- func (c Checker) PolicyBinding(ctx context.Context, pb *policybinding.PolicyBinding) error
- func (c Checker) PolicyRef(ctx context.Context, policyID string, refOwner meta.Owner) error
- func (c Checker) Pool(ctx context.Context, p *pool.Pool) error
- func (c Checker) PoolAccountRefs(ctx context.Context, ids []string, refOwner meta.Owner, hostID string) error
- func (c Checker) PoolRefs(ctx context.Context, ids []string, refOwner meta.Owner) error
- func (c Checker) Project(ctx context.Context, p *project.Project) error
- func (c Checker) RateLimitRef(ctx context.Context, rateLimitID string, refOwner meta.Owner) error
- func (c Checker) Role(ctx context.Context, r *role.Role) error
- func (c Checker) RoleBinding(ctx context.Context, rb *rolebinding.RoleBinding) error
- func (c Checker) ServiceAccount(ctx context.Context, sa *serviceaccount.ServiceAccount) error
- func (c Checker) Share(ctx context.Context, src, share *account.Account) error
- func (c Checker) ShareExists(ctx context.Context, src *account.Account, r account.Receiver) error
- func (c Checker) UsableAccount(ctx context.Context, a *account.Account, by meta.Owner) error
- func (c Checker) UsableBudget(ctx context.Context, b *budget.Budget, by meta.Owner) error
- func (c Checker) UsableHostKey(ctx context.Context, k *hostkey.HostKey, by meta.Owner) error
- func (c Checker) UsablePolicy(ctx context.Context, p *policy.Policy, by meta.Owner) error
- func (c Checker) UsablePool(ctx context.Context, p *pool.Pool, by meta.Owner) error
- func (c Checker) UsablePoolAccount(ctx context.Context, a *account.Account, by meta.Owner) error
- func (c Checker) UsableRateLimit(ctx context.Context, rl *ratelimit.RateLimit, by meta.Owner) error
- func (c Checker) UsableScope(ctx context.Context, by meta.Owner) error
- type Error
- type Grants
- type Lookup
Constants ¶
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.
const ( CodeAccountShared = "account_shared" CodeReshare = "reshare_refused" CodeShareExists = "share_exists" // CodeAlreadyReachable refuses sharing with a scope that already reaches the account through ownership. CodeAlreadyReachable = "already_reachable" )
Codes of refused share writes.
const CodeAccountNotHeld = "account_not_held"
CodeAccountNotHeld is the error code of a key naming an account it may not run in.
const CodeAccountRequired = "account_required"
CodeAccountRequired refuses a host key that names no provider account.
const CodeDuplicateBinding = "duplicate_binding"
CodeDuplicateBinding is the error code of a binding naming an account another binding already holds.
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 ¶ added in v0.30.0
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 ¶
RequireAdmin refuses a non-admin caller under a scoping authorizer. Without one (single-user mode) every authenticated caller is already the operator.
func SharedOwner ¶
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 ¶
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.
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
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
AccountRef checks that a host key owned by refOwner may name the account.
func (Checker) BindablePolicy ¶ added in v0.20.0
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
BudgetRefs checks budgets a policy owned by refOwner links.
func (Checker) CredentialRefs ¶ added in v0.20.0
CredentialRefs checks host keys a policy owned by refOwner links.
func (Checker) Group ¶
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
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 ¶
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) KeyAccount ¶ added in v0.20.0
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 ¶
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
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
PersonalProviderAccount refuses a provider account owned by a user whose personal account is turned off: it would serve nothing.
func (Checker) Policy ¶
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) Pool ¶ added in v0.20.0
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) RateLimitRef ¶
RateLimitRef applies the policy-ref rule to a rate limit a policy names.
func (Checker) Role ¶
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
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
ShareExists is the refusal of a second share of src with r.
func (Checker) UsableAccount ¶ added in v0.20.0
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
UsableBudget checks the budget for a policy owned by by.
func (Checker) UsableHostKey ¶ added in v0.20.0
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
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
UsablePool checks the pool for a policy owned by by.
func (Checker) UsablePoolAccount ¶ added in v0.20.0
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
UsableRateLimit checks the rate limit for a policy owned by by.
func (Checker) UsableScope ¶ added in v0.20.0
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.
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.
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.