pub struct CompiledPolicy {
pub generation: u64,
pub matrix: TeMatrix,
pub lattice_bytes: Vec<u8>,
pub enrollment: BTreeMap<String, SecurityLabel>,
}Expand description
A compiled, distributable policy artifact: the TE matrix, the S1 lattice it was
compiled against (embedded verbatim), and the generation that binds them. generation
ties the matrix to a specific lattice generation (S1) AND is the AVC’s cache-invalidation
key — bumping it invalidates every cached decision.
§S1 reconciliation (#570): embed the lattice, bind the version (desync-proof)
The signed policy carries the lattice’s canonical CBOR bytes (Lattice::to_bytes —
the same codec the COSE signing path uses). Because those bytes are the closed
compartment vocabulary in bit-index order, every process that loads this policy
reconstructs the identical name↔bit map: same bytes in → identical bits out, so a
SecurityLabel’s compartment bits mean the same
thing in the compiler, the PDP, and every distributed AVC. The loader additionally
enforces lattice.version().generation() == generation — a compiled matrix is valid
ONLY against the lattice generation that minted its bit assignments.
Fields§
§generation: u64Monotonic policy generation. Equals the embedded lattice’s
LatticeVersion::generation
(enforced at construction and re-checked on load).
matrix: TeMatrixThe compiled TE allow/escalate matrix (produced by S5’s compiler).
lattice_bytes: Vec<u8>The S1 lattice policy, serialized to its canonical CBOR byte form. Embedded so the
PDP and every distributed AVC reconstruct an identical name↔bit vocabulary (no
cross-process compartment-bit desync). Reconstruct via CompiledPolicy::lattice.
enrollment: BTreeMap<String, SecurityLabel>Subject clearance provenance (#698, epic #547 activation prerequisite): the authority-owned exact-subject→clearance assignment, distributed inside this same signed artifact rather than resolved live (D1, ratified 2026-07-03 — “no principal authors the function that grants its own request”, so this map is populated only by whoever compiles+signs the policy, never by the subject itself).
The UCAN grant path resolves DID strings (Ucan::audience / Ucan::root_issuer);
Policy token issuance instead resolves the exact IssueToken.subject supplied by
its authorized caller (including non-DID OAuth subjects). No DID/username aliasing
occurs here. BTreeMap keeps canonical serialization deterministic.
Empty by default (CompiledPolicy::new) — a node that never calls
Self::with_enrollment compiles a policy with no enrolled subjects, and
Self::clearance_for returns None for every subject until enrollment.
Implementations§
Source§impl CompiledPolicy
impl CompiledPolicy
Sourcepub fn new(matrix: TeMatrix, lattice: &Lattice) -> Self
pub fn new(matrix: TeMatrix, lattice: &Lattice) -> Self
Compile a policy against an S1 Lattice. The generation is taken from the lattice
version — they are definitionally equal (#570): the lattice that minted the
compartment bits IS the policy generation. The lattice is embedded verbatim (its
canonical CBOR bytes) so it travels inside the signature. Enrollment starts empty;
attach it with Self::with_enrollment.
Sourcepub fn with_enrollment(
self,
enrollment: BTreeMap<String, SecurityLabel>,
) -> Self
pub fn with_enrollment( self, enrollment: BTreeMap<String, SecurityLabel>, ) -> Self
Attach the authority-owned exact-subject→clearance enrollment table (#698). Replaces any previously attached table. The caller is the policy-compiling authority — this is where an admin/UCAN-authored assignment becomes part of the signed artifact; the grant path never constructs or mutates this map itself.
Sourcepub fn clearance_for(&self, subject: &str) -> Option<SecurityLabel>
pub fn clearance_for(&self, subject: &str) -> Option<SecurityLabel>
Look up a subject’s authority-assigned clearance by exact string. None ⇒ the subject
is not enrolled ⇒ the caller MUST deny (no default clearance) — mirrors every other
S1 “unlabeled = denied” rule in this module tree.
Sourcepub fn lattice(&self) -> Result<Lattice, LatticeCodecError>
pub fn lattice(&self) -> Result<Lattice, LatticeCodecError>
Reconstruct the embedded S1 Lattice from its canonical bytes. Fail-closed: a
malformed / tampered vocabulary (duplicate names, over-width) is rejected rather than
silently yielding a different lattice (the desync-proof property).
Sourcepub fn canonical_bytes(&self) -> Result<Vec<u8>, PolicyDistError>
pub fn canonical_bytes(&self) -> Result<Vec<u8>, PolicyDistError>
Canonical bytes for hashing/signing. Deterministic: same policy → identical bytes
(design §13a determinism). We sort the rule sets into a stable vec form first so the
HashSet iteration order never leaks into the hash.
Sourcepub fn policy_hash(&self) -> Result<[u8; 32], PolicyDistError>
pub fn policy_hash(&self) -> Result<[u8; 32], PolicyDistError>
BLAKE3 content hash of the canonical bytes — the policy_hash the approval binds to.
Trait Implementations§
Source§impl Clone for CompiledPolicy
impl Clone for CompiledPolicy
Source§fn clone(&self) -> CompiledPolicy
fn clone(&self) -> CompiledPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompiledPolicy
impl Debug for CompiledPolicy
Source§impl<'de> Deserialize<'de> for CompiledPolicy
impl<'de> Deserialize<'de> for CompiledPolicy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for CompiledPolicy
impl RefUnwindSafe for CompiledPolicy
impl Send for CompiledPolicy
impl Sync for CompiledPolicy
impl Unpin for CompiledPolicy
impl UnsafeUnpin for CompiledPolicy
impl UnwindSafe for CompiledPolicy
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request