From cc80cd4479e34ad83490a6418e55546c6911aea5 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 19 Jul 2026 19:38:18 +0100 Subject: [PATCH] Define signed daemon health authority --- crates/odin-core/src/documents.rs | 287 +++++++++++++++++++ docs/idunn-signed-daemon-health-authority.md | 117 ++++++++ 2 files changed, 404 insertions(+) create mode 100644 docs/idunn-signed-daemon-health-authority.md diff --git a/crates/odin-core/src/documents.rs b/crates/odin-core/src/documents.rs index d8df9ea..2886320 100644 --- a/crates/odin-core/src/documents.rs +++ b/crates/odin-core/src/documents.rs @@ -1,6 +1,8 @@ use cultcache_rs::DatabaseEntry; use serde_json::Value; +use anyhow::{Result, bail}; + pub const ODIN_SNAPSHOT_SCHEMA: &str = "odin.snapshot.v1"; pub const ODIN_VERSE_SCHEMA: &str = "odin.verse.v1"; pub const ODIN_SERVICE_SCHEMA: &str = "odin.service.v1"; @@ -36,6 +38,8 @@ pub const IDUNN_DAEMON_TRANSPORT_PROFILE_SCHEMA: &str = "idunn.daemon_transport_ pub const IDUNN_COMMAND_BOUNDARY_SCHEMA: &str = "idunn.command_boundary.v1"; pub const IDUNN_RUNTIME_TRANSPORT_CHECK_SCHEMA: &str = "idunn.runtime_transport_check.v1"; pub const IDUNN_RUDP_HEALTH_INGRESS_SCHEMA: &str = "idunn.rudp_health_ingress.v1"; +pub const IDUNN_SIGNED_DAEMON_HEALTH_SCHEMA: &str = "idunn.signed_daemon_health.v1"; +pub const IDUNN_DAEMON_HEALTH_TRUST_BINDING_SCHEMA: &str = "idunn.daemon_health_trust_binding.v1"; pub const MUNINN_TELEMETRY_SURFACE_SCHEMA: &str = "muninn.telemetry_surface.v1"; pub const MUNINN_CAPTURE_STREAM_SCHEMA: &str = "muninn.capture_stream.v1"; pub const MUNINN_CAPTURE_STREAM_COMMAND_SCHEMA: &str = "muninn.capture_stream_command.v1"; @@ -309,6 +313,192 @@ pub struct IdunnSignedHealthAdmissionRecord { pub signed_health_sha256: String, } +/// Provider-owned health statement. Ingress must verify `signature` over the +/// complete document with an empty signature field before admitting it. +#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] +#[cultcache( + type = "idunn.signed_daemon_health", + schema = "idunn.signed_daemon_health.v1" +)] +pub struct IdunnSignedDaemonHealthRecord { + #[cultcache(key = 0)] + pub schema_version: String, + #[cultcache(key = 1)] + pub daemon_id: String, + #[cultcache(key = 2)] + pub health_contract: String, + #[cultcache(key = 3)] + pub source_runtime_id: String, + #[cultcache(key = 4)] + pub state: String, + #[cultcache(key = 5)] + pub detail: String, + #[cultcache(key = 6)] + pub signer_identity_id: String, + #[cultcache(key = 7)] + pub publisher_incarnation_id: String, + #[cultcache(key = 8)] + pub publisher_sequence: u64, + #[cultcache(key = 9)] + pub observed_at_unix_millis: u64, + #[cultcache(key = 10)] + pub release_id: Option, + #[cultcache(key = 11)] + pub release_witness_sha256: Option, + #[cultcache(key = 12)] + pub source_commit: Option, + #[cultcache(key = 13)] + pub deployment_id: Option, + #[cultcache(key = 14)] + pub signature_algorithm: String, + #[cultcache(key = 15)] + pub signature: Vec, + #[cultcache(key = 16)] + pub private_state_exposed: bool, +} + +impl IdunnSignedDaemonHealthRecord { + pub fn validate(&self) -> Result<()> { + if self.schema_version != IDUNN_SIGNED_DAEMON_HEALTH_SCHEMA { + bail!("signed daemon health schema is unsupported"); + } + validate_identifier(&self.daemon_id, "daemon id")?; + validate_identifier(&self.health_contract, "health contract")?; + validate_identifier(&self.source_runtime_id, "source runtime id")?; + validate_identifier(&self.signer_identity_id, "signer identity id")?; + validate_identifier(&self.publisher_incarnation_id, "publisher incarnation id")?; + if !matches!( + self.state.as_str(), + "active" | "warming" | "degraded" | "failed" + ) { + bail!("signed daemon health state is invalid"); + } + if self.detail.len() > 512 { + bail!("signed daemon health detail exceeds 512 bytes"); + } + if self.signature_algorithm != "ed25519" + || self.signature.len() != 64 + { + bail!("signed daemon health signature shape is invalid"); + } + if self.publisher_sequence == 0 || self.observed_at_unix_millis == 0 { + bail!("signed daemon health sequence or observation time is invalid"); + } + validate_optional_release_binding( + &self.release_id, + &self.release_witness_sha256, + &self.source_commit, + )?; + validate_optional_identifier(&self.deployment_id, "deployment id")?; + if self.private_state_exposed { + bail!("signed daemon health exposes private state"); + } + Ok(()) + } +} + +/// Root-owned admission binding. Store ownership is the physical authority; +/// this document names the only signer accepted for one daemon/contract/runtime. +#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] +#[cultcache( + type = "idunn.daemon_health_trust_binding", + schema = "idunn.daemon_health_trust_binding.v1" +)] +pub struct IdunnDaemonHealthTrustBindingRecord { + #[cultcache(key = 0)] + pub schema_version: String, + #[cultcache(key = 1)] + pub binding_id: String, + #[cultcache(key = 2)] + pub daemon_id: String, + #[cultcache(key = 3)] + pub health_contract: String, + #[cultcache(key = 4)] + pub source_runtime_id: String, + #[cultcache(key = 5)] + pub signer_identity_id: String, + #[cultcache(key = 6)] + pub signer_public_key: Vec, + #[cultcache(key = 7)] + pub binding_authority: String, + #[cultcache(key = 8)] + pub bound_at_unix_millis: u64, + #[cultcache(key = 9)] + pub release_binding_required: bool, + #[cultcache(key = 10)] + pub private_state_exposed: bool, +} + +impl IdunnDaemonHealthTrustBindingRecord { + pub fn validate(&self) -> Result<()> { + if self.schema_version != IDUNN_DAEMON_HEALTH_TRUST_BINDING_SCHEMA { + bail!("daemon health trust binding schema is unsupported"); + } + validate_identifier(&self.binding_id, "binding id")?; + validate_identifier(&self.daemon_id, "daemon id")?; + validate_identifier(&self.health_contract, "health contract")?; + validate_identifier(&self.source_runtime_id, "source runtime id")?; + validate_identifier(&self.signer_identity_id, "signer identity id")?; + if self.signer_public_key.len() != 32 + || self.binding_authority != "root" + || self.bound_at_unix_millis == 0 + { + bail!("daemon health trust binding authority or key is invalid"); + } + if self.private_state_exposed { + bail!("daemon health trust binding exposes private state"); + } + Ok(()) + } +} + +fn validate_identifier(value: &str, label: &str) -> Result<()> { + if value.trim().is_empty() || value.len() > 256 || value.chars().any(char::is_control) { + bail!("{label} is empty, oversized, or contains control characters"); + } + Ok(()) +} + +fn validate_optional_identifier(value: &Option, label: &str) -> Result<()> { + if let Some(value) = value { + validate_identifier(value, label)?; + } + Ok(()) +} + +fn validate_optional_release_binding( + release_id: &Option, + witness: &Option, + source_commit: &Option, +) -> Result<()> { + if release_id.is_some() || witness.is_some() || source_commit.is_some() { + validate_optional_identifier(release_id, "release id")?; + let witness = witness + .as_deref() + .ok_or_else(|| anyhow::anyhow!("release witness is absent"))?; + let commit = source_commit + .as_deref() + .ok_or_else(|| anyhow::anyhow!("source commit is absent"))?; + if release_id.is_none() || !is_sha256(witness) || !is_lower_hex(commit, 40) { + bail!("release binding is incomplete or malformed"); + } + } + Ok(()) +} + +fn is_sha256(value: &str) -> bool { + value + .strip_prefix("sha256-") + .is_some_and(|digest| is_lower_hex(digest, 64)) +} + +fn is_lower_hex(value: &str, length: usize) -> bool { + value.len() == length + && value + .bytes() + .all(|byte| byte.is_ascii_hexdigit() && !byte.is_ascii_uppercase()) +} + #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache( type = "idunn.keepalive_decision", @@ -1516,6 +1706,8 @@ cultmesh_rs::cultmesh_documents!(OdinDocuments { IdunnDesiredDaemonRecord => IDUNN_DESIRED_DAEMON_SCHEMA, IdunnDaemonHealthRecord => IDUNN_DAEMON_HEALTH_SCHEMA, IdunnSignedHealthAdmissionRecord => IDUNN_SIGNED_HEALTH_ADMISSION_SCHEMA, + IdunnSignedDaemonHealthRecord => IDUNN_SIGNED_DAEMON_HEALTH_SCHEMA, + IdunnDaemonHealthTrustBindingRecord => IDUNN_DAEMON_HEALTH_TRUST_BINDING_SCHEMA, IdunnKeepaliveDecisionRecord => IDUNN_KEEPALIVE_DECISION_SCHEMA, IdunnRestartRequestRecord => IDUNN_RESTART_REQUEST_SCHEMA, IdunnRestartResultRecord => IDUNN_RESTART_RESULT_SCHEMA, @@ -1575,6 +1767,101 @@ mod tests { use anyhow::Result; use cultmesh_rs::{CultMesh, CultMeshNodeOptions}; + fn signed_health_fixture() -> IdunnSignedDaemonHealthRecord { + IdunnSignedDaemonHealthRecord { + schema_version: IDUNN_SIGNED_DAEMON_HEALTH_SCHEMA.into(), + daemon_id: "yggdrasil-epiphany".into(), + health_contract: "epiphany.cultnet-rudp-runtime-health".into(), + source_runtime_id: "epiphany-yggdrasil".into(), + state: "active".into(), + detail: "provider-authenticated resident readiness".into(), + signer_identity_id: "epiphany-host-identity".into(), + publisher_incarnation_id: "epiphany-yggdrasil/boot-7/process-11".into(), + publisher_sequence: 42, + observed_at_unix_millis: 1_784_483_200_000, + release_id: Some("release-42".into()), + release_witness_sha256: Some(format!("sha256-{}", "a".repeat(64))), + source_commit: Some("b".repeat(40)), + deployment_id: Some("deploy:yggdrasil-epiphany:42".into()), + signature_algorithm: "ed25519".into(), + signature: vec![9; 64], + private_state_exposed: false, + } + } + + fn trust_binding_fixture() -> IdunnDaemonHealthTrustBindingRecord { + let health = signed_health_fixture(); + IdunnDaemonHealthTrustBindingRecord { + schema_version: IDUNN_DAEMON_HEALTH_TRUST_BINDING_SCHEMA.into(), + binding_id: "root/yggdrasil-epiphany/health".into(), + daemon_id: health.daemon_id, + health_contract: health.health_contract, + source_runtime_id: health.source_runtime_id, + signer_identity_id: health.signer_identity_id, + signer_public_key: vec![7; 32], + binding_authority: "root".into(), + bound_at_unix_millis: 1_784_483_100_000, + release_binding_required: true, + private_state_exposed: false, + } + } + + #[test] + fn generic_signed_health_contracts_validate_and_round_trip() -> Result<()> { + let health = signed_health_fixture(); + let binding = trust_binding_fixture(); + health.validate()?; + binding.validate()?; + + let temp = tempfile::tempdir()?; + let store_path = temp.path().join("signed-health.cc"); + let mut node = CultMesh::create_node( + &store_path, + OdinDocuments, + CultMeshNodeOptions { + runtime_id: "idunn-test".into(), + pull_on_start: true, + }, + )?; + node.put(&health.daemon_id, &health)?; + node.put(&binding.binding_id, &binding)?; + assert_eq!( + node.get_required::(&health.daemon_id)?, + health + ); + assert_eq!( + node.get_required::(&binding.binding_id)?, + binding + ); + Ok(()) + } + + #[test] + fn generic_signed_health_contracts_refuse_weak_or_partial_authority() { + let mut health = signed_health_fixture(); + health.private_state_exposed = true; + assert!(health.validate().is_err()); + health = signed_health_fixture(); + health.signature.clear(); + assert!(health.validate().is_err()); + health = signed_health_fixture(); + health.release_witness_sha256 = None; + assert!(health.validate().is_err()); + health = signed_health_fixture(); + health.publisher_sequence = 0; + assert!(health.validate().is_err()); + + let mut binding = trust_binding_fixture(); + binding.binding_authority = "daemon".into(); + assert!(binding.validate().is_err()); + binding = trust_binding_fixture(); + binding.signer_public_key = vec![1; 31]; + assert!(binding.validate().is_err()); + binding = trust_binding_fixture(); + binding.private_state_exposed = true; + assert!(binding.validate().is_err()); + } + #[test] fn muninn_media_documents_round_trip_through_cultmesh() -> Result<()> { let temp = tempfile::tempdir()?; diff --git a/docs/idunn-signed-daemon-health-authority.md b/docs/idunn-signed-daemon-health-authority.md new file mode 100644 index 0000000..114ea72 --- /dev/null +++ b/docs/idunn-signed-daemon-health-authority.md @@ -0,0 +1,117 @@ +# Idunn signed daemon-health authority + +## Objective + +Idunn must know which daemon authored a health statement before that statement +can affect lifecycle judgment or operator status. A typed packet is a shape, +not an identity. The current generic `idunn.daemon_health.v1` RUDP path checks +shape, daemon id, contract, self-declared publication source, and freshness but +does not authenticate the publisher. It is diagnostic input until replaced. + +## Owner + +- Each daemon owns its health statement and signs it with its pinned service or + host identity. +- Idunn owns admission, freshness, monotonic lineage, managed-health judgment, + and the outward status projection. +- Root deployment configuration owns the trust binding between daemon id, + health contract, source runtime, and signer identity. + +No renderer, transport peer, systemd unit, PID probe, caller boolean, or typed +but unsigned packet owns health. + +## Inputs + +The daemon-authored statement binds: + +- exact daemon id and health contract; +- source runtime id and signer identity; +- observation time, publisher incarnation, and monotonic sequence; +- bounded health state and detail; +- release id, release witness, source revision, and deployment request when the + managed target is release-bound; +- `private_state_exposed=false`; +- an Ed25519 signature over the complete unsigned statement under a + domain-separated signing purpose. + +The Idunn trust binding names the only public key allowed to speak for that +daemon/contract/runtime tuple and whether release identity is required. + +## Outputs + +Idunn persists two separate facts: + +1. the admitted daemon-authored statement and its digest; +2. an Idunn-authored outward status projection binding the trust record, + admission, managed target, current deployment lineage, freshness judgment, + and observation time. + +Consumers such as Epiphany Discord Status receive only the outward projection +through CultNet/CultMesh and verify Idunn's pinned identity. Reading Idunn's +private store is not a consumer protocol. + +## Derived state + +- Process and systemd observations are diagnostic evidence only. +- RUDP source endpoints and connection ids are transport routing only. +- `publication_source`, `transport`, `ready`, and `healthy` strings are display + data unless contained inside a valid signed statement. +- An unsigned legacy health packet may be retained temporarily for diagnostics + but cannot satisfy managed health, prevent recovery, or produce a healthy + outward projection. + +## Forbidden writers + +- The inbound packet cannot choose its own trust anchor. +- A daemon cannot change its configured daemon id, contract, or source runtime + by signing different values. +- Idunn cannot manufacture daemon-authored health from PID, executable, + container, HTTP, systemd, or command exit observations. +- Epiphany, Bifrost, VoidBot, Eve, and Discord cannot infer Idunn acceptance + from a sent packet. +- A generic typed `idunn.daemon_health.v1` packet cannot fall back into + lifecycle authority when signature verification fails or trust is absent. + +## Shared paths + +Every managed daemon uses the same verification primitive: + +`signed statement -> root trust binding -> signature and tuple verification -> +monotonic admission -> target/deployment join -> Idunn outward projection` + +Epiphany's deployed `epiphany.idunn_signed_runtime_health.v0` path is migration +evidence and the first working implementation of the signature half. It is not +the permanent excuse for a service-specific verifier. The generic contract +must absorb its invariants before the special path is deleted. + +## Cut line + +1. Add generic signed-health and trust-binding contracts. +2. Make generic Idunn admission verify the pinned tuple, signature, sequence, + incarnation, freshness, and release requirements. +3. Migrate Epiphany and Bifrost publishers and install their root-owned trust + bindings. +4. Publish and verify Idunn's outward signed projection. +5. Point Discord Status at the outward projections. +6. Delete generic unsigned health from managed-health authority and delete the + Epiphany-only verifier after its last publisher migrates. + +The rebuild is incomplete while an unsigned packet can keep a managed daemon +healthy or while a status consumer must inspect Idunn's private store. + +## Verification layer + +Hostile tests must prove: + +- valid shape with no signature is not admitted; +- wrong key, daemon, contract, runtime, release, deployment, or trust record is + not admitted; +- replay, sequence rollback, time rollback, incarnation substitution, and + future/stale observations are not admitted; +- a live PID, existing executable, green HTTP response, or generic `ready` + string cannot repair failed authentication; +- one daemon's trust record cannot authenticate another daemon; +- unsigned legacy health cannot suppress recovery or yield outward healthy; +- outward status is signed by Idunn and binds the exact admitted statement; +- private detail and filesystem/process internals never enter the operator + projection.