Skip to main content

compile_sign_load_install

Function compile_sign_load_install 

Source
pub fn compile_sign_load_install(
    grant: &Ucan,
    lattice: &Lattice,
    permissions: &impl PermissionMap,
    enrollment: BTreeMap<String, SecurityLabel>,
    approval: PolicyApproval,
    ed_sk: &SigningKey,
    pq_sk: &MlDsaSigningKey,
) -> Result<(Arc<CompiledPolicy>, bool), BootPolicyError>
Expand description

Compile a validated grant into a TE policy, hybrid-PQC-sign it, verify it once at load, and install it process-globally. Returns the installed CompiledPolicy.

The signer and verifier use the supplied policy-authority keypair and run the artifact through the full sign_policy → PolicyLoader::load path (rather than short-circuiting the crypto). require_pq = true — the ML-DSA outer layer is mandatory; a classical-only signature is rejected.

The caller MUST have already validated grant’s UCAN chain — compile reads only its capability set. Enrollment is the authority-owned DID→clearance table (#698), embedded in and covered by the signature. approval MUST come from an upstream-verified S5 approval binding (normally PolicyApproval::from_verified); this generic path never derives an approval from the policy it is loading. The loader independently recomputes the compiled policy hash and rejects a mismatched approval.

§Return: (policy, installed) — the write-once truth

Returns the policy this call compiled+verified together with an installed flag from [install_compiled_policy]: true iff this call’s policy actually became the process-global seam, false if one was already installed and the global slot is unchanged. The returned Arc is always this call’s own artifact regardless — but when installed == false, that artifact is NOT what crate::mac::compiled_policy returns.

§Write-once limitation (do not build a real-policy swap on this yet)

The seam is a OnceLock: the first installed policy pins it for the process lifetime. So this API installs a real policy ONLY on a node that has not already installed the boot baseline. Configured boot artifacts are loaded before the baseline; they cannot replace it afterward. Swapping a newer verified generation in atomically (e.g. ArcSwap<CompiledPolicy> keyed by generation) is the follow-up; until then, treat installed == false as “the earlier policy still governs the seam”, never as a successful swap.

§Key provenance

ed_sk and pq_sk are the policy authority’s hybrid signing keys. The approval is a separate reviewed binding supplied by the caller and checked independently from the artifact signature.