Wire preserved update control, health evidence and record publication
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-14 23:51:59 +01:00
parent 328e440f73
commit 8e93c9ead5
34 changed files with 7071 additions and 97 deletions
+112 -3
View File
@@ -33,6 +33,8 @@ pub trait UpdateAdmissionGuard: ExecutorLedgerGuard {
/// Role comes from an authenticated concrete local participant, not IPC data.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Participant {
/// Authenticated Full reader; never a native effect participant.
Observer,
OriginalHelper,
StableUpdater,
NewHelper,
@@ -64,6 +66,11 @@ pub trait UpdateParticipantGuard: ExecutorLedgerGuard {
/// executor guard. This does not alter old schema objects, rows or file IDs.
pub fn initialize(db: &Connection, guard: &impl ExecutorLedgerGuard) -> Result<()> {
guard.check(db)?;
db.execute_batch("PRAGMA foreign_keys=ON;")?;
ensure!(
db.query_row("PRAGMA foreign_keys", [], |r| r.get::<_, bool>(0))?,
"UPDATE_LEDGER_FOREIGN_KEYS_REQUIRED"
);
db.execute_batch(
"CREATE TABLE IF NOT EXISTS agent_update_handoffs(
grant_id TEXT PRIMARY KEY REFERENCES consumed(grant_id), record BLOB NOT NULL,
@@ -81,7 +88,10 @@ pub fn initialize(db: &Connection, guard: &impl ExecutorLedgerGuard) -> Result<(
CREATE TABLE IF NOT EXISTS agent_update_native_observations(
grant_id TEXT NOT NULL,effect_key TEXT NOT NULL,claim_sha256 TEXT NOT NULL,
observation_sha256 TEXT NOT NULL,observed_at TEXT NOT NULL,PRIMARY KEY(grant_id,effect_key),
FOREIGN KEY(grant_id,effect_key) REFERENCES agent_update_native_claims(grant_id,effect_key));",
FOREIGN KEY(grant_id,effect_key) REFERENCES agent_update_native_claims(grant_id,effect_key));
CREATE TABLE IF NOT EXISTS agent_update_sync_applied(
grant_id TEXT NOT NULL REFERENCES agent_update_handoffs(grant_id),decision_id TEXT NOT NULL,
witness BLOB NOT NULL,witness_sha256 TEXT NOT NULL,PRIMARY KEY(grant_id,decision_id));",
)?;
Ok(())
}
@@ -1060,10 +1070,14 @@ pub enum NativeControlOperation {
expected_head_sha256: String,
service: NativeService,
},
ObserveStarts,
ObserveStarts {
services: Vec<rmm_updater_handoff::StartedService>,
observation_sha256: String,
},
Health {
receipt: rmm_updater_handoff::SignedHealth,
},
Finalize,
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
@@ -1079,7 +1093,8 @@ pub struct NativeControlReply {
pub owner_nonce: Uuid,
pub handoff_sha256: String,
pub ready: bool,
pub proof: rmm_domain::agent_update::UpdateInflightProof,
pub proof: Option<rmm_domain::agent_update::UpdateInflightProof>,
pub original_outcome_base64url: Option<String>,
pub claim: Option<NativeEffectClaim>,
/// Only ReadOriginal; exact retained execution_evidence.start bytes,
/// bounded to 512KiB before canonical Base64url encoding, never rewritten.
@@ -1159,3 +1174,97 @@ mod native_record_tests {
);
}
}
/// Read the exact immutable native reservation, never a dispatch token.
pub fn read_native_claim(
db: &Connection,
guard: &impl ExecutorLedgerGuard,
grant: Uuid,
effect: &NativeEffect,
) -> Result<NativeEffectClaim> {
read(db, guard, grant)?;
let raw: Vec<u8> = db.query_row(
"SELECT claim FROM agent_update_native_claims WHERE grant_id=?1 AND effect_key=?2",
params![grant.to_string(), native_key(effect)?],
|r| r.get(0),
)?;
let claim: NativeEffectClaim = serde_json::from_slice(&raw)?;
ensure!(
claim.grant_id == grant && claim.effect == *effect,
"UPDATE_NATIVE_ORIGINAL_CLAIM_REQUIRED"
);
Ok(claim)
}
/// No new capture/checkpoint or readiness is generated by this read.
pub fn current_proof(
db: &Connection,
guard: &impl ExecutorLedgerGuard,
grant: Uuid,
) -> Result<Option<rmm_domain::agent_update::UpdateInflightProof>> {
read(db, guard, grant)?;
proof_locked(db, grant)
}
/// Actual local control application, recorded by HelperSync in the SAME
/// transaction as its verified original decision. Never supplied by IPC.
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AppliedUpdateSync {
pub schema_version: u32,
pub grant_id: Uuid,
pub decision_id: Uuid,
pub request_sha256: String,
pub response_protobuf_sha256: String,
pub applied_at: DateTime<Utc>,
}
pub(crate) fn record_applied_sync(db: &Connection, witness: &AppliedUpdateSync) -> Result<()> {
ensure!(
witness.schema_version == 1
&& !witness.grant_id.is_nil()
&& !witness.decision_id.is_nil()
&& rmm_domain::agent_update::digest(&witness.request_sha256)
&& rmm_domain::agent_update::digest(&witness.response_protobuf_sha256),
"UPDATE_APPLIED_SYNC_SHAPE"
);
let raw = serde_json::to_vec(witness)?;
db.execute("INSERT INTO agent_update_sync_applied(grant_id,decision_id,witness,witness_sha256) VALUES(?1,?2,?3,?4)",params![witness.grant_id.to_string(),witness.decision_id.to_string(),raw,hash(&raw)])?;
Ok(())
}
pub fn read_applied_sync(
db: &Connection,
guard: &impl ExecutorLedgerGuard,
grant: Uuid,
decision: Uuid,
) -> Result<AppliedUpdateSync> {
use prost::Message;
guard.check(db)?;
let (raw,digest):(Vec<u8>,String)=db.query_row("SELECT witness,witness_sha256 FROM agent_update_sync_applied WHERE grant_id=?1 AND decision_id=?2",params![grant.to_string(),decision.to_string()],|r|Ok((r.get(0)?,r.get(1)?)))?;
let witness: AppliedUpdateSync = serde_json::from_slice(&raw)?;
ensure!(
raw.len() <= 2048
&& hash(&raw) == digest
&& serde_json::to_vec(&witness)? == raw
&& witness.schema_version == 1
&& witness.grant_id == grant
&& witness.decision_id == decision,
"UPDATE_APPLIED_SYNC_CHANGED"
);
let (saved_response, request): (Vec<u8>, Vec<u8>) = db.query_row(
"SELECT response,request FROM helper_sync_decisions WHERE decision_id=?1",
[decision.to_string()],
|r| Ok((r.get(0)?, r.get(1)?)),
)?;
let response: crate::helper_reconcile::SignedResponse =
serde_json::from_slice(&saved_response)?;
let protobuf = rmm_protocol::SyncResponse {
decision_bytes: response.decision_bytes,
signature: response.signature,
}
.encode_to_vec();
ensure!(
hash(&protobuf) == witness.response_protobuf_sha256
&& hash(&request) == witness.request_sha256,
"UPDATE_APPLIED_SYNC_ORIGINAL_BYTES_CHANGED"
);
guard.check(db)?;
Ok(witness)
}