Merge live Windows agent 0.1.27 source into the deployed server state
Rust development slice / linux (push) Failing after 14s

main now matches what runs on discovery.ease-technologies.de on 2026-11-20:
- Server, gateway, public API and WebUI: image rmm-dev-server:79f236b
  (schema 47), plus the follow-up docs commit fb35dbd.
- Windows agent and helper 0.1.27: signed release build 28 from 52c352c;
  hashes verified on the Windows test guest.
- Linux agent 0.1.0-mvp.14 (62cb52b) and OPNsense agent 0.1.0-opnsense.6
  are already ancestors of 79f236b.

Conflict in crates/agent-windows/src/native.rs resolved to the released
Windows side (os_inventory with missing DisplayVersion handling).
cargo check passes for the Linux workspace and for rmm-agent-windows on
x86_64-pc-windows-gnu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 10:50:18 +01:00
co-authored by Claude Opus 5.5
21 changed files with 1411 additions and 124 deletions
+53 -27
View File
@@ -205,6 +205,7 @@ pub struct HelperSync<V = DefaultVerifier> {
born: DateTime<Utc>,
capture: Option<Capture>,
lease: Option<Lease>,
integrity: Option<crate::ledger::IntegrityMonitor>,
}
impl HelperSync<DefaultVerifier> {
/// No persisted ready bit can open a newly started helper.
@@ -222,6 +223,7 @@ impl<V: Ed25519Verifier> HelperSync<V> {
born: clock.now()?,
capture: None,
lease: None,
integrity: None,
})
}
/// Select exactly one protected helper execution identity, closing leases.
@@ -230,6 +232,12 @@ impl<V: Ed25519Verifier> HelperSync<V> {
self.identity = identity;
self
}
/// Use with one protected SQLite connection retained for this instance.
/// The native owner must run a full check before any new host effect.
pub fn with_periodic_idle_integrity_checks(mut self) -> Self {
self.integrity = Some(crate::ledger::IntegrityMonitor::default());
self
}
pub fn close(&mut self) {
self.lease = None;
self.capture = None;
@@ -288,7 +296,8 @@ impl<V: Ed25519Verifier> HelperSync<V> {
ledger_fingerprint: lease.fingerprint.clone(),
captured_at: capture.captured_at,
};
self.verify_no_start_anchor(db, guard, &anchor, clock, boot)?;
let audit_history = self.integrity.is_none();
self.verify_no_start_anchor(db, guard, &anchor, clock, boot, audit_history)?;
Ok(anchor)
}
/// Consume exactly the approved update attempt and delegate its ORIGINAL
@@ -389,9 +398,9 @@ impl<V: Ed25519Verifier> HelperSync<V> {
tx.commit()?;
return Ok(outcome);
}
self.verify_no_start_anchor(&tx, guard, anchor, clock, boot)?;
self.verify_no_start_anchor(&tx, guard, anchor, clock, boot, true)?;
let observation = guard.verify_no_dispatch(request, anchor)?;
let now = self.verify_no_start_anchor(&tx, guard, anchor, clock, boot)?;
let now = self.verify_no_start_anchor(&tx, guard, anchor, clock, boot, true)?;
ensure!(
!observation.intent_id.is_nil()
&& digest(&observation.intent_sha256)
@@ -421,6 +430,7 @@ impl<V: Ed25519Verifier> HelperSync<V> {
anchor: &NoStartAnchor,
clock: &impl Clock,
boot: &impl BootSource,
audit_history: bool,
) -> Result<DateTime<Utc>> {
guard.check(db)?;
let now = clock.now()?;
@@ -445,15 +455,18 @@ impl<V: Ed25519Verifier> HelperSync<V> {
&& ledger_fingerprint(db)? == anchor.ledger_fingerprint,
"DENIAL_HELPER_LINEAGE_CHANGED"
);
// Exact equality is deliberate: a first implementation refuses even
// legitimate intervening progress rather than inventing lineage links.
verify_checkpoint_repair_history_with(
db,
&self.binding,
None,
self.identity,
&self.verifier,
)?;
// Idle anchor capture checks the current signed head. The native
// executor audits the full history before execution, and abandonment
// always audits it under the same transaction before recording evidence.
if audit_history {
verify_checkpoint_repair_history_with(
db,
&self.binding,
None,
self.identity,
&self.verifier,
)?;
}
let (response, raw): (Vec<u8>, Vec<u8>) = db.query_row(
"SELECT response,request FROM helper_sync_decisions WHERE decision_id=?1",
[anchor.decision_id.to_string()],
@@ -483,8 +496,12 @@ impl<V: Ed25519Verifier> HelperSync<V> {
&& decision.helper_journal_id == Some(anchor.journal_id)
&& decision.helper_checkpoint == anchor.checkpoint
&& decision.connection_generation == anchor.connection_generation
&& decision.request_hash == anchor.sync_request_sha256
&& capture.journal_id == anchor.journal_id
&& capture.checkpoint == anchor.checkpoint
&& capture.captured_at == anchor.captured_at
&& capture.boot_id == anchor.boot_id
&& capture.captured_at <= decision.issued_at
&& capture.captured_at <= now,
"DENIAL_CONFIRMED_READY_REQUIRED"
);
@@ -523,7 +540,12 @@ impl<V: Ed25519Verifier> HelperSync<V> {
);
let boot_id = boot.current_boot()?;
ensure!(!boot_id.is_nil(), "BOOT_ID_REQUIRED");
initialize(db, &self.binding)?;
if let Some(integrity) = &mut self.integrity {
integrity.check(db, false, "ROOT_LEDGER_INTEGRITY")?;
initialize_schema(db, &self.binding)?;
} else {
initialize(db, &self.binding)?;
}
let tx = db.transaction_with_behavior(TransactionBehavior::Immediate)?;
let meta = metadata(&tx)?;
ensure!(meta.fault.is_none(), "HELPER_MANUAL_RECOVERY_REQUIRED");
@@ -1031,13 +1053,17 @@ struct Meta {
agent_checkpoint: u64,
}
fn initialize(db: &Connection, binding: &Binding) -> Result<()> {
let check: String = db.query_row("PRAGMA integrity_check", [], |r| r.get(0))?;
ensure!(check == "ok", "ROOT_LEDGER_INTEGRITY");
crate::ledger::check_integrity(db, "ROOT_LEDGER_INTEGRITY")?;
initialize_schema(db, binding)
}
fn initialize_schema(db: &Connection, binding: &Binding) -> Result<()> {
db.execute_batch("PRAGMA synchronous=FULL;
CREATE TABLE IF NOT EXISTS helper_sync_meta(id INTEGER PRIMARY KEY CHECK(id=1),journal_id TEXT NOT NULL,checkpoint INTEGER NOT NULL DEFAULT 0,generation INTEGER NOT NULL DEFAULT 0,binding_sha256 TEXT NOT NULL,last_decision TEXT,fault TEXT,agent_journal_id TEXT,agent_checkpoint INTEGER NOT NULL DEFAULT 0);
CREATE TABLE IF NOT EXISTS helper_sync_rows(grant_id TEXT PRIMARY KEY,revision INTEGER NOT NULL,fingerprint TEXT NOT NULL);
CREATE TABLE IF NOT EXISTS helper_sync_captures(checkpoint INTEGER PRIMARY KEY,snapshot BLOB NOT NULL,fingerprint TEXT NOT NULL,captured_at TEXT NOT NULL);
CREATE TABLE IF NOT EXISTS helper_sync_decisions(decision_id TEXT PRIMARY KEY,checkpoint INTEGER NOT NULL,response BLOB NOT NULL,request BLOB NOT NULL,fingerprint TEXT NOT NULL);")?;
CREATE TABLE IF NOT EXISTS helper_sync_decisions(decision_id TEXT PRIMARY KEY,checkpoint INTEGER NOT NULL,response BLOB NOT NULL,request BLOB NOT NULL,fingerprint TEXT NOT NULL);
CREATE INDEX IF NOT EXISTS helper_sync_decisions_checkpoint ON helper_sync_decisions(checkpoint);")?;
let legacy_captures: bool = db.query_row(
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='table' AND name='helper_sync_captures')",
[], |row| row.get(0),
@@ -1175,23 +1201,23 @@ pub fn verify_checkpoint_repair_history_with(
) -> Result<()> {
let meta = metadata(db)?;
validate_history(db, binding, &meta, meta.generation, verifier)?;
let entry_count: u64 = db.query_row(
"SELECT count(*) FROM helper_sync_decisions",
[],
|row| row.get(0),
)?;
ensure!(entry_count <= 100000, "REPAIR_HISTORY_LIMIT");
let mut statement = db.prepare(
"SELECT response,request,checkpoint FROM helper_sync_decisions ORDER BY checkpoint",
)?;
let entries = statement
.query_map([], |r| {
Ok((
r.get::<_, Vec<u8>>(0)?,
r.get::<_, Vec<u8>>(1)?,
r.get::<_, u64>(2)?,
))
})?
.collect::<rusqlite::Result<Vec<_>>>()?;
ensure!(entries.len() <= 100000, "REPAIR_HISTORY_LIMIT");
let mut entries = statement.query([])?;
let mut previous = None;
let mut previous_checkpoint = 0;
let mut previous_agent_checkpoint = 0;
for (signed, raw, checkpoint) in entries {
while let Some(entry) = entries.next()? {
let signed: Vec<u8> = entry.get(0)?;
let raw: Vec<u8> = entry.get(1)?;
let checkpoint: u64 = entry.get(2)?;
let response: SignedResponse = serde_json::from_slice(&signed)?;
let parsed: ReconcileDecisionPayload = serde_json::from_slice(&response.decision_bytes)?;
let decision = verify(verifier, binding, &response, parsed.issued_at)?;
+72 -3
View File
@@ -7,7 +7,8 @@ use rmm_domain::{
jobs::hash,
reconciliation::{ReconciledOutcome, canonical_outcome_bytes},
};
use rusqlite::{OptionalExtension, TransactionBehavior, params};
use rusqlite::{Connection, OptionalExtension, TransactionBehavior, params};
use std::time::{Duration, Instant};
use uuid::Uuid;
/// Finite 1 GiB bound for durable agent/helper history. Unexpected page sizes
@@ -29,11 +30,48 @@ pub fn initialize_ledger(db: &rusqlite::Connection) -> Result<()> {
CREATE TABLE IF NOT EXISTS consumed(grant_id TEXT PRIMARY KEY, agent TEXT NOT NULL, generation INTEGER NOT NULL,
job TEXT NOT NULL, attempt TEXT NOT NULL, result BLOB, UNIQUE(agent,generation,job,attempt));
CREATE TABLE IF NOT EXISTS execution_evidence(grant_id TEXT PRIMARY KEY, start BLOB NOT NULL, outcome BLOB);")?;
let check: String = db.query_row("PRAGMA integrity_check", [], |r| r.get(0))?;
ensure!(check == "ok", "JOURNAL_INTEGRITY");
check_integrity(db, "JOURNAL_INTEGRITY")
}
pub fn check_integrity(db: &Connection, error_code: &'static str) -> Result<()> {
let check: String = db.query_row("PRAGMA integrity_check", [], |row| row.get(0))?;
ensure!(check == "ok", "{error_code}");
Ok(())
}
/// Full integrity scans for an owner holding one protected, long-lived SQLite
/// connection. External commits and schema changes require another scan even
/// when the interval has not elapsed. No cached result authorizes an effect.
#[derive(Default)]
pub(crate) struct IntegrityMonitor {
checked: Option<(u64, u64, Instant)>,
}
impl IntegrityMonitor {
pub(crate) fn check(
&mut self,
db: &Connection,
required: bool,
error_code: &'static str,
) -> Result<()> {
let data: u64 = db.query_row("PRAGMA data_version", [], |row| row.get(0))?;
let schema: u64 = db.query_row("PRAGMA schema_version", [], |row| row.get(0))?;
if !required
&& self.checked.is_some_and(|(previous_data, previous_schema, checked)| {
data == previous_data
&& schema == previous_schema
&& checked.elapsed() < Duration::from_secs(300)
})
{
return Ok(());
}
self.checked = None;
check_integrity(db, error_code)?;
self.checked = Some((data, schema, Instant::now()));
Ok(())
}
}
/// Before a human WebUI closure replaces the unresolved local outcome, keep the
/// exact original outcome bytes once. A differing second copy fails closed.
pub(crate) fn retain_closure_original(
@@ -379,3 +417,34 @@ pub fn start_witness_bytes(
"reauthentication_required":true,"postconditions_passed":false});
Ok(serde_json::to_vec(&evidence)?)
}
#[cfg(test)]
mod integrity_tests {
use super::*;
#[test]
fn idle_integrity_reuses_the_check_but_reaudits_external_changes_and_expiry() {
let path = std::env::temp_dir().join(format!("rmm-integrity-{}.sqlite", Uuid::new_v4()));
{
let db = Connection::open(&path).unwrap();
db.execute_batch("CREATE TABLE sample(id INTEGER PRIMARY KEY);").unwrap();
let mut monitor = IntegrityMonitor::default();
monitor.check(&db, false, "JOURNAL_INTEGRITY").unwrap();
let first = monitor.checked.unwrap();
db.execute("INSERT INTO sample VALUES (1)", []).unwrap();
monitor.check(&db, false, "JOURNAL_INTEGRITY").unwrap();
assert_eq!(monitor.checked, Some(first));
let peer = Connection::open(&path).unwrap();
peer.execute("INSERT INTO sample VALUES (2)", []).unwrap();
monitor.check(&db, false, "JOURNAL_INTEGRITY").unwrap();
let changed = monitor.checked.unwrap();
assert_ne!(changed.0, first.0);
monitor.checked = Some((changed.0, changed.1, changed.2 - Duration::from_secs(300)));
monitor.check(&db, false, "JOURNAL_INTEGRITY").unwrap();
assert!(monitor.checked.unwrap().2 >= changed.2);
}
std::fs::remove_file(path).unwrap();
}
}
+23 -3
View File
@@ -101,6 +101,7 @@ pub struct ClientSync<V = DefaultVerifier> {
verifier: V,
helper_identity: HelperIdentity,
pending: Option<PreparedSync>,
integrity: Option<crate::ledger::IntegrityMonitor>,
channel: Option<Channel>,
gate: Option<Gate>,
}
@@ -117,6 +118,7 @@ impl<V: Ed25519Verifier> ClientSync<V> {
verifier,
helper_identity: HelperIdentity::Root,
pending: None,
integrity: None,
channel: None,
gate: None,
}
@@ -127,6 +129,11 @@ impl<V: Ed25519Verifier> ClientSync<V> {
self.helper_identity = identity;
self
}
/// Use with one protected SQLite connection retained for this instance.
pub fn with_periodic_idle_integrity_checks(mut self) -> Self {
self.integrity = Some(crate::ledger::IntegrityMonitor::default());
self
}
/// Invoke on every authenticated/fenced ServerHello or transport loss.
pub fn close(&mut self) {
self.gate = None;
@@ -606,7 +613,17 @@ impl<V: Ed25519Verifier> ClientSync<V> {
channel.connection_generation > 0 && !channel.boot_id.is_nil(),
"UNAUTHENTICATED_CHANNEL"
);
initialize(db)?;
if let Some(integrity) = &mut self.integrity {
let work_pending: bool = db.query_row(
"SELECT EXISTS(SELECT 1 FROM job_attempts WHERE state NOT IN ('succeeded','failed','cancelled','expired','closed_unknown'))",
[],
|row| row.get(0),
)?;
integrity.check(db, work_pending, "JOURNAL_INTEGRITY")?;
initialize_schema(db)?;
} else {
initialize(db)?;
}
let tx = db.transaction_with_behavior(TransactionBehavior::Immediate)?;
let meta = metadata(&tx)?;
ensure!(meta.fault.is_none(), "SYNC_MANUAL_RECOVERY_REQUIRED");
@@ -1147,8 +1164,11 @@ impl<V: Ed25519Verifier> ClientSync<V> {
}
pub fn initialize(db: &Connection) -> Result<()> {
let check: String = db.query_row("PRAGMA integrity_check", [], |r| r.get(0))?;
ensure!(check == "ok", "JOURNAL_INTEGRITY");
crate::ledger::check_integrity(db, "JOURNAL_INTEGRITY")?;
initialize_schema(db)
}
fn initialize_schema(db: &Connection) -> Result<()> {
db.execute_batch("PRAGMA synchronous=FULL;
CREATE TABLE IF NOT EXISTS reconcile_meta(id INTEGER PRIMARY KEY CHECK(id=1),journal_id TEXT NOT NULL,checkpoint INTEGER NOT NULL DEFAULT 0,high_sequence INTEGER NOT NULL DEFAULT 0,generation INTEGER NOT NULL DEFAULT 0,last_decision TEXT,pending_request TEXT,helper_id TEXT,helper_checkpoint INTEGER NOT NULL DEFAULT 0,fault TEXT);
CREATE TABLE IF NOT EXISTS reconcile_requests(id TEXT PRIMARY KEY,request BLOB NOT NULL,envelope BLOB NOT NULL,generation INTEGER NOT NULL,response BLOB);
@@ -466,6 +466,31 @@ struct Fixture {
identity: HelperIdentity,
}
#[test]
fn idle_anchor_checks_the_head_but_abandonment_rejects_damaged_history() {
let (mut f, sync, _, request, mut guard) = denial_case();
let mut sync = sync.with_periodic_idle_integrity_checks();
f.clock.now += Duration::seconds(1);
let capture = f.snapshot(&mut sync, 7);
let raw = f.request(&capture);
let ready = f.decision(&capture, &raw, 7, true);
assert!(f.apply(&mut sync, &ready, &raw).unwrap().ready);
guard.intent_recorded_at = f.clock.now;
f.db.execute(
"UPDATE helper_sync_decisions SET response=X'00' WHERE checkpoint < ?1",
[capture.checkpoint],
).unwrap();
let anchor = sync.no_start_anchor(&f.db, &guard, 7, &f.clock, &f.boot).unwrap();
guard.anchor_sha256 = hash(&serde_json::to_vec(&anchor).unwrap());
let before = denial_ledger_bytes(&f.db);
assert!(
sync.abandon_no_start(&mut f.db, &guard, &anchor, &request, &f.clock, &f.boot)
.is_err()
);
assert_eq!(denial_ledger_bytes(&f.db), before);
}
#[test]
fn checkpoint_repair_verifies_complete_signed_history_and_detects_removed_predecessor() {
let mut f = Fixture::new();