Documentation
¶
Overview ¶
Package apply is the single loader that turns manifest documents into Postgres rows. It has two halves: Plan diffs the submitted documents against the stored rows and reports what would change; Execute authorizes every mutating entry and then writes them, in dependency order.
The boot seed is Plan+Execute over a directory with no authorizer and no prune (see app/seed), so a seed and a POST /apply of the same tree produce the same rows and the same diff vocabulary.
Deliberately out of scope: transactions across kinds (stores are per-kind with their own tx; a mid-way store failure is reported with the partial applied list and re-applying converges), field-level ownership beyond the dirty flag, and reconcile loops.
Index ¶
- Variables
- func Authorize(ctx context.Context, p *Result, authzr authz.Authorizer) error
- func CheckDocs(ctx context.Context, docs []manifest.Document) error
- type Action
- type AuthzError
- type Counts
- type DetachedLinks
- type DetachedPolicy
- type DuplicateError
- type Entry
- type GovernanceError
- type InvalidError
- type LicenseError
- type Options
- type ReservedNameError
- type Result
- type RevokeImpact
- type Rows
- type StoreError
- type Stores
- type UnsupportedKindError
Constants ¶
This section is empty.
Variables ¶
var ErrSelectorRequired = errors.New("apply: prune requires a selector")
ErrSelectorRequired is returned when Prune is set without a selector — an unfiltered prune would delete every user row the manifest omits.
var KindRoutes = map[string]struct{ Plural, Singular string }{
"Team": {"teams", "team"},
"Project": {"projects", "project"},
"Provider": {"providers", "provider"},
"Host": {"hosts", "host"},
"RateLimit": {"rate-limits", "rate-limit"},
"HostKey": {"host-keys", "host-key"},
"Model": {"models", "model"},
"Pricing": {"pricings", "pricing"},
"HostBinding": {"host-bindings", "host-binding"},
"Policy": {"policies", "policy"},
"Account": {"accounts", "account"},
"Pool": {"pools", "pool"},
"Budget": {"budgets", "budget"},
"Group": {"groups", "group"},
"Role": {"roles", "role"},
"ServiceAccount": {"service-accounts", "service-account"},
"Key": {"keys", "key"},
"RoleBinding": {"role-bindings", "role-binding"},
"PolicyBinding": {"policy-bindings", "policy-binding"},
"Overlay": {"models.overlay", "model"},
"User": {"users", "user"},
}
KindRoutes maps a manifest kind to the API plural and singular the RBAC verb and the export query use. Kinds absent from a manifest (Setting) are not listed.
Functions ¶
func Authorize ¶
Authorize checks every entry against authzr and returns an *AuthzError for the first denied write. A nil authorizer skips the pass — the boot seed has no actor. Callers that only plan (dry run) run it too, so a caller who may write nothing never sees the diff.
Non-writing entries (unchanged, skip-dirty) are authorized under get and reported as forbidden when denied — the name comes from the caller's own bundle, so saying "this one was ignored" leaks nothing, while dropping it silently made a scoped apply look complete when half of it was skipped.
Types ¶
type Action ¶
type Action string
Action is what a plan entry would do to one row.
const ( ActionCreate Action = "create" ActionUpdate Action = "update" ActionUnchanged Action = "unchanged" // ActionSkipDirty is an operator-edited row that differs from the // document and the run refused to overwrite. Reported as drift; nothing // is written. ActionSkipDirty Action = "skip-dirty" ActionDelete Action = "delete" // ActionConflict is a row another writer changed between Plan and // Execute. Nothing is written for it; re-planning picks up the change. ActionConflict Action = "conflict" // ActionForbidden is a row in the bundle the caller may not read. // Nothing is written for it and nothing about the stored row is // reported — the name is the caller's own. ActionForbidden Action = "forbidden" )
type AuthzError ¶
AuthzError reports the row that failed authorization. Nothing was written.
func (*AuthzError) Error ¶
func (e *AuthzError) Error() string
func (*AuthzError) Unwrap ¶
func (e *AuthzError) Unwrap() error
type Counts ¶
type Counts struct {
Create int `json:"create" doc:"Rows created."`
Update int `json:"update" doc:"Rows updated."`
Unchanged int `json:"unchanged" doc:"Rows already matching."`
SkipDirty int `json:"skipDirty" doc:"Operator-edited rows left alone."`
Delete int `json:"delete" doc:"Rows deleted by prune."`
Conflict int `json:"conflict" doc:"Rows another writer changed since the plan."`
Forbidden int `json:"forbidden" doc:"Rows the caller may not read."`
}
Counts summarises a plan.
type DetachedLinks ¶ added in v0.20.0
type DetachedLinks struct {
// Field is the policy field that loses the link.
Field string `json:"field" doc:"The policy field that loses the link, such as spec.budgets."`
// Policies names the policies the caller may see.
Policies []string `json:"policies,omitempty" doc:"Slugs of the affected policies the caller may see."`
// Hidden counts the policies the caller may not see.
Hidden int `json:"hidden,omitempty" doc:"Affected policies the caller may not see."`
}
DetachedLinks lists the policies a prune takes a link from. The prune is allowed: a policy stops counting a deleted rate limit or budget, and narrows to the pools it still links, never widening.
type DetachedPolicy ¶ added in v0.20.0
type DetachedPolicy struct {
ID string
Name string
Owner meta.Owner
// Field is the policy field that loses the link, in the audit vocabulary.
Field string
}
DetachedPolicy is a policy a delete takes a link from, visible or not, so the change to it is audited as the control API's delete audits it.
type DuplicateError ¶
type DuplicateError struct {
Kind, Name string
}
DuplicateError reports two submitted documents naming the same row. Last one wins would silently discard the first.
func (*DuplicateError) Error ¶
func (e *DuplicateError) Error() string
type Entry ¶
type Entry struct {
Kind string `json:"kind" doc:"Manifest kind of the document, such as Policy or HostKey."`
Name string `json:"name" doc:"metadata.name of the row."`
ID string `json:"id,omitempty" doc:"Id of the stored row, when one exists."`
// Action is what would happen (or happened) to this row.
Action Action `` /* 279-byte string literal not displayed */
// ChangedFields lists the authorable JSON paths that differ, in the
// same vocabulary an audit row's change.fields uses.
ChangedFields []string `json:"changedFields,omitempty" doc:"JSON paths that differ from the stored row, named as in audit change.fields."`
// IDMismatch reports a metadata.id in the document that does not match
// the row its name resolved to. Ids stay server-owned: the document's
// id is ignored and the mismatch reported.
IDMismatch string `` /* 140-byte string literal not displayed */
// Detached is set on a delete that takes links from policies that stay.
Detached *DetachedLinks `json:"detached,omitempty" doc:"On a delete: the policies that lose a link to the row."`
// Revokes is set on the delete of a shared account: what revoking it changes.
Revokes []RevokeImpact `` /* 279-byte string literal not displayed */
// contains filtered or unexported fields
}
Entry is one planned row change.
func Execute ¶
Execute authorizes every mutating entry up front and only then writes. A denied row aborts the whole run with an *AuthzError and no writes (all-or-nothing at the authorization step). Writes are sequential in plan order; a store failure returns a *StoreError carrying what already landed. A nil authorizer skips authorization — the boot seed has no actor.
func (Entry) Authorized ¶
Authorized returns the RBAC action the entry was authorized under, the resource kind it names, and the row's owner — what an audit row for the change records.
func (Entry) DetachedPolicies ¶ added in v0.20.0
func (e Entry) DetachedPolicies() []DetachedPolicy
DetachedPolicies lists every policy the entry's delete takes a link from.
type GovernanceError ¶
GovernanceError reports a row whose mutation the governance settings refuse. Nothing was planned or written.
func (*GovernanceError) Error ¶
func (e *GovernanceError) Error() string
func (*GovernanceError) Unwrap ¶
func (e *GovernanceError) Unwrap() error
type InvalidError ¶
InvalidError reports a document whose translated row failed its kind's Validate. Nothing was planned or written.
func (*InvalidError) Error ¶
func (e *InvalidError) Error() string
func (*InvalidError) Unwrap ¶
func (e *InvalidError) Unwrap() error
type LicenseError ¶
type LicenseError struct{ Kind, Name, Feature string }
LicenseError reports a document declaring a feature this deployment is not licensed for. Unwraps to license.ErrRequired, which the HTTP layer maps to 403 with the license_required body.
func (*LicenseError) Error ¶
func (e *LicenseError) Error() string
func (*LicenseError) Unwrap ¶
func (e *LicenseError) Unwrap() error
type Options ¶
type Options struct {
Stores *Stores
// Force writes over rows an operator edited via the control API
// (meta.Dirty), resetting them to the manifest. Default false: dirty
// rows that differ are reported as skip-dirty and left alone.
Force bool
// Prune deletes rows that match Selector and are absent from the
// submitted set. Requires Selector; never touches system-, provider-,
// or host-owned rows.
Prune bool
Selector string
// CatalogSeed marks a run that seeds a catalog tree. A stored row of a
// document's name that the organization or a tenant owns is not the
// catalog's: it is left as it is and reported as a conflict.
CatalogSeed bool
// Gov supplies the governance:<kind> sections every planned mutation is
// checked against. Nil skips the check — the boot seed runs before the
// settings cache exists.
Gov settings.Reader
// License gates the features a manifest may declare. Nil skips the
// gate: the loaders below the control API (the boot seed, the CLI's
// seed subcommand) load an operator's own tree from disk, which is not
// the surface the licence sells. The control plane always supplies one.
License license.Checker
// Authz is the authorizer Execute will use. Plan reads it only to know
// whether there is one at all: without an authorizer the caller is a
// loader running as the deployment itself (boot seed, CLI), which may
// re-parent a row the same way an admin can. The control plane always
// supplies one, so a scoped caller still cannot chown across scopes.
Authz authz.Authorizer
// Directory writes the auth module's kinds. Nil builds one over Stores
// whose grant check probes Authz; the control plane passes its own, which
// also ends an account's sessions when apply changes it.
Directory *directory.Directory
// EnvPasswords lets a User document read its password from this
// process's environment (password.valueFrom.env). Only `relay seed`
// sets it: over the API it would let a caller read the server's
// variables into an account's password.
EnvPasswords bool
// PersonalAccountOff reports whether a user's personal account is turned off, as refcheck.Lookup's does; the control plane reads it from the published plans, and nil (the loaders below it) treats every user's as on.
PersonalAccountOff func(ctx context.Context, userID string) (off bool, username string)
}
Options configures a plan.
type ReservedNameError ¶
type ReservedNameError struct{ Kind, Name string }
ReservedNameError reports a document claiming a name relay owns.
func (*ReservedNameError) Error ¶
func (e *ReservedNameError) Error() string
type Result ¶
type Result struct {
Entries []Entry `json:"entries"`
Counts Counts `json:"counts"`
// contains filtered or unexported fields
}
Result is the full ordered set of entries one apply would run — the plan. (The verb Plan is the function that builds it.)
type RevokeImpact ¶ added in v0.20.0
type RevokeImpact struct {
Kind string `json:"kind" enum:"policy-binding,key,pool" doc:"Kind of the changed rows, as an API singular."`
Change string `` /* 215-byte string literal not displayed */
Names []string `json:"names,omitempty" doc:"Slugs of the changed rows the caller may see."`
Hidden int `json:"hidden,omitempty" doc:"Changed rows the caller may not see."`
}
RevokeImpact is one kind of change revoking a pruned share makes, as the control API's delete reports it.
type Rows ¶
type Rows struct {
Providers []*provider.Provider
Hosts []*host.Host
RateLimits []*ratelimit.RateLimit
HostKeys []*hostkey.HostKey
Models []*model.Model
Pricings []*pricing.Pricing
Bindings []*binding.Binding
Policies []*policy.Policy
Keys []*key.Key
Teams []*team.Team
Projects []*project.Project
Accounts []*account.Account
Pools []*apppool.Pool
Budgets []*budget.Budget
ServiceAccounts []*serviceaccount.ServiceAccount
Groups []*group.Group
Roles []*role.Role
RoleBindings []*rolebinding.RoleBinding
PolicyBindings []*policybinding.PolicyBinding
Overlays []*overlay.Overlay
Users []*user.User
}
Rows is every existing row of every kind, loaded once so planning, pruning, and export share a single read of Postgres.
type StoreError ¶
StoreError reports a write that failed part-way through. Applied lists the entries that landed before it.
func (*StoreError) Error ¶
func (e *StoreError) Error() string
func (*StoreError) Unwrap ¶
func (e *StoreError) Unwrap() error
type Stores ¶
type Stores struct {
Provider *catalogstore.ProviderStore
Host *catalogstore.HostStore
RateLimit *catalogstore.RateLimitStore
HostKey *hostkey.Store
Model *catalogstore.ModelStore
Policy *catalogstore.PolicyStore
Pricing *catalogstore.PricingStore
HostBinding *catalogstore.BindingStore
Key *key.Store
Team *team.Store
Project *project.Store
Account *account.Store
Pool *apppool.Store
Budget *budget.Store
ServiceAccount *serviceaccount.Store
Group *group.Store
Role *role.Store
RoleBinding *rolebinding.Store
PolicyBinding *policybinding.Store
Overlay *overlay.Store
// User resolves the usernames group members, subjects and user-principal
// keys name, and holds the accounts User documents write.
User *user.Store
}
Stores bundles every store a plan reads or writes. Declared here rather than reused from app/catalog: app/catalog depends on the boot seed, which depends on this package.
type UnsupportedKindError ¶
type UnsupportedKindError struct{ Kind string }
UnsupportedKindError reports a document apply cannot write. Settings and identity rows have their own endpoints; ignoring them would make a bundle look applied when half of it was dropped.
func (*UnsupportedKindError) Error ¶
func (e *UnsupportedKindError) Error() string