Integrate independent signed Windows clocks with native Linux lease guards
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-15 10:26:24 +01:00
parent 6ddfc95fff
commit 09f7e5af84
13 changed files with 1093 additions and 37 deletions
+3 -1
View File
@@ -881,7 +881,8 @@ impl<V: Ed25519Verifier> HelperSync<V> {
) -> bool {
let result = (|| -> Result<bool> {
guard.check(db)?;
let now = clock.now()?;
let reading = clock.reading()?;
let now = reading.own_wall;
let Some(lease) = &self.lease else {
return Ok(false);
};
@@ -899,6 +900,7 @@ impl<V: Ed25519Verifier> HelperSync<V> {
&& meta.decision == Some(lease.decision_id)
&& generation == lease.generation
&& now < lease.until
&& reading.upper < lease.until
&& now >= self.born
&& boot.current_boot()? == lease.boot_id
&& ledger_fingerprint(db)? == lease.fingerprint
+18 -2
View File
@@ -21,8 +21,23 @@ use rusqlite::{Connection, OptionalExtension, TransactionBehavior, params};
use std::collections::{BTreeMap, BTreeSet};
use uuid::Uuid;
/// A fresh observation returned by the trusted local clock implementation,
/// never an IPC DTO or an execution permit. Callers must not retain it as a lease.
pub struct ClockReading {
pub own_wall: DateTime<Utc>,
pub upper: DateTime<Utc>,
}
pub trait SyncClock {
fn now(&self) -> Result<DateTime<Utc>>;
/// Existing providers retain their existing point-clock contract. Providers
/// with an independently verified interval override this atomically.
fn reading(&self) -> Result<ClockReading> {
let own_wall = self.now()?;
Ok(ClockReading {
own_wall,
upper: own_wall,
})
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Channel {
@@ -108,14 +123,15 @@ impl<V: Ed25519Verifier> ClientSync<V> {
self.gate.as_ref().map(|gate| gate.until)
}
pub fn can_start(&self, channel: &Channel, root: bool, clock: &impl SyncClock) -> bool {
let Ok(now) = clock.now() else {
let Ok(reading) = clock.reading() else {
return false;
};
self.gate.as_ref().is_some_and(|g| {
g.channel == *channel
&& g.ready
&& g.local_applied
&& now < g.until
&& reading.own_wall < g.until
&& reading.upper < g.until
&& (!root || (g.helper_ready && g.helper.is_none()))
})
}
@@ -1010,6 +1010,44 @@ fn clean_ready_shared_lock_and_reopen_start_closed() {
assert!(!sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
}
#[test]
fn system_helper_lease_denies_interval_upper_at_or_after_deadline() {
struct IntervalClock {
wall: DateTime<Utc>,
upper: DateTime<Utc>,
}
impl Clock for IntervalClock {
fn now(&self) -> anyhow::Result<DateTime<Utc>> {
Ok(self.wall)
}
fn reading(&self) -> anyhow::Result<rmm_agent_core::reconcile::ClockReading> {
Ok(rmm_agent_core::reconcile::ClockReading {
own_wall: self.wall,
upper: self.upper,
})
}
}
for overshoot in [Duration::zero(), Duration::nanoseconds(1)] {
let mut f = Fixture::new();
f.identity = HelperIdentity::System;
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let decision = f.decision(&snapshot, &raw, 1, true);
assert!(f.apply(&mut sync, &decision, &raw).unwrap().ready);
let wall = decision.valid_until - Duration::milliseconds(10);
let point = TestClock {
now: wall,
trusted: true,
};
assert!(sync.can_start(&f.db, &f.guard, 1, &point, &f.boot));
let bounded = IntervalClock {
wall,
upper: decision.valid_until + overshoot,
};
assert!(!sync.can_start(&f.db, &f.guard, 1, &bounded, &f.boot));
}
}
#[test]
fn exact_signatures_fake_key_wrong_domain_and_all_identity_bindings() {
let mut f = Fixture::new();
let mut sync = f.sync();
+42
View File
@@ -17,6 +17,48 @@ struct Clock {
now: DateTime<Utc>,
trusted: bool,
}
#[test]
fn client_lease_requires_entire_fresh_upper_before_deadline() {
struct IntervalClock {
wall: DateTime<Utc>,
upper: DateTime<Utc>,
}
impl SyncClock for IntervalClock {
fn now(&self) -> anyhow::Result<DateTime<Utc>> {
Ok(self.wall)
}
fn reading(&self) -> anyhow::Result<ClockReading> {
Ok(ClockReading {
own_wall: self.wall,
upper: self.upper,
})
}
}
let mut f = Fixture::new();
let mut client = f.client();
let prepared = f.prepare(&mut client);
let decision = f.decision(&prepared, true);
f.apply(&mut client, &decision).unwrap();
let wall = decision.valid_until - Duration::milliseconds(10);
assert!(client.can_start(
&f.channel,
false,
&Clock {
now: wall,
trusted: true
}
));
for overshoot in [Duration::zero(), Duration::nanoseconds(1)] {
assert!(!client.can_start(
&f.channel,
false,
&IntervalClock {
wall,
upper: decision.valid_until + overshoot
}
));
}
}
impl SyncClock for Clock {
fn now(&self) -> anyhow::Result<DateTime<Utc>> {
anyhow::ensure!(self.trusted, "CLOCK_UNTRUSTED");