Documentation
¶
Overview ¶
Package approval implements the bounded, four-eyes approval state machine that PR-9 uses for both operational approvals (from a PR-6 REQUIRE_APPROVAL decision) and local policy-publication requests. It is an administrative control projection only: approving a request commits a durable PR-8 approval event and yields an unforgeable Receipt, but it NEVER executes an upstream call, materializes a credential, or publishes a signed CP→DP snapshot. The Receipt is evidence a future stage MAY proceed — not an execution.
Every request is bound at creation to an immutable set of facts (tenant, capability, decision/candidate digest, and the policy/catalog/registry/ inspection revisions it was reasoned about). Approval re-verifies that binding against the live revisions at decide time, so a request whose underlying state changed (a TOCTOU race) is rejected rather than approved against stale facts.
Index ¶
- type Binding
- type Committer
- type Config
- type ID
- type Kind
- type PrincipalID
- type Receipt
- func (r Receipt) Approver() PrincipalID
- func (r Receipt) CandidateHash() string
- func (r Receipt) Capability() string
- func (r Receipt) DecisionDigest() string
- func (r Receipt) GrantedAt() time.Time
- func (r Receipt) ID() ID
- func (r Receipt) Kind() Kind
- func (r Receipt) Matches(tenant, capability, candidateHash string, proposedRevision uint64) bool
- func (r Receipt) ProposedRevision() uint64
- func (r Receipt) Tenant() string
- func (r Receipt) Valid() bool
- type Request
- func (r *Request) Approver() PrincipalID
- func (r *Request) Binding() Binding
- func (r *Request) Capability() string
- func (r *Request) Created() time.Time
- func (r *Request) DecidedAt() time.Time
- func (r *Request) Expiry() time.Time
- func (r *Request) ID() ID
- func (r *Request) Kind() Kind
- func (r *Request) Reason() string
- func (r *Request) Requester() PrincipalID
- func (r *Request) State() State
- func (r *Request) Tenant() string
- type Revisions
- type State
- type Store
- func (s *Store) Approve(id ID, approver PrincipalID, live Revisions, commit Committer) (Receipt, error)
- func (s *Store) Create(id ID, kind Kind, requester PrincipalID, b Binding) (*Request, error)
- func (s *Store) Get(id ID, tenant string) (*Request, error)
- func (s *Store) List(tenant string, stateFilter State, limit int) []*Request
- func (s *Store) Reject(id ID, approver PrincipalID, reason string, commit Committer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Binding ¶
type Binding struct {
Tenant string
Capability string // "gateway" | "management"
// Operational decision binding.
DecisionEventID string
DecisionDigest string
ServerID string
ToolFingerprint string
Resource string
Action string
OperationClass string
RiskClass string
CredentialProfile string
PowerCeiling string
// Publication binding.
CandidateHash string
BaseRevision uint64
ProposedRevision uint64
SimulationDigest string
// Revision bindings re-checked at decide time (TOCTOU guard).
Revisions Revisions
}
Binding is the immutable set of facts an approval is bound to. It carries only safe references and digests — never secrets, raw arguments, or output bodies.
type Committer ¶
type Committer interface {
CommitDecision(r *Request, decision State, approver PrincipalID) (evidenceDigest string, err error)
}
Committer durably records an approval decision through PR-8 BEFORE the store changes state. Its CommitDecision returns a safe evidence digest on success, or a classified error on failure — on which the store performs NO state change (fail closed). The adminapi service supplies an implementation backed by events.Manager.CommitDecision; tests supply a fake.
type Config ¶
Config configures a Store. maxPending/maxPerTenant/ttl come from the adminapi limits (passed as plain values to keep this package a leaf — no import cycle).
type ID ¶
type ID string
ID is an opaque approval identifier. It is not a secret and not a predictable counter exposed as a security token; it is generated by the caller (the adminapi service) from a safe unpredictable source and only ever compared for equality here.
type PrincipalID ¶
type PrincipalID string
PrincipalID is a STABLE authenticated principal identifier. Four-eyes MUST be compared on this value, never on a display name or email (which are neither stable nor unique).
type Receipt ¶
type Receipt struct {
// contains filtered or unexported fields
}
Receipt is an unforgeable record that a request was approved. Its fields are unexported and there is no public constructor that manufactures a valid receipt — only Store.Approve produces one, after a durable commit. A receipt is not a secret and carries no credential material; it is evidence a future stage MAY proceed.
func (Receipt) Approver ¶
func (r Receipt) Approver() PrincipalID
Approver returns the deciding principal.
func (Receipt) CandidateHash ¶
CandidateHash returns the bound candidate hash (publication).
func (Receipt) Capability ¶
Capability returns the bound capability.
func (Receipt) DecisionDigest ¶
DecisionDigest returns the bound decision digest (operational).
func (Receipt) Matches ¶
Matches reports whether the receipt is bound to the given publication facts. A receipt for one tenant/capability/candidate cannot authorize another.
func (Receipt) ProposedRevision ¶
ProposedRevision returns the bound proposed revision (publication).
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is an immutable approval request plus its mutable terminal outcome. Only the store mutates state, under its lock, after a durable commit.
func (*Request) Approver ¶
func (r *Request) Approver() PrincipalID
Approver returns the deciding principal (zero unless terminal).
func (*Request) Capability ¶
Capability returns the bound capability.
func (*Request) Requester ¶
func (r *Request) Requester() PrincipalID
Requester returns the stable principal that created the request.
type Revisions ¶
Revisions is the set of live revisions a request's binding is checked against at decide time. A mismatch on any bound revision invalidates the request.
type State ¶
type State uint8
State is the approval lifecycle state. Terminal states are immutable.
const ( // StateUnknown is the invalid zero value (fails closed). StateUnknown State = iota // StatePending is awaiting a four-eyes decision. StatePending // StateApproved is a terminal grant. StateApproved // StateRejected is a terminal denial. StateRejected // StateExpired is a terminal expiry (never approvable again). StateExpired )
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a bounded, in-memory, rebuildable projection of approval requests. It is the authoritative in-process view; the durable evidence is the PR-8 event stream (a Store can be rebuilt from committed approval events). All state transitions happen under the store lock, and only AFTER a durable commit.
func (*Store) Approve ¶
func (s *Store) Approve(id ID, approver PrincipalID, live Revisions, commit Committer) (Receipt, error)
Approve decides a pending request as approved. It enforces four-eyes, expiry, terminal-state immutability and the TOCTOU revision binding, then durably commits the decision through commit BEFORE changing state. A repeated approve by the same approver is idempotent (returns the same receipt); any conflicting terminal action is rejected.
func (*Store) Create ¶
Create records a new pending request bound to the given facts. The caller supplies an unpredictable, unique ID (adminapi generates it from crypto/rand). Four-eyes is not checked here — only at decision time.
func (*Store) Get ¶
Get returns the request iff it exists within the caller's tenant scope. A tenant mismatch returns not-found (uniform) so existence never leaks across tenants. A pending request past its TTL is lazily expired first.
func (*Store) List ¶
List returns a bounded, tenant-scoped view filtered by optional state. A zero stateFilter (StateUnknown) returns all states. Results are copies.