diff --git a/README.md b/README.md index 3ef18d9..961e921 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,14 @@ the canonical runtime (`yggdrasil` for `yggdrasil-local`), exact source revision (or `restart:`), exact request id, operator, signature, and short expiry. Missing, corrupt, engaged, expired, foreign, wrong-scope, substituted, or badly-signed state fails closed. Planning and lifecycle-command publication do -not bypass or cache this decision. +not bypass or cache this decision. The store and its sibling `.lock` live in +`/var/lib/gamecult/idunn-authority`, a root-owned `root:idunn` `0750` directory; +both files are `root:idunn` `0640`, and the daemon's systemd sandbox exposes the +directory read-only. Idunn holds the lock shared from its final snapshot read +through process spawn, so an engage cannot be defeated by previously captured +released bytes. A release is not one-shot: its exact request/revision grant +covers each migration and deploy spawn in that rollout until its short expiry; +every spawn independently reopens and validates the same grant. Local package surfaces: diff --git a/crates/idunn-daemon/src/main.rs b/crates/idunn-daemon/src/main.rs index 486bb9b..b723f81 100644 --- a/crates/idunn-daemon/src/main.rs +++ b/crates/idunn-daemon/src/main.rs @@ -6007,14 +6007,17 @@ fn run_shell( .with_context(|| format!("creating {}", stderr_path.display()))?; configure_command_lifetime(&mut process); - // This is deliberately the last fallible authority read before spawn. - // Preparation above has no consequence outside Idunn's temporary files. - verify_deployment_brake(options, release_id, deployment_id)?; - let child = process - .stdout(Stdio::from(stdout_file)) - .stderr(Stdio::from(stderr_file)) - .spawn() - .with_context(|| format!("running command {command:?}"))?; + // Hold the root-owned authority lock from the final read through spawn. + // An operator engage therefore wins before this gate or waits until the + // already-authorized consequence has begun; captured release bytes cannot + // race a later engage into a new spawn. + let child = with_verified_deployment_brake(options, release_id, deployment_id, || { + process + .stdout(Stdio::from(stdout_file)) + .stderr(Stdio::from(stderr_file)) + .spawn() + .with_context(|| format!("running command {command:?}")) + })?; let status = wait_for_child_status_with_timeout( child, Duration::from_secs(options.command_timeout_seconds), @@ -6044,15 +6047,30 @@ fn run_braked_shell( run_shell(command, options, release_id, deployment_id, deployment) } -fn verify_deployment_brake( +fn with_verified_deployment_brake( options: &CommonOptions, release_id: &str, deployment_id: &str, -) -> Result<()> { + consequence: impl FnOnce() -> Result, +) -> Result { let store_path = options .deployment_brake_store_path .as_ref() .ok_or_else(|| anyhow!("--deployment-brake-store is required for actuation"))?; + SingleFileMessagePackBackingStore::new(store_path) + .with_read_only_shared_snapshot(|entries| { + verify_deployment_brake_snapshot(options, release_id, deployment_id, entries)?; + consequence() + }) + .with_context(|| format!("reading deployment brake {}", store_path.display())) +} + +fn verify_deployment_brake_snapshot( + options: &CommonOptions, + release_id: &str, + deployment_id: &str, + entries: Vec, +) -> Result<()> { let anchor_path = options .deployment_brake_operator_anchor_path .as_ref() @@ -6061,10 +6079,6 @@ fn verify_deployment_brake( .deployment_brake_runtime_id .as_deref() .ok_or_else(|| anyhow!("deployment brake runtime id is not configured"))?; - - let entries = SingleFileMessagePackBackingStore::new(store_path) - .pull_all_read_only_snapshot() - .with_context(|| format!("reading deployment brake {}", store_path.display()))?; let observation = match entries.as_slice() { [entry] if entry.r#type == IdunnDeploymentBrakeRecord::TYPE @@ -7653,6 +7667,14 @@ mod tests { "--release-authority-store /srv/bifrost/state/repository-release-authority.cc" )); assert!(unit.contains("--command-timeout-seconds 21600")); + assert!(unit.contains( + "--deployment-brake-store /var/lib/gamecult/idunn-authority/deployment-brake.cc" + )); + assert!(unit.contains("ReadOnlyPaths=/var/lib/gamecult/idunn-authority")); + assert!(!unit.contains("ReadWritePaths=/var/lib/gamecult/idunn-authority")); + assert!( + !unit.contains("--deployment-brake-store /var/lib/gamecult/idunn/deployment-brake.cc") + ); assert!(unit.contains( "--trusted-epiphany-health-identity-store /etc/gamecult/idunn/epiphany-health-identity.ccmp" )); diff --git a/crates/idunn-daemon/src/provisioning.rs b/crates/idunn-daemon/src/provisioning.rs index b046f58..7638009 100644 --- a/crates/idunn-daemon/src/provisioning.rs +++ b/crates/idunn-daemon/src/provisioning.rs @@ -1137,7 +1137,7 @@ mod tests { } #[test] - fn brake_operator_can_engage_then_issue_one_exact_bounded_release() -> Result<()> { + fn brake_operator_can_issue_one_exact_bounded_rollout_grant() -> Result<()> { let temp = TempDir::new()?; let private = temp.path().join("operator-private.cc"); let anchor = temp.path().join("operator-public.cc"); @@ -1179,7 +1179,7 @@ mod tests { "--owner", "operator/metacrat", "--reason", - "one deployment", + "one rollout", "--authorization-id", "auth/r4", "--release-id", diff --git a/docs/idunn.md b/docs/idunn.md index 8e339e7..2b21813 100644 --- a/docs/idunn.md +++ b/docs/idunn.md @@ -38,6 +38,15 @@ escalation, and continuity witness state. - Shared paths: manual operator deploy/restart, scheduled deploy/restart, degraded-health repair, boot rehydration, and future remote worker recovery must pass through the same Idunn command primitive. +- Consequence gate: Yggdrasil keeps `deployment-brake.cc` and its pre-created + sibling `deployment-brake.cc.lock` in `/var/lib/gamecult/idunn-authority`. + The directory is `root:idunn` `0750`, both files are `root:idunn` `0640`, and + Idunn receives only a systemd `ReadOnlyPaths` view. It holds the lock shared + across the final read, validation, and spawn; the root-owned operator writer + takes it exclusive for engage/release. A bounded release authorizes the exact + rollout request and source revision, covering its migration and deploy spawns + until expiry. It is not consumed after the first spawn, and every spawn must + independently revalidate it. - Deletion line: any keepalive loop inside Odin, Gjallar, Eve lowerers, or renderer code must be cut or demoted to a probe that names Idunn as the restart owner. diff --git a/scripts/linux/idunn-yggdrasil.service b/scripts/linux/idunn-yggdrasil.service index 252526b..ce335f5 100644 --- a/scripts/linux/idunn-yggdrasil.service +++ b/scripts/linux/idunn-yggdrasil.service @@ -10,7 +10,7 @@ User=idunn Group=idunn # Operational cancellation ceiling only. Target daemons own readiness through # typed health; this duration must never be interpreted as deployment success. -ExecStart=/usr/local/bin/idunn --swarm-profile yggdrasil-local --repo-root /srv/odin/source --store /var/lib/gamecult/idunn/yggdrasil.keepalive.cc --release-authority-store /srv/bifrost/state/repository-release-authority.cc --deployment-brake-store /var/lib/gamecult/idunn/deployment-brake.cc --deployment-brake-operator-anchor /etc/gamecult/idunn/deployment-brake-operator-anchor.cc --rudp-health-bind 10.77.0.1:17870 --trusted-epiphany-health-identity-store /etc/gamecult/idunn/epiphany-health-identity.ccmp --command-timeout-seconds 21600 --execute +ExecStart=/usr/local/bin/idunn --swarm-profile yggdrasil-local --repo-root /srv/odin/source --store /var/lib/gamecult/idunn/yggdrasil.keepalive.cc --release-authority-store /srv/bifrost/state/repository-release-authority.cc --deployment-brake-store /var/lib/gamecult/idunn-authority/deployment-brake.cc --deployment-brake-operator-anchor /etc/gamecult/idunn/deployment-brake-operator-anchor.cc --rudp-health-bind 10.77.0.1:17870 --trusted-epiphany-health-identity-store /etc/gamecult/idunn/epiphany-health-identity.ccmp --command-timeout-seconds 21600 --execute Restart=always RestartSec=5 TimeoutStopSec=20 @@ -20,6 +20,7 @@ PrivateTmp=yes ProtectHome=yes ProtectSystem=full ReadWritePaths=/var/lib/gamecult/idunn /srv/build /srv/voidbot +ReadOnlyPaths=/var/lib/gamecult/idunn-authority [Install] WantedBy=multi-user.target diff --git a/vendor/cultcache-rs/src/lib.rs b/vendor/cultcache-rs/src/lib.rs index 54846f2..c412e35 100644 --- a/vendor/cultcache-rs/src/lib.rs +++ b/vendor/cultcache-rs/src/lib.rs @@ -144,6 +144,28 @@ impl SingleFileMessagePackBackingStore { self.read_all_unlocked() } + /// Holds the pre-created sibling lock shared while a read-only consumer + /// evaluates and acts on one snapshot. The reader never creates or writes + /// either file, so an authority owner can grant only read access. Writers + /// using `compare_exchange` cannot replace the snapshot until `action` + /// returns. + pub fn with_read_only_shared_snapshot( + &self, + action: impl FnOnce(Vec) -> Result, + ) -> Result { + let lock_path = self.lock_path(); + let lock = OpenOptions::new() + .read(true) + .open(&lock_path) + .with_context(|| format!("failed to open pre-created {}", lock_path.display()))?; + fs2::FileExt::lock_shared(&lock) + .with_context(|| format!("failed to lock {}", lock_path.display()))?; + let result = self.read_all_unlocked().and_then(action); + fs2::FileExt::unlock(&lock) + .with_context(|| format!("failed to unlock {}", lock_path.display()))?; + result + } + pub fn compare_exchange( &self, expected: &[CultCacheExpectedEnvelope], @@ -775,6 +797,8 @@ fn temporary_path_for(path: &Path) -> PathBuf { mod tests { use super::*; use pretty_assertions::assert_eq; + use std::sync::mpsc; + use std::time::Duration; #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache(type = "settings")] @@ -796,6 +820,44 @@ mod tests { cultcache_registry!(TestEntries { Settings, Note }); + #[test] + fn captured_snapshot_cannot_outlive_a_shared_consequence_gate() -> Result<()> { + let temp = tempfile::tempdir()?; + let store_path = temp.path().join("authority.cc"); + let mut store = SingleFileMessagePackBackingStore::new(&store_path); + let released = CultCacheEnvelope { + key: "brake".into(), + r#type: "brake".into(), + payload: b"released".to_vec(), + stored_at: "2026-07-20T00:00:00Z".into(), + schema_id: Some("brake.v0".into()), + }; + store.push(&released)?; + + let writer_path = store_path.clone(); + let (started_tx, started_rx) = mpsc::channel(); + let (finished_tx, finished_rx) = mpsc::channel(); + store.with_read_only_shared_snapshot(|captured| { + assert_eq!(captured, vec![released.clone()]); + std::thread::spawn(move || { + started_tx.send(()).unwrap(); + let engaged = CultCacheEnvelope { + payload: b"engaged".to_vec(), + ..released + }; + let mut writer = SingleFileMessagePackBackingStore::new(writer_path); + writer.push(&engaged).unwrap(); + finished_tx.send(()).unwrap(); + }); + started_rx.recv_timeout(Duration::from_secs(1))?; + assert!(finished_rx.recv_timeout(Duration::from_millis(100)).is_err()); + Ok(()) + })?; + finished_rx.recv_timeout(Duration::from_secs(1))?; + assert_eq!(store.pull_all_read_only_snapshot()?[0].payload, b"engaged"); + Ok(()) + } + #[test] fn familiar_cultcache_flow_persists_and_reloads_typed_documents() -> Result<()> { let temp = tempfile::tempdir()?;