From 64bb679a1b1b7990780884a262da9ce3ef9b279d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 19 Jul 2026 10:14:04 +0100 Subject: [PATCH] Read pinned Epiphany trust anchor without writer lock --- crates/idunn-daemon/src/main.rs | 48 ++++++++++++++++++++++++++++++++- vendor/cultcache-rs/src/lib.rs | 8 ++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/crates/idunn-daemon/src/main.rs b/crates/idunn-daemon/src/main.rs index 610470c..0f28d2b 100644 --- a/crates/idunn-daemon/src/main.rs +++ b/crates/idunn-daemon/src/main.rs @@ -2562,7 +2562,7 @@ fn validate_epiphany_signed_health_shape(signed: &EpiphanySignedRuntimeHealthWir } fn load_epiphany_health_identity(path: &std::path::Path) -> Result { - let entries = SingleFileMessagePackBackingStore::new(path).pull_all()?; + let entries = SingleFileMessagePackBackingStore::new(path).pull_all_read_only_snapshot()?; let envelope = entries .iter() .find(|entry| entry.r#type == HOST_IDENTITY_TYPE && entry.key == HOST_IDENTITY_KEY) @@ -7423,6 +7423,52 @@ mod tests { assert!(health_from_rudp_message(&forged, &forged_options).is_err()); } + #[test] + fn pinned_epiphany_health_identity_load_is_read_only() { + let (_message, options, _root) = signed_epiphany_health_fixture(1); + let identity_path = options + .trusted_epiphany_health_identity_store + .as_deref() + .expect("fixture trust anchor"); + let lock_path = identity_path.with_file_name(format!( + "{}.lock", + identity_path + .file_name() + .expect("trust anchor filename") + .to_string_lossy() + )); + if lock_path.exists() { + std::fs::remove_file(&lock_path).unwrap(); + } + let mut permissions = std::fs::metadata(identity_path).unwrap().permissions(); + permissions.set_readonly(true); + std::fs::set_permissions(identity_path, permissions).unwrap(); + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + std::fs::set_permissions( + identity_path.parent().unwrap(), + std::fs::Permissions::from_mode(0o555), + ) + .unwrap(); + } + + let identity = load_epiphany_health_identity(identity_path).unwrap(); + + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + std::fs::set_permissions( + identity_path.parent().unwrap(), + std::fs::Permissions::from_mode(0o755), + ) + .unwrap(); + } + + assert_eq!(identity.schema_version, HOST_IDENTITY_TYPE); + assert!(!lock_path.exists()); + } + #[test] fn unsigned_epiphany_health_is_rejected() { let (mut message, options, _root) = signed_epiphany_health_fixture(1); diff --git a/vendor/cultcache-rs/src/lib.rs b/vendor/cultcache-rs/src/lib.rs index dfaef5c..54846f2 100644 --- a/vendor/cultcache-rs/src/lib.rs +++ b/vendor/cultcache-rs/src/lib.rs @@ -136,6 +136,14 @@ impl SingleFileMessagePackBackingStore { &self.path } + /// Reads one atomically published snapshot without acquiring or creating + /// the sibling writer lock. This is for immutable, externally owned + /// documents such as pinned trust anchors where the reader has no write + /// authority over the containing directory. + pub fn pull_all_read_only_snapshot(&self) -> Result> { + self.read_all_unlocked() + } + pub fn compare_exchange( &self, expected: &[CultCacheExpectedEnvelope],