fix: reconcile configured APT effect without retroactive acceptance and retain host reboot evidence
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-13 20:00:20 +01:00
parent 34d695a778
commit b08734065a
26 changed files with 2006 additions and 36 deletions
+18
View File
@@ -97,6 +97,15 @@ pub fn validate_for_scope(
} }
let o: Observation = let o: Observation =
serde_json::from_value(item.clone()).map_err(|_| "INVALID_OBSERVATION")?; serde_json::from_value(item.clone()).map_err(|_| "INVALID_OBSERVATION")?;
// Old durable observations without this additive field remain
// acknowledgeable. A present host-level flag must stay a boolean.
let invalid_host_reboot = matches!(
o.scope.as_str(),
"linux.apt.planning" | "linux.apt.recovery-planning"
) && o
.data
.get("host_reboot_required")
.is_some_and(|v| !v.is_boolean());
if !o.scope.starts_with(prefix) if !o.scope.starts_with(prefix)
|| o.scope.len() > 64 || o.scope.len() > 64
|| !(o || !(o
@@ -121,6 +130,7 @@ pub fn validate_for_scope(
|| (o.truncated && o.completeness == "complete") || (o.truncated && o.completeness == "complete")
|| o.error_code.as_ref().is_some_and(|s| s.len() > 128) || o.error_code.as_ref().is_some_and(|s| s.len() > 128)
|| (o.quality == "valid" && o.data.is_null()) || (o.quality == "valid" && o.data.is_null())
|| invalid_host_reboot
{ {
return Err("INVALID_OBSERVATION_METADATA"); return Err("INVALID_OBSERVATION_METADATA");
} }
@@ -187,6 +197,14 @@ mod tests {
v["observations"] = json!([{"scope":"linux.apt.recovery-planning","source_id":"root-helper:apt_recovery_planning_v1","observed_at":now,"quality":"valid","completeness":"complete","truncated":false,"error_code":null,"data":{"native_recovery":{"schema_version":1}}}]); v["observations"] = json!([{"scope":"linux.apt.recovery-planning","source_id":"root-helper:apt_recovery_planning_v1","observed_at":now,"quality":"valid","completeness":"complete","truncated":false,"error_code":null,"data":{"native_recovery":{"schema_version":1}}}]);
let original = serde_json::to_vec(&v).unwrap(); let original = serde_json::to_vec(&v).unwrap();
assert_eq!(validate(&original, now).unwrap(), v); assert_eq!(validate(&original, now).unwrap(), v);
v["observations"][0]["data"]["host_reboot_required"] = json!(true);
assert!(validate(&serde_json::to_vec(&v).unwrap(), now).is_ok());
v["observations"][0]["data"]["host_reboot_required"] = json!("true");
assert_eq!(
validate(&serde_json::to_vec(&v).unwrap(), now).unwrap_err(),
"INVALID_OBSERVATION_METADATA"
);
v = serde_json::from_slice(&original).unwrap();
for rejected in [ for rejected in [
"linux.apt.other-planning", "linux.apt.other-planning",
"linux.apt.recovery-planning-extra", "linux.apt.recovery-planning-extra",
+26
View File
@@ -5,6 +5,7 @@ use anyhow::{Context, Result, bail, ensure};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use rmm_domain::jobs::{ExecutionPermitPayload, JobPayload, hash}; use rmm_domain::jobs::{ExecutionPermitPayload, JobPayload, hash};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
fs::{self, File, OpenOptions}, fs::{self, File, OpenOptions},
@@ -1169,6 +1170,31 @@ fn map_driver_result(
"APT_FIXTURE_PAYLOAD_EVIDENCE" "APT_FIXTURE_PAYLOAD_EVIDENCE"
); );
if bootstrap { if bootstrap {
let before = result
.evidence
.get("host_reboot_required_before")
.and_then(Value::as_bool);
let after = result
.evidence
.get("host_reboot_required_after")
.and_then(Value::as_bool);
ensure!(
before.is_some()
&& before == after
&& after
== result
.evidence
.get("reboot_required")
.and_then(Value::as_bool)
&& result.evidence.get("reboot_required_introduced")
== Some(&serde_json::json!(false))
&& result
.evidence
.get("host_reboot_before_sha256")
.and_then(Value::as_str)
.is_some_and(|s| sha(s).is_ok()),
"APT_NATIVE_HOST_REBOOT_BASELINE_REQUIRED"
);
if let Some(recovery) = &m.native_recovery { if let Some(recovery) = &m.native_recovery {
ensure!( ensure!(
result.evidence.get("native_recovery") == Some(&serde_json::json!(true)) result.evidence.get("native_recovery") == Some(&serde_json::json!(true))
+27 -1
View File
@@ -21,7 +21,7 @@ fn configure_only_is_explicit_native_recovery_and_never_install_acceptance() {
m.transaction_sha256 = hash(&m.transaction_bytes); m.transaction_sha256 = hash(&m.transaction_bytes);
validate_manifest(&m, "apt_native_acceptance", &config).unwrap(); validate_manifest(&m, "apt_native_acceptance", &config).unwrap();
assert!(validate_manifest(&m, "ensure_package", &config).is_err()); assert!(validate_manifest(&m, "ensure_package", &config).is_err());
let mut evidence = serde_json::json!({"test_acceptance":true,"noProductionEvidence":true,"native_recovery":true,"recovery_record_sha256":hash(b"recovery record"),"partial_proof_sha256":hash(b"partial"),"test_result_id":m.test_result_id,"effect_armed_ledger_id":"ledger","packages":[{"name":"rmm-mvp-test","architecture":"all","version":"1.0"}],"snapshot_sha256":hash(b"snapshot"),"fixture_payload_sha256":hash(b"1.0\n"),"reboot_required":false}); let mut evidence = serde_json::json!({"test_acceptance":true,"noProductionEvidence":true,"native_recovery":true,"recovery_record_sha256":hash(b"recovery record"),"partial_proof_sha256":hash(b"partial"),"test_result_id":m.test_result_id,"effect_armed_ledger_id":"ledger","packages":[{"name":"rmm-mvp-test","architecture":"all","version":"1.0"}],"snapshot_sha256":hash(b"snapshot"),"fixture_payload_sha256":hash(b"1.0\n"),"reboot_required":false,"host_reboot_required_before":false,"host_reboot_required_after":false,"reboot_required_introduced":false,"host_reboot_before_sha256":"e".repeat(64)});
let encode_result = |e: &serde_json::Value| { let encode_result = |e: &serde_json::Value| {
serde_json::to_vec(&serde_json::json!({"effect_state":"verified","code":"POSTCONDITIONS_VERIFIED","evidence":e})).unwrap() serde_json::to_vec(&serde_json::json!({"effect_state":"verified","code":"POSTCONDITIONS_VERIFIED","evidence":e})).unwrap()
}; };
@@ -642,6 +642,7 @@ fn structured_effect_state_not_process_exit_and_armed_failures_stay_unknown() {
let result = serde_json::json!({"effect_state":"verified","code":"POSTCONDITIONS_VERIFIED","evidence":{ let result = serde_json::json!({"effect_state":"verified","code":"POSTCONDITIONS_VERIFIED","evidence":{
"test_acceptance":true,"noProductionEvidence":true,"test_result_id":m.test_result_id,"native_record_sha256":"a".repeat(64), "test_acceptance":true,"noProductionEvidence":true,"test_result_id":m.test_result_id,"native_record_sha256":"a".repeat(64),
"snapshot_sha256":"b".repeat(64),"fixture_payload_sha256":hash(b"1.0\n"),"effect_armed_ledger_id":ledger,"reboot_required":false, "snapshot_sha256":"b".repeat(64),"fixture_payload_sha256":hash(b"1.0\n"),"effect_armed_ledger_id":ledger,"reboot_required":false,
"host_reboot_required_before":false,"host_reboot_required_after":false,"reboot_required_introduced":false,"host_reboot_before_sha256":"e".repeat(64),
"packages":[{"name":p.name,"architecture":p.architecture,"version":p.new_version}]}}); "packages":[{"name":p.name,"architecture":p.architecture,"version":p.new_version}]}});
let bytes = serde_json::to_vec(&result).unwrap(); let bytes = serde_json::to_vec(&result).unwrap();
assert_eq!( assert_eq!(
@@ -652,6 +653,31 @@ fn structured_effect_state_not_process_exit_and_armed_failures_stay_unknown() {
); );
assert!(map_driver_result(&bytes, Some(1), true, &m, ledger).is_err()); assert!(map_driver_result(&bytes, Some(1), true, &m, ledger).is_err());
assert!(map_driver_result(&bytes, Some(0), true, &m, "wrong").is_err()); assert!(map_driver_result(&bytes, Some(0), true, &m, "wrong").is_err());
let mut ambient = result.clone();
ambient["evidence"]["host_reboot_required_before"] = serde_json::json!(true);
ambient["evidence"]["host_reboot_required_after"] = serde_json::json!(true);
ambient["evidence"]["reboot_required"] = serde_json::json!(true);
let mapped = map_driver_result(
&serde_json::to_vec(&ambient).unwrap(),
Some(0),
true,
&m,
ledger,
)
.unwrap();
assert_eq!(mapped.state, "succeeded");
assert!(mapped.reboot_required);
ambient["evidence"]["host_reboot_required_before"] = serde_json::json!(false);
assert!(
map_driver_result(
&serde_json::to_vec(&ambient).unwrap(),
Some(0),
true,
&m,
ledger
)
.is_err()
);
let failed = serde_json::json!({"effect_state":"known_failed","code":"START_DEADLINE","evidence":{"test_acceptance":true,"noProductionEvidence":true}}); let failed = serde_json::json!({"effect_state":"known_failed","code":"START_DEADLINE","evidence":{"test_acceptance":true,"noProductionEvidence":true}});
let bytes = serde_json::to_vec(&failed).unwrap(); let bytes = serde_json::to_vec(&failed).unwrap();
assert_eq!( assert_eq!(
@@ -0,0 +1,759 @@
//! One historical configure-only fixture whose effect completed but whose old
//! acceptance rejected an ambient host reboot flag. Read-only proof, FAILED
//! acceptance, and ordinary signed Sync only; never retry or retroactive success.
use super::*;
use rmm_domain::apt_transaction::{AptNativeRecovery, AptTransactionOperation};
const TARGET_GRANT: &str = "33775478-15b0-46ec-b059-44f500dbb0b6";
const PRIOR_GRANT: &str = "31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0";
const OLD_PROVIDER: &str = "5ff260f75cb2959678f6be729d3a806a4ea29febd5ae4003317fed41afc25327";
const OLD_RUNTIME: &str = "706c74d72592db990b47869b06ebc8668dffe029d01b13df52d7ef4f22b758fe";
const CLASSIFIED: &str = "APT_RECOVERY_CONFIGURED_ACCEPTANCE_REBOOT_FLAG_VERIFIED";
const ACTIVE_NAMES: [&str; 10] = [
"context.json",
"signed-action.json",
"expectation.json",
"baseline.json",
"launch.json",
"native-prechecks.json",
"sandbox-ready.json",
"sandbox-result.json",
"hook-armed.json",
"partial-proof.json",
];
#[derive(Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
struct Proof {
schema_version: u32,
#[serde(rename = "type")]
kind: String,
transaction_sha256: String,
job_payload_sha256: String,
effect_armed_ledger_id: String,
grant_id: Uuid,
job_id: Uuid,
attempt_id: Uuid,
authorization_id: Uuid,
plan_sha256: String,
original_evidence_sha256: String,
partial_proof_sha256: String,
original_baseline_sha256: String,
observed_snapshot_sha256: String,
status_fingerprint: String,
fixture_payload_sha256: String,
snapshot: BTreeMap<String, PackageState>,
checked_at_ms: i64,
effect_complete: bool,
partial_effect: bool,
postconditions_passed: bool,
reboot_required: bool,
host_reboot_required: bool,
host_reboot_marker_sha256: String,
}
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Output {
effect_state: String,
code: String,
proof: Proof,
}
fn eligible(binding: &Binding, row: &LedgerRow) -> Result<Option<Candidate>> {
if row.grant != TARGET_GRANT {
return Ok(None);
}
ensure!(
row.start.len() <= 512 * 1024 && row.outcome.len() <= 512 * 1024,
"APT_CONFIGURED_RECORD_LIMIT"
);
let old: Outcome = serde_json::from_slice(&row.outcome)?;
if old.state != "unknown" || old.error_code != "FIXTURE_UNEXPECTED_REBOOT_REQUIRED" {
return Ok(None);
}
let start: SavedStart = serde_json::from_slice(&row.start)?;
let permit: ExecutionPermitPayload = serde_json::from_slice(&start.request.permit_bytes)?;
let (job, permit) = binding.verify(&start.request, permit.not_before)?;
ensure!(
!start.previous_boot_id.is_nil()
&& start.reauthentication_required
&& !start.postconditions_passed
&& start.reconnect_deadline.is_none()
&& start.reserved_at <= permit.start_before
&& row.agent == binding.agent_id.to_string()
&& row.generation == binding.enrollment_generation
&& row.grant == permit.grant_id.to_string()
&& row.job == job.job_id.to_string()
&& row.attempt == job.attempt_id.to_string()
&& job.execution_identity == "root",
"APT_CONFIGURED_ORIGINAL_BINDING"
);
let Action::AptNativeAcceptance {
recipe_id,
recipe_version,
apt_manifest: m,
} = &job.action
else {
return Ok(None);
};
let Some(reference) = &m.native_recovery else {
return Ok(None);
};
ensure!(
recipe_id == apt::INSTALL_RECIPE
&& recipe_version == "1"
&& m.validate()
&& m.schema_version == 4
&& m.native_retry.is_none()
&& reference.previous_grant_id.to_string() == PRIOR_GRANT
&& m.provider_sha256 == OLD_PROVIDER
&& m.runtime_sha256 == OLD_RUNTIME
&& m.resolved_apt_transaction.operation == Some(AptTransactionOperation::ConfigureOnly)
&& m.action == "apt-native-acceptance"
&& m.execution_profile == "dev-test",
"APT_CONFIGURED_FIXED_HISTORICAL_ACTION"
);
let ledger = format!("apt-{}-{}", permit.grant_id, row.rowid);
ensure!(
old.exit_code == Some(0)
&& old.stdout.is_empty()
&& old.stderr.is_empty()
&& !old.output_truncated
&& !old.reboot_required
&& old.evidence["postconditions_passed"] == false
&& old.evidence["test_acceptance"] == true
&& old.evidence["noProductionEvidence"] == true
&& old.evidence["effect_armed_ledger_id"] == ledger,
"APT_CONFIGURED_EXPECTED_UNKNOWN"
);
Ok(Some(Candidate {
request: start.request.clone(),
permit: permit.clone(),
manifest: m.clone(),
probe: ProbeRequest {
transaction_sha256: m.transaction_sha256.clone(),
job_payload_sha256: hash(&start.request.job_bytes),
effect_armed_ledger_id: ledger,
grant_id: permit.grant_id,
job_id: job.job_id,
attempt_id: job.attempt_id,
authorization_id: permit.authorization_id,
plan_sha256: permit.plan_hash.clone(),
},
original_boot_id: start.previous_boot_id,
original_outcome: row.outcome.clone(),
}))
}
fn names(reference: &AptNativeRecovery) -> Vec<String> {
ACTIVE_NAMES
.into_iter()
.map(str::to_owned)
.chain([
"bootstrap-attempt-rmm-apt-fixture-install-1.0.json".into(),
"bootstrap-retry-rmm-apt-fixture-install-1.0.json".into(),
format!("recovery-attempt-{}.json", reference.previous_grant_id),
])
.collect()
}
fn configure_protocol_sha256() -> String {
hash(&serde_json::to_vec(&json!([{"name":"rmm-mvp-test","old_version":"1.0","old_arch":"all","old_multiarch":"none",
"direction":"=","new_version":"1.0","new_arch":"all","new_multiarch":"none","action":"**CONFIGURE**"}])).expect("fixed protocol object"))
}
fn read_current(reference: &AptNativeRecovery) -> Result<BTreeMap<String, Vec<u8>>> {
let base = Path::new(BASE);
crate::private_path(base, 0, true)?;
crate::private_path(&base.join("active"), 0, true)?;
ensure!(
matches!(fs::symlink_metadata(base.join("active/host-reboot-before.json")),Err(e) if e.kind()==std::io::ErrorKind::NotFound),
"APT_CONFIGURED_HISTORICAL_BEFORE_MUST_BE_ABSENT"
);
for name in [
"acceptance-rmm-apt-fixture-install-1.0.json".into(),
"pending-acceptance-rmm-apt-fixture-install-1.0.json".into(),
format!("recovery-{}.json", reference.previous_grant_id),
format!("pending-recovery-{}.json", reference.previous_grant_id),
] {
ensure!(
matches!(fs::symlink_metadata(base.join(name)),Err(e) if e.kind()==std::io::ErrorKind::NotFound),
"APT_CONFIGURED_ACCEPTANCE_MUST_NOT_EXIST"
);
}
let mut files = BTreeMap::new();
for name in names(reference).into_iter().chain(["apt.conf".into()]) {
let root = if ACTIVE_NAMES.contains(&name.as_str()) || name == "apt.conf" {
base.join("active")
} else {
base.into()
};
files.insert(name.clone(), sealed(&root.join(name), 1024 * 1024)?);
}
Ok(files)
}
fn previous_files(reference: &AptNativeRecovery) -> Result<BTreeMap<String, Vec<u8>>> {
let root = Path::new(BASE)
.join("history")
.join(reference.previous_grant_id.to_string());
crate::private_path(&root, 0, true)?;
let mut files = BTreeMap::new();
for name in EVIDENCE_NAMES.into_iter().chain(["apt.conf"]) {
let path = if name.starts_with("bootstrap-") {
Path::new(BASE).join(name)
} else {
root.join(name)
};
files.insert(name.into(), sealed(&path, 1024 * 1024)?);
}
Ok(files)
}
fn current_evidence(
c: &Candidate,
prior: &ClosedPartial,
files: &BTreeMap<String, Vec<u8>>,
) -> Result<BTreeMap<String, PackageState>> {
let read = |name: &str| files.get(name).context("APT_CONFIGURED_EVIDENCE_MISSING");
let reference = c
.manifest
.native_recovery
.as_ref()
.context("APT_CONFIGURED_REFERENCE")?;
ensure!(
prior.reference == *reference
&& read("partial-proof.json")? == &prior.proof
&& hash(&prior.proof) == reference.partial_proof_sha256
&& prior.baseline_sha256 == c.manifest.resolved_apt_transaction.baseline_sha256
&& prior.status_fingerprint == c.manifest.resolved_apt_transaction.status_fingerprint
&& prior.previous_start_before <= c.permit.not_before
&& prior.job_id != c.probe.job_id
&& prior.authorization_id != c.probe.authorization_id
&& prior.plan_sha256 != c.probe.plan_sha256,
"APT_CONFIGURED_PRIOR_CLOSED_PROOF_BINDING"
);
ensure!(
read("signed-action.json")? == &c.request.job_bytes
&& read("expectation.json")? == &c.manifest.transaction_bytes
&& hash(read("baseline.json")?) == c.manifest.resolved_apt_transaction.baseline_sha256
&& hash(read("apt.conf")?) == c.manifest.apt_config_sha256,
"APT_CONFIGURED_HISTORICAL_FILE_HASH"
);
let context: ContextRecord = serde_json::from_slice(read("context.json")?)?;
ensure!(
context.schema_version == 2
&& context.action == "apt-native-acceptance"
&& context.execution_profile == "dev-test"
&& context.transaction_sha256 == c.probe.transaction_sha256
&& context.job_payload_sha256 == c.probe.job_payload_sha256
&& context.effect_armed_ledger_id == c.probe.effect_armed_ledger_id
&& context.grant_id == c.probe.grant_id
&& context.job_id == c.probe.job_id
&& context.attempt_id == c.probe.attempt_id
&& context.authorization_id == c.probe.authorization_id
&& context.plan_sha256 == c.probe.plan_sha256
&& context.boot_id == c.original_boot_id
&& context.not_before_ms == c.permit.not_before.timestamp_millis()
&& context.start_before_ms == c.permit.start_before.timestamp_millis()
&& context.monotonic_start_before_ns > 0,
"APT_CONFIGURED_ORIGINAL_CONTEXT"
);
let value = |name: &str| -> Result<Value> { Ok(serde_json::from_slice(read(name)?)?) };
ensure!(
value("launch.json")?
== json!({"transaction_sha256":c.probe.transaction_sha256,"effect_armed_ledger_id":c.probe.effect_armed_ledger_id})
&& value("sandbox-ready.json")?
== json!({"transaction_sha256":c.probe.transaction_sha256,"sandbox_version":1})
&& value("sandbox-result.json")?
== json!({"transaction_sha256":c.probe.transaction_sha256,"apt_exit_code":0,"reboot_required":false})
&& value("native-prechecks.json")? == native_prechecks(c),
"APT_CONFIGURED_NATIVE_CHILD_RESULT"
);
let hook = value("hook-armed.json")?;
ensure!(
hook["transaction_sha256"] == c.probe.transaction_sha256
&& hook["grant_id"] == c.probe.grant_id.to_string()
&& hook["effect_armed_ledger_id"] == c.probe.effect_armed_ledger_id
&& hook["protocol_sha256"] == configure_protocol_sha256()
&& hook["armed_at_ms"]
.as_i64()
.is_some_and(|t| t >= context.not_before_ms && t < context.start_before_ms),
"APT_CONFIGURED_ARMED_HOOK"
);
ensure!(
value(&format!(
"recovery-attempt-{}.json",
reference.previous_grant_id
))? == json!({
"transaction_sha256":c.probe.transaction_sha256,"job_payload_sha256":c.probe.job_payload_sha256,
"grant_id":c.probe.grant_id,"attempt_id":c.probe.attempt_id,"native_recovery":reference}),
"APT_CONFIGURED_ONCE_MARKER"
);
let baseline: BTreeMap<String, PackageState> = serde_json::from_slice(read("baseline.json")?)?;
ensure!(
baseline.get("rmm-mvp-test:all")
== Some(&PackageState {
version: "1.0".into(),
status: "install ok unpacked".into()
}),
"APT_CONFIGURED_ORIGINAL_UNPACKED_BASELINE"
);
Ok(baseline)
}
fn evidence_digest(c: &Candidate, files: &BTreeMap<String, Vec<u8>>) -> Result<String> {
let reference = c
.manifest
.native_recovery
.as_ref()
.context("APT_CONFIGURED_REFERENCE")?;
let hashes = names(reference)
.into_iter()
.map(|name| {
let digest = hash(
files
.get(&name)
.context("APT_CONFIGURED_EVIDENCE_MISSING")?,
);
Ok((name, digest))
})
.collect::<Result<BTreeMap<_, _>>>()?;
Ok(hash(&serde_json::to_vec(&hashes)?))
}
fn verify(
c: &Candidate,
prior: &ClosedPartial,
files: &BTreeMap<String, Vec<u8>>,
output: &Output,
now: DateTime<Utc>,
) -> Result<()> {
let mut expected = current_evidence(c, prior, files)?;
expected.insert(
"rmm-mvp-test:all".into(),
PackageState {
version: "1.0".into(),
status: "install ok installed".into(),
},
);
let p = &output.proof;
let actual = ProbeRequest {
transaction_sha256: p.transaction_sha256.clone(),
job_payload_sha256: p.job_payload_sha256.clone(),
effect_armed_ledger_id: p.effect_armed_ledger_id.clone(),
grant_id: p.grant_id,
job_id: p.job_id,
attempt_id: p.attempt_id,
authorization_id: p.authorization_id,
plan_sha256: p.plan_sha256.clone(),
};
ensure!(
output.effect_state == "known_failed"
&& output.code == CLASSIFIED
&& p.schema_version == 1
&& p.kind == "rmm.apt.configured-recovery-reconciliation"
&& actual == c.probe
&& p.effect_complete
&& !p.partial_effect
&& !p.postconditions_passed
&& p.reboot_required
&& p.host_reboot_required
&& digest(&p.host_reboot_marker_sha256)
&& p.original_evidence_sha256 == evidence_digest(c, files)?
&& p.partial_proof_sha256 == prior.reference.partial_proof_sha256
&& p.original_baseline_sha256 == c.manifest.resolved_apt_transaction.baseline_sha256
&& p.snapshot == expected
&& p.observed_snapshot_sha256
== hash(&serde_json::to_vec(&serde_json::to_value(&p.snapshot)?)?)
&& p.fixture_payload_sha256 == hash(b"1.0\n")
&& digest(&p.status_fingerprint)
&& p.checked_at_ms >= now.timestamp_millis() - 1000
&& p.checked_at_ms <= Utc::now().timestamp_millis() + 1000,
"APT_CONFIGURED_READONLY_PROOF_BINDING"
);
Ok(())
}
fn persist(db: &mut Connection, c: &Candidate, p: &Proof) -> Result<()> {
let proof = serde_json::to_vec(&serde_json::to_value(p)?)?;
let proof_sha = hash(&proof);
let outcome = Outcome {
state: "failed".into(),
stdout: vec![],
stderr: vec![],
exit_code: Some(0),
output_truncated: false,
reboot_required: true,
evidence: json!({"postconditions_passed":false,"effect_complete":true,"partial_effect":false,"reconciled_postconditions":true,
"effect_armed_ledger_id":c.probe.effect_armed_ledger_id,"test_acceptance":true,"noProductionEvidence":true,
"apt":{"test_acceptance":true,"noProductionEvidence":true,"effect_complete":true,"partial_effect":false,
"fixture_status":"install ok installed","fixture_version":"1.0","fixture_payload_sha256":p.fixture_payload_sha256,
"snapshot_sha256":p.observed_snapshot_sha256,"status_fingerprint":p.status_fingerprint,
"host_reboot_required":true,"host_reboot_marker_sha256":p.host_reboot_marker_sha256,
"host_reboot_required_before":null,"acceptance_reboot_baseline_missing":true,"reconciliation_proof_sha256":proof_sha}}),
error_code: CLASSIFIED.into(),
};
let classified = serde_json::to_vec(&outcome)?;
let tx = db.transaction_with_behavior(TransactionBehavior::Immediate)?;
// Lazy, append-only local evidence. Existing partial-proof rows are intact;
// ordinary open_ledger/probe never creates this table or changes history.
tx.execute_batch("CREATE TABLE IF NOT EXISTS apt_effect_reconciliations(grant_id TEXT PRIMARY KEY,
original_request_sha256 TEXT NOT NULL,previous_outcome_sha256 TEXT NOT NULL,previous_outcome BLOB NOT NULL,
proof_sha256 TEXT NOT NULL,proof BLOB NOT NULL,classified_outcome BLOB NOT NULL,checked_at_ms INTEGER NOT NULL);")?;
let current:(Option<Vec<u8>>,Option<Vec<u8>>)=tx.query_row("SELECT c.result,e.outcome FROM consumed c JOIN execution_evidence e USING(grant_id) WHERE grant_id=?1",
[c.probe.grant_id.to_string()],|r|Ok((r.get(0)?,r.get(1)?)))?;
ensure!(
current.0.is_none() && current.1.as_deref() == Some(c.original_outcome.as_slice()),
"APT_CONFIGURED_OUTCOME_CHANGED"
);
tx.execute(
"INSERT INTO apt_effect_reconciliations VALUES(?1,?2,?3,?4,?5,?6,?7,?8)",
params![
c.probe.grant_id.to_string(),
hash(&serde_json::to_vec(&c.request)?),
hash(&c.original_outcome),
c.original_outcome,
proof_sha,
proof,
classified,
p.checked_at_ms
],
)?;
ensure!(
tx.execute(
"UPDATE execution_evidence SET outcome=?2 WHERE grant_id=?1 AND outcome=?3",
params![c.probe.grant_id.to_string(), classified, c.original_outcome]
)? == 1,
"APT_CONFIGURED_OUTCOME_CHANGED"
);
// No consumed.result update. Only normal signed RootSync closes the lock.
tx.commit()?;
Ok(())
}
pub(super) fn refresh(
db: &mut Connection,
binding: &Binding,
row: &LedgerRow,
now: DateTime<Utc>,
) -> Result<bool> {
let Some(c) = eligible(binding, row)? else {
return Ok(false);
};
let reference = c
.manifest
.native_recovery
.as_ref()
.context("APT_CONFIGURED_REFERENCE")?;
let Ok(historical) = previous_files(reference) else {
return Ok(false);
};
let Ok(prior) = closed_partial_from(db, binding, Some(reference), || Ok(historical.clone()))
else {
return Ok(false);
};
let Ok(files) = read_current(reference) else {
return Ok(false);
};
if current_evidence(&c, &prior, &files).is_err() {
return Ok(false);
}
let Ok(raw) = probe_mode(&c, "verify-configured-recovery") else {
return Ok(false);
};
let Ok(output) = serde_json::from_slice::<Output>(&raw) else {
return Ok(false);
};
if verify(&c, &prior, &files, &output, now).is_err() {
return Ok(false);
}
// Re-read every sealed historical witness after the independent live probe.
if read_current(reference)? != files
|| previous_files(reference)? != historical
|| hash(&sealed(Path::new("/run/reboot-required"), 4096)?)
!= output.proof.host_reboot_marker_sha256
{
return Ok(false);
}
persist(db, &c, &output.proof)?;
Ok(true)
}
#[cfg(test)]
mod tests {
use super::*;
use openssl::{pkey::PKey, sign::Signer};
struct Fixture {
binding: Binding,
row: LedgerRow,
prior: ClosedPartial,
files: BTreeMap<String, Vec<u8>>,
now: DateTime<Utc>,
}
fn fixture() -> Fixture {
let now = Utc::now();
let key = PKey::generate_ed25519().unwrap();
let binding = Binding {
tenant_id: Uuid::new_v4(),
asset_id: Uuid::new_v4(),
agent_id: Uuid::new_v4(),
enrollment_generation: 1,
assignment_version: 1,
public_key_hex: hex::encode(key.raw_public_key().unwrap()),
};
let baseline = json!({"base-files:amd64":{"version":"1","status":"install ok installed"},"rmm-mvp-test:all":{"version":"1.0","status":"install ok unpacked"}});
// A trusted prior object is supplied to this unit boundary. The
// independent closed_partial_from signature/history checks have their
// existing integration guards; this fixture does not assert native proof.
let proof = serde_json::to_vec(
&json!({"isolated_verified_prior_fixture":true,"snapshot":baseline}),
)
.unwrap();
let reference = AptNativeRecovery {
schema_version: 1,
previous_grant_id: PRIOR_GRANT.parse().unwrap(),
previous_attempt_id: Uuid::new_v4(),
partial_proof_sha256: hash(&proof),
};
let baseline_sha = hash(&serde_json::to_vec(&baseline).unwrap());
let tx = json!({"schema_version":2,"operation":"configure_only","recipe_id":apt::INSTALL_RECIPE,"recipe_version":"1","platform":"ubuntu-24.04-amd64",
"resolver_config_version":"rmm-apt-local-v1","no_reboot":true,"status_fingerprint":"a".repeat(64),"baseline_sha256":baseline_sha,
"packages":[{"name":"rmm-mvp-test","architecture":"all","old_version":"1.0","new_version":"1.0","origin":"rmm-test",
"sha256":"74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867","size":20672,
"archive_path":"/var/lib/rmm-apt-transaction/archives/74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867.deb"}]});
let txbytes = serde_json::to_vec(&tx).unwrap();
let manifest = json!({"type":"rmm.apt.helper-action","schema_version":4,"action":"apt-native-acceptance","execution_profile":"dev-test",
"transaction_sha256":hash(&txbytes),"transaction_bytes":txbytes,"resolved_apt_transaction":tx,"native_recovery":reference,
"provider_sha256":OLD_PROVIDER,"hook_sha256":"b".repeat(64),"runtime_sha256":OLD_RUNTIME,"apt_config_sha256":hash(b"historical config"),"test_result_id":"configured-fixture"});
let job:JobPayload=serde_json::from_value(json!({"schema_version":1,"tenant_id":binding.tenant_id,"agent_id":binding.agent_id,"asset_id":binding.asset_id,
"enrollment_generation":1,"assignment_version":1,"job_id":Uuid::new_v4(),"attempt_id":Uuid::new_v4(),"execution_identity":"root",
"not_before":now,"start_before":now+chrono::Duration::minutes(15),"max_runtime_seconds":300,"max_output_bytes":65536,
"action":{"action":"apt_native_acceptance","recipe_id":apt::INSTALL_RECIPE,"recipe_version":"1","apt_manifest":manifest}})).unwrap();
let permit = ExecutionPermitPayload {
domain: "rmm.execution-permit".into(),
schema_version: 1,
grant_id: TARGET_GRANT.parse().unwrap(),
authorization_id: Uuid::new_v4(),
tenant_id: job.tenant_id,
asset_id: job.asset_id,
agent_id: job.agent_id,
enrollment_generation: 1,
assignment_version: 1,
job_id: job.job_id,
attempt_id: job.attempt_id,
plan_hash: "c".repeat(64),
job_payload_hash: hash(&encode(&job).unwrap()),
action: "apt_native_acceptance".into(),
execution_identity: "root".into(),
not_before: now,
start_before: now + chrono::Duration::seconds(60),
max_runtime_seconds: 300,
key_id: hash(&key.raw_public_key().unwrap()),
};
let bytes = encode(&permit).unwrap();
let request = Request {
job_bytes: encode(&job).unwrap(),
permit_bytes: bytes.clone(),
signature: Signer::new_without_digest(&key)
.unwrap()
.sign_oneshot_to_vec(&bytes)
.unwrap(),
plan_hash: permit.plan_hash.clone(),
authorization_id: permit.authorization_id,
};
let boot = Uuid::new_v4();
let ledger = format!("apt-{}-11", permit.grant_id);
let old = Outcome {
exit_code: Some(0),
evidence: json!({"postconditions_passed":false,"test_acceptance":true,"noProductionEvidence":true,"effect_armed_ledger_id":ledger}),
..Outcome::unknown("FIXTURE_UNEXPECTED_REBOOT_REQUIRED")
};
let row=LedgerRow{rowid:11,grant:permit.grant_id.to_string(),agent:binding.agent_id.to_string(),generation:1,job:job.job_id.to_string(),attempt:job.attempt_id.to_string(),outcome:serde_json::to_vec(&old).unwrap(),
start:serde_json::to_vec(&json!({"previous_boot_id":boot,"reserved_at":now,"reconnect_deadline":null,"request":request,"reauthentication_required":true,"postconditions_passed":false})).unwrap()};
let prior = ClosedPartial {
reference,
proof,
job_id: Uuid::new_v4(),
authorization_id: Uuid::new_v4(),
plan_sha256: "d".repeat(64),
previous_start_before: now - chrono::Duration::seconds(1),
baseline_sha256: baseline_sha,
status_fingerprint: "a".repeat(64),
};
let c = eligible(&binding, &row).unwrap().unwrap();
let mut files = BTreeMap::from([
("signed-action.json".into(), c.request.job_bytes.clone()),
(
"expectation.json".into(),
c.manifest.transaction_bytes.clone(),
),
(
"baseline.json".into(),
serde_json::to_vec(&baseline).unwrap(),
),
("apt.conf".into(), b"historical config".to_vec()),
("partial-proof.json".into(), prior.proof.clone()),
(
"bootstrap-attempt-rmm-apt-fixture-install-1.0.json".into(),
b"retained install marker".to_vec(),
),
(
"bootstrap-retry-rmm-apt-fixture-install-1.0.json".into(),
b"retained retry marker".to_vec(),
),
]);
for (name, value) in [
(
"context.json".into(),
json!({"schema_version":2,"transaction_sha256":c.probe.transaction_sha256,"job_payload_sha256":c.probe.job_payload_sha256,"effect_armed_ledger_id":ledger,
"grant_id":permit.grant_id,"job_id":job.job_id,"attempt_id":job.attempt_id,"authorization_id":permit.authorization_id,"plan_sha256":permit.plan_hash,
"action":"apt-native-acceptance","execution_profile":"dev-test","not_before_ms":now.timestamp_millis(),"start_before_ms":permit.start_before.timestamp_millis(),"boot_id":boot,"monotonic_start_before_ns":1}),
),
(
"launch.json".into(),
json!({"transaction_sha256":c.probe.transaction_sha256,"effect_armed_ledger_id":ledger}),
),
(
"sandbox-ready.json".into(),
json!({"transaction_sha256":c.probe.transaction_sha256,"sandbox_version":1}),
),
(
"sandbox-result.json".into(),
json!({"transaction_sha256":c.probe.transaction_sha256,"apt_exit_code":0,"reboot_required":false}),
),
("native-prechecks.json".into(), native_prechecks(&c)),
(
"hook-armed.json".into(),
json!({"transaction_sha256":c.probe.transaction_sha256,"effect_armed_ledger_id":ledger,"grant_id":permit.grant_id,"protocol_sha256":configure_protocol_sha256(),"armed_at_ms":now.timestamp_millis()}),
),
(
format!("recovery-attempt-{PRIOR_GRANT}.json"),
json!({"transaction_sha256":c.probe.transaction_sha256,"job_payload_sha256":c.probe.job_payload_sha256,"grant_id":permit.grant_id,"attempt_id":permit.attempt_id,"native_recovery":prior.reference}),
),
] {
files.insert(name, serde_json::to_vec(&value).unwrap());
}
Fixture {
binding,
row,
prior,
files,
now,
}
}
fn output(f: &Fixture, c: &Candidate) -> Output {
let mut snapshot = current_evidence(c, &f.prior, &f.files).unwrap();
snapshot.get_mut("rmm-mvp-test:all").unwrap().status = "install ok installed".into();
Output {
effect_state: "known_failed".into(),
code: CLASSIFIED.into(),
proof: Proof {
schema_version: 1,
kind: "rmm.apt.configured-recovery-reconciliation".into(),
transaction_sha256: c.probe.transaction_sha256.clone(),
job_payload_sha256: c.probe.job_payload_sha256.clone(),
effect_armed_ledger_id: c.probe.effect_armed_ledger_id.clone(),
grant_id: c.probe.grant_id,
job_id: c.probe.job_id,
attempt_id: c.probe.attempt_id,
authorization_id: c.probe.authorization_id,
plan_sha256: c.probe.plan_sha256.clone(),
original_evidence_sha256: evidence_digest(c, &f.files).unwrap(),
partial_proof_sha256: f.prior.reference.partial_proof_sha256.clone(),
original_baseline_sha256: f.prior.baseline_sha256.clone(),
observed_snapshot_sha256: hash(
&serde_json::to_vec(&serde_json::to_value(&snapshot).unwrap()).unwrap(),
),
status_fingerprint: "e".repeat(64),
fixture_payload_sha256: hash(b"1.0\n"),
snapshot,
checked_at_ms: f.now.timestamp_millis(),
effect_complete: true,
partial_effect: false,
postconditions_passed: false,
reboot_required: true,
host_reboot_required: true,
host_reboot_marker_sha256: "f".repeat(64),
},
}
}
#[test]
fn configured_exact_signed_candidate_and_full_proof_do_not_invent_before_or_success() {
let f = fixture();
let c = eligible(&f.binding, &f.row).unwrap().unwrap();
let out = output(&f, &c);
verify(&c, &f.prior, &f.files, &out, f.now).unwrap();
for variant in 0..6 {
let mut changed = output(&f, &c);
match variant {
0 => changed.proof.postconditions_passed = true,
1 => changed.proof.reboot_required = false,
2 => changed.proof.partial_effect = true,
3 => {
changed
.proof
.snapshot
.get_mut("base-files:amd64")
.unwrap()
.version = "unrelated change".into()
}
4 => changed.proof.grant_id = Uuid::new_v4(),
_ => changed.proof.checked_at_ms -= 60000,
}
assert!(verify(&c, &f.prior, &f.files, &changed, f.now).is_err());
}
let mut row = f.row.clone();
row.grant = Uuid::new_v4().to_string();
assert!(eligible(&f.binding, &row).unwrap().is_none());
let mut tampered = f.files.clone();
let mut hook: Value = serde_json::from_slice(&tampered["hook-armed.json"]).unwrap();
hook["protocol_sha256"] = json!("0".repeat(64));
tampered.insert("hook-armed.json".into(), serde_json::to_vec(&hook).unwrap());
assert!(current_evidence(&c, &f.prior, &tampered).is_err());
}
#[test]
fn configured_append_preserves_original_unknown_and_consumed_lock_until_signed_sync() {
let f = fixture();
let c = eligible(&f.binding, &f.row).unwrap().unwrap();
let out = output(&f, &c);
let mut db = Connection::open_in_memory().unwrap();
db.execute_batch("CREATE TABLE consumed(grant_id TEXT PRIMARY KEY,result BLOB);CREATE TABLE execution_evidence(grant_id TEXT PRIMARY KEY,outcome BLOB);").unwrap();
db.execute(
"INSERT INTO consumed VALUES(?1,NULL)",
[&c.probe.grant_id.to_string()],
)
.unwrap();
db.execute(
"INSERT INTO execution_evidence VALUES(?1,?2)",
params![c.probe.grant_id.to_string(), c.original_outcome],
)
.unwrap();
persist(&mut db, &c, &out.proof).unwrap();
assert!(
db.query_row("SELECT result IS NULL FROM consumed", [], |r| r
.get::<_, bool>(0))
.unwrap()
);
assert_eq!(
db.query_row(
"SELECT previous_outcome FROM apt_effect_reconciliations",
[],
|r| r.get::<_, Vec<u8>>(0)
)
.unwrap(),
c.original_outcome
);
let classified: Vec<u8> = db
.query_row("SELECT outcome FROM execution_evidence", [], |r| r.get(0))
.unwrap();
let value: Outcome = serde_json::from_slice(&classified).unwrap();
assert_eq!(value.state, "failed");
assert_eq!(value.error_code, CLASSIFIED);
assert!(value.reboot_required);
assert_eq!(value.evidence["effect_complete"], true);
assert_eq!(value.evidence["postconditions_passed"], false);
assert_eq!(
value.evidence["apt"]["host_reboot_required_before"],
Value::Null
);
assert!(persist(&mut db, &c, &out.proof).is_err());
assert_eq!(
db.query_row("SELECT count(*) FROM apt_effect_reconciliations", [], |r| r
.get::<_, u64>(0))
.unwrap(),
1
);
}
}
+15 -2
View File
@@ -526,9 +526,16 @@ fn verify_proof(
Ok(()) Ok(())
} }
fn probe(c: &Candidate) -> Result<ProbeOutput> { fn probe(c: &Candidate) -> Result<ProbeOutput> {
Ok(serde_json::from_slice(&probe_mode(c, "verify-partial")?)?)
}
fn probe_mode(c: &Candidate, mode: &str) -> Result<Vec<u8>> {
ensure!(
matches!(mode, "verify-partial" | "verify-configured-recovery"),
"APT_RECONCILE_PROBE_MODE"
);
apt::verify_installation()?; apt::verify_installation()?;
let mut child = Command::new("/usr/bin/python3") let mut child = Command::new("/usr/bin/python3")
.args(["-I", apt::CODE, "verify-partial"]) .args(["-I", apt::CODE, mode])
.env_clear() .env_clear()
.env("PATH", "/usr/bin:/bin") .env("PATH", "/usr/bin:/bin")
.env("LC_ALL", "C") .env("LC_ALL", "C")
@@ -558,7 +565,7 @@ fn probe(c: &Candidate) -> Result<ProbeOutput> {
} }
let status = child.wait()?; let status = child.wait()?;
ensure!(status.success() && !overflow, "APT_RECONCILE_NOT_PROVEN"); ensure!(status.success() && !overflow, "APT_RECONCILE_NOT_PROVEN");
Ok(serde_json::from_slice(&bytes)?) Ok(bytes)
} }
fn persist(db: &mut Connection, c: &Candidate, proof: &PartialProof) -> Result<()> { fn persist(db: &mut Connection, c: &Candidate, proof: &PartialProof) -> Result<()> {
let proof_bytes = serde_json::to_vec(&serde_json::to_value(proof)?)?; let proof_bytes = serde_json::to_vec(&serde_json::to_value(proof)?)?;
@@ -636,6 +643,9 @@ pub fn refresh(
drop(statement); drop(statement);
ensure!(rows.len() <= 256, "APT_RECONCILE_CAPACITY"); ensure!(rows.len() <= 256, "APT_RECONCILE_CAPACITY");
for row in rows { for row in rows {
if configured::refresh(db, binding, &row, now)? {
continue;
}
let Some(candidate) = eligible(binding, row)? else { let Some(candidate) = eligible(binding, row)? else {
continue; continue;
}; };
@@ -658,6 +668,9 @@ pub fn refresh(
Ok(()) Ok(())
} }
#[path = "apt_configured_reconcile.rs"]
mod configured;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
@@ -85,6 +85,7 @@ pub struct PlanningResult {
pub status_fingerprint: String, pub status_fingerprint: String,
pub dpkg_updates_empty: bool, pub dpkg_updates_empty: bool,
pub pending_triggers_empty: bool, pub pending_triggers_empty: bool,
pub host_reboot_required: bool,
pub runtime: std::collections::BTreeMap<String, serde_json::Value>, pub runtime: std::collections::BTreeMap<String, serde_json::Value>,
pub runtime_sha256: String, pub runtime_sha256: String,
pub provider_sha256: String, pub provider_sha256: String,
@@ -665,6 +666,7 @@ mod tests {
status_fingerprint: "c".repeat(64), status_fingerprint: "c".repeat(64),
dpkg_updates_empty: true, dpkg_updates_empty: true,
pending_triggers_empty: true, pending_triggers_empty: true,
host_reboot_required: false,
runtime, runtime,
runtime_sha256: hash(raw.as_bytes()), runtime_sha256: hash(raw.as_bytes()),
provider_sha256: "d".repeat(64), provider_sha256: "d".repeat(64),
+2
View File
@@ -73,6 +73,7 @@ function checkAction(p, expected) {
await page.getByLabel('Begründung', { exact: true }).fill(expected.request.reason); await page.getByLabel('Begründung', { exact: true }).fill(expected.request.reason);
await page.getByRole('button', { name: 'Plan erstellen · noch keine Ausführung' }).click(); await page.getByRole('button', { name: 'Plan erstellen · noch keine Ausführung' }).click();
await detail.locator('pre').waitFor(); const plan = JSON.parse(await detail.locator('pre').innerText()); await detail.locator('pre').waitFor(); const plan = JSON.parse(await detail.locator('pre').innerText());
assert(JSON.parse(Buffer.from(plan.plan_payload_bytes)).reason === expected.request.reason);
assert(plan.jobs.length === 1); checkAction(plan.jobs[0].payload, expected); assert(plan.jobs.length === 1); checkAction(plan.jobs[0].payload, expected);
assert(crypto.createHash('sha256').update(Buffer.from(plan.plan_payload_bytes)).digest('hex') === plan.plan_hash); assert(crypto.createHash('sha256').update(Buffer.from(plan.plan_payload_bytes)).digest('hex') === plan.plan_hash);
await detail.getByRole('button', { name: 'Antrag absenden · pending_approval' }).click(); await detail.getByRole('button', { name: 'Antrag absenden · pending_approval' }).click();
@@ -88,6 +89,7 @@ function checkAction(p, expected) {
assert(pending.approval_state === 'pending_approval' && pending.job_count === 0 && pending.execution_state === null); assert(pending.approval_state === 'pending_approval' && pending.job_count === 0 && pending.execution_state === null);
await op.getByRole('button', { name: 'Unveränderlichen Plan zur Prüfung öffnen' }).click(); await op.getByRole('button', { name: 'Unveränderlichen Plan zur Prüfung öffnen' }).click();
const plan = JSON.parse(await detail.locator('pre').innerText()); const plan = JSON.parse(await detail.locator('pre').innerText());
assert(JSON.parse(Buffer.from(plan.plan_payload_bytes)).reason === expected.request.reason);
// Submission changes request metadata, never the fixed plan bytes/jobs. // Submission changes request metadata, never the fixed plan bytes/jobs.
// Require the new pending state explicitly and compare EVERY other field. // Require the new pending state explicitly and compare EVERY other field.
const { approval_state: currentState, ...currentPlan } = plan; const { approval_state: currentState, ...currentPlan } = plan;
+22 -3
View File
@@ -20,6 +20,13 @@ CASES=('apt_configure_recovery','apt_native_update','ensure_package','apply_upda
def runtime_session(): def runtime_session():
configured=BASE/'configured-reconcile-runtime.json'
if configured.exists():
report=cloud.contract.protected_json(configured)
require(report['completed'] and report['preserved_state'] and report['readiness_only'] and
not report['native_acceptance'] and report['unknown_grant']=='33775478-15b0-46ec-b059-44f500dbb0b6',
'qualified preserving configured-reconciliation runtime')
return report,BASE/'configured-reconcile-runtime'
latest=BASE/'journal-capacity-runtime.json' latest=BASE/'journal-capacity-runtime.json'
if latest.exists(): if latest.exists():
report=cloud.contract.protected_json(latest) report=cloud.contract.protected_json(latest)
@@ -76,7 +83,15 @@ def enable():
apt_config_sha256=ready['apt_config_sha256'],provider_sha256=ready['provider_sha256'], apt_config_sha256=ready['apt_config_sha256'],provider_sha256=ready['provider_sha256'],
hook_sha256=hashlib.sha256((cloud.ROOT/'tools/apt-transaction/hook').read_bytes()).hexdigest())) hook_sha256=hashlib.sha256((cloud.ROOT/'tools/apt-transaction/hook').read_bytes()).hexdigest()))
policy=dict(schema_version=1,profile='development',expires_at=(m.now()+dt.timedelta(hours=1)).isoformat(),scopes=[scope]) policy=dict(schema_version=1,profile='development',expires_at=(m.now()+dt.timedelta(hours=1)).isoformat(),scopes=[scope])
old=m.protected_json(BASE/'recovery-policy-closed.json' if session!=BASE else cloud.ROOT/'devstate/cloud-logs/policy-closed.json') if session==BASE/'configured-reconcile-runtime':
old=m.protected_json(BASE/'capacity-recovery/recovery-policy-closed-unknown.json')
prior_checkpoint=m.protected_json(BASE/'capacity-recovery/cases/apt_configure_recovery/checkpoint.json')
closed=cloud.Backend().call('jobs.get',dict(tenant_id=cloud.TENANT,job_id=prior_checkpoint['plan']['jobs'][0]['job_id']))
require(closed['state']=='failed' and closed['result']['error_code']=='APT_RECOVERY_CONFIGURED_ACCEPTANCE_REBOOT_FLAG_VERIFIED' and
closed['result']['grant_id']=='33775478-15b0-46ec-b059-44f500dbb0b6',
'ordinary signed Sync must first close the exact historical configured effect as failed')
else:
old=m.protected_json(BASE/'recovery-policy-closed.json' if session!=BASE else cloud.ROOT/'devstate/cloud-logs/policy-closed.json')
record=cloud.bootstrap.rpc('server.conf',prior.replace_policy,dict(id=str(uuid.uuid4()),previous_sha256=old['policy_sha256'],policy=policy)) record=cloud.bootstrap.rpc('server.conf',prior.replace_policy,dict(id=str(uuid.uuid4()),previous_sha256=old['policy_sha256'],policy=policy))
m.write_private(session/'recovery-policy.json',dict(record,policy=policy)) m.write_private(session/'recovery-policy.json',dict(record,policy=policy))
print('Fixed APT runtime endpoint and expiring limits enabled; no job or approval created') print('Fixed APT runtime endpoint and expiring limits enabled; no job or approval created')
@@ -97,6 +112,8 @@ def accept(case,resume_unsubmitted=False):
m=cloud.contract;target=prior.prior.identity() m=cloud.contract;target=prior.prior.identity()
require(prior.prior.evidence('gate')['unresolved']==0,'no unresolved attempt') require(prior.prior.evidence('gate')['unresolved']==0,'no unresolved attempt')
ready,session=runtime_session();cases=session/'cases';cases.mkdir(mode=0o700,exist_ok=True) ready,session=runtime_session();cases=session/'cases';cases.mkdir(mode=0o700,exist_ok=True)
require(session!=BASE/'configured-reconcile-runtime' or case!='apt_configure_recovery',
'configured historical1.0 is never executed again; next action is separate native1.1 upgrade')
if session!=BASE and case=='apt_configure_recovery': if session!=BASE and case=='apt_configure_recovery':
original=m.protected_json(STATE/case/'checkpoint-capacity-terminal.json') original=m.protected_json(STATE/case/'checkpoint-capacity-terminal.json')
old_job=original['plan']['jobs'][0] old_job=original['plan']['jobs'][0]
@@ -123,8 +140,10 @@ def accept(case,resume_unsubmitted=False):
break break
except m.GuardError: except m.GuardError:
require(time.monotonic()<deadline,'fresh stored exact planning unavailable; no job submitted');time.sleep(3) require(time.monotonic()<deadline,'fresh stored exact planning unavailable; no job submitted');time.sleep(3)
request=recovery_request(device,target) if case=='apt_configure_recovery' else None request=recovery_request(device,target) if case=='apt_configure_recovery' else m.case_input(case,target,planning=data)
if request is not None and session!=BASE: if data['host_reboot_required']:
request['reason']+='; Host reboot already required; flag unchanged; no reboot in this job'
if request is not None and session==BASE/'capacity-recovery':
request['reason']+='; prior fixed plan expired with zero grants at the old journal capacity; preserve it and authorize this fresh plan separately' request['reason']+='; prior fixed plan expired with zero grants at the old journal capacity; preserve it and authorize this fresh plan separately'
prior.accept(case,request=request,folder_root=cases) prior.accept(case,request=request,folder_root=cases)
+45
View File
@@ -0,0 +1,45 @@
"""Preserved witnesses of the one already approved configure-only attempt."""
def maintenance_status(payload):
root=Path('/var/lib/rmm-bootstrap-history')
reports=[]
for folder in sorted(root.glob('cloud-configured-reconcile-*')):
require(not folder.is_symlink() and folder.stat().st_uid==0,'known private maintenance directory')
path=folder/'report.json'
if path.exists():
require(not path.is_symlink() and path.stat().st_size<=1024*1024,'bounded maintenance report')
reports.append(dict(path=str(path),report=json.loads(path.read_text())))
require(len(reports)<=3,'bounded configured maintenance reports')
states={}
for unit in ('rmm-agent-remote.service','rmm-helper-cloud.service','rmm-apt-helper.service'):
raw=subprocess.run(['systemctl','show',unit,'-p','ActiveState','-p','SubState','-p','MainPID'],capture_output=True,check=True,timeout=10).stdout.decode()
states[unit]=dict(line.split('=',1) for line in raw.splitlines())
hashes={name:hashlib.sha256(Path(path).read_bytes()).hexdigest() for name,path in (
('agent','/usr/local/libexec/rmm-agent-remote'),('helper','/usr/local/libexec/rmm-privileged-helper'),
('provider','/usr/lib/rmm-apt-transaction/apt_transaction.py'))}
return dict(reports=reports,services=states,installed_sha256=hashes)
def stored_configured(payload):
import stat
base=Path('/var/lib/rmm-apt-transaction');active=base/'active'
context=json.loads((active/'context.json').read_text())
require(all(context[k]==str(uuid.UUID(payload[k])) for k in ('job_id','attempt_id','grant_id')),'same already approved configure attempt')
require(context['grant_id']=='33775478-15b0-46ec-b059-44f500dbb0b6','one preserved configure attempt')
def witness(path):
require(not path.is_symlink(),'witness symlink')
if not path.exists():return dict(exists=False)
s=path.stat();require(stat.S_ISREG(s.st_mode) and s.st_uid==0 and s.st_size<=1024*1024,'bounded original root file')
return dict(exists=True,sha256=hashlib.sha256(path.read_bytes()).hexdigest(),size=s.st_size,
inode=s.st_ino,mtime_ns=s.st_mtime_ns,ctime_ns=s.st_ctime_ns)
names=('context.json','signed-action.json','expectation.json','baseline.json','partial-proof.json',
'hook-armed.json','sandbox-result.json','native-prechecks.json','sandbox-ready.json','launch.json')
files={name:witness(active/name) for name in names}
original='31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0'
for name in ('recovery-attempt-'+original+'.json','recovery-'+original+'.json','pending-recovery-'+original+'.json',
'bootstrap-attempt-rmm-apt-fixture-install-1.0.json','bootstrap-retry-rmm-apt-fixture-install-1.0.json'):
files[name]=witness(base/name)
return dict(files=files,marker_current=witness(Path('/run/reboot-required')),
same_boot=Path('/proc/sys/kernel/random/boot_id').read_text().strip()==context['boot_id'],
marker_observation_phase='after_original_effect_only',original_state_changed=False)
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
"""Read/audit ONLY the existing 337 configured attempt; never execute/unlock."""
import hashlib
import json
import os
from pathlib import Path
import uuid
import cloud_mvp_acceptance as cloud
GRANT='33775478-15b0-46ec-b059-44f500dbb0b6'
PRIOR='31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0'
PARTIAL='dc3bf3870ea77c12f9291bac712c53ae72194eaec980a8646155a7fb5c0dbe21'
CODE='APT_RECOVERY_CONFIGURED_ACCEPTANCE_REBOOT_FLAG_VERIFIED'
STATE=cloud.ROOT/'devstate/cloud-apt-recovery/capacity-recovery'
def stored(payload):
import sqlite3
grant='33775478-15b0-46ec-b059-44f500dbb0b6'
code='APT_RECOVERY_CONFIGURED_ACCEPTANCE_REBOOT_FLAG_VERIFIED'
path=Path('/var/lib/rmm-helper/consumption.sqlite')
with sqlite3.connect(path.as_uri()+'?mode=ro',uri=True) as db:
require(db.execute('PRAGMA integrity_check').fetchone()[0]=='ok','root ledger integrity')
row=db.execute('SELECT c.job,c.attempt,c.result,e.start,e.outcome FROM consumed c JOIN execution_evidence e USING(grant_id) WHERE c.grant_id=?',(grant,)).fetchone()
require(row is not None,'one exact retained configured attempt')
job,attempt,result,start,outcome=row
require(job==payload['job_id'] and attempt==payload['attempt_id'],'original job/attempt')
names=[r[1] for r in db.execute('PRAGMA table_info(apt_effect_reconciliations)')]
proofrow=db.execute('SELECT * FROM apt_effect_reconciliations WHERE grant_id=?',(grant,)).fetchone() if names else None
record=dict(zip(names,proofrow)) if proofrow else None
original=json.loads(record['previous_outcome']) if record else None
proof=json.loads(record['proof']) if record else None
request=json.loads(start)['request']
# Match the original Request struct codec, without reading any key.
request_raw=json.dumps({k:request[k] for k in ('job_bytes','permit_bytes','signature','plan_hash','authorization_id')},separators=(',',':')).encode()
binding=bool(record and hashlib.sha256(request_raw).hexdigest()==record['original_request_sha256']
and hashlib.sha256(record['previous_outcome']).hexdigest()==record['previous_outcome_sha256']
and hashlib.sha256(record['proof']).hexdigest()==record['proof_sha256']
and original['state']=='unknown' and original['error_code']=='FIXTURE_UNEXPECTED_REBOOT_REQUIRED'
and proof['grant_id']==grant and proof['job_id']==job and proof['attempt_id']==attempt
and proof['job_payload_sha256']==hashlib.sha256(bytes(request['job_bytes'])).hexdigest()
and proof['effect_complete'] is True and proof['postconditions_passed'] is False
and proof['reboot_required'] is True and proof['host_reboot_required'] is True)
classified=json.loads(outcome) if outcome else None;finished=json.loads(result) if result else None
closed=bool(binding and finished==classified==json.loads(record['classified_outcome'])
and finished['state']=='failed' and finished['error_code']==code
and finished['evidence']['effect_complete'] is True and finished['evidence']['postconditions_passed'] is False
and finished['reboot_required'] is True and finished['evidence']['apt']['host_reboot_required_before'] is None)
partials=[dict(grant_id=g,proof_sha256=s) for g,s in db.execute('SELECT grant_id,proof_sha256 FROM apt_partial_reconciliations')]
stats=dict(consumed=db.execute('SELECT count(*) FROM consumed').fetchone()[0],unresolved=db.execute('SELECT count(*) FROM consumed WHERE result IS NULL').fetchone()[0],faults=db.execute('SELECT count(*) FROM helper_sync_meta WHERE fault IS NOT NULL').fetchone()[0])
result=dict(ledger=stats,classified=classified,original_unknown=original,proof=proof,proof_sha256=record['proof_sha256'] if record else None,
immutable_binding_verified=binding,closed_by_normal_sync=closed,result_bytes_equal_outcome=result==outcome,partial_rows=partials,
effect_reconciliation_rows=db.execute('SELECT count(*) FROM apt_effect_reconciliations').fetchone()[0] if names else 0)
base=Path('/var/lib/rmm-apt-transaction')
result['forbidden_acceptance_records']={name:(base/name).exists() for name in
('acceptance-rmm-apt-fixture-install-1.0.json','pending-acceptance-rmm-apt-fixture-install-1.0.json',
'recovery-31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0.json','pending-recovery-31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0.json')}
return result
def main():
os.umask(0o077)
checkpoint=cloud.contract.protected_json(STATE/'cases/apt_configure_recovery/checkpoint.json')
job=checkpoint['plan']['jobs'][0]
report=cloud.bootstrap.rpc('linux-vm.conf',stored,dict(job_id=job['job_id'],attempt_id=job['payload']['attempt_id']))
identity=cloud.contract.protected_json(cloud.ROOT/'devstate/remote-vm.json')['identity']
counts=cloud.bootstrap.rpc('server.conf',cloud.server,dict(kind='gate',tenant_id=cloud.TENANT,agent_id=identity['agent_id']))
result=cloud.Backend().call('jobs.get',dict(tenant_id=cloud.TENANT,job_id=job['job_id']))
cloud.contract.write_private(STATE/('configured-closure-'+uuid.uuid4().hex+'.json'),dict(native=report,counts=counts,central=result))
cloud.contract.require(report['immutable_binding_verified'] and report['closed_by_normal_sync'] and report['result_bytes_equal_outcome']
and report['ledger']==dict(consumed=11,unresolved=0,faults=0) and report['partial_rows']==[dict(grant_id=PRIOR,proof_sha256=PARTIAL)]
and report['effect_reconciliation_rows']==1 and not any(report['forbidden_acceptance_records'].values())
and counts==dict(jobs=20,outbox=20,permits=18,unresolved=0) and result['state']=='failed' and result['result']['error_code']==CODE,
'same-attempt classified failure and normal signed closure not yet proven')
print('PASS exact337 failed acceptance/effect complete, truthful host rebootrequired, immutable oldunknown/partial proof, normal Sync closed Root11/0/fault0 central20/20/18/0; no success/retry')
if __name__=='__main__':
try:main()
except Exception as error:
print('CONFIGURED_CLOSURE_INCOMPLETE:'+(str(error) if isinstance(error,cloud.contract.GuardError) else type(error).__name__))
raise SystemExit(2) from None
@@ -0,0 +1,406 @@
#!/usr/bin/env python3
"""Preserve UNKNOWN337 while installing its narrowly bound readonly verifier.
Only bootstrap runtime/probe maintenance; no package effect, new grant, retry,
acceptance record, identity reset or direct consumed/result update. General and
agent restart only after immutable state and copied-dpkg probe qualification.
"""
import argparse
import base64
import hashlib
import importlib.util
import json
import os
from pathlib import Path
import re
import sys
import uuid
import cloud_apt_recovery_upgrade as previous
cloud = previous.cloud
require = cloud.require
STATE = previous.STATE
UNKNOWN = '33775478-15b0-46ec-b059-44f500dbb0b6'
OLD = dict(helper='332eae004d9416234eabf7ed3d5c9ece5440d1e0c764ea63357961c16b673b6b',
agent='2ce885cf5e6881e77383482b7d3a87a02c6847aa26b82e5fd70d2ebd8a45360d',
provider='5ff260f75cb2959678f6be729d3a806a4ea29febd5ae4003317fed41afc25327')
def upgrade_configured(payload):
import ast
import fcntl
import sqlite3
import time
import traceback
os.umask(0o077)
base = Path('/var/lib/rmm-apt-transaction'); state = Path('/var/lib/rmm-agent-remote')
ledger = Path('/var/lib/rmm-helper/consumption.sqlite')
helper = Path('/usr/local/libexec/rmm-privileged-helper'); agent = Path('/usr/local/libexec/rmm-agent-remote')
provider = Path('/usr/lib/rmm-apt-transaction/apt_transaction.py')
config = Path('/etc/rmm/apt-helper.json'); proof_file = Path('/etc/rmm-remote/apt-helper-proof.json')
metadata = base/'install-metadata.json'; readiness_file = base/'native-readiness.json'
dropin = Path('/etc/systemd/system/rmm-agent-remote.service.d/30-cloud-root.conf')
reduced = ('[Service]\nEnvironment=RMM_HELPER_SOCKET=/run/rmm-helper-cloud/control.sock\n'
'Environment=RMM_HELPER_POLICY_FILE=/etc/rmm-remote/general-helper-proof.json\n'
'Environment=RMM_LOG_UNITS_FILE=/etc/rmm-remote/log-units.json\n')
full = reduced.replace('Environment=RMM_LOG_UNITS_FILE=',
'Environment=RMM_APT_HELPER_SOCKET=/run/rmm-apt-helper/helper.sock\n'
'Environment=RMM_APT_HELPER_PROOF_FILE=/etc/rmm-remote/apt-helper-proof.json\n'
'Environment=RMM_LOG_UNITS_FILE=')
def run(args, **kwargs):
return subprocess.run(args, capture_output=True, check=True, timeout=90, **kwargs).stdout
def sha(raw): return hashlib.sha256(raw).hexdigest()
def canonical(value): return json.dumps(value, sort_keys=True, separators=(',', ':'), ensure_ascii=True).encode()
def fsync_dir(path):
fd = os.open(path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
try: os.fsync(fd)
finally: os.close(fd)
def create(path, raw, mode=0o600, gid=0):
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, mode)
with os.fdopen(fd, 'wb') as stream:
stream.write(raw); stream.flush(); os.fchown(stream.fileno(), 0, gid)
os.fchmod(stream.fileno(), mode); os.fsync(stream.fileno())
fsync_dir(path.parent)
def manifest(path):
require(not path.is_symlink(), 'preserved directory symlink')
if not path.exists(): return {'__absent__':True}
require(path.is_dir(), 'preserved directory required')
result = {}
for p in [path, *sorted(path.rglob('*'))]:
s = p.lstat(); require(not p.is_symlink() and (p.is_dir() or p.is_file()), 'preserved regular state required')
result[str(p.relative_to(path))] = dict(dev=s.st_dev, inode=s.st_ino, mode=s.st_mode,
uid=s.st_uid, gid=s.st_gid, sha256=sha(p.read_bytes()) if p.is_file() else None)
return result
def guard():
require(len(payload['expected_grants']) == 11 and payload['unknown_grant'] ==
'33775478-15b0-46ec-b059-44f500dbb0b6', 'exact reviewed eleven Root grants')
with sqlite3.connect(ledger.as_uri()+'?mode=ro', uri=True) as db:
db.row_factory = sqlite3.Row
require(db.execute('PRAGMA integrity_check').fetchone()[0] == 'ok' and
{r[0] for r in db.execute('SELECT grant_id FROM consumed')} == set(payload['expected_grants']) and
db.execute('SELECT count(*) FROM helper_sync_meta WHERE fault IS NOT NULL').fetchone()[0] == 0,
'exact preserved Root history without faults')
rows = db.execute('SELECT c.grant_id,c.result,e.outcome,e.start FROM consumed c JOIN execution_evidence e USING(grant_id) WHERE c.result IS NULL').fetchall()
require(len(rows) == 1 and rows[0]['grant_id'] == payload['unknown_grant'], 'only known configure unknown may remain')
outcome = json.loads(rows[0]['outcome'])
require(outcome == payload['unknown_outcome'] and outcome['state'] == 'unknown' and
outcome['error_code'] == 'FIXTURE_UNEXPECTED_REBOOT_REQUIRED', 'original unknown bytes must retain their meaning')
saved = json.loads(rows[0]['start']); request = saved['request']
job = json.loads(bytes(request['job_bytes']))
require(job['job_id'] == payload['context']['job_id'] and
job['attempt_id'] == payload['context']['attempt_id'] and
job['agent_id'] == payload['agent_id'], 'original saved request binding')
unknown_witness = dict(outcome_sha256=sha(rows[0]['outcome']),start_sha256=sha(rows[0]['start']))
rows = db.execute('SELECT * FROM apt_partial_reconciliations').fetchall()
require(len(rows) == 1, 'one immutable old partial proof required')
row = dict(rows[0]); expected = payload['proof_row']
for key in ('grant_id','original_request_sha256','previous_outcome_sha256','proof_sha256','checked_at_ms'):
require(row[key] == expected[key], 'old partial binding drift')
for key in ('previous_outcome','proof','classified_outcome'):
require(sha(row[key]) == expected[key]['sha256'] and len(row[key]) == expected[key]['size'], 'old partial bytes drift')
require(row['grant_id'] == payload['partial_grant'] and sha(row['proof']) == payload['partial_proof_sha256'], 'original partial proof unchanged')
old = db.execute('SELECT c.result,e.outcome FROM consumed c JOIN execution_evidence e USING(grant_id) WHERE c.grant_id=?',(payload['partial_grant'],)).fetchone()
require(old['result'] is not None and json.loads(old['result']) == json.loads(old['outcome']) == json.loads(row['classified_outcome']), 'old partial stays signed-Sync closed')
if db.execute("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='apt_effect_reconciliations'").fetchone()[0]:
require(db.execute('SELECT count(*) FROM apt_effect_reconciliations').fetchone()[0] == 0, 'configure classification must not already exist')
journal = state/'journal.sqlite'; sidecars = [Path(str(journal)+s) for s in ('-wal','-shm')]
existing_sidecars = {p for p in sidecars if p.exists()}
owner = journal.stat()
with sqlite3.connect(journal.as_uri()+'?mode=ro', uri=True) as db:
require(db.execute('PRAGMA integrity_check').fetchone()[0] == 'ok' and
db.execute('SELECT count(*) FROM reconcile_meta WHERE fault IS NOT NULL').fetchone()[0] == 0, 'agent journal integrity without fault')
rows = db.execute("SELECT job,attempt,state,grant_id FROM job_attempts WHERE state NOT IN ('succeeded','failed','cancelled','expired')").fetchall()
require(rows == [(payload['context']['job_id'],payload['context']['attempt_id'],'unknown',payload['unknown_grant'])], 'only bound known agent unknown may remain')
# Read-only SQLite can create WAL sidecars. Correct only our newly
# created fixed-name files, never existing state or recursive ownership.
for p in sidecars:
if p not in existing_sidecars and p.exists():
require(not p.is_symlink() and p.stat().st_uid == 0, 'new fixed SQLite sidecar owner')
os.chown(p,owner.st_uid,owner.st_gid)
if p.exists(): require(not p.is_symlink() and p.stat().st_uid == owner.st_uid, 'agent SQLite sidecar ownership preserved')
active = base/'active'
for name,expected in payload['file_witnesses'].items():
p = (base if name.startswith(('bootstrap-','recovery-','pending-recovery-')) else active)/name
require(not p.is_symlink(), 'historical witness symlink')
require(p.exists() == expected['exists'], 'historical file existence changed')
if expected['exists']:
s = p.stat()
require(s.st_ino == expected['inode'] and s.st_size == expected['size']
and s.st_mtime_ns == expected['mtime_ns'] and s.st_ctime_ns == expected['ctime_ns']
and sha(p.read_bytes()) == expected['sha256'], 'historical exact witness bytes/inode changed')
pending = Path('/run/reboot-required'); expected = payload['host_marker_witness']
require(not pending.is_symlink() and pending.exists() == expected['exists'], 'host pending reboot marker changed')
if expected['exists']:
s = pending.stat()
require(s.st_ino == expected['inode'] and s.st_size == expected['size']
and s.st_mtime_ns == expected['mtime_ns'] and s.st_ctime_ns == expected['ctime_ns']
and sha(pending.read_bytes()) == expected['sha256'], 'host pending reboot marker must remain unchanged')
ctx = json.loads((active/'context.json').read_bytes())
require(ctx == payload['context'] and ctx['grant_id'] == payload['unknown_grant'], 'original active configure context')
require(Path('/proc/sys/kernel/random/boot_id').read_text().strip() == ctx['boot_id'], 'original configure boot must remain current')
for name,key in (('signed-action.json','job_payload_sha256'),('expectation.json','transaction_sha256')):
require(sha((active/name).read_bytes()) == ctx[key], 'original active signed bytes')
for name,expected in payload['records'].items():
require(json.loads((active/name).read_bytes()) == expected, 'original configure native record unchanged')
require(payload['records']['sandbox-result.json'] == dict(transaction_sha256=ctx['transaction_sha256'],apt_exit_code=0,reboot_required=False), 'completed native sandbox APT0 required')
action = json.loads((active/'signed-action.json').read_bytes())['action']['apt_manifest']
tx = json.loads((active/'expectation.json').read_bytes())
ref = action['native_recovery']
require(action['schema_version'] == 4 and action['action'] == 'apt-native-acceptance' and
tx['schema_version'] == 2 and tx['operation'] == 'configure_only' and
tx['recipe_id'] == 'rmm-apt-fixture-install-1.0' and len(tx['packages']) == 1 and
tx['packages'][0]['old_version'] == tx['packages'][0]['new_version'] == '1.0' and
ref == dict(schema_version=1,previous_grant_id=payload['partial_grant'],previous_attempt_id=payload['partial_attempt'],partial_proof_sha256=payload['partial_proof_sha256']), 'exact historical schema4 configure-only reference')
require(sha((active/'baseline.json').read_bytes()) == tx['baseline_sha256'] and
sha((active/'partial-proof.json').read_bytes()) == payload['partial_proof_sha256'], 'original partial baseline and staged proof')
marker = base/('recovery-attempt-'+payload['partial_grant']+'.json')
require(json.loads(marker.read_bytes()) == dict(transaction_sha256=ctx['transaction_sha256'],job_payload_sha256=ctx['job_payload_sha256'],grant_id=ctx['grant_id'],attempt_id=ctx['attempt_id'],native_recovery=ref), 'original recovery once marker required')
require(Path('/usr/share/rmm-mvp-test/version').read_bytes() == b'1.0\n', 'existing fixture payload remains1.0')
fixture = []
for paragraph in Path('/var/lib/dpkg/status').read_text().split('\n\n'):
fields = dict(line.split(': ',1) for line in paragraph.splitlines() if ': ' in line and not line[0].isspace())
if fields.get('Package') == 'rmm-mvp-test': fixture.append(fields)
require(len(fixture) == 1 and all(fixture[0].get(k) == v for k,v in
dict(Architecture='all',Version='1.0',Status='install ok installed').items()), 'existing installed1.0 status required for copied probe')
require(not list(base.glob('acceptance-*.json')) and not list(base.glob('pending-acceptance-*.json')), 'no fabricated normal acceptance')
require({p.name for p in base.glob('recovery-*.json')} == {marker.name} and
not list(base.glob('pending-recovery-*.json')), 'only original recovery attempt, no recovery acceptance')
return unknown_witness
require(json.loads((state/'identity.json').read_text())['agent_id'] == payload['agent_id'], 'permanent Cloud identity required')
require(not dropin.is_symlink() and dropin.read_text() in (full,reduced), 'only reviewed endpoint env allowed')
old_endpoint = dropin.read_text() == full
active_state = run(['systemctl','show','rmm-apt-helper.service','-p','ActiveState','--value']).strip()
main_pid = int(run(['systemctl','show','rmm-apt-helper.service','-p','MainPID','--value']).strip())
require((active_state == b'inactive' and main_pid == 0) or (active_state == b'active' and main_pid > 0), 'known APT helper state required')
cgroup = Path('/sys/fs/cgroup/system.slice/rmm-apt-helper.service')
pids = {int(pid) for p in cgroup.rglob('cgroup.procs') for pid in p.read_text().split()} if cgroup.exists() else set()
require(pids == ({main_pid} if main_pid else set()), 'no native sandbox/package child may remain')
for name, pin in payload['old_files'].items():
p = Path(name); require(not p.is_symlink() and p.stat().st_uid == 0 and p.stat().st_mode & 0o022 == 0 and sha(p.read_bytes()) == pin, 'installed file drift')
require(Path('/etc/systemd/system/rmm-apt-helper.service').read_text() == payload['unit'], 'exact reviewed APT service required')
markers = {base/'bootstrap-attempt-rmm-apt-fixture-install-1.0.json':'ec84aa4df8065f0b54b282bd273a6f342f07a6d47312289608389d05c7fb6053',
base/'bootstrap-retry-rmm-apt-fixture-install-1.0.json':'a118072812553dca1a8ffee84550be0b2d514d555ad7cbcfc4722675a211a0e3'}
require({p.name for p in base.glob('bootstrap-*.json')} == {p.name for p in markers} and
all(sha(p.read_bytes()) == pin for p,pin in markers.items()), 'original/retry tombstones required')
original_unknown = guard()
raw = {name:base64.b64decode(payload[name], validate=True) for name in ('helper','agent','provider')}
pins = {name:payload[name+'_sha256'] for name in ('helper','agent','provider')}
require(all(sha(raw[name]) == pin == payload[name+'_sha256'] for name,pin in pins.items()), 'qualified exact recovery runtime required')
for name in ('helper','agent'):
require(raw[name][:6] == b'\x7fELF\x02\x01' and raw[name][18:20] == b'\x3e\x00', 'Linux x64 binary required')
ast.parse(raw['provider'])
if payload.get('preflight_only') is True:
return dict(stage='preflight_validated', completed=False, preflight_only=True,
package_effects=False, maintenance_mutations=False, expected_grants=len(payload['expected_grants']),
partial_proof_sha256=payload['partial_proof_sha256'], apt_endpoint_enabled=old_endpoint,
unknown_grant=payload['unknown_grant'],original_unknown=original_unknown)
backup = Path('/var/lib/rmm-bootstrap-history')/('cloud-configured-reconcile-'+payload['id']); backup.mkdir(mode=0o700)
report = dict(stage='validated', completed=False, backup=str(backup), package_effects=False,
apt_endpoint_enabled=old_endpoint, partial_proof_sha256=payload['partial_proof_sha256'], backups={})
def save():
next_path = backup/'.report-next.json'; create(next_path,json.dumps(report,indent=2).encode())
os.replace(next_path,backup/'report.json'); fsync_dir(backup)
def replace(path, staged=None):
target = backup/str(path).lstrip('/').replace('/','__')
require(not path.is_symlink() and path.stat().st_dev == backup.stat().st_dev and not target.exists(), 'exclusive same-filesystem versioned replacement')
os.rename(path,target); fsync_dir(path.parent); fsync_dir(backup)
report['backups'][str(path)] = str(target); save()
if staged is not None:
os.rename(staged,path); fsync_dir(path.parent); fsync_dir(backup)
lock = None
try:
save()
for name in ('helper','agent','provider'): create(backup/(name+'-next'), raw[name], 0o755)
for name in ('helper','agent'): run(['/lib64/ld-linux-x86-64.so.2','--list',str(backup/(name+'-next'))])
run(['systemctl','stop','rmm-agent-remote.service','rmm-helper-cloud.service','rmm-apt-helper.service'])
lock = os.open(ledger.parent/'executor.lock', os.O_RDWR | os.O_NOFOLLOW)
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
require(guard() == original_unknown, 'unknown outcome/start bytes unchanged')
if old_endpoint:
create(backup/'dropin-next',reduced.encode(),0o644); replace(dropin,backup/'dropin-next')
run(['systemctl','daemon-reload'])
report['apt_endpoint_enabled'] = False; save()
preserved = {str(p):manifest(p) for p in (state,Path('/var/lib/rmm-agent'),ledger.parent)}
preserved_base = manifest(base)
witnesses = {}
for p in (Path('/var/lib/dpkg/status'),Path('/usr/share/rmm-mvp-test/version'),dropin,
Path('/etc/systemd/system/rmm-apt-helper.service'),Path('/usr/lib/rmm-apt-transaction/hook'),
Path('/etc/rmm-remote/general-helper-proof.json'),Path('/etc/rmm-remote/helper-general.json')):
s = p.stat(); witnesses[str(p)] = (s.st_dev,s.st_ino,sha(p.read_bytes()))
general_bytes = Path('/etc/rmm-remote/general-helper-proof.json').read_bytes()
general_config = Path('/etc/rmm-remote/helper-general.json').read_bytes()
old_metadata = json.loads(metadata.read_text()); old_config = json.loads(config.read_text())
require(old_metadata['schema_version'] == 2 and old_metadata['provider_sha256'] == sha(provider.read_bytes()) and
old_metadata['hook_sha256'] == sha(Path('/usr/lib/rmm-apt-transaction/hook').read_bytes()) and
old_metadata['unit_sha256'] == sha(payload['unit'].encode()), 'old install metadata required')
for path,name in ((helper,'helper'),(agent,'agent'),(provider,'provider')): replace(path,backup/(name+'-next'))
create(backup/'metadata-next',json.dumps(dict(old_metadata,provider_sha256=sha(raw['provider']))).encode()); replace(metadata,backup/'metadata-next')
command = ['/usr/bin/python3','-I',str(provider)]
config_bytes = run(command+['print-config']); config_sha = sha(config_bytes)
require(config_sha == payload['reviewed_config_sha256'] and all(line in config_bytes for line in (
b'DPkg::ConfigurePending "false";', b'DPkg::TriggersPending "false";', b'dpkg::selection::remove::approved "false";')), 'reviewed exact configure/no-pending settings')
runtime = json.loads(run(command+['inspect-runtime'])); runtime_sha = sha(canonical(runtime))
old_config['apt_provider'].update(runtime_sha256=runtime_sha,apt_config_sha256=config_sha)
create(backup/'config-next',json.dumps(old_config).encode()); replace(config,backup/'config-next')
pin = json.loads(run([str(helper),'--inspect-apt-profile'],env=dict(os.environ,RMM_HELPER_CONFIG=str(config))))
require(pin['identity'] == json.loads(general_bytes)['identity'], 'same helper identity required')
create(backup/'proof-next',json.dumps(pin).encode(),0o640,984); replace(proof_file,backup/'proof-next')
general = json.loads(run([str(helper),'--inspect-general-profile'],env=dict(os.environ,RMM_HELPER_CONFIG='/etc/rmm-remote/helper-general.json')))
require(general == json.loads(general_bytes) and Path('/etc/rmm-remote/helper-general.json').read_bytes() == general_config, 'General helper policy unchanged')
for name,values in preserved.items(): require(manifest(Path(name)) == values, 'identity/journal/Root ledger bytes or inode changed')
def preserved_original_base():
current = manifest(base)
require(all(current.get(name) == value for name,value in preserved_base.items() if name not in ('install-metadata.json','native-readiness.json')), 'original APT state/archive/hook/probe changed')
for name,value in witnesses.items():
p=Path(name);s=p.stat();require((s.st_dev,s.st_ino,sha(p.read_bytes())) == value, 'original package/control file bytes or inode changed')
return current
preserved_original_base(); require(guard() == original_unknown, 'unknown outcome/start bytes unchanged')
report.update(stage='installed_preserved',preserved_state=True,helper_sha256=pins['helper'],agent_sha256=pins['agent'],
unknown_grant=payload['unknown_grant'],original_unknown=original_unknown,provider_sha256=pins['provider'],runtime_sha256=runtime_sha,apt_config_sha256=config_sha,apt_pin=pin,general_pin=general)
save()
# No client can reach this endpoint; it exists only for the service's
# ExecStartPre copied-database probe, then is stopped before restart.
run(['systemd-analyze','verify','/etc/systemd/system/rmm-apt-helper.service'])
replace(readiness_file)
# Daemon startup itself takes executor.lock to open the existing DB.
# Installation is complete; agent/General remain stopped during probe.
fcntl.flock(lock,fcntl.LOCK_UN);os.close(lock);lock=None
run(['systemctl','start','rmm-apt-helper.service'])
for _ in range(3):
status = run(['systemctl','show','rmm-apt-helper.service','-p','ActiveState','-p','SubState','-p','NRestarts']).decode()
require('ActiveState=active\n' in status and 'SubState=running\n' in status and 'NRestarts=0\n' in status, 'stable native probe helper required')
time.sleep(1)
run(['systemctl','stop','rmm-apt-helper.service'])
lock = os.open(ledger.parent/'executor.lock', os.O_RDWR | os.O_NOFOLLOW)
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
ready = json.loads(readiness_file.read_text())
require(ready['runtime'] == runtime and ready['readiness_only'] is True and ready['native_acceptance'] is False and
ready['host_status_sha256'] == sha(Path('/var/lib/dpkg/status').read_bytes()), 'exact new copied-database probe required')
workspace = base/'probes'/str(uuid.UUID(ready['probe_id']))
require((workspace/'dpkg/status').read_bytes() == Path('/var/lib/dpkg/status').read_bytes() and
(workspace/'apt.conf').read_bytes().count(b'dpkg::selection::remove::approved "false";') == 1,
'installed copied status and configure fix required')
current = preserved_original_base()
require(all(name in preserved_base or name.startswith('probes/'+ready['probe_id']+'/') or name == 'probes/'+ready['probe_id']
for name in current), 'only generated readiness probe metadata may be added')
for name,values in preserved.items(): require(manifest(Path(name)) == values, 'journal/ledger bytes or inode changed during probe')
require(guard() == original_unknown, 'unknown outcome/start bytes unchanged')
require(dropin.read_text() == reduced and Path('/etc/rmm-remote/general-helper-proof.json').read_bytes() == general_bytes, 'endpoint/General proof unchanged')
report.update(stage='native_probe_preserved',readiness_only=True,native_acceptance=False,
journals_preserved_before_restart=True,readiness_sha256=sha(readiness_file.read_bytes()),probe_id=ready['probe_id'])
save()
fcntl.flock(lock,fcntl.LOCK_UN);os.close(lock);lock=None
run(['systemctl','start','rmm-helper-cloud.service','rmm-agent-remote.service'])
require(run(['systemctl','show','rmm-apt-helper.service','-p','ActiveState','--value']).strip() == b'inactive', 'APT endpoint must remain stopped')
report.update(stage='qualified_runtime_started',completed=True);save()
except Exception as error:
report.update(error_class=type(error).__name__,frames=[dict(function=f.name,line=f.lineno) for f in traceback.extract_tb(error.__traceback__)])
save()
finally:
if lock is not None: fcntl.flock(lock,fcntl.LOCK_UN);os.close(lock)
subprocess.run(['systemctl','stop','rmm-apt-helper.service'],capture_output=True,timeout=30)
return report
def build_payload(args):
m = cloud.contract
installed = m.protected_json(cloud.ROOT/'devstate/remote-vm.json')
old = m.protected_json(STATE/'journal-capacity-runtime.json')
require(old['completed'] and all(old[n+'_sha256'] == pin for n,pin in OLD.items())
and installed['binary_sha256'] == OLD['agent'], 'known qualified capacity runtime required')
stored = m.protected_json(STATE/'configure-attempt-stored.json')
witnesses = m.protected_json(STATE/'configure-attempt-witnesses.json')
require(witnesses['same_boot'] is True and witnesses['original_state_changed'] is False,
'unchanged same-boot historical witnesses required')
context = stored['context']; outcome = stored['ledger']['outcome']
require(context['grant_id'] == UNKNOWN and stored['ledger']['consumed'] == 11
and stored['ledger']['unresolved'] == 1 and stored['ledger']['result'] is None
and outcome['state'] == 'unknown' and outcome['error_code'] == 'FIXTURE_UNEXPECTED_REBOOT_REQUIRED',
'exact original persisted configure unknown')
checkpoint = m.protected_json(STATE/'capacity-recovery/cases/apt_configure_recovery/checkpoint.json')
job = checkpoint['plan']['jobs'][0]
require(checkpoint['result']['state'] == 'unknown' and checkpoint['result']['result']['grant_id'] == UNKNOWN
and job['job_id'] == context['job_id']
and job['attempt_id'] == context['attempt_id'], 'bound actual UI configure attempt')
readonly = m.protected_json(STATE/'readonly-result-first.json')
require(readonly['unresolved'] == readonly['faults'] == 0 and len(readonly['proof']) == 1
and readonly['proof'][0]['grant_id'] == previous.PARTIAL_GRANT
and readonly['proof'][0]['proof_sha256'] == previous.PARTIAL_PROOF, 'original closed partial proof')
folders = [cloud.ROOT/'devstate/cloud-root/cases'/n for n in ('service_setup','service_start','service_stop','apt_native_install','query_logs')]
folders += [previous.previous.apt.prior.STATE/n for n in ('diagnosis','diagnosis-acquisition','diagnosis-hook','diagnosis-local-hook')]
grants = [str(uuid.UUID(m.protected_json(p/'checkpoint.json')['result']['result']['grant_id'])) for p in folders]
grants += [previous.PARTIAL_GRANT, UNKNOWN]
require(len(grants) == len(set(grants)) == 11, 'exact original ten grants plus configure337')
raw = {}; pins = {}; qualifications = {}
for name in ('helper','agent','provider'):
pin = getattr(args,name+'_sha256')
require(isinstance(pin,str) and re.fullmatch('[0-9a-f]{64}',pin) and pin != OLD[name], 'independently supplied new qualified artifact pin')
path = STATE/(name+'-configured-reconcile'+('.py' if name == 'provider' else ''))
raw[name] = path.read_bytes(); pins[name] = pin
require(hashlib.sha256(raw[name]).hexdigest() == pin, 'qualified artifact bytes drift')
if name != 'provider':
qualification = m.protected_json(path.with_name(path.name+'.json'))
require(qualification['binary_sha256'] == pin and qualification['release_build'] is True
and qualification['architecture'] == 'x86_64-unknown-linux-gnu'
and qualification['provider_sha256'] == args.provider_sha256
and qualification['source_files'], 'bounded release qualification required')
for filename,sha in qualification['source_files'].items():
source = (cloud.ROOT/filename).resolve()
require(source.is_relative_to(cloud.ROOT.resolve()) and
hashlib.sha256(source.read_bytes()).hexdigest() == sha, 'qualified source snapshot drift')
qualifications[name] = qualification
require(raw['provider'] == (cloud.ROOT/'tools/apt-transaction/apt_transaction.py').read_bytes(), 'qualified provider/source bytes mismatch')
spec = importlib.util.spec_from_file_location('reviewed_configured_reconcile_provider',cloud.ROOT/'tools/apt-transaction/apt_transaction.py')
module = importlib.util.module_from_spec(spec); sys.modules[spec.name] = module; spec.loader.exec_module(module)
return dict(id=str(uuid.uuid4()),agent_id=installed['identity']['agent_id'],expected_grants=grants,
unknown_grant=UNKNOWN,unknown_outcome=outcome,context=context,records=stored['records'],
file_witnesses=witnesses['files'],host_marker_witness=witnesses['marker_current'],
partial_grant=previous.PARTIAL_GRANT,partial_proof_sha256=previous.PARTIAL_PROOF,
partial_attempt=checkpoint['request']['parameters']['apt_manifest']['native_recovery']['previous_attempt_id'],
proof_row=readonly['proof'][0],unit=(cloud.ROOT/'deploy/linux/rmm-apt-helper.service').read_text(),
reviewed_config_sha256=hashlib.sha256(module.apt_config()).hexdigest(),
qualifications=qualifications,
**{name:base64.b64encode(data).decode() for name,data in raw.items()},
**{name+'_sha256':pin for name,pin in pins.items()}), installed
def main():
parser = argparse.ArgumentParser(description=__doc__)
mode = parser.add_mutually_exclusive_group(required=True)
mode.add_argument('--preflight-only',action='store_true')
mode.add_argument('--install-reviewed-artifacts',action='store_true')
for name in ('helper','agent','provider'): parser.add_argument('--'+name+'-sha256',required=True)
args = parser.parse_args(); os.umask(0o077)
require(not (STATE/'configured-reconcile-runtime.json').exists(), 'existing runtime pointer retained; never repeat maintenance automatically')
payload,installed = build_payload(args)
policy = cloud.bootstrap.rpc('server.conf',previous.closed_policy,{})
expected_policy = cloud.contract.protected_json(STATE/'capacity-recovery/recovery-policy-closed-unknown.json')
require(expected_policy['closed'] is True and expected_policy['policy_sha256'] ==
'06e4484cd95b88c77bf1674c84d867f852ee71b3083d3697f6609867b54893f7'
and policy['policy_sha256'] == expected_policy['policy_sha256'], 'exact reviewed deny-only policy must remain closed')
gate = cloud.bootstrap.rpc('server.conf',cloud.server,dict(kind='gate',tenant_id=cloud.TENANT,
agent_id=payload['agent_id'],job_id=payload['context']['job_id']))
require(gate == dict(jobs=1,outbox=1,permits=1,unresolved=1), 'only exact approved configure unknown may remain')
old = cloud.bootstrap.rpc('linux-vm.conf',previous.installed_metadata,OLD)
payload.update(old_files=old['files'],preflight_only=args.preflight_only)
report = cloud.bootstrap.rpc('linux-vm.conf',upgrade_configured,payload)
cloud.contract.write_private(STATE/('configured-reconcile-'+('preflight-' if args.preflight_only else 'install-')+payload['id']+'.json'),dict(report,closed_policy=policy,central_gate=gate,qualification=payload['qualifications']))
if args.preflight_only:
require(report.get('preflight_only') is True and report.get('maintenance_mutations') is False, 'read-only preflight response required')
print('PASS reviewed configured-reconciliation preflight; original unknown retained'); return
require(report['completed'] and report['preserved_state'] and report['journals_preserved_before_restart']
and report['unknown_grant'] == UNKNOWN and report['provider_sha256'] == args.provider_sha256,
'preserving installation incomplete; retain report, never repeat automatically')
previous.previous.record_agent_upgrade(report,installed)
cloud.contract.write_private(STATE/'configured-reconcile-runtime.json',report)
print('PASS preserving configured-reconciliation runtime; APT endpoint stopped, normal signed RootSync still required')
if __name__ == '__main__':
try:
main()
except Exception as error:
print('CLOUD_CONFIGURED_RECONCILE_INCOMPLETE:'+type(error).__name__)
if str(error).startswith('remote bootstrap incomplete: '): print(str(error))
raise SystemExit(2) from None
+30 -5
View File
@@ -93,8 +93,19 @@ def main():
operations = []; submit_contexts = {} operations = []; submit_contexts = {}
for path in args.checkpoint: for path in args.checkpoint:
checkpoint, source = witness(path) checkpoint, source = witness(path)
if checkpoint.get('case') == 'reboot_last' and checkpoint.get('verified') is not True:
final, final_source = witness(Path(path).with_name('result.json'))
job = checkpoint['plan']['jobs'][0]
require(final.get('verified') is True and final['result']['state'] == 'succeeded'
and final['result']['job_id'] == job['job_id'] and final['result']['attempt_id'] == job['attempt_id']
and final['result']['result']['evidence']['postconditions_passed'] is True
and final['result']['result']['evidence']['reconciled_after_reboot'] is True
and final['central']['grant_id'] == final['result']['result']['grant_id'],
'separate verified reboot result is not bound to original checkpoint')
source['completion'] = final_source
checkpoint = dict(checkpoint, verified=True, audit=final['audit'], postapproval=final['postapproval'])
require(checkpoint.get('verified') is True, 'native checkpoint not verified') require(checkpoint.get('verified') is True, 'native checkpoint not verified')
plan = checkpoint['plan']; job = checkpoint['job'] plan = checkpoint['plan']; job = checkpoint.get('job', plan['jobs'][0])
require(hashlib.sha256(bytes(plan['plan_payload_bytes'])).hexdigest() == plan['plan_hash'], 'immutable plan bytes mismatch') require(hashlib.sha256(bytes(plan['plan_payload_bytes'])).hexdigest() == plan['plan_hash'], 'immutable plan bytes mismatch')
require(plan['resolved_targets'] == [identity] and len(plan['jobs']) == 1 require(plan['resolved_targets'] == [identity] and len(plan['jobs']) == 1
and plan['jobs'][0] == job and job['agent_id'] == identity['agent_id'] and plan['jobs'][0] == job and job['agent_id'] == identity['agent_id']
@@ -130,20 +141,34 @@ def main():
and cloud.contract.timestamp(receipt['observed_at']) < context['valid_until'], and cloud.contract.timestamp(receipt['observed_at']) < context['valid_until'],
'live existing-submit receipt not bound to selected operation') 'live existing-submit receipt not bound to selected operation')
receipt = dict(source=source, observation=receipt) receipt = dict(source=source, observation=receipt)
required_cases = {'hello','refresh_inventory','service_setup','service_start','service_stop','offline_wait'}
successful_cases = {o['case'] for o in operations if o['operation']['execution_state'] == 'succeeded'
and o['operation']['counts'] == dict(succeeded=1)}
reference_complete = (required_cases <= successful_cases and receipt is not None
and all(o['operation']['execution_state'] in ('succeeded','failed','cancelled') for o in operations))
health = backend.call('monitoring.get_health', dict(tenant_id=cloud.TENANT))
# Keep the health projection's honest timestamps/coverage without repeating
# every device's full inventory in this bounded private reference report.
health['items'] = [{k: d.get(k) for k in ('agent_id','asset_id','presence','health','quality',
'completeness','last_contact_at','observed_at','received_at','source_id')}
for d in health['items']]
report = dict(schema_version=1, observed_at=cloud.contract.now().isoformat(), report = dict(schema_version=1, observed_at=cloud.contract.now().isoformat(),
target=dict(tenant_id=cloud.TENANT,**identity), verified=reference_complete,
scope='one explicitly selected real Linux Cloud VM; no multi-device concurrency proof', scope='one explicitly selected real Linux Cloud VM; no multi-device concurrency proof',
tenants=tenants, list_pages=pages, selected_targets=[identity], selected_device=device, tenants=tenants, list_pages=pages, selected_targets=[identity], selected_device=device,
other_devices=[{k: d.get(k) for k in ('agent_id', 'asset_id', 'presence', 'source_id', 'observed_at', 'received_at')} other_devices=[{k: d.get(k) for k in ('agent_id', 'asset_id', 'presence', 'source_id', 'observed_at', 'received_at')}
for d in devices if d['agent_id'] != identity['agent_id']], for d in devices if d['agent_id'] != identity['agent_id']],
health=backend.call('monitoring.get_health', dict(tenant_id=cloud.TENANT)), health=health,
operations=operations, live_submit_idempotency=receipt, operations=operations, live_submit_idempotency=receipt,
idempotency_status='observed' if receipt else 'not_attached', idempotency_status='observed' if receipt else 'not_attached',
no_new_plans_jobs_or_approvals=True) no_new_plans_jobs_or_approvals=True)
output.parent.mkdir(mode=0o700, parents=True, exist_ok=True) output.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
encoded = (json.dumps(report, indent=2)+'\n').encode()
require(len(encoded) <= 1024*1024, 'bounded protected reference report size')
fd = os.open(output, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, 0o600) fd = os.open(output, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, 0o600)
with os.fdopen(fd, 'w') as stream: with os.fdopen(fd, 'wb') as stream:
json.dump(report, stream, indent=2); stream.write('\n'); stream.flush(); os.fsync(stream.fileno()) stream.write(encoded); stream.flush(); os.fsync(stream.fileno())
print('PASS stored MCP reference: one fixed Linux target, '+str(len(operations))+' existing operations; idempotency '+report['idempotency_status']) print('Stored MCP reference saved: one fixed Linux target, '+str(len(operations))+' existing operations; verified='+str(reference_complete)+'; idempotency '+report['idempotency_status'])
if __name__ == '__main__': if __name__ == '__main__':
+1
View File
@@ -262,6 +262,7 @@ def close(ident):
def main(): def main():
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('action',choices=('enable','accept','finish','close'));parser.add_argument('--id');parser.add_argument('--prerequisites');args=parser.parse_args();os.umask(0o077) parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('action',choices=('enable','accept','finish','close'));parser.add_argument('--id');parser.add_argument('--prerequisites');args=parser.parse_args();os.umask(0o077)
require(not (Path.home()/'.local/share/rust-discovery/remote-agent').exists(),'notebook development only')
if args.action=='enable':require(args.prerequisites,'explicit completed native prerequisite manifest required');enable(args.prerequisites) if args.action=='enable':require(args.prerequisites,'explicit completed native prerequisite manifest required');enable(args.prerequisites)
else:require(args.id,'one existing bound reboot session required');{'accept':accept,'finish':finish,'close':close}[args.action](args.id) else:require(args.id,'one existing bound reboot session required');{'accept':accept,'finish':finish,'close':close}[args.action](args.id)
+2 -1
View File
@@ -16,7 +16,7 @@ RECIPES = {'apt_native_install':'rmm-apt-fixture-install-1.0','ensure_package':'
PINS = {'1.0':'74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867', PINS = {'1.0':'74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867',
'1.1':'ef67c9fe0ba1443fcfe465768e1204763063c369a2a1da04af6027d8a9c00491'} '1.1':'ef67c9fe0ba1443fcfe465768e1204763063c369a2a1da04af6027d8a9c00491'}
PLANNING_FIELDS = ('fixture_package','baseline_sha256','sealed_baseline_sha256','status_fingerprint', PLANNING_FIELDS = ('fixture_package','baseline_sha256','sealed_baseline_sha256','status_fingerprint',
'dpkg_updates_empty','pending_triggers_empty','runtime','runtime_sha256', 'dpkg_updates_empty','pending_triggers_empty','host_reboot_required','runtime','runtime_sha256',
'provider_sha256','hook_sha256','apt_config_sha256','prefetch') 'provider_sha256','hook_sha256','apt_config_sha256','prefetch')
@@ -47,6 +47,7 @@ def planning_from_device(device,recovery=False):
missing=[key for key in PLANNING_FIELDS if key not in data] missing=[key for key in PLANNING_FIELDS if key not in data]
m.require(not missing,'not_configured:apt_planning_fields_missing:'+','.join(missing)) m.require(not missing,'not_configured:apt_planning_fields_missing:'+','.join(missing))
m.require(data['dpkg_updates_empty'] is True and data['pending_triggers_empty'] is True,'not_configured:dpkg_dirty') m.require(data['dpkg_updates_empty'] is True and data['pending_triggers_empty'] is True,'not_configured:dpkg_dirty')
m.require(type(data['host_reboot_required']) is bool,'not_configured:actual_host_reboot_flag_required')
m.require(data['baseline_sha256']==data['sealed_baseline_sha256'] and __import__('re').fullmatch('[a-f0-9]{64}',data['baseline_sha256']), m.require(data['baseline_sha256']==data['sealed_baseline_sha256'] and __import__('re').fullmatch('[a-f0-9]{64}',data['baseline_sha256']),
'not_configured:actual_sealed_baseline_binding') 'not_configured:actual_sealed_baseline_binding')
if 'baseline' in data: if 'baseline' in data:
+11
View File
@@ -1,5 +1,16 @@
# Übergabe / Entwicklungspause — 2026-11-12 # Übergabe / Entwicklungspause — 2026-11-12
**Neuester tatsächlicher Stand2026-11-13:** Configure337 jetzt durch gebundenen
Readonly-Nachweis und normalen signierten RootSync geschlossen: failed
`APT_RECOVERY_CONFIGURED_ACCEPTANCE_REBOOT_FLAG_VERIFIED`, vollständige Wirkung,
keine nachträgliche erfolgreiche Acceptance. Hostflagtrue/historischvorhernull.
Root11/0offen/0Faults, zentral20/20/18/0. Native erhaltende Runtimef40c/bbd2/1dc
und copied-Sandboxprobe bestanden; APTinactive/Endpunktentfernt/Policygeschlossen.
SSH40s-Timeout verlor nur Antwort, unabhängiger erhaltener Endbericht und
Dateihashes bestätigten abgeschlossene Installation; keine Wiederholung.
Nächster Schritt eigener UI-Upgradeplan1.0→1.1, danach Noops und übrige Gates.
Details oben in implementation-status.md; ältere Unknownzustände unten historisch.
**Aktuelle Fortsetzung2026-11-13:** Automatischer WSS→HTTPS-Fallback auf der **Aktuelle Fortsetzung2026-11-13:** Automatischer WSS→HTTPS-Fallback auf der
permanenten Cloud-VM bestanden; Hook wieder deaktiviert, WSS operativ permanenten Cloud-VM bestanden; Hook wieder deaktiviert, WSS operativ
wiederhergestellt, keine neuen Jobs. Danach eigener Configureplan tatsächlich wiederhergestellt, keine neuen Jobs. Danach eigener Configureplan tatsächlich
+40
View File
@@ -1,5 +1,45 @@
# Tatsächlicher Implementierungsstand # Tatsächlicher Implementierungsstand
## Configurewirkung nativ gebunden abgeglichen, Abnahme ehrlich failed — 2026-11-13
Identitäts-/journalbewahrende Installation von Agent`f40c7e26…`, Helper`bbd2cf80…`
und Provider`1dc0237d…` auf der tatsächlichen Cloud-VM bestanden. Vorheriger
Readonly-Preflight prüfte exakt den offenen337-Versuch und ursprünglichen31-
Partial-Proof. Erhaltene DBbytes/Inodes, alle elf Grants, Active-/History-/Archive,
Marker und Generalpolicy vor dem Neustart nachgewiesen; neue kopierte native
dpkg-Sandboxprobe86e320fd-c06e-40d3-92c7-da4e7870cd74 bestanden. Keine Paketwirkung
durch Wartung oder Probe. APT-Endpunkt entfernt/inactive, Agent/General aktiv.
SSH-Clienttimeout40Sekunden verlor die Installationsantwort. Kein zweiter Lauf:
gespeicherter Endbericht166630b0-bc96-4090-977a-574d35c8669d war bereits
`qualified_runtime_started/completed=true`. Unabhängige erneute Ablesung der
drei tatsächlichen Datei-SHAs und Dienstzustände bestätigte den Abschluss;
erst danach lokale Deploymentmetadaten einmalig finalisiert.
Der neue Helper prüfte ausschließlich den ursprünglich signierten337-Auftrag,
gebundene alte Hook-/APT0-/Schema1-/Recoverymarker und die vollständige aktuelle
Paketbaseline zweimal unabhängig. Vollständig installed1.0, richtige Nutzdatei,
keine fremden Paketänderungen und gleicher Boot nachgewiesen. Originalunknown
und24-Feld-Proof append-only in eigener`apt_effect_reconciliations` erhalten.
Klassifizierung **failed/APT_RECOVERY_CONFIGURED_ACCEPTANCE_REBOOT_FLAG_VERIFIED**,
`effect_complete=true`, `postconditions_passed=false`, `reboot_required=true`,
historischer Host-Vorherwert ausdrücklich null. Keine rückwirkende Acceptance.
Anschließender **gewöhnlicher signierter RootSync** schloss genau denselben
Verbrauch. Rein lesender Abschlussbericht bestand: Root11/0offen/0Faults,
Zentrale20Jobs/20Outbox/18Grants/0offen, result-/outcomebytes gleich, ursprünglicher
31/dc3-Proof erhalten, keine install-/recovery-Acceptancedateien erzeugt.
Private Belege`devstate/cloud-apt-recovery/configured-maintenance-*.json`,
`configured-reconcile-runtime.json` und`capacity-recovery/configured-closure-*.json`.
Gezielt lokal qualifiziert:81Python-Tests ohne Skips einschließlich echtem
isoliertem APT-Protokoll,41Helperlibtests,3Inventarprüfungen,1Startupguard,
28VM-Adapterguards, Agent-/Helper-Alltargets-Clippy und Bookwormrelease.
Neue Fixturewirkungen erfassen Hostflag vor/nach der Wirkung außerhalb des
privaten`/run`; keine Flagänderung/kein eigenmächtiger Reboot erlaubt.
**MVP weiter offen:** native1.0→1.1-Acceptance, beide1.1-Noops, aktive Offlinefälle,
Prozessabbruch, abschließender MCP-Bericht und letzter eigener Rebootplan.
## Automatischer Cloud-Fallback bestanden; neuer APT-Abgleich offen — 2026-11-13 ## Automatischer Cloud-Fallback bestanden; neuer APT-Abgleich offen — 2026-11-13
Passiver Automatikfall `697b19ba-e7ff-4ebf-8a45-f5a0b0514fea` auf der bestehenden Passiver Automatikfall `697b19ba-e7ff-4ebf-8a45-f5a0b0514fea` auf der bestehenden
+9
View File
@@ -32,6 +32,15 @@ Abnahme. Historische Teilnachweise gelten nur für ihren dokumentierten Stand.
## Priorisierte offene Arbeit ## Priorisierte offene Arbeit
**Neuester abgeschlossener Schritt:**337-Configureversuch rein lesend unter
Originalsignatur vollständig nachgewiesen und durch normalen signierten Sync
geschlossen. Ehrlich **failed** Abnahme trotz`effect_complete=true`; historischer
Host-Vorherwert null, aktueller Neustartbedarf true, keine rückwirkende Acceptance.
Root11/0offen/0Faults, zentral20/20/18/0. Neue Runtimef40c/bbd2/1dc samt kopierter
nativer Probe unter Erhalt aller Historien installiert; APTinactive/Endpunkt
entfernt/Rootpolicygeschlossen. Nächster eigener UI-Plan: Upgrade1.0→1.1,
danach beide echten Noops. Weitere Gates unten bleiben offen.
**Aktueller Folgestand:** Automatischer passiver WSS→HTTPS-Fallback auf derselben **Aktueller Folgestand:** Automatischer passiver WSS→HTTPS-Fallback auf derselben
Cloudidentität bestanden, Fall `697b19ba-e7ff-4ebf-8a45-f5a0b0514fea`. Cloudidentität bestanden, Fall `697b19ba-e7ff-4ebf-8a45-f5a0b0514fea`.
Zwei tatsächliche authentisierte503, HTTPS-Heartbeat/signierter Sync, Hook auf Zwei tatsächliche authentisierte503, HTTPS-Heartbeat/signierter Sync, Hook auf
@@ -0,0 +1,81 @@
"""Bound HOST-before/after logic; no native package, namespace or reboot calls."""
import copy
from pathlib import Path
import tempfile
from unittest import TestCase
from unittest.mock import patch
from test_guard import apt
import test_native_acceptance as fixture
class AmbientRebootTests(TestCase):
def scenario(self, before, after, private=False, missing=False, changed_boot=False):
ctx=fixture.context()
with tempfile.TemporaryDirectory(dir='/tmp/opencode') as temp:
base=Path(temp);active=fixture.CompletionTests().setup_files(base,ctx)
record=fixture.host_before(ctx,before)
(active/'host-reboot-before.json').write_bytes(apt.canonical(record))
(active/'native-prechecks.json').write_bytes(apt.canonical(fixture.prechecks(ctx,record)))
(active/'sandbox-result.json').write_bytes(apt.canonical({'transaction_sha256':ctx.transaction_sha256,'apt_exit_code':0,'reboot_required':private}))
if missing:(active/'host-reboot-before.json').unlink()
original_exists=Path.exists
with patch.object(apt,'BASE',base),patch.object(apt,'ACTIVE',active),patch.object(apt,'secure_path'), \
patch.object(apt,'sealed_read',side_effect=lambda path,*a,**k:path.read_bytes()), \
patch.object(apt,'runtime_identity',return_value={}), \
patch.object(Path,'exists',lambda path:after if str(path)=='/run/reboot-required' else original_exists(path)), \
patch.object(Path,'read_text',return_value='other-boot' if changed_boot else ctx.boot_id), \
patch.object(apt.subprocess,'Popen',side_effect=AssertionError('No effects in acceptance publication')):
obj=fixture.fixture_transaction();tx=apt.ResolvedAptTransaction.parse(obj)
evidence={'reboot_required':after}
if before!=after or private or missing or changed_boot:
with self.assertRaises((apt.Veto,OSError)):
apt.complete_acceptance(tx,ctx,fixture.action_manifest(ctx,obj,{}),{},evidence)
self.assertFalse(apt.record_path(tx).exists())
else:
apt.complete_acceptance(tx,ctx,fixture.action_manifest(ctx,obj,{}),{},evidence)
self.assertTrue(apt.record_path(tx).exists())
self.assertIs(evidence['reboot_required'],before)
self.assertIs(evidence['host_reboot_required_before'],before)
self.assertIs(evidence['host_reboot_required_after'],after)
self.assertFalse(evidence['reboot_required_introduced'])
self.assertEqual(evidence['host_reboot_before_sha256'],apt.digest(apt.canonical(record)))
proof=apt.json_bytes(apt.record_path(tx).read_bytes())
self.assertEqual(proof['schema_version'],3)
self.assertEqual(proof['native_prechecks_schema_version'],2)
apt.validate_acceptance_record(proof,apt.fixture_scope(tx),{})
for key,value in (('schema_version',2),('native_prechecks_schema_version',1),
('host_reboot_required_after',not before),('host_reboot_required_before',int(before)),
('reboot_required_introduced',True)):
bad=copy.deepcopy(proof);bad[key]=value
with self.subTest(field=key),self.assertRaises(apt.Veto):apt.validate_acceptance_record(bad,apt.fixture_scope(tx),{})
def test_ambient_false_false_and_true_true_are_honest_success(self):
for pending in (False,True):
with self.subTest(pending=pending):self.scenario(pending,pending)
def test_host_changes_private_reboot_missing_before_and_boot_change_never_accept(self):
for before,after in ((False,True),(True,False)):
with self.subTest(before=before,after=after):self.scenario(before,after)
self.scenario(True,True,private=True)
self.scenario(False,False,missing=True)
self.scenario(False,False,changed_boot=True)
def test_parent_capture_is_once_and_child_prechecks_only_bind_that_sample(self):
ctx=fixture.context()
with tempfile.TemporaryDirectory(dir='/tmp/opencode') as temp:
active=Path(temp)
with patch.object(apt,'ACTIVE',active),patch.object(apt,'secure_path'), \
patch.object(apt,'sealed_read',side_effect=lambda path,*a,**k:path.read_bytes()), \
patch.object(apt.VerifiedHelperContext,'check_deadline'),patch.object(apt.time,'time_ns',return_value=2000000000), \
patch.object(Path,'exists',return_value=True):
apt.capture_host_reboot_before(ctx)
before,sha=apt.load_host_reboot_before(ctx)
self.assertTrue(before['host_reboot_required'])
with self.assertRaisesRegex(apt.Veto,'ALREADY_HANDED_OFF'):apt.capture_host_reboot_before(ctx)
with patch.object(Path,'exists',return_value=False) as child_private_flag, \
patch.object(apt,'sandbox_checks',return_value=fixture.prechecks(ctx)['checks']):
checks=apt.native_prechecks(ctx)
self.assertTrue(checks['host_reboot_required_before'])
self.assertEqual(checks['host_reboot_before_sha256'],sha)
child_private_flag.assert_not_called()
@@ -0,0 +1,83 @@
"""Historical configure-only proof is FAILED, never retrospective acceptance."""
import copy
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch
from test_guard import apt
import test_native_acceptance as fixture
from test_native_recovery import recovery_files
class ConfiguredReconciliationTests(TestCase):
def scenario(self,variation=None):
with recovery_files() as (base,tx,ctx,action,partial,previous):
active=apt.ACTIVE
# This deliberately models the historical runtime with NO HOST-before
# observation, not a current schema2-prechecks execution.
(active/'host-reboot-before.json').unlink()
protocol=apt.digest(apt.canonical([apt.Action('rmm-mvp-test','1.0','all','none','=','1.0','all','none','**CONFIGURE**').__dict__]))
records={'launch.json':{'transaction_sha256':ctx.transaction_sha256,'effect_armed_ledger_id':ctx.effect_armed_ledger_id},
'native-prechecks.json':fixture.prechecks(ctx),
'sandbox-ready.json':{'transaction_sha256':ctx.transaction_sha256,'sandbox_version':1},
'hook-armed.json':{'armed_at_ms':2000,'effect_armed_ledger_id':ctx.effect_armed_ledger_id,'grant_id':ctx.grant_id,'transaction_sha256':ctx.transaction_sha256,'protocol_sha256':protocol}}
for name,obj in records.items():(active/name).write_bytes(apt.canonical(obj))
path,binding=apt.bootstrap_binding(tx,ctx,action);apt.durable_once(path,binding)
pins=dict(grant_id=ctx.grant_id,previous_grant_id=partial['grant_id'],partial_proof_sha256=action['native_recovery']['partial_proof_sha256'],provider_sha256=action['provider_sha256'])
fields='transaction_sha256 job_payload_sha256 effect_armed_ledger_id grant_id job_id attempt_id authorization_id plan_sha256'.split()
request={k:getattr(ctx,k) for k in fields}
observed=copy.deepcopy(partial['snapshot']);observed['rmm-mvp-test:all']['status']='install ok installed'
if variation=='different-package':observed['other:amd64']={'version':'1','status':'install ok installed'}
elif variation=='unpacked':observed['rmm-mvp-test:all']['status']='install ok unpacked'
elif variation=='wrong-context':request['job_payload_sha256']='0'*64
elif variation=='wrong-grant':pins['grant_id']='different'
elif variation=='missing-hook':(active/'hook-armed.json').unlink()
elif variation in ('apt-failed','child-reboot'):
obj={'transaction_sha256':ctx.transaction_sha256,'apt_exit_code':100 if variation=='apt-failed' else 0,'reboot_required':variation=='child-reboot'}
(active/'sandbox-result.json').write_bytes(apt.canonical(obj))
elif variation=='fake-before':(active/'host-reboot-before.json').write_bytes(apt.canonical(fixture.host_before(ctx,True)))
elif variation=='new-prechecks':(active/'native-prechecks.json').write_bytes(apt.canonical(fixture.prechecks(ctx,fixture.host_before(ctx,True))))
elif variation=='partial-proof':(active/'partial-proof.json').write_bytes(b'{}')
elif variation=='record-created':(base/('recovery-'+partial['grant_id']+'.json')).write_bytes(b'{}')
elif variation=='history':(previous/'sandbox-result.json').write_bytes(b'{}')
elif variation=='protocol':
records['hook-armed.json']['protocol_sha256']='0'*64
(active/'hook-armed.json').write_bytes(apt.canonical(records['hook-armed.json']))
before={str(p.relative_to(base)):p.read_bytes() for p in base.rglob('*') if p.is_file()}
old_read=apt.sealed_read;original_exists=Path.exists
def read(path,*a,**k):
if str(path)=='/run/reboot-required':return b'Current HOST restart required\n'
if str(path)=='/usr/share/rmm-mvp-test/version' and variation=='payload':return b'1.1\n'
return old_read(path,*a,**k)
with patch.object(apt,'HISTORICAL_CONFIGURED_RECOVERY',pins),patch.object(apt.os,'geteuid',return_value=0), \
patch.object(apt,'sealed_read',side_effect=read),patch.object(Path,'read_text',return_value='other' if variation=='boot' else ctx.boot_id), \
patch.object(Path,'exists',lambda p:variation!='host-false' if str(p)=='/run/reboot-required' else original_exists(p)), \
patch.object(apt,'observe_host_frontend_lock',return_value=variation=='foreign-lock'), \
patch.object(apt,'status_fingerprint',return_value='a'*64,side_effect=['a'*64,'b'*64] if variation=='drift' else None), \
patch.object(apt,'installed_snapshot',return_value=observed),patch.object(apt,'verify_archive'), \
patch.object(apt,'run_read',return_value=b'not clean' if variation=='audit' else b''), \
patch.object(apt.subprocess,'Popen',side_effect=AssertionError('No package effects allowed')):
if variation is None:
result=apt.verify_configured_recovery(request)
self.assertEqual(result['effect_state'],'known_failed')
self.assertEqual(result['code'],'APT_RECOVERY_CONFIGURED_ACCEPTANCE_REBOOT_FLAG_VERIFIED')
proof=result['proof'];self.assertEqual(len(proof),24)
self.assertTrue(proof['effect_complete']);self.assertFalse(proof['postconditions_passed'])
self.assertFalse(proof['partial_effect']);self.assertTrue(proof['host_reboot_required']);self.assertTrue(proof['reboot_required'])
self.assertEqual(proof['snapshot'],observed)
self.assertNotIn('host_reboot_required_before',proof)
else:
with self.assertRaises((apt.Veto,OSError,ValueError)):apt.verify_configured_recovery(request)
after={str(p.relative_to(base)):p.read_bytes() for p in base.rglob('*') if p.is_file()}
self.assertEqual(before,after,'readonly classification must preserve EVERY witness and marker')
def test_complete_effect_with_missing_historical_before_is_failed_without_writes(self):
self.scenario()
def test_binding_history_native_result_or_retroactive_before_mismatch_never_closes(self):
for variation in ('wrong-context','wrong-grant','missing-hook','apt-failed','child-reboot','fake-before','new-prechecks','partial-proof','record-created','history','protocol'):
with self.subTest(variation=variation):self.scenario(variation)
def test_current_state_must_remain_exact_configured_fixture_and_host_flag(self):
for variation in ('different-package','unpacked','payload','boot','host-false','foreign-lock','drift','audit'):
with self.subTest(variation=variation):self.scenario(variation)
@@ -57,8 +57,14 @@ def signed_job(ctx, manifest):
'apt_manifest': manifest}} 'apt_manifest': manifest}}
def prechecks(ctx): def host_before(ctx, pending=False):
return {'schema_version': 1, 'transaction_sha256': ctx.transaction_sha256, return {'schema_version':1,'transaction_sha256':ctx.transaction_sha256,'job_payload_sha256':ctx.job_payload_sha256,
'effect_armed_ledger_id':ctx.effect_armed_ledger_id,'grant_id':ctx.grant_id,'boot_id':ctx.boot_id,
'host_reboot_required':pending,'observed_at_ms':2000}
def prechecks(ctx, before=None):
result = {'schema_version': 1, 'transaction_sha256': ctx.transaction_sha256,
'job_payload_sha256': ctx.job_payload_sha256, 'boot_id': ctx.boot_id, 'job_payload_sha256': ctx.job_payload_sha256, 'boot_id': ctx.boot_id,
'checks': {'namespaces_caps_nnp_seccomp': True, 'readonly_controlpaths': True, 'checks': {'namespaces_caps_nnp_seccomp': True, 'readonly_controlpaths': True,
'private_tmpfs_sockets': True, 'private_tmpfs_sockets': True,
@@ -66,6 +72,10 @@ def prechecks(ctx):
'invalid_kexec_load_flags': 'EPERM', 'invalid_kexec_load_flags': 'EPERM',
'invalid_kexec_file_fds_flags': 'EPERM'}, 'invalid_kexec_file_fds_flags': 'EPERM'},
'frontend_lock': 'native-apt-check-conflict'}} 'frontend_lock': 'native-apt-check-conflict'}}
if before is not None:
result.update(schema_version=2,host_reboot_before_sha256=apt.digest(apt.canonical(before)),
host_reboot_required_before=before['host_reboot_required'])
return result
class BindingTests(TestCase): class BindingTests(TestCase):
@@ -201,8 +211,9 @@ class NativeProbeTests(TestCase):
patch.object(apt, 'invalid_control_syscall_probes', return_value=prechecks(context())['checks']['control_syscalls']), \ patch.object(apt, 'invalid_control_syscall_probes', return_value=prechecks(context())['checks']['control_syscalls']), \
patch.object(apt, 'frontend_lock_probe', return_value='native-apt-check-conflict'), \ patch.object(apt, 'frontend_lock_probe', return_value='native-apt-check-conflict'), \
patch.object(apt.socket, 'socket', side_effect=OSError(apt.errno.EAFNOSUPPORT, 'mocked kernel denial')), \ patch.object(apt.socket, 'socket', side_effect=OSError(apt.errno.EAFNOSUPPORT, 'mocked kernel denial')), \
patch.object(apt,'load_host_reboot_before',return_value=(host_before(context()),apt.digest(apt.canonical(host_before(context()))))), \
patch.object(apt.VerifiedHelperContext, 'check_deadline'): patch.object(apt.VerifiedHelperContext, 'check_deadline'):
self.assertEqual(apt.native_prechecks(context()), prechecks(context())) self.assertEqual(apt.native_prechecks(context()), prechecks(context(),host_before(context())))
def test_safe_invalid_syscall_probes_in_unprivileged_filtered_child(self): def test_safe_invalid_syscall_probes_in_unprivileged_filtered_child(self):
code = '''import importlib.util,sys,json code = '''import importlib.util,sys,json
@@ -235,7 +246,10 @@ class CompletionTests(TestCase):
def setup_files(self, base, ctx): def setup_files(self, base, ctx):
active = base / 'active' active = base / 'active'
active.mkdir() active.mkdir()
(active / 'native-prechecks.json').write_bytes(apt.canonical(prechecks(ctx))) before=host_before(ctx)
(active / 'host-reboot-before.json').write_bytes(apt.canonical(before))
(active / 'native-prechecks.json').write_bytes(apt.canonical(prechecks(ctx,before)))
(active / 'sandbox-result.json').write_bytes(apt.canonical({'transaction_sha256':ctx.transaction_sha256,'apt_exit_code':0,'reboot_required':False}))
(active / 'hook-armed.json').write_bytes(apt.canonical({'grant_id': ctx.grant_id})) (active / 'hook-armed.json').write_bytes(apt.canonical({'grant_id': ctx.grant_id}))
(base / 'bootstrap-attempt-rmm-apt-fixture-install-1.0.json').write_bytes(apt.canonical({ (base / 'bootstrap-attempt-rmm-apt-fixture-install-1.0.json').write_bytes(apt.canonical({
'transaction_sha256': ctx.transaction_sha256, 'job_payload_sha256': ctx.job_payload_sha256, 'transaction_sha256': ctx.transaction_sha256, 'job_payload_sha256': ctx.job_payload_sha256,
@@ -250,6 +264,7 @@ class CompletionTests(TestCase):
with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \ with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \
patch.object(apt, 'secure_path'), patch.object(apt, 'sealed_read', side_effect=lambda p, *a: p.read_bytes()), \ patch.object(apt, 'secure_path'), patch.object(apt, 'sealed_read', side_effect=lambda p, *a: p.read_bytes()), \
patch.object(apt, 'runtime_identity', return_value={}), \ patch.object(apt, 'runtime_identity', return_value={}), \
patch.object(Path,'read_text',return_value=ctx.boot_id), \
patch.object(apt.os, 'fsync', wraps=os.fsync) as sync: patch.object(apt.os, 'fsync', wraps=os.fsync) as sync:
obj = fixture_transaction() obj = fixture_transaction()
tx = apt.ResolvedAptTransaction.parse(obj) tx = apt.ResolvedAptTransaction.parse(obj)
@@ -281,7 +296,7 @@ class CompletionTests(TestCase):
elif variation == 'partial': elif variation == 'partial':
checkfile.write_bytes(b'{') checkfile.write_bytes(b'{')
elif variation in ('negative', 'binding'): elif variation in ('negative', 'binding'):
obj = prechecks(ctx) obj = prechecks(ctx,host_before(ctx))
if variation == 'negative': if variation == 'negative':
obj['checks']['namespaces_caps_nnp_seccomp'] = False obj['checks']['namespaces_caps_nnp_seccomp'] = False
else: else:
@@ -289,7 +304,8 @@ class CompletionTests(TestCase):
checkfile.write_bytes(apt.canonical(obj)) checkfile.write_bytes(apt.canonical(obj))
with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \ with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \
patch.object(apt, 'secure_path'), patch.object(apt, 'sealed_read', side_effect=lambda p, *a: p.read_bytes()), \ patch.object(apt, 'secure_path'), patch.object(apt, 'sealed_read', side_effect=lambda p, *a: p.read_bytes()), \
patch.object(apt, 'runtime_identity', return_value={'changed': True} if variation == 'runtime' else {}): patch.object(apt, 'runtime_identity', return_value={'changed': True} if variation == 'runtime' else {}), \
patch.object(Path,'read_text',return_value=ctx.boot_id):
obj = fixture_transaction() obj = fixture_transaction()
tx = apt.ResolvedAptTransaction.parse(obj) tx = apt.ResolvedAptTransaction.parse(obj)
with self.subTest(variation=variation), self.assertRaises((apt.Veto, OSError)): with self.subTest(variation=variation), self.assertRaises((apt.Veto, OSError)):
@@ -305,6 +321,7 @@ class CompletionTests(TestCase):
with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \ with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \
patch.object(apt, 'sealed_read', side_effect=lambda p, *a: p.read_bytes()), \ patch.object(apt, 'sealed_read', side_effect=lambda p, *a: p.read_bytes()), \
patch.object(apt, 'runtime_identity', return_value={}), \ patch.object(apt, 'runtime_identity', return_value={}), \
patch.object(Path,'read_text',return_value=ctx.boot_id), \
patch.object(apt, 'durable_once', side_effect=OSError('fsync failure')): patch.object(apt, 'durable_once', side_effect=OSError('fsync failure')):
obj = fixture_transaction() obj = fixture_transaction()
tx = apt.ResolvedAptTransaction.parse(obj) tx = apt.ResolvedAptTransaction.parse(obj)
@@ -350,7 +367,7 @@ class DriverTests(TestCase):
'transaction_sha256': ctx.transaction_sha256, 'apt_exit_code': native_code, 'transaction_sha256': ctx.transaction_sha256, 'apt_exit_code': native_code,
'reboot_required': False})) 'reboot_required': False}))
if scenario != 'missing-prechecks': if scenario != 'missing-prechecks':
(active / 'native-prechecks.json').write_bytes(apt.canonical(prechecks(ctx))) (active / 'native-prechecks.json').write_bytes(apt.canonical(prechecks(ctx,json.loads((active/'host-reboot-before.json').read_bytes()))))
return type('MockNativeChild', (), {'wait': lambda _: native_code})() return type('MockNativeChild', (), {'wait': lambda _: native_code})()
with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \ with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \
@@ -358,6 +375,7 @@ class DriverTests(TestCase):
patch.object(apt, 'sealed_read', side_effect=read), patch.object(apt, 'runtime_identity', return_value={}), \ patch.object(apt, 'sealed_read', side_effect=read), patch.object(apt, 'runtime_identity', return_value={}), \
patch.object(apt, 'check_current_baseline'), patch.object(apt, 'check_preconditions'), patch.object(apt, 'verify_archive'), \ patch.object(apt, 'check_current_baseline'), patch.object(apt, 'check_preconditions'), patch.object(apt, 'verify_archive'), \
patch.object(apt, 'run_read', return_value=b''), patch.object(apt, 'installed_snapshot', return_value={}), \ patch.object(apt, 'run_read', return_value=b''), patch.object(apt, 'installed_snapshot', return_value={}), \
patch.object(Path,'read_text',return_value=ctx.boot_id), patch.object(apt.time,'time_ns',return_value=2000000000), \
patch.object(apt.VerifiedHelperContext, 'check_deadline', patch.object(apt.VerifiedHelperContext, 'check_deadline',
side_effect=apt.Veto('START_DEADLINE') if scenario == 'stale' else None), \ side_effect=apt.Veto('START_DEADLINE') if scenario == 'stale' else None), \
patch.object(apt.subprocess, 'Popen', side_effect=child) as spawn: patch.object(apt.subprocess, 'Popen', side_effect=child) as spawn:
@@ -9,7 +9,7 @@ from unittest import TestCase
from unittest.mock import patch from unittest.mock import patch
from test_guard import apt from test_guard import apt
from test_native_acceptance import context, fixture_transaction, action_manifest, signed_job, prechecks from test_native_acceptance import context, fixture_transaction, action_manifest, signed_job, prechecks, host_before
import test_native_retry as retry_fixture import test_native_retry as retry_fixture
@@ -80,7 +80,9 @@ def recovery_files():
for name, data in {'context.json': apt.canonical(new.__dict__), 'signed-action.json': new_job, for name, data in {'context.json': apt.canonical(new.__dict__), 'signed-action.json': new_job,
'expectation.json': apt.canonical(obj), 'baseline.json': apt.canonical(snapshot), 'expectation.json': apt.canonical(obj), 'baseline.json': apt.canonical(snapshot),
'partial-proof.json': apt.canonical(proof), 'apt.conf': apt.apt_config(), 'partial-proof.json': apt.canonical(proof), 'apt.conf': apt.apt_config(),
'native-prechecks.json': apt.canonical(prechecks(new)), 'host-reboot-before.json': apt.canonical(host_before(new)),
'native-prechecks.json': apt.canonical(prechecks(new,host_before(new))),
'sandbox-result.json': apt.canonical({'transaction_sha256':new.transaction_sha256,'apt_exit_code':0,'reboot_required':False}),
'hook-armed.json': b'{}'}.items(): 'hook-armed.json': b'{}'}.items():
(active/name).write_bytes(data) (active/name).write_bytes(data)
yield base, tx, new, action, proof, previous yield base, tx, new, action, proof, previous
@@ -114,7 +116,7 @@ class NativeRecoveryTests(TestCase):
self.assertEqual(path.name,'recovery-attempt-'+proof['grant_id']+'.json') self.assertEqual(path.name,'recovery-attempt-'+proof['grant_id']+'.json')
apt.durable_once(path,binding) apt.durable_once(path,binding)
with self.assertRaisesRegex(apt.Veto,'ALREADY_HANDED_OFF'): apt.durable_once(path,binding) with self.assertRaisesRegex(apt.Veto,'ALREADY_HANDED_OFF'): apt.durable_once(path,binding)
with patch.object(apt,'runtime_identity',return_value={}): with patch.object(apt,'runtime_identity',return_value={}),patch.object(Path,'read_text',return_value=ctx.boot_id):
evidence = apt.complete_acceptance(tx,ctx,action,{}, {'reboot_required':False}) evidence = apt.complete_acceptance(tx,ctx,action,{}, {'reboot_required':False})
self.assertTrue(evidence['native_recovery']) self.assertTrue(evidence['native_recovery'])
self.assertNotIn('native_record_sha256',evidence) self.assertNotIn('native_record_sha256',evidence)
@@ -61,6 +61,7 @@ class PlanningTests(TestCase):
patch.object(apt, 'runtime_identity', return_value=runtime), \ patch.object(apt, 'runtime_identity', return_value=runtime), \
patch.object(apt.os, 'fsync', wraps=os.fsync) as sync: patch.object(apt.os, 'fsync', wraps=os.fsync) as sync:
first = apt.planning_status() first = apt.planning_status()
self.assertIs(type(first['host_reboot_required']),bool)
self.assertGreaterEqual(sync.call_count, 2) self.assertGreaterEqual(sync.call_count, 2)
self.assertNotIn('private-business-package', json.dumps(first)) self.assertNotIn('private-business-package', json.dumps(first))
sealed = base / 'baselines' / (first['baseline_sha256'] + '.json') sealed = base / 'baselines' / (first['baseline_sha256'] + '.json')
+1 -1
View File
@@ -162,7 +162,7 @@ class Guards(unittest.TestCase):
runtime=dict(apt_config_sha256='e'*64) runtime=dict(apt_config_sha256='e'*64)
return dict(fixture_package=baseline.get('rmm-mvp-test:all'),baseline=baseline,baseline_sha256=advanced.digest(advanced.canonical(baseline)), return dict(fixture_package=baseline.get('rmm-mvp-test:all'),baseline=baseline,baseline_sha256=advanced.digest(advanced.canonical(baseline)),
sealed_baseline_sha256=advanced.digest(advanced.canonical(baseline)),status_records={},status_fingerprint=advanced.digest(b'{}'), sealed_baseline_sha256=advanced.digest(advanced.canonical(baseline)),status_records={},status_fingerprint=advanced.digest(b'{}'),
dpkg_updates_empty=True,pending_triggers_empty=True,runtime=runtime,runtime_sha256=advanced.digest(advanced.canonical(runtime)), dpkg_updates_empty=True,pending_triggers_empty=True,host_reboot_required=False,runtime=runtime,runtime_sha256=advanced.digest(advanced.canonical(runtime)),
provider_sha256='c'*64,hook_sha256='d'*64,apt_config_sha256='e'*64, provider_sha256='c'*64,hook_sha256='d'*64,apt_config_sha256='e'*64,
prefetch={pin:dict(schema_version=1,sha256=pin,size=20672,sealed_at_ms=1) for pin in advanced.PINS.values()}) prefetch={pin:dict(schema_version=1,sha256=pin,size=20672,sealed_at_ms=1) for pin in advanced.PINS.values()})
+53
View File
@@ -1,5 +1,58 @@
# Typed RootHelper bridge contract (implementation, not native acceptance) # Typed RootHelper bridge contract (implementation, not native acceptance)
## Host reboot evidence and historical configured effect (Spec 1.13)
An ambient `reboot_required=true` is honest pending evidence, not an implicit
reboot request or a failed package postcondition. Future fixture effects must
prove equal HOST flags before/after, unchanged boot and no private-worker flag.
The parent captures `active/host-reboot-before.json` **before unshare/private
`/run`**. Schema 1 fields are `transaction_sha256`, `job_payload_sha256`,
`effect_armed_ledger_id`, `grant_id`, `boot_id`, `host_reboot_required` (bool),
and `observed_at_ms`, plus `schema_version`. Creation is exclusive and fsynced;
its observation must belong to the original grant window. New native prechecks
use schema 2, retaining the old exact checks and adding
`host_reboot_before_sha256` and `host_reboot_required_before`. The child binds the
saved host observation; its private `/run` never measures the host flag.
After real APT success the parent verifies the current host flag equals the
saved value, boot is unchanged and `sandbox-result.reboot_required` is false.
False/false and true/true are valid; either change or a private-worker flag
vetoes acceptance. Outcome evidence includes `host_reboot_required_before`,
`host_reboot_required_after`, `host_reboot_before_sha256`,
`reboot_required_introduced:false`; `reboot_required` truthfully retains ambient
true. Ordinary acceptance record **schema 3** explicitly binds those fields and
`native_prechecks_schema_version:2`. The reader rejects old record schemas or
inconsistent values. Separate future recovery records use schema 2 and retain
their distinct `rmm.apt.native-recovery` type. Noop observations remain effect-free
and report their actual current reboot flag. Fresh planning adds the required
public bool `host_reboot_required`; known ambient true is shown in the fixed
WebUI plan reason.
Historical grant `33775478-15b0-46ec-b059-44f500dbb0b6` had **no host-before
sample**. It must never acquire retroactive success or an acceptance record.
Fixed mode `verify-configured-recovery` receives the same eight original binding
fields as `verify-partial`. Only its signed schema-4 configure-only job, old
provider `5ff260…`, old schema-1 prechecks, original partial grant `31ef5e5e…` /
proof `dc3bf387…`, preserved recovery once marker, exact Configure hook, APT exit
0 and private-worker false are eligible. It checks complete stable installed
1.0 state, clean audit, actual payload, unchanged boot, idle locks and current
host marker contents twice, rechecking all thirteen immutable witnesses.
Output is `known_failed` /
`APT_RECOVERY_CONFIGURED_ACCEPTANCE_REBOOT_FLAG_VERIFIED`. Its 24-field proof
contains the original eight bindings, type/schema, original evidence digest,
partial proof hash, original baseline and current snapshot hashes/fingerprint,
payload hash, full snapshot, check time, `effect_complete:true`,
`partial_effect:false`, `postconditions_passed:false`, `reboot_required:true`,
`host_reboot_required:true` and `host_reboot_marker_sha256`. No ctime-based
inference becomes a before measurement. It writes nothing and runs no package
mutation. Rust independently verifies the saved signature/old unknown code,
appends a separate immutable proof, and leaves consumption locked until normal
signed RootSync. Native classification and future 1.1 acceptance remain pending
until actually executed; **81 local Python tests passed**, including both actual
APT argument regressions under the readonly unprivileged offline container.
## Configure-only partial recovery (schema 4, local implementation) ## Configure-only partial recovery (schema 4, local implementation)
This is a **new, separately WebUI-approved** dev-test native action. Schema 4 This is a **new, separately WebUI-approved** dev-test native action. Schema 4
+18 -1
View File
@@ -1,6 +1,23 @@
# Root-helper APT transaction provider / explicit first native acceptance # Root-helper APT transaction provider / explicit first native acceptance
**Current 2026-11-13:** The Cloud fixture retry reached armed hook and APT exit 0, **Latest 2026-11-13:** The separately WebUI-approved configure-only attempt
`33775478…` reached APT 0 and completely installed fixture 1.0, but old provider
`5ff260…` rejected acceptance on the actual host reboot flag. Its private worker
reported false; the historical job had no HOST-before sample. It remains
**unknown** (`FIXTURE_UNEXPECTED_REBOOT_REQUIRED`), with no acceptance record,
Root scope closed and APT endpoint stopped. No before measurement or successful
acceptance is inferred retrospectively.
New source implements an original-bound readonly failed-effect classification
and a parent-namespace host-before/after contract for future jobs, matching
Spec 1.13. Ambient true/true is reported honestly; changed host flags, private
worker flags or changed boot reject acceptance. All **81 Python tests passed**
in the readonly unprivileged offline container, including actual APT argument
regressions with guarded fake effects and unchanged real/copied status. Native
classification/new-runtime 1.1 acceptance remain pending. See
[`HELPER-CONTRACT.md`](HELPER-CONTRACT.md) for the exact versioned contract.
**Earlier 2026-11-13:** The Cloud fixture retry reached armed hook and APT exit 0,
leaving fixture 1.0 unpacked/unconfigured. An original-bound readonly proof and leaving fixture 1.0 unpacked/unconfigured. An original-bound readonly proof and
normal signed RootSync now classified that original attempt as **failed** normal signed RootSync now classified that original attempt as **failed**
(`APT_PARTIAL_UNCONFIGURED_VERIFIED`), preserving all histories/tombstones. (`APT_PARTIAL_UNCONFIGURED_VERIFIED`), preserving all histories/tombstones.
+242 -12
View File
@@ -41,6 +41,12 @@ FIXTURE_RECIPES = {'rmm-apt-fixture-install-1.0': (None, '1.0'),
# dpkg-deb control/payload inspection. No runtime-supplied fixture hash is trusted. # dpkg-deb control/payload inspection. No runtime-supplied fixture hash is trusted.
FIXTURE_SHA256 = {'1.0': '74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867', FIXTURE_SHA256 = {'1.0': '74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867',
'1.1': 'ef67c9fe0ba1443fcfe465768e1204763063c369a2a1da04af6027d8a9c00491'} '1.1': 'ef67c9fe0ba1443fcfe465768e1204763063c369a2a1da04af6027d8a9c00491'}
HISTORICAL_CONFIGURED_RECOVERY = {
'grant_id': '33775478-15b0-46ec-b059-44f500dbb0b6',
'previous_grant_id': '31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0',
'partial_proof_sha256': 'dc3bf3870ea77c12f9291bac712c53ae72194eaec980a8646155a7fb5c0dbe21',
'provider_sha256': '5ff260f75cb2959678f6be729d3a806a4ea29febd5ae4003317fed41afc25327',
}
ENV = {'PATH': '/usr/sbin:/usr/bin:/sbin:/bin', 'LC_ALL': 'C', ENV = {'PATH': '/usr/sbin:/usr/bin:/sbin:/bin', 'LC_ALL': 'C',
'DEBIAN_FRONTEND': 'noninteractive', 'HOME': '/root'} 'DEBIAN_FRONTEND': 'noninteractive', 'HOME': '/root'}
NAME = re.compile(r'[a-z0-9][a-z0-9+.-]{1,127}\Z') NAME = re.compile(r'[a-z0-9][a-z0-9+.-]{1,127}\Z')
@@ -453,17 +459,22 @@ def validate_acceptance_record(proof, scope, runtime):
exact(proof, 'schema_version scope runtime test_acceptance noProductionEvidence ' exact(proof, 'schema_version scope runtime test_acceptance noProductionEvidence '
'test_result_id transaction_sha256 job_payload_sha256 grant_id job_id attempt_id ' 'test_result_id transaction_sha256 job_payload_sha256 grant_id job_id attempt_id '
'authorization_id plan_sha256 native_prechecks_sha256 hook_marker_sha256 ' 'authorization_id plan_sha256 native_prechecks_sha256 hook_marker_sha256 '
'postconditions_sha256 completed_at_ms') 'postconditions_sha256 completed_at_ms native_prechecks_schema_version host_reboot_before_sha256 '
require(type(proof['schema_version']) is int and proof['schema_version'] == 2 and 'host_reboot_required_before host_reboot_required_after reboot_required_introduced')
require(type(proof['schema_version']) is int and proof['schema_version'] == 3 and
proof['scope'] == scope and proof['runtime'] == runtime and proof['scope'] == scope and proof['runtime'] == runtime and
proof['test_acceptance'] is True and proof['noProductionEvidence'] is True, proof['test_acceptance'] is True and proof['noProductionEvidence'] is True,
'NATIVE_PROOF_SCOPE_OR_RUNTIME') 'NATIVE_PROOF_SCOPE_OR_RUNTIME')
for key in ('transaction_sha256', 'job_payload_sha256', 'plan_sha256', for key in ('transaction_sha256', 'job_payload_sha256', 'plan_sha256',
'native_prechecks_sha256', 'hook_marker_sha256', 'postconditions_sha256'): 'native_prechecks_sha256', 'hook_marker_sha256', 'postconditions_sha256', 'host_reboot_before_sha256'):
token(proof[key], HASH, 'NATIVE_PROOF_HASH') token(proof[key], HASH, 'NATIVE_PROOF_HASH')
for key in ('test_result_id', 'grant_id', 'job_id', 'attempt_id', 'authorization_id'): for key in ('test_result_id', 'grant_id', 'job_id', 'attempt_id', 'authorization_id'):
token(proof[key], IDENT, 'NATIVE_PROOF_ID') token(proof[key], IDENT, 'NATIVE_PROOF_ID')
require(type(proof['completed_at_ms']) is int and proof['completed_at_ms'] > 0, 'NATIVE_PROOF_TIME') require(type(proof['completed_at_ms']) is int and proof['completed_at_ms'] > 0, 'NATIVE_PROOF_TIME')
require(type(proof['native_prechecks_schema_version']) is int and proof['native_prechecks_schema_version'] == 2 and
type(proof['host_reboot_required_before']) is bool and type(proof['host_reboot_required_after']) is bool and
proof['host_reboot_required_before'] == proof['host_reboot_required_after'] and
proof['reboot_required_introduced'] is False, 'NATIVE_PROOF_BOUND_HOST_REBOOT')
def runtime_identity(): def runtime_identity():
@@ -744,11 +755,63 @@ def sandbox_checks(workspace=None):
def native_prechecks(context): def native_prechecks(context):
checks = sandbox_checks() checks = sandbox_checks()
context.check_deadline() context.check_deadline()
return {'schema_version': 1, 'transaction_sha256': context.transaction_sha256, before, before_sha = load_host_reboot_before(context)
return {'schema_version': 2, 'transaction_sha256': context.transaction_sha256,
'job_payload_sha256': context.job_payload_sha256, 'boot_id': context.boot_id, 'job_payload_sha256': context.job_payload_sha256, 'boot_id': context.boot_id,
'host_reboot_before_sha256': before_sha,
'host_reboot_required_before': before['host_reboot_required'],
'checks': checks} 'checks': checks}
def capture_host_reboot_before(context):
"""Parent namespace only, BEFORE unshare replaces /run with private tmpfs."""
context.check_deadline()
record = {'schema_version': 1, 'transaction_sha256': context.transaction_sha256,
'job_payload_sha256': context.job_payload_sha256,
'effect_armed_ledger_id': context.effect_armed_ledger_id,
'grant_id': context.grant_id, 'boot_id': context.boot_id,
'host_reboot_required': Path('/run/reboot-required').exists(),
'observed_at_ms': time.time_ns() // 1000000}
durable_once(ACTIVE / 'host-reboot-before.json', record)
context.check_deadline()
def load_host_reboot_before(context):
raw = sealed_read(ACTIVE / 'host-reboot-before.json')
record = json_bytes(raw)
exact(record, 'schema_version transaction_sha256 job_payload_sha256 effect_armed_ledger_id '
'grant_id boot_id host_reboot_required observed_at_ms')
require(raw == canonical(record) and type(record['schema_version']) is int and record['schema_version'] == 1 and
all(record[key] == getattr(context, key) for key in
('transaction_sha256', 'job_payload_sha256', 'effect_armed_ledger_id', 'grant_id', 'boot_id')) and
type(record['host_reboot_required']) is bool and type(record['observed_at_ms']) is int and
context.not_before_ms <= record['observed_at_ms'] < context.start_before_ms and
record['observed_at_ms'] <= time.time_ns() // 1000000, 'HOST_REBOOT_BEFORE_BINDING')
return record, digest(raw)
def verify_host_reboot_after(context, evidence):
"""Parent namespace observation; ambient true is honest pending evidence.
The private worker must never introduce a reboot request. Equal HOST flags
(including true/true) do not imply that a reboot was requested or performed.
"""
before, before_sha = load_host_reboot_before(context)
after = Path('/run/reboot-required').exists()
require(Path('/proc/sys/kernel/random/boot_id').read_text().strip() == context.boot_id,
'BOOT_CHANGED_DURING_TRANSACTION')
child = json_bytes(sealed_read(ACTIVE / 'sandbox-result.json'))
exact(child, 'transaction_sha256 apt_exit_code reboot_required')
require(child['transaction_sha256'] == context.transaction_sha256 and
type(child['apt_exit_code']) is int and child['apt_exit_code'] == 0 and
child['reboot_required'] is False, 'FIXTURE_PRIVATE_REBOOT_FLAG_INTRODUCED')
require(after == before['host_reboot_required'] and evidence['reboot_required'] is after,
'HOST_REBOOT_STATE_CHANGED_DURING_TRANSACTION')
return {'host_reboot_required_before': before['host_reboot_required'],
'host_reboot_required_after': after, 'host_reboot_before_sha256': before_sha,
'reboot_required_introduced': False}
def complete_acceptance(transaction, context, action, runtime, evidence): def complete_acceptance(transaction, context, action, runtime, evidence):
"""Called only after real child success, armed hook AND independent verify.""" """Called only after real child success, armed hook AND independent verify."""
require(context.action == 'apt-native-acceptance' and context.execution_profile == 'dev-test', require(context.action == 'apt-native-acceptance' and context.execution_profile == 'dev-test',
@@ -761,12 +824,15 @@ def complete_acceptance(transaction, context, action, runtime, evidence):
'invalid_kexec_load_flags': 'EPERM', 'invalid_kexec_load_flags': 'EPERM',
'invalid_kexec_file_fds_flags': 'EPERM'}, 'invalid_kexec_file_fds_flags': 'EPERM'},
'frontend_lock': 'native-apt-check-conflict'} 'frontend_lock': 'native-apt-check-conflict'}
require(prechecks == {'schema_version': 1, 'transaction_sha256': context.transaction_sha256, before, before_sha = load_host_reboot_before(context)
require(prechecks == {'schema_version': 2, 'transaction_sha256': context.transaction_sha256,
'job_payload_sha256': context.job_payload_sha256, 'job_payload_sha256': context.job_payload_sha256,
'boot_id': context.boot_id, 'checks': expected_checks}, 'NATIVE_PRECHECKS_REQUIRED') 'boot_id': context.boot_id, 'host_reboot_before_sha256': before_sha,
require(not evidence['reboot_required'], 'FIXTURE_UNEXPECTED_REBOOT_REQUIRED') 'host_reboot_required_before': before['host_reboot_required'],
'checks': expected_checks}, 'NATIVE_PRECHECKS_REQUIRED')
evidence.update(verify_host_reboot_after(context, evidence))
require(runtime_identity() == runtime, 'RUNTIME_CHANGED_DURING_ACCEPTANCE') require(runtime_identity() == runtime, 'RUNTIME_CHANGED_DURING_ACCEPTANCE')
proof = {'schema_version': 2, 'scope': fixture_scope(transaction), 'runtime': runtime, proof = {'schema_version': 3, 'scope': fixture_scope(transaction), 'runtime': runtime,
'test_acceptance': True, 'noProductionEvidence': True, 'test_acceptance': True, 'noProductionEvidence': True,
'test_result_id': action['test_result_id'], 'test_result_id': action['test_result_id'],
'transaction_sha256': context.transaction_sha256, 'transaction_sha256': context.transaction_sha256,
@@ -774,6 +840,11 @@ def complete_acceptance(transaction, context, action, runtime, evidence):
'job_id': context.job_id, 'attempt_id': context.attempt_id, 'job_id': context.job_id, 'attempt_id': context.attempt_id,
'authorization_id': context.authorization_id, 'plan_sha256': context.plan_sha256, 'authorization_id': context.authorization_id, 'plan_sha256': context.plan_sha256,
'native_prechecks_sha256': digest(canonical(prechecks)), 'native_prechecks_sha256': digest(canonical(prechecks)),
'native_prechecks_schema_version': 2,
'host_reboot_before_sha256': before_sha,
'host_reboot_required_before': evidence['host_reboot_required_before'],
'host_reboot_required_after': evidence['host_reboot_required_after'],
'reboot_required_introduced': False,
'hook_marker_sha256': digest(sealed_read(ACTIVE / 'hook-armed.json')), 'hook_marker_sha256': digest(sealed_read(ACTIVE / 'hook-armed.json')),
'postconditions_sha256': digest(canonical(evidence)), 'postconditions_sha256': digest(canonical(evidence)),
'completed_at_ms': time.time_ns() // 1000000} 'completed_at_ms': time.time_ns() // 1000000}
@@ -782,7 +853,7 @@ def complete_acceptance(transaction, context, action, runtime, evidence):
recovery = action.get('native_recovery') recovery = action.get('native_recovery')
if recovery is not None: if recovery is not None:
verify_recovery_reference(transaction, context, action) verify_recovery_reference(transaction, context, action)
proof.update(schema_version=1, type='rmm.apt.native-recovery', operation='configure_only', proof.update(schema_version=2, type='rmm.apt.native-recovery', operation='configure_only',
native_recovery=recovery) native_recovery=recovery)
path = BASE / ('recovery-' + recovery['previous_grant_id'] + '.json') path = BASE / ('recovery-' + recovery['previous_grant_id'] + '.json')
staged = BASE / ('pending-recovery-' + recovery['previous_grant_id'] + '.json') staged = BASE / ('pending-recovery-' + recovery['previous_grant_id'] + '.json')
@@ -1532,6 +1603,157 @@ def verify_partial(request):
return result return result
def verify_configured_recovery(request):
"""Readonly classification of the ONE historical schema-4 attempt.
Rust independently checks the original signed Request, immutable ledger
unknown code and the closed original partial proof. No host-before sample
exists for this old runtime: even complete package effects NEVER become a
retroactive acceptance or success. No package mutation or metadata write.
"""
require(os.geteuid() == 0, 'ROOT_REQUIRED')
fields = ('transaction_sha256 job_payload_sha256 effect_armed_ledger_id grant_id '
'job_id attempt_id authorization_id plan_sha256')
exact(request, fields)
for key in ('transaction_sha256', 'job_payload_sha256', 'plan_sha256'):
token(request[key], HASH, 'CONFIGURED_REQUEST_HASH')
token(request['effect_armed_ledger_id'], IDENT, 'CONFIGURED_REQUEST_LEDGER')
for key in ('grant_id', 'job_id', 'attempt_id', 'authorization_id'):
value = request[key]
require(type(value) is str and str(uuid.UUID(value)) == value and uuid.UUID(value).int != 0,
'CONFIGURED_REQUEST_ID')
pin = HISTORICAL_CONFIGURED_RECOVERY
require(request['grant_id'] == pin['grant_id'], 'CONFIGURED_HISTORICAL_GRANT_ONLY')
secure_path(BASE, directory=True, private=True)
secure_path(ACTIVE, directory=True, private=True)
names = ('context.json', 'signed-action.json', 'expectation.json', 'baseline.json',
'launch.json', 'native-prechecks.json', 'sandbox-ready.json', 'sandbox-result.json',
'hook-armed.json', 'partial-proof.json')
raw = {name: sealed_read(ACTIVE / name) for name in names}
for name in ('bootstrap-attempt-rmm-apt-fixture-install-1.0.json',
'bootstrap-retry-rmm-apt-fixture-install-1.0.json',
'recovery-attempt-' + pin['previous_grant_id'] + '.json'):
raw[name] = sealed_read(BASE / name)
require(not os.path.lexists(ACTIVE / 'host-reboot-before.json'),
'CONFIGURED_HISTORICAL_BEFORE_SAMPLE_ABSENT')
context = VerifiedHelperContext.parse(json_bytes(raw['context.json']))
require(context.action == 'apt-native-acceptance' and context.execution_profile == 'dev-test' and
all(getattr(context, key) == request[key] for key in fields.split()), 'CONFIGURED_CONTEXT_BINDING')
require(Path('/proc/sys/kernel/random/boot_id').read_text().strip() == context.boot_id,
'CONFIGURED_BOOT_CHANGED')
require(digest(raw['signed-action.json']) == context.job_payload_sha256 and
digest(raw['expectation.json']) == context.transaction_sha256, 'CONFIGURED_SIGNED_BYTES')
transaction = ResolvedAptTransaction.parse(json_bytes(raw['expectation.json']))
fixture_scope(transaction)
require(transaction.schema_version == 2 and transaction.operation == 'configure_only',
'CONFIGURED_FIXED_OPERATION')
baseline = json_bytes(raw['baseline.json'])
require(type(baseline) is dict and raw['baseline.json'] == canonical(baseline) and
digest(raw['baseline.json']) == transaction.baseline_sha256 and
baseline.get('rmm-mvp-test:all') == {'version': '1.0', 'status': 'install ok unpacked'},
'CONFIGURED_ORIGINAL_PARTIAL_BASELINE')
job = json_bytes(raw['signed-action.json'])
exact(job, 'schema_version tenant_id asset_id agent_id enrollment_generation assignment_version '
'job_id attempt_id action execution_identity not_before start_before max_runtime_seconds max_output_bytes')
require(type(job['schema_version']) is int and job['schema_version'] == 1 and
job['execution_identity'] == 'root' and job['job_id'] == context.job_id and
job['attempt_id'] == context.attempt_id, 'CONFIGURED_ORIGINAL_JOB')
outer = job['action']; exact(outer, 'action recipe_id recipe_version apt_manifest')
require(outer['action'] == 'apt_native_acceptance' and outer['recipe_id'] == transaction.recipe_id and
outer['recipe_version'] == transaction.recipe_version, 'CONFIGURED_ORIGINAL_ACTION')
action = outer['apt_manifest']
exact(action, 'type schema_version action execution_profile transaction_sha256 '
'resolved_apt_transaction provider_sha256 hook_sha256 apt_config_sha256 runtime_sha256 '
'test_result_id transaction_bytes native_recovery')
require(action['type'] == 'rmm.apt.helper-action' and type(action['schema_version']) is int and
action['schema_version'] == 4 and action['action'] == context.action and
action['execution_profile'] == context.execution_profile and
action['provider_sha256'] == pin['provider_sha256'] and
action['transaction_sha256'] == context.transaction_sha256 and
canonical(action['resolved_apt_transaction']) == canonical(json_bytes(raw['expectation.json'])) and
type(action['transaction_bytes']) is list and
all(type(value) is int and 0 <= value <= 255 for value in action['transaction_bytes']) and
bytes(action['transaction_bytes']) == raw['expectation.json'], 'CONFIGURED_ORIGINAL_MANIFEST')
for key in ('provider_sha256', 'hook_sha256', 'apt_config_sha256', 'runtime_sha256'):
token(action[key], HASH, 'CONFIGURED_ORIGINAL_RUNTIME_HASH')
token(action['test_result_id'], IDENT, 'CONFIGURED_ORIGINAL_TEST_ID')
require(digest(sealed_read(ACTIVE / 'apt.conf')) == action['apt_config_sha256'],
'CONFIGURED_ORIGINAL_APT_CONFIG')
reference = action['native_recovery']; validate_recovery_reference(reference)
require(reference['previous_grant_id'] == pin['previous_grant_id'] and
reference['partial_proof_sha256'] == pin['partial_proof_sha256'], 'CONFIGURED_ORIGINAL_PARTIAL_REFERENCE')
verify_recovery_reference(transaction, context, action)
check_bootstrap_attempt(transaction, context, action)
require(canonical(json_bytes(raw['launch.json'])) == canonical({
'transaction_sha256': context.transaction_sha256,
'effect_armed_ledger_id': context.effect_armed_ledger_id}) and
canonical(json_bytes(raw['sandbox-ready.json'])) == canonical({
'transaction_sha256': context.transaction_sha256, 'sandbox_version': 1}) and
canonical(json_bytes(raw['sandbox-result.json'])) == canonical({
'transaction_sha256': context.transaction_sha256, 'apt_exit_code': 0, 'reboot_required': False}),
'CONFIGURED_NATIVE_COMPLETION')
checks = {'schema_version': 1, 'transaction_sha256': context.transaction_sha256,
'job_payload_sha256': context.job_payload_sha256, 'boot_id': context.boot_id,
'checks': {'namespaces_caps_nnp_seccomp': True, 'readonly_controlpaths': True,
'private_tmpfs_sockets': True,
'control_syscalls': {'invalid_reboot_magic': 'EPERM',
'invalid_kexec_load_flags': 'EPERM',
'invalid_kexec_file_fds_flags': 'EPERM'},
'frontend_lock': 'native-apt-check-conflict'}}
require(canonical(json_bytes(raw['native-prechecks.json'])) == canonical(checks),
'CONFIGURED_HISTORICAL_PRECHECKS')
marker = json_bytes(raw['hook-armed.json'])
exact(marker, 'armed_at_ms effect_armed_ledger_id grant_id protocol_sha256 transaction_sha256')
require(marker['effect_armed_ledger_id'] == context.effect_armed_ledger_id and
marker['grant_id'] == context.grant_id and marker['transaction_sha256'] == context.transaction_sha256 and
type(marker['armed_at_ms']) is int and
context.not_before_ms <= marker['armed_at_ms'] < context.start_before_ms,
'CONFIGURED_HOOK_BINDING')
token(marker['protocol_sha256'], HASH, 'CONFIGURED_HOOK_PROTOCOL_HASH')
require(marker['protocol_sha256'] == digest(canonical([
Action('rmm-mvp-test', '1.0', 'all', 'none', '=', '1.0', 'all', 'none', '**CONFIGURE**').__dict__])),
'CONFIGURED_EXACT_CONFIGURE_PROTOCOL')
for name in ('acceptance-rmm-apt-fixture-install-1.0.json', 'pending-acceptance-rmm-apt-fixture-install-1.0.json',
'recovery-' + pin['previous_grant_id'] + '.json', 'pending-recovery-' + pin['previous_grant_id'] + '.json'):
require(not os.path.lexists(BASE / name), 'CONFIGURED_NO_RETROACTIVE_ACCEPTANCE')
require(not observe_host_frontend_lock() and not observe_host_frontend_lock(Path('/var/lib/dpkg/lock')),
'FOREIGN_PACKAGE_LOCK')
fingerprint = status_fingerprint(); observed = installed_snapshot()
expected = dict(baseline); expected['rmm-mvp-test:all'] = {'version': '1.0', 'status': 'install ok installed'}
require(observed == expected, 'CONFIGURED_UNEXPECTED_PACKAGE_CHANGE')
verify_archive(transaction.packages[0])
require(run_read(['/usr/bin/dpkg', '--audit']) == b'', 'CONFIGURED_DPKG_AUDIT')
payload = sealed_read(Path('/usr/share/rmm-mvp-test/version'), limit=32)
require(payload == b'1.0\n', 'CONFIGURED_FIXTURE_PAYLOAD')
host_marker = sealed_read(Path('/run/reboot-required'), limit=4096)
require(Path('/run/reboot-required').exists(), 'CONFIGURED_ACTUAL_HOST_REBOOT_FLAG')
require(status_fingerprint() == fingerprint and installed_snapshot() == observed and
run_read(['/usr/bin/dpkg', '--audit']) == b'' and
sealed_read(Path('/usr/share/rmm-mvp-test/version'), limit=32) == payload and
sealed_read(Path('/run/reboot-required'), limit=4096) == host_marker and
Path('/run/reboot-required').exists() and
Path('/proc/sys/kernel/random/boot_id').read_text().strip() == context.boot_id and
not observe_host_frontend_lock() and not observe_host_frontend_lock(Path('/var/lib/dpkg/lock')),
'CONFIGURED_CURRENT_STATE_CHANGED')
verify_recovery_reference(transaction, context, action)
for name, data in raw.items():
require(sealed_read(ACTIVE / name if name in names else BASE / name) == data,
'CONFIGURED_HISTORICAL_EVIDENCE_CHANGED')
require(not os.path.lexists(ACTIVE / 'host-reboot-before.json'),
'CONFIGURED_HISTORICAL_BEFORE_SAMPLE_ABSENT')
proof = dict(schema_version=1, type='rmm.apt.configured-recovery-reconciliation', **request,
original_evidence_sha256=digest(canonical({name: digest(data) for name, data in raw.items()})),
partial_proof_sha256=reference['partial_proof_sha256'],
original_baseline_sha256=transaction.baseline_sha256,
observed_snapshot_sha256=digest(canonical(observed)), status_fingerprint=fingerprint,
fixture_payload_sha256=digest(payload), snapshot=observed, checked_at_ms=time.time_ns() // 1000000,
effect_complete=True, partial_effect=False, postconditions_passed=False,
reboot_required=True, host_reboot_required=True, host_reboot_marker_sha256=digest(host_marker))
result = dict(effect_state='known_failed', code='APT_RECOVERY_CONFIGURED_ACCEPTANCE_REBOOT_FLAG_VERIFIED', proof=proof)
require(len(canonical(result)) <= MAX_INPUT, 'CONFIGURED_PROOF_LIMIT')
return result
def verified_no_change(transaction, baseline, context): def verified_no_change(transaction, baseline, context):
"""Independently verify the full selected postcondition, never run APT.""" """Independently verify the full selected postcondition, never run APT."""
fixture_scope(transaction) # Cannot promote unknown catalog recipes. fixture_scope(transaction) # Cannot promote unknown catalog recipes.
@@ -1585,7 +1807,7 @@ def execute(request, native_acceptance=False):
not list(secure_path(ACTIVE / 'lists', directory=True).iterdir()), 'ISOLATED_APT_DIRS') not list(secure_path(ACTIVE / 'lists', directory=True).iterdir()), 'ISOLATED_APT_DIRS')
secure_path(ACTIVE / 'cache', directory=True, private=True) secure_path(ACTIVE / 'cache', directory=True, private=True)
for path in ('hook-armed.json', 'sandbox-ready.json', 'sandbox-result.json', 'native-prechecks.json', for path in ('hook-armed.json', 'sandbox-ready.json', 'sandbox-result.json', 'native-prechecks.json',
'host-namespaces.json', 'launch.json'): 'host-namespaces.json', 'host-reboot-before.json', 'launch.json'):
require(not (ACTIVE / path).exists(), 'PRIOR_ATTEMPT_UNKNOWN') require(not (ACTIVE / path).exists(), 'PRIOR_ATTEMPT_UNKNOWN')
check_current_baseline(transaction, baseline) check_current_baseline(transaction, baseline)
for package in transaction.packages: for package in transaction.packages:
@@ -1609,6 +1831,7 @@ def execute(request, native_acceptance=False):
# create-once tombstone, never a reset of the original attempt. # create-once tombstone, never a reset of the original attempt.
path, binding = bootstrap_binding(transaction, context, action) path, binding = bootstrap_binding(transaction, context, action)
durable_once(path, binding) durable_once(path, binding)
capture_host_reboot_before(context)
durable_once(ACTIVE / 'host-namespaces.json', { durable_once(ACTIVE / 'host-namespaces.json', {
name: os.readlink('/proc/self/ns/' + name) for name in ('pid', 'mnt', 'net')}) name: os.readlink('/proc/self/ns/' + name) for name in ('pid', 'mnt', 'net')})
durable_once(ACTIVE / 'launch.json', {'transaction_sha256': context.transaction_sha256, durable_once(ACTIVE / 'launch.json', {'transaction_sha256': context.transaction_sha256,
@@ -1641,6 +1864,7 @@ def execute(request, native_acceptance=False):
type(child_result['reboot_required']) is bool, 'SANDBOX_RESULT_BINDING') type(child_result['reboot_required']) is bool, 'SANDBOX_RESULT_BINDING')
evidence['reboot_required'] |= child_result['reboot_required'] evidence['reboot_required'] |= child_result['reboot_required']
evidence['effect_armed_ledger_id'] = context.effect_armed_ledger_id evidence['effect_armed_ledger_id'] = context.effect_armed_ledger_id
evidence.update(verify_host_reboot_after(context, evidence))
if native_acceptance: if native_acceptance:
evidence.update(complete_acceptance(transaction, context, action, runtime, evidence)) evidence.update(complete_acceptance(transaction, context, action, runtime, evidence))
# This recipe has version/consistency postconditions, not post-boot # This recipe has version/consistency postconditions, not post-boot
@@ -1756,6 +1980,7 @@ def _planning_status(recovery_proof=None):
fingerprint = status_fingerprint() # Vetoes dirty updates/pending triggers. fingerprint = status_fingerprint() # Vetoes dirty updates/pending triggers.
snapshot_reader = partial_installed_snapshot if recovery_proof is not None else installed_snapshot snapshot_reader = partial_installed_snapshot if recovery_proof is not None else installed_snapshot
snapshot = snapshot_reader() snapshot = snapshot_reader()
host_reboot_required = Path('/run/reboot-required').exists()
if recovery_proof is not None: if recovery_proof is not None:
require(snapshot == recovery_proof['snapshot'] and fingerprint == recovery_proof['status_fingerprint'], require(snapshot == recovery_proof['snapshot'] and fingerprint == recovery_proof['status_fingerprint'],
'RECOVERY_PLANNING_STATE_CHANGED') 'RECOVERY_PLANNING_STATE_CHANGED')
@@ -1774,7 +1999,8 @@ def _planning_status(recovery_proof=None):
type(receipt['sealed_at_ms']) is int and 0 < receipt['sealed_at_ms'] <= time.time_ns() // 1000000, type(receipt['sealed_at_ms']) is int and 0 < receipt['sealed_at_ms'] <= time.time_ns() // 1000000,
'PREFETCH_RECEIPT') 'PREFETCH_RECEIPT')
prefetch[sha] = receipt prefetch[sha] = receipt
require(status_fingerprint() == fingerprint and snapshot_reader() == snapshot, require(status_fingerprint() == fingerprint and snapshot_reader() == snapshot and
Path('/run/reboot-required').exists() == host_reboot_required,
'PLANNING_STATE_CHANGED') 'PLANNING_STATE_CHANGED')
require(not observe_host_frontend_lock() and require(not observe_host_frontend_lock() and
not observe_host_frontend_lock(Path('/var/lib/dpkg/lock')), 'FOREIGN_PACKAGE_LOCK') not observe_host_frontend_lock(Path('/var/lib/dpkg/lock')), 'FOREIGN_PACKAGE_LOCK')
@@ -1799,9 +2025,11 @@ def _planning_status(recovery_proof=None):
else: else:
durable_once(path, snapshot) durable_once(path, snapshot)
# Do not publish a stale baseline if state changed during fsync. # Do not publish a stale baseline if state changed during fsync.
require(status_fingerprint() == fingerprint and snapshot_reader() == snapshot, require(status_fingerprint() == fingerprint and snapshot_reader() == snapshot and
Path('/run/reboot-required').exists() == host_reboot_required,
'PLANNING_STATE_CHANGED') 'PLANNING_STATE_CHANGED')
return {'observed_at': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), return {'observed_at': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
'host_reboot_required': host_reboot_required,
'fixture_package': snapshot.get('rmm-mvp-test:all'), 'fixture_package': snapshot.get('rmm-mvp-test:all'),
'baseline_sha256': baseline_sha, 'sealed_baseline_sha256': baseline_sha, 'baseline_sha256': baseline_sha, 'sealed_baseline_sha256': baseline_sha,
'status_fingerprint': fingerprint, 'dpkg_updates_empty': True, 'pending_triggers_empty': True, 'status_fingerprint': fingerprint, 'dpkg_updates_empty': True, 'pending_triggers_empty': True,
@@ -2033,6 +2261,8 @@ def main():
sys.stdout.buffer.write(canonical(readiness_status()) + b'\n') sys.stdout.buffer.write(canonical(readiness_status()) + b'\n')
elif mode == 'verify-partial': elif mode == 'verify-partial':
sys.stdout.buffer.write(canonical(verify_partial(json_bytes(sys.stdin.buffer.read(MAX_INPUT + 1)))) + b'\n') sys.stdout.buffer.write(canonical(verify_partial(json_bytes(sys.stdin.buffer.read(MAX_INPUT + 1)))) + b'\n')
elif mode == 'verify-configured-recovery':
sys.stdout.buffer.write(canonical(verify_configured_recovery(json_bytes(sys.stdin.buffer.read(MAX_INPUT + 1)))) + b'\n')
elif mode == 'verify-controller': elif mode == 'verify-controller':
verify_controller_profile() verify_controller_profile()
elif mode == 'inspect-sandbox': elif mode == 'inspect-sandbox':