Avoid replaying the helper journal history during idle sync
This commit is contained in:
@@ -296,7 +296,8 @@ impl<V: Ed25519Verifier> HelperSync<V> {
|
|||||||
ledger_fingerprint: lease.fingerprint.clone(),
|
ledger_fingerprint: lease.fingerprint.clone(),
|
||||||
captured_at: capture.captured_at,
|
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)
|
Ok(anchor)
|
||||||
}
|
}
|
||||||
/// Consume exactly the approved update attempt and delegate its ORIGINAL
|
/// Consume exactly the approved update attempt and delegate its ORIGINAL
|
||||||
@@ -397,9 +398,9 @@ impl<V: Ed25519Verifier> HelperSync<V> {
|
|||||||
tx.commit()?;
|
tx.commit()?;
|
||||||
return Ok(outcome);
|
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 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!(
|
ensure!(
|
||||||
!observation.intent_id.is_nil()
|
!observation.intent_id.is_nil()
|
||||||
&& digest(&observation.intent_sha256)
|
&& digest(&observation.intent_sha256)
|
||||||
@@ -429,6 +430,7 @@ impl<V: Ed25519Verifier> HelperSync<V> {
|
|||||||
anchor: &NoStartAnchor,
|
anchor: &NoStartAnchor,
|
||||||
clock: &impl Clock,
|
clock: &impl Clock,
|
||||||
boot: &impl BootSource,
|
boot: &impl BootSource,
|
||||||
|
audit_history: bool,
|
||||||
) -> Result<DateTime<Utc>> {
|
) -> Result<DateTime<Utc>> {
|
||||||
guard.check(db)?;
|
guard.check(db)?;
|
||||||
let now = clock.now()?;
|
let now = clock.now()?;
|
||||||
@@ -453,15 +455,18 @@ impl<V: Ed25519Verifier> HelperSync<V> {
|
|||||||
&& ledger_fingerprint(db)? == anchor.ledger_fingerprint,
|
&& ledger_fingerprint(db)? == anchor.ledger_fingerprint,
|
||||||
"DENIAL_HELPER_LINEAGE_CHANGED"
|
"DENIAL_HELPER_LINEAGE_CHANGED"
|
||||||
);
|
);
|
||||||
// Exact equality is deliberate: a first implementation refuses even
|
// Idle anchor capture checks the current signed head. The native
|
||||||
// legitimate intervening progress rather than inventing lineage links.
|
// executor audits the full history before execution, and abandonment
|
||||||
verify_checkpoint_repair_history_with(
|
// always audits it under the same transaction before recording evidence.
|
||||||
db,
|
if audit_history {
|
||||||
&self.binding,
|
verify_checkpoint_repair_history_with(
|
||||||
None,
|
db,
|
||||||
self.identity,
|
&self.binding,
|
||||||
&self.verifier,
|
None,
|
||||||
)?;
|
self.identity,
|
||||||
|
&self.verifier,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
let (response, raw): (Vec<u8>, Vec<u8>) = db.query_row(
|
let (response, raw): (Vec<u8>, Vec<u8>) = db.query_row(
|
||||||
"SELECT response,request FROM helper_sync_decisions WHERE decision_id=?1",
|
"SELECT response,request FROM helper_sync_decisions WHERE decision_id=?1",
|
||||||
[anchor.decision_id.to_string()],
|
[anchor.decision_id.to_string()],
|
||||||
@@ -491,8 +496,12 @@ impl<V: Ed25519Verifier> HelperSync<V> {
|
|||||||
&& decision.helper_journal_id == Some(anchor.journal_id)
|
&& decision.helper_journal_id == Some(anchor.journal_id)
|
||||||
&& decision.helper_checkpoint == anchor.checkpoint
|
&& decision.helper_checkpoint == anchor.checkpoint
|
||||||
&& decision.connection_generation == anchor.connection_generation
|
&& 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.captured_at == anchor.captured_at
|
||||||
&& capture.boot_id == anchor.boot_id
|
&& capture.boot_id == anchor.boot_id
|
||||||
|
&& capture.captured_at <= decision.issued_at
|
||||||
&& capture.captured_at <= now,
|
&& capture.captured_at <= now,
|
||||||
"DENIAL_CONFIRMED_READY_REQUIRED"
|
"DENIAL_CONFIRMED_READY_REQUIRED"
|
||||||
);
|
);
|
||||||
@@ -1053,7 +1062,8 @@ fn initialize_schema(db: &Connection, binding: &Binding) -> Result<()> {
|
|||||||
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_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_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_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(
|
let legacy_captures: bool = db.query_row(
|
||||||
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='table' AND name='helper_sync_captures')",
|
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='table' AND name='helper_sync_captures')",
|
||||||
[], |row| row.get(0),
|
[], |row| row.get(0),
|
||||||
@@ -1191,23 +1201,23 @@ pub fn verify_checkpoint_repair_history_with(
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let meta = metadata(db)?;
|
let meta = metadata(db)?;
|
||||||
validate_history(db, binding, &meta, meta.generation, verifier)?;
|
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(
|
let mut statement = db.prepare(
|
||||||
"SELECT response,request,checkpoint FROM helper_sync_decisions ORDER BY checkpoint",
|
"SELECT response,request,checkpoint FROM helper_sync_decisions ORDER BY checkpoint",
|
||||||
)?;
|
)?;
|
||||||
let entries = statement
|
let mut entries = statement.query([])?;
|
||||||
.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 previous = None;
|
let mut previous = None;
|
||||||
let mut previous_checkpoint = 0;
|
let mut previous_checkpoint = 0;
|
||||||
let mut previous_agent_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 response: SignedResponse = serde_json::from_slice(&signed)?;
|
||||||
let parsed: ReconcileDecisionPayload = serde_json::from_slice(&response.decision_bytes)?;
|
let parsed: ReconcileDecisionPayload = serde_json::from_slice(&response.decision_bytes)?;
|
||||||
let decision = verify(verifier, binding, &response, parsed.issued_at)?;
|
let decision = verify(verifier, binding, &response, parsed.issued_at)?;
|
||||||
|
|||||||
@@ -1293,6 +1293,13 @@ impl SystemHelper {
|
|||||||
verified_window(&self.settings.binding, request, &self.clock)?;
|
verified_window(&self.settings.binding, request, &self.clock)?;
|
||||||
if self.settings.managed_scripts() {
|
if self.settings.managed_scripts() {
|
||||||
ledger::check_integrity(&self.db, "ROOT_LEDGER_INTEGRITY")?;
|
ledger::check_integrity(&self.db, "ROOT_LEDGER_INTEGRITY")?;
|
||||||
|
rmm_agent_core::helper_reconcile::verify_checkpoint_repair_history_with(
|
||||||
|
&self.db,
|
||||||
|
&self.settings.binding,
|
||||||
|
None,
|
||||||
|
HelperIdentity::System,
|
||||||
|
&DalekVerifier,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
self.sync()?;
|
self.sync()?;
|
||||||
ensure!(
|
ensure!(
|
||||||
|
|||||||
Reference in New Issue
Block a user