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 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) 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) HostKeyRefs(ctx context.Context, keyIDs []string, refOwner meta.Owner) error
- func (c Checker) Key(ctx context.Context, k *key.Key) error
- func (c Checker) KeyOwner(ctx context.Context, k *key.Key) 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) 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
- type Error
- type Grants
- type Lookup
Constants ¶
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 ¶
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 system. 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
}
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 ¶
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 or policy 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 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 ¶
HostKeyRefs checks the host keys a policy spends. Missing ids pass: the inference path skips a key it cannot find.
func (Checker) Key ¶
Key derives the key's owner from its principal and checks the policy it carries.
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) 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) 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 and policy it names.
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
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)
// 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.