Read pinned Epiphany trust anchor without writer lock
This commit is contained in:
parent
a17b0b6bfd
commit
64bb679a1b
2 changed files with 55 additions and 1 deletions
|
|
@ -2562,7 +2562,7 @@ fn validate_epiphany_signed_health_shape(signed: &EpiphanySignedRuntimeHealthWir
|
|||
}
|
||||
|
||||
fn load_epiphany_health_identity(path: &std::path::Path) -> Result<EpiphanyHostIdentityWire> {
|
||||
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);
|
||||
|
|
|
|||
8
vendor/cultcache-rs/src/lib.rs
vendored
8
vendor/cultcache-rs/src/lib.rs
vendored
|
|
@ -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<Vec<CultCacheEnvelope>> {
|
||||
self.read_all_unlocked()
|
||||
}
|
||||
|
||||
pub fn compare_exchange(
|
||||
&self,
|
||||
expected: &[CultCacheExpectedEnvelope],
|
||||
|
|
|
|||
Loading…
Reference in a new issue