schemeadmin

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package schemeadmin implements the authority-bounded scheme publication surface described in analysis/2026-10-22-authority-bounded-capability-publication-architecture.md.

The package defines two immutable artifacts — CLC-SCHEME-PACKAGE-v1 and CLC-SCHEME-TRANSITION-v1 — and a deployer-side confirmation path that recomputes authority from explicit inputs. It adds no CLC grammar and no CLC verdict: authorization is delegated to the semantics package through the CLC-1.19 declared-domain relations (`ContainsWithDomains`, `AuthorizeSetWithDomains`).

Deliberate non-features:

  • no trusted `authorized`, `verified` or `approved` member is read from any artifact; both artifacts are closed objects, so such a member is a shape error rather than a claim;
  • `scheme:verify` does not exist, because verification is unprivileged;
  • nothing is deleted. Revocation creates a tombstone and a revoked digest stays revoked for every later generation;
  • `scheme:root-rotate` never accepts a key that is only in the proposed next root. It must be authorized by the current root and it must satisfy the separately configured next-root threshold.

Index

Constants

View Source
const (
	// SchemeID is the provisional project-local administration scheme name.
	// It is not a registered IETF or CLC namespace.
	SchemeID = "varwof/scheme-admin-v1"

	// PackageVersion is the artifact version of a scheme package.
	PackageVersion = "CLC-SCHEME-PACKAGE-v1"
	// TransitionVersion is the artifact version of a scheme transition.
	TransitionVersion = "CLC-SCHEME-TRANSITION-v1"
	// DeclarationVersion is the CLC-1.19 scheme declaration version.
	DeclarationVersion = "CLC-SCHEME-v1"

	// VerdictAccept and VerdictReject are the only confirmation outcomes.
	VerdictAccept = "accept"
	VerdictReject = "reject"
)
View Source
const (
	CapCreate     = "scheme:create"
	CapUpdate     = "scheme:update"
	CapRevoke     = "scheme:revoke"
	CapDelegate   = "scheme:delegate"
	CapRootRotate = "scheme:root-rotate"
	CapApprove    = "scheme:approve"
)

Administration capabilities. `scheme:verify` is intentionally absent: any party may verify schemas, digests and compatibility, and a signed result is governance evidence only under an explicit approval profile.

View Source
const (
	ActionCreate     = "create"
	ActionUpdate     = "update"
	ActionRevoke     = "revoke"
	ActionRootRotate = "root-rotate"
)

Transition actions. These are the four actions a transition artifact may name; delegation is a grant relation, not a package transition.

View Source
const (
	ChangePatch = "patch"
	ChangeMinor = "minor"
	ChangeMajor = "major"
)

Change classes, coarsest last.

View Source
const (
	CodePackageShape               = "package_shape"
	CodePackageDigestMismatch      = "package_digest_mismatch"
	CodeDeclarationInvalid         = "declaration_invalid"
	CodeTransitionShape            = "transition_shape"
	CodeTransitionDigestMismatch   = "transition_digest_mismatch"
	CodePackageTransitionMismatch  = "package_transition_mismatch"
	CodeSignatureMissing           = "signature_missing"
	CodeSignatureInvalid           = "signature_invalid"
	CodeSignatureChain             = "signature_chain"
	CodeSignatureNoAIC             = "signature_no_aic"
	CodeTransitionSignatureMissing = "transition_signature_missing"
	CodeTransitionSignatureInvalid = "transition_signature_invalid"
	CodePublisherMismatch          = "publisher_mismatch"
	CodePublisherKeyBinding        = "publisher_key_binding"
	CodeAuthorityNoGrant           = "authority_no_grant"
	CodeAuthorityNotContained      = "authority_not_contained"
	CodeAuthorityNotAuthorized     = "authority_not_authorized"
	CodeNamespaceOutsidePolicy     = "namespace_outside_policy"
	CodeNamespaceMismatch          = "namespace_mismatch"
	CodeCLCSupported               = "clc_revision_unsupported"
	CodeMajorExceedsLimit          = "major_exceeds_limit"
	CodeChangeClassInvalid         = "change_class_invalid"
	CodeCreateShape                = "create_shape"
	CodeStateNotEmpty              = "state_not_empty"
	CodeStateShape                 = "state_shape"
	CodeStateUnverified            = "state_unverified"
	CodeStateGeneration            = "state_generation_mismatch"
	CodeStateDigest                = "state_digest_mismatch"
	CodeGenerationRollback         = "generation_rollback"
	CodeGenerationFork             = "generation_fork"
	CodePackageRevoked             = "package_revoked"
	CodeRevocationInvalid          = "revocation_invalid"
	CodePackageExpired             = "package_expired"
	CodePackageStale               = "package_stale"
	CodeApprovalInsufficient       = "approval_insufficient"
	CodeApprovalInvalid            = "approval_invalid"
	CodeRootNoCurrentRoot          = "root_rotate_no_current_root"
	CodeRootSelfAuthorized         = "root_rotate_self_authorized"
	CodeRootPolicyMismatch         = "root_rotate_policy_mismatch"
	CodeRootThreshold              = "root_rotate_threshold"
	CodeDelegationNotContained     = "delegation_not_contained"
)

Stable failure codes. A confirmation returns at most one of these; the detail string carries the underlying CLC reason where one exists.

Variables

This section is empty.

Functions

func ApprovalSigningBytes

func ApprovalSigningBytes(pkg Package, tr Transition) ([]byte, error)

ApprovalSigningBytes is the exact payload an approver signs: the canonical scheme:approve operation for this package and transition. It binds both digests, the namespace and the target CLC revision.

func BuildApprovalOperation

func BuildApprovalOperation(pkg Package, tr Transition) (semantics.Operation, error)

BuildApprovalOperation constructs the exact approval operation. It is only used when the deployer's trust policy requires an approval threshold, and it pins the package and transition digests exactly.

func BuildDelegationOperation

func BuildDelegationOperation(d Delegation) (semantics.Operation, error)

BuildDelegationOperation builds the CLC operation a delegator must be authorized for. It is the parent capability applied to the child's declared dimensions.

func BuildManagementOperation

func BuildManagementOperation(pkg Package, tr Transition) (semantics.Operation, error)

BuildManagementOperation constructs the concrete CLC operation a deployer authorizes for this package/transition pair.

The operation carries only the bounded dimensions the scheme declares: namespace, change_class, major and clc_revision. The package and transition digests are integrity bindings — they are covered by the publisher's signature and emitted in the confirmation record — and are not operation parameters, because CLC-1.19 requires every operation parameter to be declared by the granting capability and a long-lived namespace grant cannot enumerate future digests. The optional approval operation pins them exactly.

func CanonicalDigest

func CanonicalDigest(v any) (string, error)

CanonicalDigest returns the JCS (RFC 8785) digest of a JSON value.

func CapabilityFor

func CapabilityFor(action string) (string, error)

CapabilityFor maps a transition action to its administration capability.

func CodeOf

func CodeOf(err error) string

CodeOf returns the stable failure code of err, or "" when err is not a schemeadmin failure.

func Digest

func Digest(raw []byte) string

Digest returns `sha256:<base64url-unpadded>` over the exact bytes.

func FullCapabilityID

func FullCapabilityID(capability string) string

FullCapabilityID prefixes a bare administration capability with the scheme.

func KeyID

func KeyID(cert *x509.Certificate) string

KeyID returns the `sha256:` key id of a certificate, the value a trust policy pins in `root_keys` / `next_root_keys`.

func MajorOf

func MajorOf(revision string) (int, error)

MajorOf parses the integer major component of a `major.minor` revision.

func MinorOf

func MinorOf(revision string) (int, error)

MinorOf parses the integer minor component of a `major.minor` revision.

func OperationDigest

func OperationDigest(op semantics.Operation) (string, error)

OperationDigest is the content address of a management operation.

func PackageDigest

func PackageDigest(pkg Package) (string, error)

PackageDigest is the content address of a package object.

func ParseDeclaration

func ParseDeclaration(raw []byte) (*schemedecl.Declaration, error)

ParseDeclaration validates a CLC-SCHEME-v1 declaration from its exact bytes.

func TransitionDigest

func TransitionDigest(tr Transition) (string, error)

TransitionDigest is the content address of a transition object.

func ValidateDelegation

func ValidateDelegation(d Delegation, policy TrustPolicy) error

ValidateDelegation checks that a child grant never exceeds the delegator's own grant, using the CLC-1.19 declared-domain containment relation.

The relation is CLC containment, so an identical grant is not wider and is accepted. What is refused is any widening: a broader namespace, an added change class, a higher major bound, an added CLC revision, or a capability the delegator does not hold.

func ValidatePackage

func ValidatePackage(pkg Package) error

ValidatePackage checks the closed package schema and its internal consistency. It does not look at payload bytes; use ValidatePayload for that.

func ValidatePayload

func ValidatePayload(pkg Package, definition, declaration []byte) error

ValidatePayload binds a package to the exact definition and declaration bytes. The declaration is additionally self-checked (version, digest, scheme, CLC revision). It does not parse the definition's capability list: the deployer's authority check uses the declaration, so a declaration that names an undeclared definition capability is a known limitation, not a check this function performs.

func ValidatePolicy

func ValidatePolicy(p TrustPolicy) error

ValidatePolicy checks the bootstrap configuration is usable at all.

func ValidateSignedDelegation

func ValidateSignedDelegation(raw, signature []byte, roots []*x509.Certificate, policy TrustPolicy) error

ValidateSignedDelegation verifies a detached PKCS#7 signature over the exact delegation bytes, checks the signer chain/AIC, binds an optional delegator principal, and requires the signer's AIC to actually hold the parent grant. It then applies the same CLC containment relation as ValidateDelegation.

func ValidateTransition

func ValidateTransition(tr Transition) error

ValidateTransition checks the closed transition schema and the per-action required members. State-independent checks only; Confirm compares the transition with the local registry state.

Types

type Approval

type Approval struct {
	PackageDigest    string `json:"package_digest"`
	TransitionDigest string `json:"transition_digest"`
	Approver         string `json:"approver"`
	Signature        []byte `json:"signature,omitempty"`
}

Approval is one recorded exact approval for a package/transition pair. The signature is a detached PKCS#7 over ApprovalSigningBytes (the canonical scheme:approve operation); Approver names the AIC principal that must match the recovered signer certificate.

type Confirmation

type Confirmation struct {
	Package    Package
	Transition Transition

	// Definition and Declaration are the exact payload bytes the package
	// digests pin.
	Definition  []byte
	Declaration []byte

	// TransitionBytes/TransitionSignature are the exact signed transition
	// artifact.  ConfirmSigned supplies them so a revoke can persist a tombstone
	// signature in state.
	TransitionBytes     []byte
	TransitionSignature []byte

	// PublisherCert is the certificate recovered from the detached PKCS#7
	// signature over the package bytes.  Roots are the trust anchors the
	// certificate chain must reach.
	PublisherCert *x509.Certificate
	Roots         []*x509.Certificate

	State  RegistryState
	Policy TrustPolicy
	// contains filtered or unexported fields
}

Confirmation is the complete input of one deployer decision. Every value is explicit: the library never reads a clock, a network or an environment.

type ConfirmationResult

type ConfirmationResult struct {
	Verdict    string `json:"verdict"`
	Reason     string `json:"reason,omitempty"`
	Detail     string `json:"detail,omitempty"`
	Action     string `json:"action"`
	Scheme     string `json:"scheme"`
	Namespace  string `json:"namespace"`
	Generation int64  `json:"generation"`

	PackageDigest              string `json:"package_digest"`
	TransitionDigest           string `json:"transition_digest"`
	ManagementOperationDigest  string `json:"management_operation_digest,omitempty"`
	ApprovalOperationDigest    string `json:"approval_operation_digest,omitempty"`
	PublisherCertificateDigest string `json:"publisher_certificate_digest,omitempty"`
	PublisherKeyID             string `json:"publisher_key_id,omitempty"`
	TrustPolicyDigest          string `json:"trust_policy_digest,omitempty"`
	RegistryStateDigest        string `json:"registry_state_digest,omitempty"`
	InputsDigest               string `json:"inputs_digest,omitempty"`

	RevokedPackageDigest    string `json:"revoked_package_digest,omitempty"`
	RevocationReason        string `json:"revocation_reason,omitempty"`
	RevocationEffectiveTime string `json:"revocation_effective_time,omitempty"`
	ReplacementDigest       string `json:"replacement_digest,omitempty"`
	TombstoneGeneration     int64  `json:"tombstone_generation,omitempty"`
	// contains filtered or unexported fields
}

ConfirmationResult is the replayable decision record. It binds every input digest and never carries a bare trust boolean: the verdict is the deployer's own recomputation.

func Confirm

Confirm is retained only as a fail-closed compatibility stub. A caller that has a recovered certificate but no detached signature proof must not be able to admit a package; use ConfirmSigned, which verifies the exact package and transition bytes.

func ConfirmSigned

func ConfirmSigned(c SignedConfirmation) (res ConfirmationResult, err error)

ConfirmSigned verifies every detached signature over the exact package and transition bytes before parsing either artifact, verifies every signer certificate against Roots, selects the publisher candidate whose AIC binds the package publisher and whose key signed the transition, and then runs the normal confirmation path. For a root rotation, checkRootRotation counts the distinct current-root keys among the verified package signers and enforces policy.root_threshold.

type Delegation

type Delegation struct {
	// Delegator is optional in the pure relation, but a signed delegation must
	// name the principal whose AIC key signed it.
	Delegator string          `json:"delegator,omitempty"`
	Grantee   string          `json:"grantee"`
	Parent    semantics.Grant `json:"parent"`
	Child     semantics.Grant `json:"child"`
}

Delegation is a proposed sub-grant of administration authority from one principal to another. The parent grant is the delegator's own grant; the child grant is what it proposes to hand on.

Delegation is a grant relation, not a package transition: it never carries a transition artifact and it never mints a package.

type Error

type Error struct {
	Code   string
	Detail string
}

Error is a fail-closed confirmation failure with a stable code.

func (*Error) Error

func (e *Error) Error() string

Error implements error.

type Package

type Package struct {
	Version               string `json:"@version"`
	Scheme                string `json:"scheme"`
	Revision              string `json:"revision"`
	DefinitionDigest      string `json:"definition_digest"`
	DeclarationDigest     string `json:"declaration_digest"`
	CLCRevision           string `json:"clc_revision"`
	ChangeClass           string `json:"change_class"`
	PreviousPackageDigest string `json:"previous_package_digest,omitempty"`
	Publisher             string `json:"publisher"`
	Generation            int64  `json:"generation"`
	IssuedAt              string `json:"issued_at,omitempty"`
	ValidUntil            string `json:"valid_until,omitempty"`
}

Package is the immutable CLC-SCHEME-PACKAGE-v1 artifact. The struct is the closed schema: every member below is the whole of what a deployer reads.

The payload bytes are not carried here. `ValidatePayload` binds this object to the exact definition and declaration bytes the deployment fixture pins, so the digest members can never be satisfied by a re-encoded object.

func ParsePackage

func ParsePackage(raw []byte) (Package, error)

ParsePackage decodes a package from its exact JSON bytes. Undeclared members are refused, so an embedded `authorized`/`verified`/`approved` member is a shape error.

type RegistryEntry

type RegistryEntry struct {
	Generation    int64  `json:"generation"`
	PackageDigest string `json:"package_digest"`
}

RegistryEntry is one accepted generation.

type RegistryState

type RegistryState struct {
	Scheme        string          `json:"scheme"`
	Revision      string          `json:"revision,omitempty"`
	Generation    int64           `json:"generation"`
	PackageDigest string          `json:"package_digest"`
	History       []RegistryEntry `json:"history,omitempty"`
	Revoked       []Revocation    `json:"revoked,omitempty"`
	Approvals     []Approval      `json:"approvals,omitempty"`
}

RegistryState is the deployer's local view of one scheme namespace.

func ParseState

func ParseState(raw []byte) (RegistryState, error)

ParseState decodes a closed local registry state from exact bytes.

func (RegistryState) Accept

Accept returns the registry state to persist after a successful confirmation. It is deliberately a pure state transition: the caller must pass the result of Confirm/ConfirmSigned, and this method re-checks that the result binds the same package and transition before advancing the head. It never mutates the receiver.

func (RegistryState) AcceptSigned

AcceptSigned verifies a full SignedConfirmation and then advances state with the exact signed transition available for the tombstone record.

func (RegistryState) HeadOf

func (s RegistryState) HeadOf() int64

HeadOf returns the highest generation recorded in the state.

type Revocation

type Revocation struct {
	PackageDigest     string `json:"package_digest"`
	Generation        int64  `json:"generation"`
	EffectiveTime     string `json:"effective_time"`
	Reason            string `json:"reason"`
	ReplacementDigest string `json:"replacement_digest,omitempty"`

	// Tombstone is the exact signed revocation transition and Signature is the
	// detached PKCS#7 over it.  A state file cannot invent a revocation without
	// a trusted signature.
	Tombstone []byte `json:"tombstone,omitempty"`
	Signature []byte `json:"signature,omitempty"`
}

Revocation is the local record of a signed tombstone. Revoked digests stay revoked; nothing is deleted.

type SignedConfirmation

type SignedConfirmation struct {
	PackageBytes         []byte
	Signatures           [][]byte
	TransitionBytes      []byte
	TransitionSignatures [][]byte

	Definition  []byte
	Declaration []byte

	Roots  []*x509.Certificate
	State  RegistryState
	Policy TrustPolicy
}

SignedConfirmation is the complete input for a deployer decision that verifies the detached PKCS#7 signatures itself. PackageBytes and TransitionBytes must be the exact bytes that were signed; Signatures and TransitionSignatures are detached PKCS#7 values over those bytes.

type Transition

type Transition struct {
	Version           string `json:"@version"`
	Action            string `json:"action"`
	Scheme            string `json:"scheme"`
	Namespace         string `json:"namespace"`
	FromGeneration    *int64 `json:"from_generation,omitempty"`
	ToGeneration      int64  `json:"to_generation"`
	FromDigest        string `json:"from_digest,omitempty"`
	ToDigest          string `json:"to_digest"`
	ChangeClass       string `json:"change_class"`
	TargetCLCRevision string `json:"target_clc_revision"`

	// revoke / tombstone
	RevocationReason        string `json:"revocation_reason,omitempty"`
	RevocationEffectiveTime string `json:"revocation_effective_time,omitempty"`
	ReplacementDigest       string `json:"replacement_digest,omitempty"`
	TombstoneGeneration     *int64 `json:"tombstone_generation,omitempty"`

	// root-rotate
	NextRootPackageDigest string   `json:"next_root_package_digest,omitempty"`
	NextRootKeys          []string `json:"next_root_keys,omitempty"`
	NextRootThreshold     int      `json:"next_root_threshold,omitempty"`
}

Transition is the immutable CLC-SCHEME-TRANSITION-v1 artifact. The struct is the closed schema. A transition never carries an authorization result; the deployer builds the management operation from it.

func ParseTransition

func ParseTransition(raw []byte) (Transition, error)

ParseTransition decodes a transition from its exact JSON bytes, refusing undeclared members.

type TrustPolicy

type TrustPolicy struct {
	RootPackageDigest string            `json:"root_package_digest"`
	RootKeys          []string          `json:"root_keys"`
	RootThreshold     int               `json:"root_threshold"`
	RootGrants        []semantics.Grant `json:"root_grants"`

	SupportedCLCRevisions []string `json:"supported_clc_revisions"`
	NamespacePrefixes     []string `json:"namespace_prefixes"`
	MaxMajor              int      `json:"max_major"`

	// AdministrationDeclaration is the pinned CLC-SCHEME-v1 declaration of the
	// administration scheme itself.  It is what gives `namespace` its
	// path-prefix domain and `change_class`/`clc_revision` their enum domains;
	// without it CLC would fall back to shape inference and path containment
	// would become exact equality.
	AdministrationDeclaration json.RawMessage `json:"administration_declaration"`

	// ObservedAt is the deployer's clock input, never "now()" read inside the
	// library.  Freshness decisions must be replayable.
	ObservedAt          string `json:"observed_at"`
	MaxStalenessSeconds int64  `json:"max_staleness_seconds,omitempty"`
	ApprovalThreshold   int    `json:"approval_threshold,omitempty"`

	// Separately configured next root.  A rotation is accepted only when the
	// current root authorizes it and this next-root threshold is met.
	NextRootPackageDigest string   `json:"next_root_package_digest,omitempty"`
	NextRootKeys          []string `json:"next_root_keys,omitempty"`
	NextRootThreshold     int      `json:"next_root_threshold,omitempty"`
}

TrustPolicy is the deployer's local bootstrap configuration. It is not published authority: every value here is a local adoption decision that may be stricter than global publication.

RootKeys are `sha256:` ids over a certificate's SubjectPublicKeyInfo. RootGrants are the configured authority the publisher's grant must stay inside; they are pinned together with the root administration package digest so that the bootstrap is auditable.

Jump to

Keyboard shortcuts

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