approval

package
v1.0.310 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 3 Imported by: 0 modules, 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 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

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

type Config struct {
	Clock        func() time.Time
	MaxPending   int
	MaxPerTenant int
	TTL          time.Duration
}

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 Kind

type Kind uint8

Kind distinguishes the two request families PR-9 gates.

const (
	// KindUnset is the invalid zero value.
	KindUnset Kind = iota
	// KindOperational is an approval for a PR-6 REQUIRE_APPROVAL runtime decision.
	KindOperational
	// KindPublication is an approval to publish a candidate policy into the local
	// capability-scoped PR-6 store.
	KindPublication
)

func (Kind) String

func (k Kind) String() string

String returns a stable label for the kind.

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

func (r Receipt) CandidateHash() string

CandidateHash returns the bound candidate hash (publication).

func (Receipt) Capability

func (r Receipt) Capability() string

Capability returns the bound capability.

func (Receipt) DecisionDigest

func (r Receipt) DecisionDigest() string

DecisionDigest returns the bound decision digest (operational).

func (Receipt) GrantedAt

func (r Receipt) GrantedAt() time.Time

GrantedAt returns the grant time.

func (Receipt) ID

func (r Receipt) ID() ID

ID returns the approved request's identifier.

func (Receipt) Kind

func (r Receipt) Kind() Kind

Kind returns the approved request's family.

func (Receipt) Matches

func (r Receipt) Matches(tenant, capability, candidateHash string, proposedRevision uint64) bool

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

func (r Receipt) ProposedRevision() uint64

ProposedRevision returns the bound proposed revision (publication).

func (Receipt) Tenant

func (r Receipt) Tenant() string

Tenant returns the bound tenant.

func (Receipt) Valid

func (r Receipt) Valid() bool

Valid reports whether the receipt was produced by a real approval.

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) Binding

func (r *Request) Binding() Binding

Binding returns a copy of the immutable binding.

func (*Request) Capability

func (r *Request) Capability() string

Capability returns the bound capability.

func (*Request) Created

func (r *Request) Created() time.Time

Created returns the creation time.

func (*Request) DecidedAt

func (r *Request) DecidedAt() time.Time

DecidedAt returns the decision time (zero unless terminal).

func (*Request) Expiry

func (r *Request) Expiry() time.Time

Expiry returns the expiry time.

func (*Request) ID

func (r *Request) ID() ID

ID returns the opaque approval identifier.

func (*Request) Kind

func (r *Request) Kind() Kind

Kind returns the request family.

func (*Request) Reason

func (r *Request) Reason() string

Reason returns the safe decision reason (set on rejection).

func (*Request) Requester

func (r *Request) Requester() PrincipalID

Requester returns the stable principal that created the request.

func (*Request) State

func (r *Request) State() State

State returns the current lifecycle state.

func (*Request) Tenant

func (r *Request) Tenant() string

Tenant returns the bound tenant.

type Revisions

type Revisions struct {
	Policy     uint64
	Catalog    uint64
	Registry   uint64
	Inspection uint64
}

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
)

func (State) String

func (s State) String() string

String returns a stable label for the state.

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 NewStore

func NewStore(cfg Config) *Store

NewStore returns a bounded approval store.

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

func (s *Store) Create(id ID, kind Kind, requester PrincipalID, b Binding) (*Request, error)

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

func (s *Store) Get(id ID, tenant string) (*Request, error)

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

func (s *Store) List(tenant string, stateFilter State, limit int) []*Request

List returns a bounded, tenant-scoped view filtered by optional state. A zero stateFilter (StateUnknown) returns all states. Results are copies.

func (*Store) Reject

func (s *Store) Reject(id ID, approver PrincipalID, reason string, commit Committer) error

Reject decides a pending request as rejected. It commits the decision durably before changing state. A repeated identical rejection is idempotent; a conflicting terminal action is rejected.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL