cellos_core/authority/mod.rs
1//! Typed authority validator (Authority Model §14 + ADG).
2//!
3//! # Status — preview
4//!
5//! This module ships under the **`CELLOS_AUTHORITY_VALIDATOR_PREVIEW=1`** policy
6//! authorized by the ADR-0005 SLA council (see
7//! [Plans/cellos-code-complete-roadmap.md §7 Phase B1](../../../../Plans/cellos-code-complete-roadmap.md)).
8//! At time of landing, ADR-0005 is **Proposed**; the council recommended
9//! pre-merging the B2 validator scaffold behind this preview flag if the
10//! ADR-0005 Accept SLA (deadline 2026-05-20) slips, so post-1.0 work has a
11//! stable foundation to rest on.
12//!
13//! **What lands here (B2-1 / B2-2 / B2-3 + T3.A / F2):**
14//!
15//! * The four typed authority variants ([`ObservedAuthority`],
16//! [`ProvenAuthority`], [`ImposedAuthority`], [`DeclaredAuthority`]) —
17//! mechanically separated per
18//! [docs/authority-model.md §14](../../../../docs/authority-model.md)
19//! and [ADR-0006](../../../../docs/adr/0006-in-vm-observability-runner-evidence.md) §1.
20//! * The validator function and supporting enums:
21//! [`AuthorityDerivation`], [`EpistemicStatus`], [`RuleClass`], [`Rule`],
22//! [`BindingStatus`], [`ValidationError`].
23//! * The compile-fail [`GuestEventBuilder`] gate (T3.A / F2).
24//! * Property tests for the §9 non-inflation invariants
25//! (see `tests` submodule).
26//!
27//! **What deliberately does NOT land here (B3, post-1.0):**
28//!
29//! * No producer (event-builder, supervisor admission, sni_proxy) wires these
30//! types in yet. The CloudEvent emitters keep producing today's untyped
31//! shape until the post-1.0 wiring slice replaces them.
32//! * No JSON Schema integration with `contracts/schemas/`. The schema
33//! `cell-observability-l7-authority-evidence-v1.schema.json` lands as part
34//! of B3 (post-1.0).
35//!
36//! # `DeclaredAuthority` — F2 / T3.A
37//!
38//! [ADR-0006](../../../../docs/adr/0006-in-vm-observability-runner-evidence.md)
39//! defines the fourth variant [`DeclaredAuthority`] (Tier ceiling 1,
40//! epistemic status [`EpistemicStatus::Declared`]) for guest-side
41//! `cellos-telemetry` declarations forwarded over the per-cell vsock
42//! channel. The mono-class envelope ([`RuleClass::GuestAgentDeclaration`])
43//! prevents host-side classes from co-occurring inside the same typed
44//! authority. The companion [`GuestEventBuilder`] trait pins the rule-class
45//! at compile time via a `const`-asserted check, so a guest event-builder
46//! cannot accidentally route through a stronger class.
47//!
48//! # Doctrine gates
49//!
50//! * **D9 (mechanical separation):** the three types share no common base
51//! trait, expose no [`From`] / [`Into`] conversions between each other,
52//! and each carry their own validated [`AuthorityDerivation`]. Merging two
53//! stacks is a compile error, not a runtime contract.
54//! * **D11 (no I/O in `cellos-core`):** the validator is pure. It takes
55//! plain values, returns [`Result`]. No tokio, no reqwest, no syscalls.
56//!
57//! # Overview
58//!
59//! The Authority Derivation Graph (ADG) — see
60//! [docs/authority-derivation-graph.md](../../../../docs/authority-derivation-graph.md)
61//! — is the canonical record of *how* an authority emission was computed.
62//! Every typed authority MUST carry an [`AuthorityDerivation`] and the
63//! validator enforces six invariants on construction:
64//!
65//! 1. **Confidence non-inflation** — `output.confidence ≤ max(inputs.confidence)`.
66//! 2. **Tier ceiling** — `output.tier ≤ min(rule_class_tier_ceiling)`.
67//! 3. **Epistemic determinism** — `output.epistemic_status` is the unique
68//! image of the rule-class set under the canonical mapping.
69//! 4. **ADG presence** — emissions cannot construct without an ADG (gated
70//! by builder API and refused by the validator if `inputs` or
71//! `rules_applied` is empty).
72//! 5. **Rule → class consistency** — every applied rule's declared class
73//! matches the canonical mapping.
74//! 6. **Type-class compatibility** — `ObservedAuthority` cannot carry
75//! `CRYPTOGRAPHIC_PROOF` rules; `ProvenAuthority` cannot be built without
76//! one; `ImposedAuthority` requires `IMPOSED_INTERCEPTION`.
77//!
78//! See submodule [`validator`] for the typed-authority constructors and
79//! [`crate::authority::tests`] (cfg(test)-only) for the property tests.
80
81#![deny(missing_docs)]
82
83mod validator;
84
85/// T2-B21 — typed result variants for `verify_authority_derivation`.
86///
87/// Sibling to [`validator`] (which hosts the ADR-0006 typed-authority
88/// builders). This submodule is the foundation for the typed-validator
89/// scaffold from PR #40 / T2.A: it gives admission-side callers a pattern-
90/// matchable result enum without disturbing the existing
91/// `Result<(), CellosError>` public surface.
92pub mod derivation_result;
93
94/// F2 — guest-declared capability surface and the subset validator the host
95/// runs before accepting in-VM telemetry.
96///
97/// Companion to [`validator`]'s ADG-validated [`DeclaredAuthority`] (the
98/// *evidence* form). This submodule ships [`declared::DeclaredAuthoritySurface`]
99/// (the *surface* form, three plain fields) plus
100/// [`declared::validate_declared_authority_surface`], the subset check the
101/// supervisor runs before accepting any guest declaration. See the module
102/// docs in [`declared`] for the evidence-vs-surface split.
103pub mod declared;
104
105#[cfg(test)]
106mod tests;
107
108pub use validator::{
109 canonical_class_for_rule, epistemic_for_class_set, max_tier_for_class, AppliedRule,
110 AuthorityDerivation, AuthorityInput, AuthorityInputType, AuthorityOutput, BindingStatus,
111 DeclaredAuthority, EpistemicStatus, GuestEventBuilder, ImposedAuthority, ObservedAuthority,
112 ProvenAuthority, ProvenAuthorityArtifact, Rule, RuleClass, ValidationError,
113};
114
115pub use derivation_result::{validate_authority_derivation, AuthorityValidationResult};
116
117pub use declared::{validate_declared_authority_surface, DeclaredAuthoritySurface};