feat: qualify bound configure-only recovery runtime on cloud VM
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-13 18:07:46 +01:00
parent b24314da9e
commit 2230235dfb
21 changed files with 1749 additions and 80 deletions
+16 -1
View File
@@ -1,6 +1,6 @@
# Rust RMM: Architektur und Implementierungsspezifikation
Version 1.10 · 2026-11-13 · Sprache: Deutsch
Version 1.11 · 2026-11-13 · Sprache: Deutsch
**Zweck:** Vollständige, eigenständig nutzbare Grundlage für die Implementierung einer mandantenfähigen Plattform zur Inventarisierung, Überwachung und Fernadministration von Kundengeräten durch eine Coding-KI und ein Entwicklungsteam.
@@ -66,6 +66,21 @@ Deploymentdaten, offene Konfiguration und reale Nachweise:
### 0.1 Auftrag an die implementierende KI
**Technische Präzisierung Version 1.11 — neuer Configure-only-Plan:**
Nach unabhängig belegtem und durch normalen signierten RootSync abgeschlossenem
Fehler „Fixture1.0 ausschließlich entpackt“ darf ein neuer fester WebUI-Plan
allein dieses Paket konfigurieren. Manifestschema4 bindet ursprünglichen
Grant/Versuch und unveränderlichen Partial-Proof; Transaktionsschema2 verlangt
explizit `operation=configure_only` und alte/neue Version1.0. Frische vollständige
Teilzustandsplanung hat eine eigene authentisierte Operation/Inventarquelle;
normale Planung und Baseline bleiben strikt. Tatsächlicher v3-Hook und dpkg-
Aufruf dürfen ausschließlich die Konfiguration dieses exakten Pakets enthalten,
kein Unpack, Pending, Triggerlauf oder Fremdpaket. Eigene Create-once-
Recoverymarker/-Nachweise; alte Marker und History bleiben erhalten. Dies
bescheinigt keine nachträgliche frische Installationsabnahme. Danach braucht ein
Upgrade1.0→1.1 einen eigenen neuen festen WebUI-Plan und native Nachprüfung;
gewünschte Noops werden getrennt und ehrlich als Noops abgenommen.
**Technische Präzisierung Version 1.10 — wirkungslose Kontrollkettenreparatur:**
Ein nachweislich nicht serverseitig persistierter Sync-Request darf im expliziten
Entwicklungsprofil über ein eng begrenztes Root-Bootstrapwerkzeug abgeglichen
+62 -5
View File
@@ -41,6 +41,14 @@ fn status(binding: &Binding) -> Result<readiness::Response> {
std::env::var_os("RMM_APT_HELPER_SOCKET").context("APT_HELPER_SOCKET_NOT_CONFIGURED")?;
readiness::probe(Path::new(&socket), binding, &pin)
}
fn recovery_status(binding: &Binding) -> Result<readiness::Response> {
let path =
std::env::var_os("RMM_APT_HELPER_PROOF_FILE").context("APT_RECOVERY_PIN_REQUIRED")?;
let pin = readiness::Pin::read(Path::new(&path), binding)?;
let socket =
std::env::var_os("RMM_APT_HELPER_SOCKET").context("APT_RECOVERY_SOCKET_REQUIRED")?;
readiness::planning_for_recovery(Path::new(&socket), binding, &pin)
}
pub fn capabilities_from(response: &readiness::Response) -> Vec<String> {
if response.profile != "apt_only" {
return vec![];
@@ -62,7 +70,7 @@ pub fn capabilities_from(response: &readiness::Response) -> Vec<String> {
result
}
pub fn capabilities(binding: &Binding) -> Vec<String> {
status(binding)
let normal = status(binding)
.map(|s| {
let mut caps = capabilities_from(&s);
if !caps.is_empty() {
@@ -82,6 +90,21 @@ pub fn capabilities(binding: &Binding) -> Vec<String> {
}
caps
})
.unwrap_or_default();
if !normal.is_empty() {
return normal;
}
recovery_status(binding)
.map(|s| {
vec![
"apt_native_acceptance".into(),
"root:apt_native_acceptance".into(),
"helper.root.v1".into(),
format!("helper.policy.sha256:{}", s.provider_stack_sha256),
"apt.manifest.v2".into(),
"apt.native-acceptance.v1".into(),
]
})
.unwrap_or_default()
}
@@ -95,13 +118,15 @@ pub fn planning_observation(binding: Option<&Binding>) -> serde_json::Value {
let pin = readiness::Pin::read(Path::new(&path), binding)?;
let socket =
std::env::var_os("RMM_APT_HELPER_SOCKET").context("APT_PLANNING_NOT_CONFIGURED")?;
readiness::planning(Path::new(&socket), binding, &pin)?
readiness::planning(Path::new(&socket), binding, &pin)
.or_else(|_| readiness::planning_for_recovery(Path::new(&socket), binding, &pin))?
.planning
.context("APT_PLANNING_UNAVAILABLE")
})();
match result {
Ok(planning) => {
serde_json::json!({"scope":"linux.apt.planning", "source_id":"root-helper:apt_planning_v1",
let recovery = planning.native_recovery.is_some();
serde_json::json!({"scope":if recovery{"linux.apt.recovery-planning"}else{"linux.apt.planning"}, "source_id":if recovery{"root-helper:apt_recovery_planning_v1"}else{"root-helper:apt_planning_v1"},
"observed_at":planning.observed_at, "quality":"valid", "completeness":"complete", "truncated":false, "data":planning})
}
Err(_) => {
@@ -125,6 +150,28 @@ fn recipe_ready(job: &JobPayload, response: &readiness::Response) -> Result<()>
)?;
manifest.resolved_apt_transaction.validate_fixture()?;
let recipe = &manifest.resolved_apt_transaction.recipe_id;
if let Some(reference) = &manifest.native_recovery {
let planning = response
.planning
.as_ref()
.context("APT_RECOVERY_PLANNING_REQUIRED")?;
planning.validate(chrono::Utc::now())?;
ensure!(
job.action.name() == "apt_native_acceptance"
&& manifest.schema_version == 4
&& manifest.action == "apt-native-acceptance"
&& planning.native_recovery.as_ref() == Some(reference)
&& planning.baseline_sha256 == manifest.resolved_apt_transaction.baseline_sha256
&& planning.status_fingerprint
== manifest.resolved_apt_transaction.status_fingerprint
&& planning.runtime_sha256 == manifest.runtime_sha256
&& planning.provider_sha256 == manifest.provider_sha256
&& planning.hook_sha256 == manifest.hook_sha256
&& planning.apt_config_sha256 == manifest.apt_config_sha256,
"APT_RECOVERY_FRESH_PLAN_BINDING"
);
return Ok(());
}
if job.action.name() == "apt_native_acceptance" {
ensure!(
manifest.action == "apt-native-acceptance"
@@ -145,7 +192,17 @@ fn recipe_ready(job: &JobPayload, response: &readiness::Response) -> Result<()>
Ok(())
}
pub fn supported(binding: &Binding, job: &JobPayload) -> bool {
status(binding).and_then(|s| recipe_ready(job, &s)).is_ok()
job_status(binding, job)
.and_then(|s| recipe_ready(job, &s))
.is_ok()
}
fn job_status(binding: &Binding, job: &JobPayload) -> Result<readiness::Response> {
if matches!(&job.action,rmm_domain::jobs::Action::AptNativeAcceptance{apt_manifest,..}if apt_manifest.native_recovery.is_some())
{
recovery_status(binding)
} else {
status(binding)
}
}
pub fn invoke(binding: &Binding, job: &JobPayload, request: &Request) -> Result<Outcome> {
let socket = socket_for(
@@ -154,7 +211,7 @@ pub fn invoke(binding: &Binding, job: &JobPayload, request: &Request) -> Result<
std::env::var_os("RMM_APT_HELPER_SOCKET"),
)?;
if provider::is_apt_action(job) {
recipe_ready(job, &status(binding)?)?;
recipe_ready(job, &job_status(binding, job)?)?;
}
rmm_privileged_helper::invoke(&socket, request, job.max_runtime_seconds)
}
+86 -8
View File
@@ -10,6 +10,8 @@ pub const UPDATE_SHA: &str = "ef67c9fe0ba1443fcfe465768e1204763063c369a2a1da04af
#[serde(deny_unknown_fields)]
pub struct ResolvedAptTransaction {
pub schema_version: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub operation: Option<AptTransactionOperation>,
pub recipe_id: String,
pub recipe_version: String,
pub platform: String,
@@ -33,6 +35,29 @@ pub struct PackageArchive {
}
pub type AptExpectation = ResolvedAptTransaction;
pub type AptExpectedPackage = PackageArchive;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, schemars::JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum AptTransactionOperation {
ConfigureOnly,
}
/// One new explicitly approved configure-only job after a proven partial
/// fixture effect. This does not retry the old consumed attempt.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, schemars::JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct AptNativeRecovery {
pub schema_version: u32,
pub previous_grant_id: uuid::Uuid,
pub previous_attempt_id: uuid::Uuid,
pub partial_proof_sha256: String,
}
impl AptNativeRecovery {
pub fn validate(&self) -> bool {
self.schema_version == 1
&& !self.previous_grant_id.is_nil()
&& !self.previous_attempt_id.is_nil()
&& digest(&self.partial_proof_sha256)
}
}
/// One explicitly approved recovery of a fixture acceptance that failed before
/// the trusted pre-dpkg hook. The original create-once marker remains intact.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, schemars::JsonSchema)]
@@ -69,11 +94,12 @@ pub struct AptExecutionManifest {
pub test_result_id: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub native_retry: Option<AptNativeRetry>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub native_recovery: Option<AptNativeRecovery>,
}
impl ResolvedAptTransaction {
pub fn validate_fixture(&self) -> bool {
if self.schema_version != 1
|| self.recipe_version != "1"
if self.recipe_version != "1"
|| self.platform != "ubuntu-24.04-amd64"
|| self.resolver_config_version != "rmm-apt-local-v1"
|| !self.no_reboot
@@ -84,9 +110,16 @@ impl ResolvedAptTransaction {
return false;
}
let package = &self.packages[0];
let (old, new, sha) = match self.recipe_id.as_str() {
INSTALL_RECIPE => (None, "1.0", INSTALL_SHA),
UPDATE_RECIPE => (Some("1.0"), "1.1", UPDATE_SHA),
let (old, new, sha) = match (
self.schema_version,
&self.operation,
self.recipe_id.as_str(),
) {
(1, None, INSTALL_RECIPE) => (None, "1.0", INSTALL_SHA),
(1, None, UPDATE_RECIPE) => (Some("1.0"), "1.1", UPDATE_SHA),
(2, Some(AptTransactionOperation::ConfigureOnly), INSTALL_RECIPE) => {
(Some("1.0"), "1.0", INSTALL_SHA)
}
_ => return false,
};
package.name == "rmm-mvp-test"
@@ -106,9 +139,23 @@ impl ResolvedAptTransaction {
impl AptExecutionManifest {
pub fn validate(&self) -> bool {
self.kind == "rmm.apt.helper-action"
&& match (&self.native_retry, self.schema_version) {
(None, 2) => true,
(Some(retry), 3) => self.action == "apt-native-acceptance" && retry.validate(),
&& match (
&self.native_retry,
&self.native_recovery,
self.schema_version,
) {
(None, None, 2) => self.resolved_apt_transaction.operation.is_none(),
(Some(retry), None, 3) => {
self.action == "apt-native-acceptance"
&& retry.validate()
&& self.resolved_apt_transaction.operation.is_none()
}
(None, Some(recovery), 4) => {
self.action == "apt-native-acceptance"
&& recovery.validate()
&& self.resolved_apt_transaction.operation
== Some(AptTransactionOperation::ConfigureOnly)
}
_ => false,
}
&& matches!(
@@ -197,6 +244,7 @@ impl PinnedAptTransaction {
let expectation: AptExpectation = serde_json::from_slice(&self.expectation_bytes)
.map_err(|_| "INVALID_APT_EXPECTATION")?;
if expectation.schema_version != 1
|| expectation.operation.is_some()
|| expectation.platform != "ubuntu-24.04-amd64"
|| !expectation.no_reboot
|| !label(&expectation.recipe_id)
@@ -312,6 +360,7 @@ mod tests {
fn helper_schema_two_roundtrip_and_strict_action_binding() {
let t = ResolvedAptTransaction {
schema_version: 1,
operation: None,
recipe_id: INSTALL_RECIPE.into(),
recipe_version: "1".into(),
platform: "ubuntu-24.04-amd64".into(),
@@ -345,8 +394,36 @@ mod tests {
runtime_sha256: hash(b"runtime"),
test_result_id: "fixture-test-1".into(),
native_retry: None,
native_recovery: None,
};
assert!(m.validate());
let mut recovery = m.clone();
recovery.schema_version = 4;
recovery.native_recovery = Some(AptNativeRecovery {
schema_version: 1,
previous_grant_id: Uuid::new_v4(),
previous_attempt_id: Uuid::new_v4(),
partial_proof_sha256: hash(b"closed partial"),
});
recovery.resolved_apt_transaction.schema_version = 2;
recovery.resolved_apt_transaction.operation = Some(AptTransactionOperation::ConfigureOnly);
recovery.resolved_apt_transaction.packages[0].old_version = Some("1.0".into());
recovery.transaction_bytes =
crate::jobs::encode(&recovery.resolved_apt_transaction).unwrap();
recovery.transaction_sha256 = hash(&recovery.transaction_bytes);
assert!(recovery.validate());
let mut disguised = recovery.clone();
disguised.schema_version = 2;
assert!(!disguised.validate());
disguised = recovery.clone();
disguised.action = "apt-execute".into();
assert!(!disguised.validate());
disguised = recovery.clone();
disguised.native_recovery = None;
assert!(!disguised.validate());
let mut equal_normal = m.resolved_apt_transaction.clone();
equal_normal.packages[0].old_version = Some("1.0".into());
assert!(!equal_normal.validate_fixture());
assert!(
!serde_json::to_value(&m)
.unwrap()
@@ -408,6 +485,7 @@ mod tests {
};
let expectation = AptExpectation {
schema_version: 1,
operation: None,
recipe_id: "fixture".into(),
recipe_version: "1".into(),
platform: "ubuntu-24.04-amd64".into(),
+105 -14
View File
@@ -70,6 +70,8 @@ pub struct PackageArchive {
#[serde(deny_unknown_fields)]
pub struct ResolvedAptTransaction {
pub schema_version: u32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub operation: Option<rmm_domain::apt_transaction::AptTransactionOperation>,
pub recipe_id: String,
pub recipe_version: String,
pub platform: String,
@@ -82,8 +84,7 @@ pub struct ResolvedAptTransaction {
impl ResolvedAptTransaction {
pub fn validate_fixture(&self) -> Result<()> {
ensure!(
self.schema_version == 1
&& self.recipe_version == "1"
self.recipe_version == "1"
&& self.platform == "ubuntu-24.04-amd64"
&& self.resolver_config_version == "rmm-apt-local-v1"
&& self.no_reboot
@@ -93,9 +94,18 @@ impl ResolvedAptTransaction {
sha(&self.status_fingerprint)?;
sha(&self.baseline_sha256)?;
let p = &self.packages[0];
let (old, new, expected_hash) = match self.recipe_id.as_str() {
INSTALL_RECIPE => (None, "1.0", INSTALL_SHA),
UPDATE_RECIPE => (Some("1.0"), "1.1", UPDATE_SHA),
let (old, new, expected_hash) = match (
self.schema_version,
&self.operation,
self.recipe_id.as_str(),
) {
(1, None, INSTALL_RECIPE) => (None, "1.0", INSTALL_SHA),
(1, None, UPDATE_RECIPE) => (Some("1.0"), "1.1", UPDATE_SHA),
(
2,
Some(rmm_domain::apt_transaction::AptTransactionOperation::ConfigureOnly),
INSTALL_RECIPE,
) => (Some("1.0"), "1.0", INSTALL_SHA),
_ => bail!("APT_RECIPE_NOT_CONFIGURED"),
};
ensure!(
@@ -133,6 +143,8 @@ pub struct AptExecutionManifest {
pub test_result_id: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub native_retry: Option<rmm_domain::apt_transaction::AptNativeRetry>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub native_recovery: Option<rmm_domain::apt_transaction::AptNativeRecovery>,
}
#[derive(Deserialize)]
@@ -299,11 +311,20 @@ fn validate_manifest(
config.validate()?;
ensure!(
m.kind == "rmm.apt.helper-action"
&& match (&m.native_retry, m.schema_version) {
(None, 2) => true,
(Some(retry), 3) => {
action == "apt_native_acceptance" && retry.validate()
&& match (&m.native_retry, &m.native_recovery, m.schema_version) {
(None, None, 2) => m.resolved_apt_transaction.operation.is_none(),
(Some(retry), None, 3) => {
action == "apt_native_acceptance"
&& retry.validate()
&& m.resolved_apt_transaction.operation.is_none()
}
(None, Some(recovery), 4) =>
action == "apt_native_acceptance"
&& recovery.validate()
&& m.resolved_apt_transaction.operation
== Some(
rmm_domain::apt_transaction::AptTransactionOperation::ConfigureOnly
),
_ => false,
}
&& m.execution_profile == config.execution_profile
@@ -600,6 +621,10 @@ impl PreparedApt {
/// Read-only prerequisite under the caller's device ExecutorGuard. A new
/// signed retry does not clear an unknown effect or change an old record.
pub fn verify_retry_history(&self, db: &rusqlite::Connection) -> Result<()> {
if self.manifest.native_recovery.is_some() {
self.recovery_partial(db)?;
return Ok(());
}
let Some(retry) = &self.manifest.native_retry else {
return Ok(());
};
@@ -647,6 +672,44 @@ impl PreparedApt {
self.verify_retry_evidence(db, &evidence)
}
fn recovery_partial(
&self,
db: &rusqlite::Connection,
) -> Result<crate::apt_reconcile::ClosedPartial> {
let reference = self
.manifest
.native_recovery
.as_ref()
.context("APT_RECOVERY_REFERENCE_REQUIRED")?;
let prior = crate::apt_reconcile::closed_partial(db, &self.binding, Some(reference))?;
ensure!(
self.manifest.schema_version == 4
&& self.manifest.action == "apt-native-acceptance"
&& self.manifest.execution_profile == "dev-test"
&& reference.previous_grant_id != self.permit.grant_id
&& reference.previous_attempt_id != self.job.attempt_id
&& prior.job_id != self.job.job_id
&& prior.authorization_id != self.permit.authorization_id
&& prior.plan_sha256 != self.permit.plan_hash
&& prior.previous_start_before <= self.permit.not_before
&& self.manifest.resolved_apt_transaction.baseline_sha256 == prior.baseline_sha256
&& self.manifest.resolved_apt_transaction.status_fingerprint
== prior.status_fingerprint,
"APT_RECOVERY_NEW_APPROVED_BINDING"
);
for name in [
format!("recovery-attempt-{}.json", reference.previous_grant_id),
format!("recovery-{}.json", reference.previous_grant_id),
format!("pending-recovery-{}.json", reference.previous_grant_id),
] {
ensure!(
absent_nofollow(&Path::new(BASE).join(name))?,
"APT_RECOVERY_ALREADY_ATTEMPTED"
);
}
Ok(prior)
}
fn verify_retry_evidence(
&self,
db: &rusqlite::Connection,
@@ -901,6 +964,11 @@ impl PreparedApt {
fn stage(&self, db: &rusqlite::Connection, ledger_id: &str) -> Result<PathBuf> {
verify_installation()?;
verify_prefetched(&self.manifest, &self.permit)?;
let partial = if self.manifest.native_recovery.is_some() {
Some(self.recovery_partial(db)?)
} else {
None
};
let remaining = (self.permit.start_before - Utc::now())
.num_nanoseconds()
.context("APT_DEADLINE_RANGE")?;
@@ -959,6 +1027,9 @@ impl PreparedApt {
1024 * 1024,
)?;
write_once(&active.join("baseline.json"), &baseline, 0o600)?;
if let Some(partial) = partial {
write_once(&active.join("partial-proof.json"), &partial.proof, 0o600)?;
}
let config = Command::new("/usr/bin/python3")
.args(["-I", CODE, "print-config"])
.env_clear()
@@ -1098,11 +1169,31 @@ fn map_driver_result(
"APT_FIXTURE_PAYLOAD_EVIDENCE"
);
if bootstrap {
sha(result
.evidence
.get("native_record_sha256")
.and_then(|v| v.as_str())
.context("APT_NATIVE_RECORD")?)?;
if let Some(recovery) = &m.native_recovery {
ensure!(
result.evidence.get("native_recovery") == Some(&serde_json::json!(true))
&& result.evidence.get("partial_proof_sha256")
== Some(&serde_json::json!(recovery.partial_proof_sha256))
&& result.evidence.get("native_record_sha256").is_none(),
"APT_RECOVERY_SEPARATE_RECORD_REQUIRED"
);
sha(result
.evidence
.get("recovery_record_sha256")
.and_then(|v| v.as_str())
.context("APT_RECOVERY_RECORD")?)?;
} else {
ensure!(
result.evidence.get("native_recovery").is_none()
&& result.evidence.get("recovery_record_sha256").is_none(),
"APT_RECOVERY_WRONG_ACTION"
);
sha(result
.evidence
.get("native_record_sha256")
.and_then(|v| v.as_str())
.context("APT_NATIVE_RECORD")?)?;
}
ensure!(
result.evidence.get("test_result_id")
== Some(&serde_json::json!(m.test_result_id)),
+42
View File
@@ -3,6 +3,46 @@ use openssl::{pkey::PKey, sign::Signer};
use rmm_domain::jobs::{Action, encode};
use uuid::Uuid;
#[test]
fn configure_only_is_explicit_native_recovery_and_never_install_acceptance() {
let (config, mut m) = manifest(true);
m.schema_version = 4;
m.native_recovery = Some(rmm_domain::apt_transaction::AptNativeRecovery {
schema_version: 1,
previous_grant_id: Uuid::new_v4(),
previous_attempt_id: Uuid::new_v4(),
partial_proof_sha256: hash(b"partial"),
});
m.resolved_apt_transaction.schema_version = 2;
m.resolved_apt_transaction.operation =
Some(rmm_domain::apt_transaction::AptTransactionOperation::ConfigureOnly);
m.resolved_apt_transaction.packages[0].old_version = Some("1.0".into());
m.transaction_bytes = serde_json::to_vec(&m.resolved_apt_transaction).unwrap();
m.transaction_sha256 = hash(&m.transaction_bytes);
validate_manifest(&m, "apt_native_acceptance", &config).unwrap();
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 encode_result = |e: &serde_json::Value| {
serde_json::to_vec(&serde_json::json!({"effect_state":"verified","code":"POSTCONDITIONS_VERIFIED","evidence":e})).unwrap()
};
assert_eq!(
map_driver_result(&encode_result(&evidence), Some(0), true, &m, "ledger")
.unwrap()
.state,
"succeeded"
);
evidence["native_record_sha256"] = serde_json::json!(hash(b"fake install acceptance"));
assert!(map_driver_result(&encode_result(&evidence), Some(0), true, &m, "ledger").is_err());
evidence
.as_object_mut()
.unwrap()
.remove("native_record_sha256");
evidence["partial_proof_sha256"] = serde_json::json!(hash(b"other"));
assert!(map_driver_result(&encode_result(&evidence), Some(0), true, &m, "ledger").is_err());
m.schema_version = 2;
assert!(validate_manifest(&m, "apt_native_acceptance", &config).is_err());
}
#[test]
fn actual_domain_native_action_roundtrips_exact_signed_manifest_to_helper() {
let (binding, mut request, key, now) = signed_request();
@@ -352,6 +392,7 @@ fn consumed_parent_row_and_original_start_request_are_mandatory() {
fn manifest(bootstrap: bool) -> (ProviderConfig, AptExecutionManifest) {
let transaction = ResolvedAptTransaction {
schema_version: 1,
operation: None,
recipe_id: INSTALL_RECIPE.into(),
recipe_version: "1".into(),
platform: "ubuntu-24.04-amd64".into(),
@@ -398,6 +439,7 @@ fn manifest(bootstrap: bool) -> (ProviderConfig, AptExecutionManifest) {
runtime_sha256: config.runtime_sha256.clone(),
test_result_id: "fixture-test-1".into(),
native_retry: None,
native_recovery: None,
};
(config, manifest)
}
@@ -132,6 +132,120 @@ struct LedgerRow {
start: Vec<u8>,
outcome: Vec<u8>,
}
pub struct ClosedPartial {
pub reference: rmm_domain::apt_transaction::AptNativeRecovery,
pub proof: Vec<u8>,
pub job_id: Uuid,
pub authorization_id: Uuid,
pub plan_sha256: String,
pub previous_start_before: DateTime<Utc>,
pub baseline_sha256: String,
pub status_fingerprint: String,
}
/// Only a previously classified partial whose exact outcome was closed by
/// signed RootSync can seed a new, separately approved configure-only job.
pub fn closed_partial(
db: &Connection,
binding: &Binding,
wanted: Option<&rmm_domain::apt_transaction::AptNativeRecovery>,
) -> Result<ClosedPartial> {
closed_partial_from(db, binding, wanted, read_evidence)
}
fn closed_partial_from(
db: &Connection,
binding: &Binding,
wanted: Option<&rmm_domain::apt_transaction::AptNativeRecovery>,
read: impl Fn() -> Result<BTreeMap<String, Vec<u8>>>,
) -> Result<ClosedPartial> {
let mut q=db.prepare("SELECT c.rowid,c.grant_id,c.agent,c.generation,c.job,c.attempt,e.start,c.result,e.outcome,p.original_request_sha256,p.previous_outcome_sha256,p.previous_outcome,p.proof_sha256,p.proof,p.classified_outcome,p.checked_at_ms FROM apt_partial_reconciliations p JOIN consumed c USING(grant_id) JOIN execution_evidence e USING(grant_id) ORDER BY c.rowid")?;
let rows = q
.query_map([], |r| {
Ok((
LedgerRow {
rowid: r.get(0)?,
grant: r.get(1)?,
agent: r.get(2)?,
generation: r.get(3)?,
job: r.get(4)?,
attempt: r.get(5)?,
start: r.get(6)?,
outcome: r.get(11)?,
},
r.get::<_, Option<Vec<u8>>>(7)?,
r.get::<_, Option<Vec<u8>>>(8)?,
r.get::<_, String>(9)?,
r.get::<_, String>(10)?,
r.get::<_, String>(12)?,
r.get::<_, Vec<u8>>(13)?,
r.get::<_, Vec<u8>>(14)?,
r.get::<_, i64>(15)?,
))
})?
.collect::<rusqlite::Result<Vec<_>>>()?;
ensure!(rows.len() <= 256, "APT_RECOVERY_PROOF_LIMIT");
let mut found = None;
for (row, result, outcome, request_sha, old_sha, proof_sha, proof, classified, checked) in rows
{
if wanted.is_some_and(|w| w.previous_grant_id.to_string() != row.grant) {
continue;
}
let Some(c) = eligible(binding, row)? else {
continue;
};
let reference = rmm_domain::apt_transaction::AptNativeRecovery {
schema_version: 1,
previous_grant_id: c.probe.grant_id,
previous_attempt_id: c.probe.attempt_id,
partial_proof_sha256: proof_sha.clone(),
};
ensure!(
wanted.is_none_or(|w| w == &reference)
&& reference.validate()
&& hash(&proof) == proof_sha
&& hash(&c.original_outcome) == old_sha
&& hash(&serde_json::to_vec(&c.request)?) == request_sha,
"APT_RECOVERY_IMMUTABLE_PROOF"
);
let result: Outcome =
serde_json::from_slice(&result.context("APT_RECOVERY_PRIOR_UNRESOLVED")?)?;
let classified_value: Value = serde_json::from_slice(&classified)?;
ensure!(
result.state == "failed"
&& result.error_code == CODE
&& !result.reboot_required
&& serde_json::to_value(&result)? == classified_value
&& serde_json::from_slice::<Value>(
&outcome.context("APT_RECOVERY_PRIOR_OUTCOME")?
)? == classified_value,
"APT_RECOVERY_PRIOR_NOT_CLOSED_PARTIAL"
);
let p: PartialProof = serde_json::from_slice(&proof)?;
ensure!(p.checked_at_ms == checked, "APT_RECOVERY_PROOF_TIME");
let files = read()?;
verify_proof(
&c,
&files,
&ProbeOutput {
effect_state: "known_failed".into(),
code: CODE.into(),
proof: p.clone(),
},
DateTime::from_timestamp_millis(checked).context("APT_RECOVERY_PROOF_TIME")?,
)?;
ensure!(found.is_none(), "APT_RECOVERY_AMBIGUOUS_PROOFS");
found = Some(ClosedPartial {
reference,
proof,
job_id: c.probe.job_id,
authorization_id: c.probe.authorization_id,
plan_sha256: c.probe.plan_sha256,
previous_start_before: c.permit.start_before,
baseline_sha256: p.observed_snapshot_sha256,
status_fingerprint: p.status_fingerprint,
});
}
found.context("APT_RECOVERY_CLOSED_PROOF_REQUIRED")
}
fn digest(s: &str) -> bool {
s.len() == 64
&& s.bytes()
@@ -176,6 +290,9 @@ fn eligible(binding: &Binding, row: LedgerRow) -> Result<Option<Candidate>> {
else {
return Ok(None);
};
if apt_manifest.schema_version != 3 || apt_manifest.native_retry.is_none() {
return Ok(None);
}
ensure!(
recipe_id == apt::INSTALL_RECIPE
&& recipe_version == "1"
@@ -847,4 +964,38 @@ mod tests {
classified
);
}
#[test]
fn new_recovery_requires_exact_closed_partial_signed_history_and_immutable_proof() {
let (binding, row, files, now) = fixture();
let c = eligible(&binding, row.clone()).unwrap().unwrap();
let proof = output(&c, &files, now).proof;
let mut db = Connection::open_in_memory().unwrap();
db.execute_batch("CREATE TABLE consumed(grant_id TEXT PRIMARY KEY,agent TEXT,generation INTEGER,job TEXT,attempt TEXT,result BLOB);CREATE TABLE execution_evidence(grant_id TEXT PRIMARY KEY,start BLOB,outcome BLOB);").unwrap();
db.execute("INSERT INTO consumed(rowid,grant_id,agent,generation,job,attempt,result) VALUES(?1,?2,?3,?4,?5,?6,NULL)",params![row.rowid,row.grant,row.agent,row.generation,row.job,row.attempt]).unwrap();
db.execute(
"INSERT INTO execution_evidence VALUES(?1,?2,?3)",
params![row.grant, row.start, row.outcome],
)
.unwrap();
persist(&mut db, &c, &proof).unwrap();
assert!(closed_partial_from(&db, &binding, None, || Ok(files.clone())).is_err());
db.execute(
"UPDATE consumed SET result=(SELECT outcome FROM execution_evidence)",
[],
)
.unwrap();
let closed = closed_partial_from(&db, &binding, None, || Ok(files.clone())).unwrap();
assert_eq!(closed.reference.previous_grant_id, c.probe.grant_id);
assert_eq!(closed.reference.previous_attempt_id, c.probe.attempt_id);
assert_eq!(closed.baseline_sha256, proof.observed_snapshot_sha256);
let mut changed = closed.reference.clone();
changed.previous_attempt_id = Uuid::new_v4();
assert!(closed_partial_from(&db, &binding, Some(&changed), || Ok(files.clone())).is_err());
let mut changed_files = files.clone();
changed_files.insert("signed-action.json".into(), b"{}".to_vec());
assert!(closed_partial_from(&db, &binding, None, || Ok(changed_files.clone())).is_err());
db.execute("UPDATE apt_partial_reconciliations SET proof=x'7b7d'", [])
.unwrap();
assert!(closed_partial_from(&db, &binding, None, || Ok(files.clone())).is_err());
}
}
+182 -7
View File
@@ -76,6 +76,8 @@ pub struct Response {
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PlanningResult {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub native_recovery: Option<rmm_domain::apt_transaction::AptNativeRecovery>,
pub observed_at: chrono::DateTime<chrono::Utc>,
pub fixture_package: Option<FixturePackage>,
pub baseline_sha256: String,
@@ -106,6 +108,16 @@ pub struct PlanningReceipt {
}
impl PlanningResult {
pub fn validate(&self, now: chrono::DateTime<chrono::Utc>) -> Result<()> {
if let Some(reference) = &self.native_recovery {
ensure!(
reference.validate()
&& self
.fixture_package
.as_ref()
.is_some_and(|p| p.version == "1.0" && p.status == "install ok unpacked"),
"APT_RECOVERY_PLANNING_SCOPE"
);
}
ensure!(
self.observed_at <= now
&& now - self.observed_at < chrono::Duration::seconds(30)
@@ -235,18 +247,28 @@ pub fn validate_response(request: &Request, response: &Response) -> Result<()> {
ensure!(
matches!(
request.operation.as_str(),
"apt_readiness_v1" | "apt_planning_v1"
"apt_readiness_v1" | "apt_planning_v1" | "apt_recovery_planning_v1"
),
"APT_PROBE_OPERATION"
);
if let Some(planning) = &response.planning {
ensure!(
request.operation == "apt_planning_v1",
matches!(
request.operation.as_str(),
"apt_planning_v1" | "apt_recovery_planning_v1"
),
"APT_PLANNING_OPERATION"
);
planning.validate(chrono::Utc::now())?;
ensure!(
(request.operation == "apt_recovery_planning_v1") == planning.native_recovery.is_some(),
"APT_RECOVERY_PLANNING_OPERATION"
);
}
if request.operation == "apt_planning_v1" {
if matches!(
request.operation.as_str(),
"apt_planning_v1" | "apt_recovery_planning_v1"
) {
ensure!(
response.planning.is_some()
&& !response.fixture_acceptance_ready
@@ -292,6 +314,9 @@ pub fn probe(socket: &Path, binding: &Binding, pin: &Pin) -> Result<Response> {
pub fn planning(socket: &Path, binding: &Binding, pin: &Pin) -> Result<Response> {
probe_operation(socket, binding, pin, "apt_planning_v1")
}
pub fn planning_for_recovery(socket: &Path, binding: &Binding, pin: &Pin) -> Result<Response> {
probe_operation(socket, binding, pin, "apt_recovery_planning_v1")
}
fn probe_operation(
socket: &Path,
binding: &Binding,
@@ -368,7 +393,7 @@ pub fn answer(
ensure!(
matches!(
request.operation.as_str(),
"apt_readiness_v1" | "apt_planning_v1"
"apt_readiness_v1" | "apt_planning_v1" | "apt_recovery_planning_v1"
) && !request.challenge.is_nil()
&& request.identity == Identity::from_binding(binding)?,
"APT_PROBE_REQUEST_BINDING"
@@ -378,11 +403,21 @@ pub fn answer(
stack == request.expected_stack_sha256,
"APT_PROBE_STACK_MISMATCH"
);
if request.operation == "apt_planning_v1" {
if matches!(
request.operation.as_str(),
"apt_planning_v1" | "apt_recovery_planning_v1"
) {
// A metadata-only process is bounded separately from package execution.
// Missing/unsafe/dirty/unprefetched state closes only this observation.
let planning: PlanningResult =
serde_json::from_slice(&rmm_agent_linux::apt_planning_metadata()?)?;
let planning: PlanningResult = if request.operation == "apt_recovery_planning_v1" {
recovery_planning(ledger, binding)?
} else {
serde_json::from_slice(&rmm_agent_linux::apt_planning_metadata()?)?
};
ensure!(
(request.operation == "apt_recovery_planning_v1") == planning.native_recovery.is_some(),
"APT_RECOVERY_PLANNING_OPERATION"
);
planning.validate(chrono::Utc::now())?;
ensure!(
planning.runtime_sha256 == config.runtime_sha256
@@ -475,14 +510,154 @@ pub fn answer(
Ok(response)
}
fn recovery_planning(ledger: &rusqlite::Connection, binding: &Binding) -> Result<PlanningResult> {
use anyhow::Context;
use std::{
os::unix::process::CommandExt,
process::{Command, Stdio},
time::{Duration, Instant},
};
ensure!(
ledger.query_row(
"SELECT count(*) FROM consumed WHERE result IS NULL",
[],
|r| r.get::<_, u64>(0)
)? == 0,
"APT_RECOVERY_PLANNING_UNRESOLVED"
);
apt::verify_installation()?;
let partial = crate::apt_reconcile::closed_partial(ledger, binding, None)?;
let proof: serde_json::Value = serde_json::from_slice(&partial.proof)?;
let input = serde_json::to_vec(
&serde_json::json!({"native_recovery":partial.reference,"proof":proof}),
)?;
ensure!(
input.len() <= 1024 * 1024,
"APT_RECOVERY_PLANNING_INPUT_LIMIT"
);
let mut child = Command::new("/usr/bin/python3")
.args(["-I", apt::CODE, "recovery-planning"])
.env_clear()
.env("PATH", "/usr/sbin:/usr/bin:/sbin:/bin")
.env("LC_ALL", "C")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::null())
.process_group(0)
.spawn()?;
let result = (|| -> Result<Vec<u8>> {
let mut stdin = Some(child.stdin.take().context("APT_RECOVERY_PLANNING_STDIN")?);
let mut stdout = child
.stdout
.take()
.context("APT_RECOVERY_PLANNING_STDOUT")?;
for fd in [
stdin
.as_ref()
.context("APT_RECOVERY_PLANNING_STDIN")?
.as_raw_fd(),
stdout.as_raw_fd(),
] {
let flags = unsafe { libc::fcntl(fd, libc::F_GETFL) };
ensure!(
flags >= 0
&& unsafe { libc::fcntl(fd, libc::F_SETFL, flags | libc::O_NONBLOCK) } >= 0,
"APT_RECOVERY_PLANNING_PIPE"
);
}
let deadline = Instant::now() + Duration::from_secs(4);
let mut written = 0;
let mut output = vec![];
let mut exited = None;
let mut eof = false;
loop {
ensure!(Instant::now() < deadline, "APT_RECOVERY_PLANNING_TIMEOUT");
if let Some(pipe) = stdin.as_mut() {
match pipe.write(&input[written..]) {
Ok(n) => written += n,
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {}
Err(e) => return Err(e.into()),
};
if written == input.len() {
stdin = None;
}
}
let mut buf = [0; 4096];
for _ in 0..16 {
match stdout.read(&mut buf) {
Ok(0) => {
eof = true;
break;
}
Ok(n) => {
ensure!(
output.len() + n <= 32768,
"APT_RECOVERY_PLANNING_OUTPUT_LIMIT"
);
output.extend_from_slice(&buf[..n]);
}
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => break,
Err(e) => return Err(e.into()),
}
}
if exited.is_none() {
exited = child.try_wait()?;
}
if eof && let Some(status) = exited {
ensure!(
status.success() && written == input.len(),
"APT_RECOVERY_PLANNING_FAILED"
);
return Ok(output);
}
std::thread::sleep(Duration::from_millis(5));
}
})();
unsafe {
libc::kill(-(child.id() as i32), libc::SIGKILL);
}
let _ = child.wait();
let planning: PlanningResult = serde_json::from_slice(&result?)?;
ensure!(
planning.native_recovery.as_ref() == Some(&partial.reference)
&& planning.baseline_sha256 == partial.baseline_sha256
&& planning.status_fingerprint == partial.status_fingerprint,
"APT_RECOVERY_PLANNING_PROOF_BINDING"
);
Ok(planning)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn recovery_planning_is_a_distinct_bound_partial_observation() {
let mut p = planning_fixture();
let r = rmm_domain::apt_transaction::AptNativeRecovery {
schema_version: 1,
previous_grant_id: Uuid::new_v4(),
previous_attempt_id: Uuid::new_v4(),
partial_proof_sha256: "a".repeat(64),
};
p.native_recovery = Some(r);
assert!(p.validate(chrono::Utc::now()).is_err());
p.fixture_package = Some(FixturePackage {
version: "1.0".into(),
status: "install ok unpacked".into(),
});
p.validate(chrono::Utc::now()).unwrap();
p.fixture_package.as_mut().unwrap().status = "install ok installed".into();
assert!(p.validate(chrono::Utc::now()).is_err());
p.fixture_package.as_mut().unwrap().status = "install ok unpacked".into();
p.native_recovery.as_mut().unwrap().previous_grant_id = Uuid::nil();
assert!(p.validate(chrono::Utc::now()).is_err());
}
fn planning_fixture() -> PlanningResult {
let raw =
include_str!("../../../tests/apt_transaction/fixtures/planning-canonical.json").trim();
let runtime = serde_json::from_str(raw).unwrap();
PlanningResult {
native_recovery: None,
observed_at: chrono::Utc::now(),
fixture_package: None,
baseline_sha256: "b".repeat(64),
+12 -4
View File
@@ -12,14 +12,15 @@ function readPrivate(file) {
return JSON.parse(fs.readFileSync(file, 'utf8'));
}
function checkAction(p, expected) {
const native = ['apt_install_retry', 'apt_native_update'].includes(expected.case);
const version = expected.case === 'apt_install_retry' ? '1.0' : '1.1';
const recovery = expected.case === 'apt_configure_recovery';
const native = recovery || ['apt_install_retry', 'apt_native_update'].includes(expected.case);
const version = recovery || expected.case === 'apt_install_retry' ? '1.0' : '1.1';
const recipe = version === '1.0' ? 'rmm-apt-fixture-install-1.0' : 'rmm-apt-fixture-update-1.1';
const action = p.action; const m = action.apt_manifest; const tx = m.resolved_apt_transaction;
assert(action.action === (native ? 'apt_native_acceptance' : expected.case));
assert(p.execution_identity === 'root' && p.max_runtime_seconds === 300 && p.max_output_bytes === 65536);
assert(m.type === 'rmm.apt.helper-action' && m.execution_profile === 'dev-test' && m.action === (native ? 'apt-native-acceptance' : 'apt-execute'));
assert(m.schema_version === (expected.case === 'apt_install_retry' ? 3 : 2));
assert(m.schema_version === (recovery ? 4 : expected.case === 'apt_install_retry' ? 3 : 2));
assert(tx.recipe_id === recipe && tx.recipe_version === '1' && tx.no_reboot === true && tx.packages.length === 1);
const pkg = tx.packages[0];
const sha = version === '1.0' ? '74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867' : 'ef67c9fe0ba1443fcfe465768e1204763063c369a2a1da04af6027d8a9c00491';
@@ -27,6 +28,13 @@ function checkAction(p, expected) {
assert(crypto.createHash('sha256').update(Buffer.from(m.transaction_bytes)).digest('hex') === m.transaction_sha256);
assert(equal(JSON.parse(Buffer.from(m.transaction_bytes)), tx));
assert(equal(m, expected.request.parameters.apt_manifest));
if (recovery) {
assert(tx.schema_version === 2 && tx.operation === 'configure_only' && pkg.old_version === '1.0');
assert(m.native_retry === undefined && m.native_recovery.schema_version === 1);
assert(m.native_recovery.previous_grant_id === '31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0');
assert(m.native_recovery.previous_attempt_id !== p.attempt_id);
assert(m.native_recovery.partial_proof_sha256 === 'dc3bf3870ea77c12f9291bac712c53ae72194eaec980a8646155a7fb5c0dbe21');
} else assert(tx.schema_version === 1 && tx.operation === undefined);
if (expected.case === 'apt_install_retry') {
assert(m.native_retry.schema_version === 1 && m.native_retry.bootstrap_marker_sha256 === 'ec84aa4df8065f0b54b282bd273a6f342f07a6d47312289608389d05c7fb6053');
assert(m.native_retry.previous_attempt_id !== p.attempt_id);
@@ -34,7 +42,7 @@ function checkAction(p, expected) {
}
(async () => {
const file = path.resolve(process.argv[2]); const expected = readPrivate(file);
assert(expected.profile === 'dev/test' && ['apt_install_retry', 'apt_native_update', 'ensure_package', 'apply_updates'].includes(expected.case) && expected.expected_principal === 'simulated-testprincipal-a');
assert(expected.profile === 'dev/test' && ['apt_configure_recovery', 'apt_install_retry', 'apt_native_update', 'ensure_package', 'apply_updates'].includes(expected.case) && expected.expected_principal === 'simulated-testprincipal-a');
const login = readPrivate(path.join(root, 'credentials/server-browser-login.json'));
const browsers = path.join(root, 'web/node_modules/.cache/playwright-browsers');
const version = fs.readdirSync(browsers).find(x => /^chromium-/.test(x));
+120
View File
@@ -0,0 +1,120 @@
#!/usr/bin/env python3
"""Exact configure-only recovery followed by separate fixture upgrade/noops."""
import argparse
import datetime as dt
import hashlib
import json
import os
import time
import uuid
import cloud_apt_retry as prior
import cloud_root_evidence
import cloud_root_policy
cloud=prior.cloud
require=cloud.require
BASE=cloud.ROOT/'devstate/cloud-apt-recovery'
STATE=BASE/'cases'
CASES=('apt_configure_recovery','apt_native_update','ensure_package','apply_updates')
def recovery_request(device,target):
m=cloud.contract;data=prior.adapters.planning_from_device(device,recovery=True)
closed=m.protected_json(BASE/'readonly-central-result.json')['result']
reference=dict(schema_version=1,previous_grant_id=closed['result']['grant_id'],previous_attempt_id=closed['attempt_id'],
partial_proof_sha256=closed['result']['evidence']['apt']['reconciliation_proof_sha256'])
require(closed['state']=='failed' and closed['result']['error_code']=='APT_PARTIAL_UNCONFIGURED_VERIFIED' and
data['native_recovery']==reference,'exact previously closed partial reference')
pin=prior.adapters.PINS['1.0'];start=m.now();receipt=data['prefetch'][pin]
require(receipt['schema_version']==1 and receipt['sha256']==pin and receipt['size']==20672 and
receipt['sealed_at_ms']<=int(start.timestamp()*1000),'actual pregrant archive receipt')
tx=dict(schema_version=2,operation='configure_only',recipe_id='rmm-apt-fixture-install-1.0',recipe_version='1',
platform='ubuntu-24.04-amd64',resolver_config_version='rmm-apt-local-v1',no_reboot=True,
status_fingerprint=data['status_fingerprint'],baseline_sha256=data['baseline_sha256'],packages=[
dict(name='rmm-mvp-test',architecture='all',old_version='1.0',new_version='1.0',origin='rmm-test',sha256=pin,
size=20672,archive_path='/var/lib/rmm-apt-transaction/archives/'+pin+'.deb')])
raw=prior.adapters.canonical(tx)
manifest=dict(type='rmm.apt.helper-action',schema_version=4,action='apt-native-acceptance',execution_profile='dev-test',
transaction_sha256=hashlib.sha256(raw).hexdigest(),resolved_apt_transaction=tx,transaction_bytes=list(raw),
native_recovery=reference,test_result_id='configure-recovery-'+uuid.uuid4().hex,
**{k:data[k] for k in ('provider_sha256','hook_sha256','apt_config_sha256','runtime_sha256')})
m.validate_apt_manifest(manifest)
return dict(tenant_id=target['tenant_id'],action='apt_native_acceptance',targets=dict(asset_ids=[target['asset_id']]),
parameters=dict(execution_identity='root',timeout_seconds=300,max_output_bytes=65536,
recipe_id=tx['recipe_id'],recipe_version='1',apt_manifest=manifest),
schedule=m.schedule(start,start+dt.timedelta(minutes=15)),rollout=dict(max_parallel=1,halt_after_failures=1),
reason='Configure ONLY the exactly proven unpacked fixture1.0; new attempt and separate recovery record; no unpack, pending packages, reinstall or reboot')
def enable():
m=cloud.contract;require(prior.prior.evidence('gate')['unresolved']==0,'no unresolved attempt')
ready=m.protected_json(BASE/'configure-runtime.json')
require(ready['completed'] and ready['readiness_only'] and ready['preserved_state'] and not ready['native_acceptance'],
'qualified native probe, no invented package acceptance')
target=prior.prior.identity();pin=ready['apt_pin'];identity=pin['identity']
require(all(identity[k]==target[k] for k in target),'same permanent Cloud VM')
endpoint=cloud.bootstrap.rpc('linux-vm.conf',prior.switch_endpoint,dict(id=str(uuid.uuid4()),enabled=True,
agent_id=target['agent_id'],binary_sha256=ready['helper_sha256']))
m.write_private(BASE/'recovery-endpoint-enabled.json',endpoint)
peers=cloud.bootstrap.rpc('linux-vm.conf',cloud_root_evidence.inspect_helpers,target)
require(peers['ledger']['faults']==0 and peers['apt']['provider_stack_sha256']==pin['provider_stack_sha256'],
'actual fixed helper peer and stack')
scope={k:identity[k] for k in ('tenant_id','asset_id','agent_id','enrollment_generation','assignment_version')}
scope.update(principals=['simulated-testprincipal-a'],helper_policy_sha256=pin['provider_stack_sha256'],
acceptance_evidence_id='cloud-configure-recovery-probe:'+ready['readiness_sha256'],allowed_services=[],allow_root_scripts=False,allow_reboot=False,
apt=dict(allow_native_acceptance=True,allow_execute=True,runtime_sha256=ready['runtime_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()))
policy=dict(schema_version=1,profile='development',expires_at=(m.now()+dt.timedelta(hours=1)).isoformat(),scopes=[scope])
old=m.protected_json(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))
m.write_private(BASE/'recovery-policy.json',dict(record,policy=policy))
print('Fixed APT runtime endpoint and expiring limits enabled; no job or approval created')
def accept(case):
m=cloud.contract;target=prior.prior.identity()
require(prior.prior.evidence('gate')['unresolved']==0,'no unresolved attempt')
# A maintenance restart only refreshes passive inventory from the preserved
# agent; it never issues a package diagnostic or executes a job.
deadline=time.monotonic()+90
while True:
device=cloud.Backend().call('inventory.get_device',{k:target[k] for k in ('tenant_id','asset_id')})
try:
data=prior.adapters.planning_from_device(device,recovery=case=='apt_configure_recovery')
break
except m.GuardError:
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
prior.accept(case,request=request,folder_root=STATE)
def close():
m=cloud.contract;require(prior.prior.evidence('gate')['unresolved']==0,'no unresolved attempt')
record=m.protected_json(BASE/'recovery-policy.json')
closed=cloud.bootstrap.rpc('server.conf',cloud_root_policy.close_policy,dict(expected_sha256=record['policy_sha256'],backup=record['backup']))
m.write_private(BASE/'recovery-policy-closed.json',closed)
ready=m.protected_json(BASE/'configure-runtime.json')
endpoint=cloud.bootstrap.rpc('linux-vm.conf',prior.switch_endpoint,dict(id=str(uuid.uuid4()),enabled=False,
agent_id=prior.prior.identity()['agent_id'],binary_sha256=ready['helper_sha256']))
m.write_private(BASE/'recovery-endpoint-disabled.json',endpoint)
print('APT test limits closed and endpoint stopped; original histories retained')
def main():
p=argparse.ArgumentParser(description=__doc__);p.add_argument('action',choices=('enable','accept','finish','close'));p.add_argument('--case',choices=CASES)
args=p.parse_args();os.umask(0o077);STATE.mkdir(mode=0o700,exist_ok=True)
if args.action in ('accept','finish'):
require(args.case is not None,'one fixed case required')
if args.action=='accept':accept(args.case)
else:prior.finish(args.case,folder_root=STATE)
else:(enable if args.action=='enable' else close)()
if __name__=='__main__':
try:main()
except Exception as error:
message=str(error)
print(message if message.startswith('remote bootstrap incomplete: ') else 'CLOUD_APT_RECOVERY_INCOMPLETE:'+type(error).__name__)
raise SystemExit(2) from None
+332
View File
@@ -0,0 +1,332 @@
#!/usr/bin/env python3
"""Versioned Cloud runtime upgrade for the one signed, closed APT partial.
No package recovery, approval or enrollment. Original active hook, once markers,
signed histories and SQLite state survive the maintenance/probe byte-for-byte.
The APT endpoint remains absent; only the copied-database native probe runs.
"""
import base64
import argparse
import hashlib
import importlib.util
import json
import os
from pathlib import Path
import sys
import uuid
import cloud_apt_reconcile_upgrade as previous
cloud = previous.cloud
require = cloud.require
STATE = previous.STATE
PARTIAL_GRANT = '31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0'
PARTIAL_PROOF = 'dc3bf3870ea77c12f9291bac712c53ae72194eaec980a8646155a7fb5c0dbe21'
PINS = dict(helper='ab7bbc87c75f68c1aa3d35941db9a2ece8d398f92a67e655b1d420bbd3287bd9',
agent='44ae91151ff08a186ce4dff587697eb604cb7c0a22f0c9d618724a9ba8a67234',
provider='5ff260f75cb2959678f6be729d3a806a4ea29febd5ae4003317fed41afc25327')
def closed_policy(payload):
import datetime as dt
path = Path('/opt/rust-discovery/devstate/root-policy/policy.json')
require(not path.is_symlink() and path.stat().st_uid == 10001 and path.stat().st_mode & 0o777 == 0o600, 'safe Root policy required')
raw = path.read_bytes(); policy = json.loads(raw)
require(policy['schema_version'] == 1 and policy['profile'] == 'development' and
dt.datetime.fromisoformat(policy['expires_at']) <= dt.datetime.now(dt.timezone.utc), 'Root policy must stay closed')
return dict(closed=True, policy_sha256=hashlib.sha256(raw).hexdigest())
def installed_metadata(payload):
pins = {'/usr/local/libexec/rmm-privileged-helper': payload['helper'],
'/usr/local/libexec/rmm-agent-remote': payload['agent'],
'/usr/lib/rmm-apt-transaction/apt_transaction.py': payload['provider']}
names = list(pins) + ['/etc/rmm/apt-helper.json', '/etc/rmm-remote/apt-helper-proof.json',
'/var/lib/rmm-apt-transaction/install-metadata.json']
files = {}
for name in names:
p = Path(name)
require(not p.is_symlink() and p.is_file() and p.stat().st_uid == 0 and p.stat().st_mode & 0o022 == 0, 'safe installed file required')
files[name] = hashlib.sha256(p.read_bytes()).hexdigest()
require(all(files[name] == pin for name, pin in pins.items()), 'reviewed readonly runtime required')
return dict(files=files)
def upgrade(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')
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(payload['partial_grant'] == '31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0' and
payload['partial_proof_sha256'] == 'dc3bf3870ea77c12f9291bac712c53ae72194eaec980a8646155a7fb5c0dbe21', 'one reviewed closed partial only')
with sqlite3.connect(ledger.as_uri()+'?mode=ro', uri=True) as db:
require(db.execute('PRAGMA integrity_check').fetchone()[0] == 'ok', 'Root ledger integrity')
require({r[0] for r in db.execute('SELECT grant_id FROM consumed')} == set(payload['expected_grants']) and
db.execute('SELECT count(*) FROM consumed WHERE result IS NULL').fetchone()[0] == 0 and
db.execute('SELECT count(*) FROM helper_sync_meta WHERE fault IS NOT NULL').fetchone()[0] == 0, 'exact known closed Root attempts')
db.row_factory = sqlite3.Row
rows = db.execute('SELECT * FROM apt_partial_reconciliations').fetchall()
require(len(rows) == 1, 'one immutable 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], 'immutable 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'], 'immutable partial bytes drift')
require(row['grant_id'] == payload['partial_grant'] and sha(row['proof']) == payload['partial_proof_sha256'], 'closed proof hash required')
proof = json.loads(row['proof']); result = db.execute('SELECT c.result,e.outcome,e.start FROM consumed c JOIN execution_evidence e USING(grant_id) WHERE grant_id=?', (payload['partial_grant'],)).fetchone()
classified = json.loads(row['classified_outcome'])
require(json.loads(result['result']) == json.loads(result['outcome']) == classified and
classified['state'] == 'failed' and classified['error_code'] == 'APT_PARTIAL_UNCONFIGURED_VERIFIED', 'normal signed RootSync closure required')
saved = json.loads(result['start'])
# save_start nests Request through serde_json::Value (sorted keys),
# whereas the immutable proof hashes serde's Request struct codec.
request_fields = ('job_bytes','permit_bytes','signature','plan_hash','authorization_id')
require(set(saved['request']) == set(request_fields), 'original Request fields required')
request_bytes = json.dumps({key:saved['request'][key] for key in request_fields},
separators=(',', ':'), ensure_ascii=False).encode()
require(sha(request_bytes) == row['original_request_sha256'], 'original signed request hash required')
require(proof['grant_id'] == payload['partial_grant'] and proof['attempt_id'] == payload['partial_attempt'] and
proof['snapshot']['rmm-mvp-test:all'] == {'version':'1.0','status':'install ok unpacked'}, 'exact partial fixture required')
with sqlite3.connect((state/'journal.sqlite').as_uri()+'?mode=ro', uri=True) as db:
require(db.execute('PRAGMA integrity_check').fetchone()[0] == 'ok' and
db.execute("SELECT count(*) FROM job_attempts WHERE state NOT IN ('succeeded','failed','cancelled','expired')").fetchone()[0] == 0 and
db.execute('SELECT count(*) FROM reconcile_meta WHERE fault IS NOT NULL').fetchone()[0] == 0, 'no unresolved or faulted agent attempt')
require(Path('/usr/share/rmm-mvp-test/version').read_bytes() == b'1.0\n', 'existing unpacked fixture payload required')
require(not list(base.glob('acceptance-*.json')) and not list(base.glob('pending-acceptance-*.json')) and
not list(base.glob('recovery-*.json')) and not list(base.glob('pending-recovery-*.json')), 'no existing acceptance or recovery attempt')
return proof
def bound_partial(proof):
keys = 'transaction_sha256 job_payload_sha256 effect_armed_ledger_id grant_id job_id attempt_id authorization_id plan_sha256'.split()
value = json.loads(run(['/usr/bin/python3','-I',str(provider),'verify-partial'], input=canonical({k:proof[k] for k in keys})))
require(value['effect_state'] == 'known_failed' and value['code'] == 'APT_PARTIAL_UNCONFIGURED_VERIFIED' and
{k:v for k,v in value['proof'].items() if k != 'checked_at_ms'} ==
{k:v for k,v in proof.items() if k != 'checked_at_ms'}, 'fresh original-bound partial state required')
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() == reduced, 'APT endpoint must remain absent')
require(run(['systemctl','show','rmm-apt-helper.service','-p','ActiveState','--value']).strip() == b'inactive', 'APT helper must be stopped')
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')
partial = guard(); bound_partial(partial)
raw = {name:base64.b64decode(payload[name], validate=True) for name in ('helper','agent','provider')}
pins = {'helper':'ab7bbc87c75f68c1aa3d35941db9a2ece8d398f92a67e655b1d420bbd3287bd9',
'agent':'44ae91151ff08a186ce4dff587697eb604cb7c0a22f0c9d618724a9ba8a67234',
'provider':'5ff260f75cb2959678f6be729d3a806a4ea29febd5ae4003317fed41afc25327'}
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=False)
backup = Path('/var/lib/rmm-bootstrap-history')/('cloud-configure-recovery-'+payload['id']); backup.mkdir(mode=0o700)
report = dict(stage='validated', completed=False, backup=str(backup), package_effects=False,
apt_endpoint_enabled=False, 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)
partial = guard(); bound_partial(partial)
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(); bound_partial(guard())
report.update(stage='installed_preserved',preserved_state=True,helper_sha256=pins['helper'],agent_sha256=pins['agent'],
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,
'partial 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')
bound_partial(guard())
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():
m = cloud.contract
checkpoint = m.protected_json(previous.apt.STATE/'apt_install_retry/checkpoint.json')
readonly = m.protected_json(STATE/'readonly-result-first.json')
require(readonly['unresolved'] == readonly['faults'] == 0 and readonly['original_result']['state'] == 'failed' and
readonly['original_result']['error_code'] == 'APT_PARTIAL_UNCONFIGURED_VERIFIED', 'actual closed partial evidence required')
require(len(readonly['proof']) == 1 and readonly['proof'][0]['grant_id'] == PARTIAL_GRANT and readonly['proof'][0]['proof_sha256'] == PARTIAL_PROOF, 'one reviewed actual partial proof')
folders = [cloud.ROOT/'devstate/cloud-root/cases'/n for n in ('service_setup','service_start','service_stop','apt_native_install')]
folders += [previous.apt.prior.STATE/n for n in ('diagnosis','diagnosis-acquisition','diagnosis-hook','diagnosis-local-hook')]
query = cloud.ROOT/'devstate/cloud-root/cases/query_logs/checkpoint.json'
if query.exists():
require(m.protected_json(query)['verified'] is True, 'actual completed query_logs checkpoint required')
folders.append(query.parent)
expected = [str(uuid.UUID(m.protected_json(p/'checkpoint.json')['result']['result']['grant_id'])) for p in folders] + [PARTIAL_GRANT]
require(len(expected) == len(set(expected)) and len(expected) in (9,10), 'exact known checkpoint grants required')
raw = {name:(STATE/filename).read_bytes() for name,filename in (
('helper','helper-configure-recovery'),('agent','agent-configure-recovery'),('provider','provider-configure-recovery.py'))}
require(all(hashlib.sha256(raw[name]).hexdigest() == pin for name,pin in PINS.items()), 'qualified artifacts changed')
require(raw['provider'] == (cloud.ROOT/'tools/apt-transaction/apt_transaction.py').read_bytes(), 'source/qualified provider mismatch')
spec = importlib.util.spec_from_file_location('reviewed_recovery_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=previous.apt.prior.identity()['agent_id'],expected_grants=expected,
partial_grant=PARTIAL_GRANT,partial_attempt=checkpoint['plan']['jobs'][0]['attempt_id'],partial_proof_sha256=PARTIAL_PROOF,
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(),
**{name:base64.b64encode(data).decode() for name,data in raw.items()}, **{name+'_sha256':pin for name,pin in PINS.items()})
def main():
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--preflight-only', action='store_true')
args=parser.parse_args()
os.umask(0o077);STATE.mkdir(mode=0o700,exist_ok=True)
require(not (STATE/'configure-runtime.json').exists(), 'existing qualified runtime retained; no implicit repeat')
require(previous.apt.prior.evidence('gate')['unresolved'] == 0, 'no unresolved central job')
policy = cloud.bootstrap.rpc('server.conf',closed_policy,{})
installed = cloud.contract.protected_json(cloud.ROOT/'devstate/remote-vm.json')
old = cloud.bootstrap.rpc('linux-vm.conf',installed_metadata,dict(
helper='5ad30cdf6e258df1efd05958ecdb6545e76568d84389a2800ed449b01118fc03',
agent=installed['binary_sha256'],provider='edd1950db26b3ca0b2c1335ff65bf88d5a83e3c946159cbcbb56d8f562252d70'))
payload = dict(build_payload(),old_files=old['files'],preflight_only=args.preflight_only)
report = cloud.bootstrap.rpc('linux-vm.conf',upgrade,payload)
if args.preflight_only:
require(report.get('preflight_only') is True and report.get('maintenance_mutations') is False, 'fixed preflight response required')
print(report);return
cloud.contract.write_private(STATE/('runtime-upgrade-'+payload['id']+'.json'),dict(report,closed_policy=policy))
require(report['completed'], 'preserve incomplete maintenance report; never repeat automatically')
previous.record_agent_upgrade(report,installed)
cloud.contract.write_private(STATE/'configure-runtime.json',report)
print({k:report[k] for k in ('completed','stage','preserved_state','journals_preserved_before_restart','readiness_only','apt_endpoint_enabled')})
if __name__ == '__main__':
try: main()
except Exception as error:
print('CLOUD_APT_RECOVERY_UPGRADE_INCOMPLETE:'+type(error).__name__)
prefix='remote bootstrap incomplete: '
if isinstance(error,RuntimeError) and str(error).startswith(prefix):
try:
detail=json.loads(str(error)[len(prefix):])
safe=dict(error_class=str(detail['error_class']),frames=[
dict(function=str(frame['function']),line=int(frame['line'])) for frame in detail['frames']])
print('REMOTE_BOOTSTRAP_INCOMPLETE:'+json.dumps(safe))
except (ValueError,TypeError,KeyError):pass
raise SystemExit(2) from None
+15 -9
View File
@@ -180,14 +180,15 @@ def enable():
print('APT-only expiring limits installed; no job or approval created')
def accept(case):
def accept(case, *, request=None, folder_root=STATE):
m = cloud.contract; target = prior.identity(); backend = cloud.Backend()
require(prior.evidence('gate')['unresolved'] == 0, 'unresolved central job; no new attempt')
device = backend.call('inventory.get_device', {k:target[k] for k in ('tenant_id','asset_id')})
require(device['presence'] == 'online', 'online cloud VM required')
planning = adapters.planning_from_device(device)
source_case = 'apt_native_install' if case == 'apt_install_retry' else case
request = m.case_input(source_case, target, planning=planning)
if request is None:
planning = adapters.planning_from_device(device)
source_case = 'apt_native_install' if case == 'apt_install_retry' else case
request = m.case_input(source_case, target, planning=planning)
if case == 'apt_install_retry':
old = m.protected_json(cloud.ROOT/'devstate/cloud-root/cases/apt_native_install/checkpoint.json')
require(old['result']['state'] == 'failed' and old['result']['result']['error_code'] == 'HOOK_NOT_HANDED_OFF', 'original definitive pre-hook failure')
@@ -197,7 +198,7 @@ def accept(case):
bootstrap_marker_sha256='ec84aa4df8065f0b54b282bd273a6f342f07a6d47312289608389d05c7fb6053'))
request['reason'] = 'One new UI-approved fixture attempt: preserve original failed attempt, verify known no-handoff history, separate retry tombstone; never reboot'
require({'rmm.sync.v1','helper.root.v1','root:'+request['action'],request['action']} <= set(device['capabilities']), 'native root capability required')
folder = STATE/case; folder.mkdir(mode=0o700, exist_ok=False)
folder = folder_root/case; folder.mkdir(mode=0o700, exist_ok=False)
common = dict(profile='dev/test', case=case, expected_principal='simulated-testprincipal-a', **target)
prepare = folder/'prepare.json'; output = folder/'prepared.json'
m.write_private(prepare, dict(common, phase='prepare', request=request, output_file=str(output)))
@@ -216,11 +217,11 @@ def accept(case):
m.write_private(folder/'checkpoint.json', checkpoint)
approval = folder/'approve.json'; m.write_private(approval, dict(checkpoint, phase='approve'))
print(case+': pending 0/0/0 verified; separate actual UI approval', flush=True); browser(approval)
finish(case)
finish(case,folder_root=folder_root)
def finish(case):
m = cloud.contract; folder = STATE/case; checkpoint = m.protected_json(folder/'checkpoint.json')
def finish(case, *, folder_root=STATE):
m = cloud.contract; folder = folder_root/case; checkpoint = m.protected_json(folder/'checkpoint.json')
job = checkpoint['plan']['jobs'][0]; backend = cloud.Backend(); end = time.monotonic()+420
while True:
result = backend.call('jobs.get', dict(tenant_id=checkpoint['tenant_id'], job_id=job['job_id']))
@@ -239,7 +240,12 @@ def finish(case):
package = manifest['resolved_apt_transaction']['packages'][0]
require(apt['packages'] == [dict(name='rmm-mvp-test', architecture='all', version=package['new_version'])] and
apt['fixture_payload_sha256'] == hashlib.sha256((package['new_version']+'\n').encode()).hexdigest(), 'native version/payload proof')
if case in ('apt_install_retry','apt_native_update'):
if case=='apt_configure_recovery':
require(apt.get('native_recovery') is True and apt.get('partial_proof_sha256')==manifest['native_recovery']['partial_proof_sha256'] and
len(apt.get('recovery_record_sha256',''))==64 and 'native_record_sha256' not in apt and
apt['test_result_id']==manifest['test_result_id'] and apt['noProductionEvidence'] is True,
'separate configure-only recovery record; never fresh installation acceptance')
elif case in ('apt_install_retry','apt_native_update'):
require(apt['test_acceptance'] is True and apt['noProductionEvidence'] is True and apt['test_result_id'] == manifest['test_result_id'] and
len(apt['native_record_sha256']) == 64, 'real scoped native acceptance required')
else:
+15 -4
View File
@@ -186,21 +186,32 @@ def validate_apt_manifest(value):
"""Pure format verification, NEVER evidence that live planning/acceptance ran."""
fields = {'type', 'schema_version', 'action', 'execution_profile', 'transaction_sha256', 'resolved_apt_transaction',
'transaction_bytes', 'provider_sha256', 'hook_sha256', 'apt_config_sha256', 'runtime_sha256', 'test_result_id'}
require(set(value) == fields and value['type'] == 'rmm.apt.helper-action' and value['schema_version'] == 2
recovery=value.get('schema_version')==4
if recovery:fields.add('native_recovery')
require(set(value) == fields and value['type'] == 'rmm.apt.helper-action' and value['schema_version'] in (2,4)
and value['action'] in ('apt-native-acceptance', 'apt-execute') and value['execution_profile'] == 'dev-test', 'apt_manifest_schema')
if recovery:
reference=value['native_recovery']
require(value['action']=='apt-native-acceptance' and set(reference)=={'schema_version','previous_grant_id','previous_attempt_id','partial_proof_sha256'}
and reference['schema_version']==1 and all(str(uuid.UUID(reference[k]))==reference[k] and uuid.UUID(reference[k]).int!=0
for k in ('previous_grant_id','previous_attempt_id')) and re.fullmatch('[a-f0-9]{64}',reference['partial_proof_sha256']),
'typed native recovery reference')
raw = value['transaction_bytes']
require(isinstance(raw, list) and len(raw) <= 65536 and all(type(n) is int and 0 <= n < 256 for n in raw), 'apt_exact_transaction_bytes')
raw = bytes(raw)
require(hashlib.sha256(raw).hexdigest() == value['transaction_sha256'], 'apt_transaction_hash')
transaction = json.loads(raw, object_pairs_hook=strict_object)
require(transaction == value['resolved_apt_transaction'] and set(transaction) == {'schema_version', 'recipe_id', 'recipe_version', 'platform',
'resolver_config_version', 'no_reboot', 'status_fingerprint', 'baseline_sha256', 'packages'}, 'apt_full_typed_transaction')
require(type(transaction['schema_version']) is int and transaction['schema_version'] == 1 and transaction['recipe_version'] == '1' and transaction['platform'] == 'ubuntu-24.04-amd64'
txfields={'schema_version','recipe_id','recipe_version','platform','resolver_config_version','no_reboot','status_fingerprint','baseline_sha256','packages'}
if recovery:txfields.add('operation')
require(transaction == value['resolved_apt_transaction'] and set(transaction) == txfields, 'apt_full_typed_transaction')
require(type(transaction['schema_version']) is int and transaction['schema_version'] == (2 if recovery else 1) and transaction['recipe_version'] == '1' and transaction['platform'] == 'ubuntu-24.04-amd64'
and transaction['resolver_config_version'] == 'rmm-apt-local-v1' and transaction['no_reboot'] is True, 'apt_fixture_profile_no_reboot')
if recovery:require(transaction['operation']=='configure_only' and transaction['recipe_id']=='rmm-apt-fixture-install-1.0','same fixture configure-only mode')
pins = {'rmm-apt-fixture-install-1.0': (None, '1.0', '74036ae81223deab3aae994fd2a2a695af408741777e1ce17dcb4e32f1235867'),
'rmm-apt-fixture-update-1.1': ('1.0', '1.1', 'ef67c9fe0ba1443fcfe465768e1204763063c369a2a1da04af6027d8a9c00491')}
require(transaction['recipe_id'] in pins and len(transaction['packages']) == 1, 'apt_fixed_single_package_recipe')
old, new, pin = pins[transaction['recipe_id']]
if recovery:old='1.0'
package = transaction['packages'][0]
require(package == dict(name='rmm-mvp-test', architecture='all', old_version=old, new_version=new, origin='rmm-test',
sha256=pin, size=20672, archive_path='/var/lib/rmm-apt-transaction/archives/' + pin + '.deb'), 'apt_pinned_fixture_archive')
+9 -2
View File
@@ -28,15 +28,22 @@ def digest(value):
return hashlib.sha256(value).hexdigest()
def planning_from_device(device):
def planning_from_device(device,recovery=False):
"""Only already stored passive observation, never an SSH package scan."""
observations=(device.get('inventory') or {}).get('observations',[])
observation=next((x for x in observations if x.get('scope')=='linux.apt.planning'),None)
scope='linux.apt.recovery-planning' if recovery else 'linux.apt.planning'
observation=next((x for x in observations if x.get('scope')==scope),None)
m.require(observation is not None,'not_configured:stored_linux.apt.planning_observation_missing')
m.require(observation.get('quality')=='valid' and observation.get('completeness')=='complete'
and observation.get('truncated') is False and 0 <= (m.now()-m.timestamp(observation['observed_at'])).total_seconds()<90,
'not_configured:fresh_complete_apt_planning_required')
data=observation.get('data',{})
if recovery:
m.require(observation['source_id']=='root-helper:apt_recovery_planning_v1' and
data.get('fixture_package')==dict(version='1.0',status='install ok unpacked') and
set(data.get('native_recovery',{}))=={'schema_version','previous_grant_id','previous_attempt_id','partial_proof_sha256'},
'dedicated exact partial recovery observation required')
else:m.require(data.get('native_recovery') is None,'normal planning cannot use partial recovery')
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(data['dpkg_updates_empty'] is True and data['pending_triggers_empty'] is True,'not_configured:dpkg_dirty')
+43
View File
@@ -1,5 +1,48 @@
# Tatsächlicher Implementierungsstand
## Neue Configure-only-Runtime nativ qualifiziert; Paketwirkung noch offen — 2026-11-13
Configure-only-Vertrag implementiert und lokal geprüft: Schema4 mit exaktem
Originalgrant/-versuch/Partial-Proof, Schema2 `configure_only`, ausschließlich
Fixture1.0 konfigurieren. Eigene Recoverymarker/-Records, keine Freshinstall-
Acceptance und kein Überschreiben alter Marker. Frische eigene authentisierte
Recovery-Planung; normale Paketplanung/Closure bleibt strikt. Native neue
Paketwirkung durch diesen Abschnitt **noch nicht ausgeführt**.
Tatsächlich lokal **75 Python-Tests ohne Skips** im isolierten schreibgeschützten
UID1000-Container, einschließlich echtem APT2.6.2-Protokoll und kontrolliertem
Fake-dpkg ohne Paketwirkung: ausschließlich `=`/CONFIGURE und exaktes
`--configure rmm-mvp-test:all`, kein Unpack/Remove/Pending; reale/kopierte
Statusdateien unverändert. Qualifikation Rust: **12 Domain,37 Helper-Library,
3 Helperbinary,21 RootSync,24 Agentbinary,18 Agent-Reconcile-Tests**;
Format/Clippy `-D warnings` und Releasebuilds bestanden. Betroffene bestehenden
Cloudadapterguards: **28 bestanden**, Python-/Node-Syntax geprüft.
Neuer ARM64-Serverbuild und bewusstes Deployment auf endgültigem Server
bestanden, keine neuen Jobs/Freigaben. Auf Cloud-VM anschließend qualifizierte
Artefakte versioniert installiert: Agent `44ae9115…`, Helper `ab7bbc87…`, Provider
`5ff260f7…`; tatsächliche Loaderchecks bestanden. Native Sandboxprobe an exakt
kopierter vorhandener dpkg-Datenbank mit Teilzustand bestanden, echte neue
Configure-/No-Pending-Konfiguration und Runtimepins geprüft. Alle zehn bekannten
abgeschlossenen Rootgrants, beide Marker, ursprünglicher Partial-Proof und
Active-/History-/Archivebytes erhalten. Agent-/Ledgerbytes und Inodes vor
Normalneustart nachweislich gleich, Generalpolicy unverändert. Danach normale
Agent-/Generalhelperaktivität; APT-Endpunkt bleibt absent/Helper **inactive**.
Keine neue Pakettransaktion oder Acceptance durch Wartung/Probe.
Die erste Vorprüfung stoppte korrekt vor Austausch an einem Orchestrator-
Codecfehler: gespeicherter Request hatte sortierte JSON-Objektschlüssel,
Originalhash verwendet die Rust-Strukturreihenfolge. Exakten fünfteiligen
Requestcodec wiederhergestellt; danach ausdrücklicher mutationsfreier
`--preflight-only` mit identischen Zeugen bestanden, erst dann versionierter
Upgrade-/Probelauf. Keine Lockerung der Originalhash-/Signaturprüfung und kein
Wiederholen eines teilweise mutierten Installationslaufs.
Geschützte Nachweise `devstate/cloud-apt-recovery/configure-runtime.json`,
`runtime-upgrade-*.json` und VM-seitige versionierte Bootstrap-Historie.
**MVP weiterhin offen:** jetzt neuer fester tatsächlich UI-genehmigter
Configure-only-Plan, danach separater Upgrade-/Noopnachweis und restliche Gates.
## Nativer Verlust einer Ergebnisbestätigung bestanden — 2026-11-13
Beim eng gebundenen WSS-Fall nach tatsächlicher simulierter UI-Genehmigung
+2 -2
View File
@@ -1,6 +1,6 @@
# Linux-MVP: Abnahmegates
Stand 2026-11-13, ursprüngliche Auditbasis `d38d93d`, Spezifikation 1.10. Die
Stand 2026-11-13, ursprüngliche Auditbasis `d38d93d`, Spezifikation 1.11. Die
Bestandsaufnahme selbst hat keine Tests, Jobs oder Deployments ausgeführt;
anschließende tatsächliche Nachweise sind unten ausdrücklich ergänzt. Einzelbelege und spätere
Ergebnisse stehen im [Implementierungsstand](implementation-status.md).
@@ -45,7 +45,7 @@ normalem signiertem RootSync bestanden. Beidefaultfrei; Ledger 9/0 unresolved,
zentral 13/13/12/0. Derselbe Versuch jetzt ehrlich failed
`APT_PARTIAL_UNCONFIGURED_VERIFIED`, Fixture1.0 unpacked, keine Paket-Acceptance.
Agent/Generalhelper aktiv, APT-Endpunkt gestoppt, Rootpolicy geschlossen.
Nächster Paketpfad ist der neue feste UI-Configure-only-Wiederherstellungsplan.
Neue Configure-only-Runtime samt kopierter nativer Sandboxprobe ist inzwischen qualifiziert; Paketwirkung noch nicht ausgeführt. Nächster Paketpfad ist der neue feste UI-Configure-only-Wiederherstellungsplan.
Die noch offenen Teile der folgenden Gates sind **geplant, nicht ausgeführt**. Native Teilergebnisse stehen ausdrücklich bei den Gates und im Implementierungsstand.
Jeder Ausführungsjob braucht weiterhin seinen eigenen festen WebUI-genehmigten
+12 -1
View File
@@ -1,6 +1,6 @@
# Verbindliche Projektentscheidungen
Stand: **2026-11-13**, Spezifikation **1.10** (`Rust_RMM_Implementierungsspezifikation.md`). Die ausdrücklichen normativen Entscheidungen in Kapitel 0 haben Vorrang vor früheren Architekturannahmen. Version 1.6 ersetzt die lokale Servertopologie durch den dedizierten Internetserver; Version 1.7 präzisiert das Notebook als reinen Entwicklungsrechner; Version 1.8 erlaubt vorgezogene parallele Windows-Entwicklung.
Stand: **2026-11-13**, Spezifikation **1.11** (`Rust_RMM_Implementierungsspezifikation.md`). Die ausdrücklichen normativen Entscheidungen in Kapitel 0 haben Vorrang vor früheren Architekturannahmen. Version 1.6 ersetzt die lokale Servertopologie durch den dedizierten Internetserver; Version 1.7 präzisiert das Notebook als reinen Entwicklungsrechner; Version 1.8 erlaubt vorgezogene parallele Windows-Entwicklung.
## Einzelner signierter APT-Wiederaufnahmeversuch (2026-11-13)
@@ -125,3 +125,14 @@ Bereit-Lease, Änderung von Outcome oder Verbrauch, keine Journalrücksetzung.
Native Prüfung und Grenzen: `implementation-status.md`. Direkte API-/DB-
Jobfreigaben bleiben verboten; anschließende Paketwirkung benötigt neuen festen
WebUI-genehmigten Plan.
## Gebundene Configure-only-Wiederherstellung
Spezifikation1.11 präzisiert einen notwendigen neuen Ausführungsplan nach dem
abgeschlossenen APT-Teilwirkungsnachweis: Manifestschema4/native_recovery mit
Originalgrant/-versuch/Partial-Proof, Transaktionsschema2 ausschließlich
configure_only/Fixture1.0. Separate authentisierte Teilzustandsplanung;
normale Baselines bleiben strikt. Eigene Recoverymarker, kein Überschreiben
früherer Testmarker oder falsche Freshinstall-Acceptance. Jede Paketwirkung,
anschließendes Upgrade und beide Noops erhalten eigene tatsächliche WebUI-
Plangenehmigungen. Runtimeprobe allein ist kein Ausführungsnachweis.
@@ -0,0 +1,110 @@
"""Local real-APT configure-only proof with independently vetoed dpkg effects.
Run only in the same readonly/offline/unprivileged development container as
test_apt_configure_arguments.py. No Cloud-VM or native recovery evidence.
"""
import json
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
from test_guard import apt
from test_apt_configure_arguments import digest, guarded_dpkg
from test_native_acceptance import fixture_transaction
def run_partial_case(work, capture_hook):
for name in ('empty','lists','cache','log','state','dpkg'):
(work/name).mkdir(mode=0o700)
for name in ('updates','triggers'):
(work/'dpkg'/name).mkdir(mode=0o700)
status = work/'dpkg/status'
original = Path('/var/lib/dpkg/status').read_bytes()
if b'Package: rmm-mvp-test\n' in original:
raise AssertionError('fixture must not be installed in regression image')
fixture_status = (b'Package: rmm-mvp-test\nStatus: install ok unpacked\n'
b'Priority: optional\nSection: misc\nArchitecture: all\n'
b'Version: 1.0\nDescription: RMM configure-only argument fixture\n')
status.write_bytes(original.rstrip(b'\n')+b'\n\n'+fixture_status+b'\n')
calls = work/'dpkg-calls.jsonl'; guard = work/'dpkg-guard'
guarded_dpkg(guard, calls)
config = '\n'.join(line for line in apt.apt_config().decode('ascii').splitlines()
if not line.startswith(('DPkg::Pre-Install-Pkgs','DPkg::Tools::Options'))) + '\n'
config = config.replace(str(apt.ACTIVE), str(work)).replace(str(apt.BASE/'log'), str(work/'log'))
config = config.replace(str(apt.BASE/'state'), str(work/'state')).replace('/var/lib/dpkg/status', str(status))
config = config.replace('Dir::Bin::dpkg "/usr/bin/dpkg";', 'Dir::Bin::dpkg "'+str(guard)+'";')
config += 'Dir::State "'+str(work/'state')+'";\nDir::Cache "'+str(work/'cache')+'";\n'
protocol = work/'actual-protocol-v3.txt'
if capture_hook:
hook = work/'collector'
hook.write_text('#!/usr/bin/python3 -I\nimport sys\nfrom pathlib import Path\n'
'raw=sys.stdin.buffer.read(1048577)\n'
'with Path('+repr(str(protocol))+').open("xb") as output: output.write(raw)\n'
'sys.exit(73)\n')
hook.chmod(0o700)
config += ('DPkg::Pre-Install-Pkgs { "'+str(hook)+'"; };\n'
'DPkg::Tools::Options::'+str(hook)+'::Version "3";\n'
'DPkg::Tools::Options::'+str(hook)+'::InfoFD "0";\n')
config_path = work/'apt.conf'; config_path.write_text(config)
before = digest(status)
result = subprocess.run(['/usr/bin/apt-get','--yes','--no-remove','--no-install-recommends',
'install','--','rmm-mvp-test=1.0'],
stdin=subprocess.DEVNULL, capture_output=True, timeout=25,
env={'PATH':'/usr/sbin:/usr/bin:/sbin:/bin','LC_ALL':'C',
'DEBIAN_FRONTEND':'noninteractive','HOME':str(work),'APT_CONFIG':str(config_path)})
return dict(exit_code=result.returncode, status_unchanged=digest(status)==before,
calls=[json.loads(line) for line in calls.read_text().splitlines()] if calls.exists() else [],
protocol=protocol.read_bytes() if protocol.exists() else None,
stderr=result.stderr.decode('ascii',errors='replace'))
@unittest.skipUnless(os.environ.get('RMM_APT_ARGUMENT_REGRESSION') == '1',
'explicit offline read-only container regression only')
class RealConfigureOnlyProtocol(unittest.TestCase):
def test_actual_protocol_and_command_are_configure_only_without_pending(self):
self.assertNotEqual(os.geteuid(),0,'must run unprivileged')
original = digest(Path('/var/lib/dpkg/status'))
with tempfile.TemporaryDirectory(prefix='rmm-configure-only-') as temp:
root = Path(temp); capture = root/'capture'; capture.mkdir(mode=0o700)
vetoed = run_partial_case(capture, True)
self.assertEqual(vetoed['exit_code'],100,vetoed['stderr'])
self.assertTrue(vetoed['status_unchanged'])
self.assertIsNotNone(vetoed['protocol'])
_, actions = apt.parse_protocol3(vetoed['protocol'])
self.assertEqual(len(actions),1)
action = actions[0]
self.assertEqual(action.name,'rmm-mvp-test')
self.assertEqual(action.old_version,'1.0')
self.assertEqual(action.new_version,'1.0')
self.assertEqual(action.old_arch,'all')
self.assertEqual(action.new_arch,'all')
self.assertEqual(action.action,'**CONFIGURE**')
self.assertEqual(action.direction,'=')
obj = fixture_transaction()
obj.update(schema_version=2, operation='configure_only')
obj['packages'][0]['old_version'] = '1.0'
tx = apt.ResolvedAptTransaction.parse(obj)
apt.validate_actions(tx, actions)
self.assertEqual(apt.apt_argv(tx), ['/usr/bin/apt-get','--yes','--no-remove',
'--no-install-recommends','install','--','rmm-mvp-test=1.0'])
self.assertFalse(any('--configure' in c['argv'] or '--unpack' in c['argv'] for c in vetoed['calls']))
simulate = root/'simulate'; simulate.mkdir(mode=0o700)
completed = run_partial_case(simulate, False)
self.assertEqual(completed['exit_code'],0,completed['stderr'])
self.assertTrue(completed['status_unchanged'])
effects = []
for call in completed['calls']:
args = call['argv']
self.assertFalse(any(flag in args for flag in ('--pending','--triggers-only','--unpack','--remove','--purge')))
if '--configure' in args:
self.assertEqual(args[args.index('--configure')+1:],['rmm-mvp-test:all'])
effects.append('configure:rmm-mvp-test:all')
else:
self.assertIn('--set-selections',args)
self.assertTrue(all(line.split()[0].split(':')[0]=='rmm-mvp-test' for line in call['stdin'].splitlines()))
self.assertEqual(effects,['configure:rmm-mvp-test:all'])
self.assertEqual(digest(Path('/var/lib/dpkg/status')),original)
print(json.dumps({'configure_only_protocol':action.__dict__,'dpkg_effects_simulated':True,
'host_and_copied_status_unchanged':True,'configure_only_calls':effects}))
@@ -0,0 +1,176 @@
"""Bound configure-only recovery on temporary sealed files; no package effects."""
import copy
from contextlib import contextmanager
from dataclasses import replace
from pathlib import Path
import tempfile
import uuid
from unittest import TestCase
from unittest.mock import patch
from test_guard import apt
from test_native_acceptance import context, fixture_transaction, action_manifest, signed_job, prechecks
import test_native_retry as retry_fixture
def recovery_transaction():
obj = fixture_transaction()
obj.update(schema_version=2, operation='configure_only')
obj['packages'][0]['old_version'] = '1.0'
return obj
@contextmanager
def recovery_files():
with tempfile.TemporaryDirectory(dir='/tmp/opencode') as temp:
base = Path(temp)
def read(path, *args, **kwargs):
if path == apt.CODE: return b'code'
if path == Path(apt.HOOK): return apt.hook_script()
if path == Path('/usr/share/rmm-mvp-test/version'): return b'1.0\n'
return path.read_bytes()
with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', base/'active'), \
patch.object(apt, 'secure_path', side_effect=lambda path, **kwargs: path), \
patch.object(apt, 'sealed_read', side_effect=read):
tx, old, action, _, _, _ = retry_fixture.NativeRetryTests().setup_history(base)
old = replace(old, job_id=str(uuid.uuid4()), authorization_id=str(uuid.uuid4()))
old_job = apt.canonical(signed_job(old, action))
old = replace(old, job_payload_sha256=apt.digest(old_job))
active = apt.ACTIVE
(active/'context.json').write_bytes(apt.canonical(old.__dict__))
(active/'signed-action.json').write_bytes(old_job)
(active/'apt.conf').write_bytes(apt.apt_config())
marker, binding = apt.bootstrap_binding(tx, old, action)
apt.durable_once(marker, binding)
files = {'launch.json': {'transaction_sha256': old.transaction_sha256,
'effect_armed_ledger_id': old.effect_armed_ledger_id},
'native-prechecks.json': prechecks(old),
'sandbox-ready.json': {'sandbox_version': 1, 'transaction_sha256': old.transaction_sha256},
'sandbox-result.json': {'transaction_sha256': old.transaction_sha256,
'apt_exit_code': 0, 'reboot_required': False},
'hook-armed.json': {'armed_at_ms': 2000, 'effect_armed_ledger_id': old.effect_armed_ledger_id,
'grant_id': old.grant_id, 'transaction_sha256': old.transaction_sha256,
'protocol_sha256': 'e'*64}}
for name, obj in files.items(): (active/name).write_bytes(apt.canonical(obj))
snapshot = {'rmm-mvp-test:all': {'version': '1.0', 'status': 'install ok unpacked'}}
fields = ('transaction_sha256 job_payload_sha256 effect_armed_ledger_id grant_id '
'job_id attempt_id authorization_id plan_sha256')
with patch.object(apt.os, 'geteuid', return_value=0), \
patch.object(Path, 'read_text', return_value=old.boot_id), \
patch.object(apt, 'observe_host_frontend_lock', return_value=False), \
patch.object(apt, 'status_fingerprint', return_value='a'*64), \
patch.object(apt, 'partial_installed_snapshot', return_value=snapshot), \
patch.object(apt, 'verify_archive'):
proof = apt.verify_partial({key: getattr(old, key) for key in fields.split()})['proof']
previous = base/'history'/old.grant_id
active.rename(previous)
active.mkdir()
obj = recovery_transaction()
obj.update(status_fingerprint=proof['status_fingerprint'], baseline_sha256=proof['observed_snapshot_sha256'])
tx = apt.ResolvedAptTransaction.parse(obj)
new = replace(context(), transaction_sha256=apt.digest(apt.canonical(obj)),
grant_id=str(uuid.uuid4()), attempt_id=str(uuid.uuid4()), job_id=str(uuid.uuid4()),
authorization_id=str(uuid.uuid4()), plan_sha256='f'*64)
action = action_manifest(new, obj, {})
action.update(schema_version=4, native_recovery={'schema_version': 1,
'previous_grant_id': old.grant_id, 'previous_attempt_id': old.attempt_id,
'partial_proof_sha256': apt.digest(apt.canonical(proof))})
new_job = apt.canonical(signed_job(new, action))
new = replace(new, job_payload_sha256=apt.digest(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),
'partial-proof.json': apt.canonical(proof), 'apt.conf': apt.apt_config(),
'native-prechecks.json': apt.canonical(prechecks(new)),
'hook-armed.json': b'{}'}.items():
(active/name).write_bytes(data)
yield base, tx, new, action, proof, previous
class NativeRecoveryTests(TestCase):
def test_configure_only_schema_and_actual_action_set_are_fixed(self):
obj = recovery_transaction()
tx = apt.ResolvedAptTransaction.parse(obj)
configure = apt.Action('rmm-mvp-test','1.0','all','none','=','1.0','all','none','**CONFIGURE**')
apt.validate_actions(tx, (configure,))
for actions in ((), (configure,configure), (replace(configure, action=tx.packages[0].archive_path),),
(replace(configure, direction='<'),), (replace(configure, name='other'),),
(replace(configure, new_version='1.1'),)):
with self.subTest(actions=actions), self.assertRaises(apt.Veto): apt.validate_actions(tx, actions)
for change in ({'schema_version':1}, {'operation':'repair_pending'}, {'recipe_id':'other'}):
bad = copy.deepcopy(obj);bad.update(change)
with self.subTest(change=change), self.assertRaises(apt.Veto): apt.ResolvedAptTransaction.parse(bad)
for old,new in ((None,'1.0'),('1.0','1.1'),('1.1','1.1')):
bad = copy.deepcopy(obj);bad['packages'][0].update(old_version=old,new_version=new)
with self.assertRaises(apt.Veto): apt.ResolvedAptTransaction.parse(bad)
def test_new_signed_recovery_preserves_history_and_cannot_create_install_acceptance(self):
with recovery_files() as (base,tx,ctx,action,proof,previous):
original = {str(p.relative_to(base)): p.read_bytes() for p in base.rglob('*')
if p.is_file() and 'active/' not in str(p.relative_to(base))}
self.assertEqual(apt.load_signed_action(tx,ctx),action)
self.assertEqual(apt.verify_recovery_reference(tx,ctx,action),proof)
apt.check_native_gate(tx,ctx,action,{},True)
path,binding = apt.bootstrap_binding(tx,ctx,action)
self.assertEqual(path.name,'recovery-attempt-'+proof['grant_id']+'.json')
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={}):
evidence = apt.complete_acceptance(tx,ctx,action,{}, {'reboot_required':False})
self.assertTrue(evidence['native_recovery'])
self.assertNotIn('native_record_sha256',evidence)
record = apt.json_bytes((base/('recovery-'+proof['grant_id']+'.json')).read_bytes())
self.assertEqual(record['operation'],'configure_only')
self.assertEqual(record['native_recovery'],action['native_recovery'])
self.assertFalse(apt.record_path(tx).exists())
for name,data in original.items(): self.assertEqual((base/name).read_bytes(),data)
with self.assertRaisesRegex(apt.Veto,'RECOVERY_ALREADY_RECORDED'):
apt.check_native_gate(tx,ctx,action,{},True)
def test_recovery_rejects_proof_history_approval_and_current_state_mismatch(self):
with recovery_files() as (_,tx,ctx,action,proof,previous):
for changed in (replace(ctx,grant_id=proof['grant_id']),replace(ctx,job_id=proof['job_id']),
replace(ctx,authorization_id=proof['authorization_id']),replace(ctx,plan_sha256=proof['plan_sha256'])):
with self.assertRaises(apt.Veto): apt.verify_recovery_reference(tx,changed,action)
bad = copy.deepcopy(action);bad['native_recovery']['partial_proof_sha256']='0'*64
with self.assertRaises(apt.Veto): apt.verify_recovery_reference(tx,ctx,bad)
(previous/'sandbox-result.json').write_bytes(b'{}')
with self.assertRaisesRegex(apt.Veto,'RECOVERY_HISTORY_CHANGED'): apt.verify_recovery_reference(tx,ctx,action)
with patch.object(apt,'status_fingerprint',return_value=tx.status_fingerprint), \
patch.object(apt,'partial_installed_snapshot',return_value={}), \
patch.object(apt,'installed_snapshot',side_effect=AssertionError('ordinary parser stays strict')):
with self.assertRaisesRegex(apt.Veto,'STATUS_BASELINE_CHANGED'):
apt.check_preconditions(tx,proof['snapshot'])
def test_passive_recovery_planning_rechecks_original_and_seals_only_exact_partial_baseline(self):
with recovery_files() as (base,tx,ctx,action,proof,previous):
apt.ACTIVE.rename(base/'new-staged')
previous.rename(apt.ACTIVE)
old = apt.json_bytes((apt.ACTIVE/'context.json').read_bytes())
(base/'archives').mkdir();(base/'baselines').mkdir()
for version,sha in apt.FIXTURE_SHA256.items():
(base/'archives'/(sha+'.deb')).write_bytes(apt.fixture_archive(version))
(base/('prefetch-'+sha+'.json')).write_bytes(apt.canonical({
'schema_version':1,'sha256':sha,'size':20672,'sealed_at_ms':1000}))
request = {'native_recovery':action['native_recovery'],'proof':proof}
before = {p:p.read_bytes() for p in base.rglob('*') if p.is_file()}
with patch.object(apt.os,'geteuid',return_value=0), \
patch.object(Path,'read_text',return_value=old['boot_id']), \
patch.object(apt,'observe_host_frontend_lock',return_value=False), \
patch.object(apt,'status_fingerprint',return_value=proof['status_fingerprint']), \
patch.object(apt,'partial_installed_snapshot',return_value=proof['snapshot']), \
patch.object(apt,'installed_snapshot',side_effect=apt.Veto('DPKG_INCONSISTENT')), \
patch.object(apt,'verify_archive'),patch.object(apt,'archive_metadata'), \
patch.object(apt,'runtime_identity',return_value={}):
result = apt.recovery_planning(request)
self.assertEqual(result['native_recovery'],request['native_recovery'])
self.assertEqual(result['baseline_sha256'],proof['observed_snapshot_sha256'])
self.assertEqual(result['fixture_package'],{'version':'1.0','status':'install ok unpacked'})
with self.assertRaisesRegex(apt.Veto,'DPKG_INCONSISTENT'): apt.planning_status()
changed = copy.deepcopy(request);changed['proof']['original_evidence_sha256']='0'*64
changed['native_recovery']['partial_proof_sha256']=apt.digest(apt.canonical(changed['proof']))
with self.assertRaisesRegex(apt.Veto,'RECOVERY_PLANNING_STATE_CHANGED'): apt.recovery_planning(changed)
with patch.object(apt,'observe_host_frontend_lock',return_value=True):
with self.assertRaisesRegex(apt.Veto,'FOREIGN_PACKAGE_LOCK'): apt.recovery_planning(request)
for path,data in before.items(): self.assertEqual(path.read_bytes(),data)
self.assertEqual((base/'baselines'/(proof['observed_snapshot_sha256']+'.json')).read_bytes(),apt.canonical(proof['snapshot']))
self.assertFalse((base/('recovery-attempt-'+proof['grant_id']+'.json')).exists())
+40
View File
@@ -1,5 +1,45 @@
# Typed RootHelper bridge contract (implementation, not native acceptance)
## Configure-only partial recovery (schema 4, local implementation)
This is a **new, separately WebUI-approved** dev-test native action. Schema 4
requires `native_recovery = {schema_version:1, previous_grant_id,
previous_attempt_id, partial_proof_sha256}` and forbids `native_retry`.
Resolved transaction schema 2 adds `operation:"configure_only"`; only the
existing `rmm-apt-fixture-install-1.0` recipe/version 1, pinned fixture archive,
and old/new version `1.0` are eligible. Schema 1 retains its exact encoding.
The helper first requires the original saved signed request, immutable SQLite
partial proof, definitive `APT_PARTIAL_UNCONFIGURED_VERIFIED` outcome, and closed
consumed row. `recovery-planning` receives exactly `{native_recovery, proof}`;
Python rechecks the original still-active witnesses and complete current partial
snapshot. It seals only the content-addressed baseline and returns the normal
planning projection plus `native_recovery`. Ordinary planning continues to reject
unconfigured packages. This passive projection creates no job or authorization.
For execution the helper archives the definitive old active directory, stages
the exact proof as `active/partial-proof.json`, and binds its hash in the new
signed manifest. Python independently checks history, original target, full
partial baseline and installed fixture bytes. APT receives only
`install -- rmm-mvp-test=1.0`; the actual v3 hook must contain exactly one
equal-version `**CONFIGURE**` action. Unpack, removal, foreign packages and pending
configuration remain forbidden. The same native sandbox, grant deadlines,
locked-store handoff and complete postcondition/audit checks apply.
Create-once markers are `recovery-attempt-<previous_grant>.json`,
`pending-recovery-<previous_grant>.json`, and `recovery-<previous_grant>.json`.
Original/retry markers, signed histories and the original unknown proof remain
intact. Recovery produces `native_recovery:true`, `recovery_record_sha256` and
`partial_proof_sha256`; it creates no fresh-install acceptance record or
`native_record_sha256`. A later separately approved native 1.1 upgrade must
provide the ordinary acceptance evidence for the changed provider/runtime.
Local actual APT 2.6.2, with a vetoing collector and independently guarded fake
dpkg, emitted only the exact configure action/target; real and copied package
status stayed unchanged. This is **local regression evidence**, not Cloud-VM
recovery acceptance. Native deployment, UI approval and execution remain the
parent's next acceptance step.
## Explicit one-attempt recovery (schema 3, 2026-11-13)
Schema 2 keeps its exact old encoding (the optional field is omitted). Schema 3
+16 -6
View File
@@ -1,11 +1,21 @@
# Root-helper APT transaction provider / explicit first native acceptance
**Current 2026-11-13:** Cloud fixture retry reached armed hook and APT exit 0,
but independent verification found an unpacked/unconfigured package; outcome
remains **unknown**, with all original/retry tombstones and ledger preserved.
No native acceptance record, package repair or further retry. Root test policy
**Current 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
normal signed RootSync now classified that original attempt as **failed**
(`APT_PARTIAL_UNCONFIGURED_VERIFIED`), preserving all histories/tombstones.
No native acceptance record or package repair exists. Root test policy remains
closed. Detailed real evidence: `../../docs/implementation-status.md`.
The configure-only recovery path, requiring its own new fixed WebUI approval, is implemented in source
(schema 4 manifest, transaction schema 2), with a dedicated passive recovery
projection and separate immutable recovery records. Its qualified runtime is now installed and its actual Cloud copied-database
sandbox readiness probe passed, preserving original state. **No configure-only
package effect or native package acceptance has yet run.** All **75 Python tests passed** in the offline readonly
unprivileged container, including actual APT 2.6.2 configure-only protocol and
guarded fake-dpkg arguments with unchanged real/copied status. See
[`HELPER-CONTRACT.md`](HELPER-CONTRACT.md) for the precise recovery boundary.
Source configuration now disables APT's `dpkg::selection::remove::approved`
rewrite, retaining the exact package's Configure operation while both pending
modes remain disabled and hook-pinned. Upstream explanation:
@@ -13,8 +23,8 @@ modes remain disabled and hook-pinned. Upstream explanation:
Local actual APT 2.6.2 regression in an offline readonly unprivileged container
proved unpack + exact `--configure rmm-mvp-test:all`, no `--pending` or foreign
target; independent dpkg guard simulated effects, real/copied status unchanged.
67 Python tests passed with this opt-in regression. **This source correction
is not deployed or natively accepted on the Cloud VM.** No automatic repair,
67 Python tests passed with this opt-in regression. **This correction is now installed and sandbox-probed on the Cloud VM;
its native package effect remains unaccepted.** No automatic repair,
marker reset or implicit unknown-resolution is introduced. Older sections below
describe historical increments; current operational status is the linked log.
+203 -17
View File
@@ -196,16 +196,19 @@ class PackageArchive:
archive_path: str
@classmethod
def parse(cls, obj):
def parse(cls, obj, configure_only=False):
exact(obj, 'name architecture old_version new_version origin sha256 size archive_path')
token(obj['name'], NAME, 'PACKAGE_NAME')
require(not FORBIDDEN.match(obj['name']), 'PROTECTED_PACKAGE')
require(obj['architecture'] in ('amd64', 'all'), 'ARCHITECTURE')
token(obj['new_version'], VERSION, 'VERSION')
if configure_only:
require(obj['old_version'] == obj['new_version'] == '1.0', 'RECOVERY_VERSION')
if obj['old_version'] is not None:
token(obj['old_version'], VERSION, 'VERSION')
# Debian ordering, not lexical/semver ordering. Read-only argv.
require(subprocess.run(['/usr/bin/dpkg', '--compare-versions', obj['old_version'],
require((obj['old_version'] == obj['new_version'] == '1.0') if configure_only else
subprocess.run(['/usr/bin/dpkg', '--compare-versions', obj['old_version'],
'lt', obj['new_version']], env=ENV,
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL).returncode == 0,
@@ -229,12 +232,16 @@ class ResolvedAptTransaction:
status_fingerprint: str
baseline_sha256: str
packages: Tuple[PackageArchive, ...]
operation: Optional[str] = None
@classmethod
def parse(cls, obj):
version = obj.get('schema_version') if type(obj) is dict else None
exact(obj, 'schema_version recipe_id recipe_version platform resolver_config_version '
'no_reboot status_fingerprint baseline_sha256 packages')
require(type(obj['schema_version']) is int and obj['schema_version'] == 1, 'SCHEMA_VERSION')
'no_reboot status_fingerprint baseline_sha256 packages' + (' operation' if version == 2 else ''))
require(type(version) is int and version in (1, 2), 'SCHEMA_VERSION')
configure_only = version == 2
require(not configure_only or obj['operation'] == 'configure_only', 'TRANSACTION_OPERATION')
token(obj['recipe_id'], IDENT, 'RECIPE_ID')
token(obj['recipe_version'], IDENT, 'RECIPE_VERSION')
require(obj['platform'] == 'ubuntu-24.04-amd64', 'UNSUPPORTED_PLATFORM')
@@ -244,9 +251,12 @@ class ResolvedAptTransaction:
token(obj['baseline_sha256'], HASH, 'FINGERPRINT')
require(type(obj['packages']) is list and 0 < len(obj['packages']) <= MAX_PACKAGES,
'PACKAGE_COUNT')
packages = tuple(PackageArchive.parse(p) for p in obj['packages'])
packages = tuple(PackageArchive.parse(p, configure_only=configure_only) for p in obj['packages'])
require(len({(p.name, p.architecture) for p in packages}) == len(packages), 'DUPLICATE_PACKAGE')
return cls(**{**obj, 'packages': packages})
transaction = cls(**{**obj, 'packages': packages})
if configure_only:
fixture_scope(transaction)
return transaction
@dataclass(frozen=True)
@@ -336,6 +346,10 @@ def fixture_scope(transaction):
'FIXTURE_RECIPE')
require(len(transaction.packages) == 1, 'FIXTURE_CLOSURE')
old, new = FIXTURE_RECIPES[transaction.recipe_id]
if transaction.operation == 'configure_only':
require(transaction.schema_version == 2 and transaction.recipe_id == 'rmm-apt-fixture-install-1.0',
'RECOVERY_FIXED_RECIPE')
old = new = '1.0'
package = transaction.packages[0]
require(package.name == 'rmm-mvp-test' and package.architecture == 'all' and
package.origin == 'rmm-test' and package.old_version == old and package.new_version == new,
@@ -370,14 +384,20 @@ def load_signed_action(transaction, context):
manifest_keys += ('resolved_apt_transaction provider_sha256 hook_sha256 apt_config_sha256 '
'runtime_sha256 test_result_id transaction_bytes')
version = action.get('schema_version') if type(action) is dict else None
exact(action, manifest_keys + (' native_retry' if version == 3 else ''))
exact(action, manifest_keys + (' native_retry' if version == 3 else ' native_recovery' if version == 4 else ''))
require(action['type'] == 'rmm.apt.helper-action' and
type(version) is int and version in (2, 3),
type(version) is int and version in (2, 3, 4),
'SIGNED_ACTION_SCHEMA')
if version == 3:
validate_retry_reference(action['native_retry'])
require(context.action == 'apt-native-acceptance' and context.execution_profile == 'dev-test',
'RETRY_NATIVE_TEST_ONLY')
if version == 4:
validate_recovery_reference(action['native_recovery'])
require(context.action == 'apt-native-acceptance' and context.execution_profile == 'dev-test' and
transaction.operation == 'configure_only', 'RECOVERY_NATIVE_CONFIGURE_ONLY')
else:
require(transaction.operation is None, 'RECOVERY_MANIFEST_REQUIRED')
expected_bytes = sealed_read(ACTIVE / 'expectation.json')
require(type(action['transaction_bytes']) is list and len(action['transaction_bytes']) <= 65536 and
all(type(value) is int and 0 <= value <= 255 for value in action['transaction_bytes']) and
@@ -418,6 +438,11 @@ def check_native_gate(transaction, context, action, runtime, native_acceptance):
'DEDICATED_HELPER_ACTION_REQUIRED')
path = record_path(transaction)
if native_acceptance:
if action.get('native_recovery') is not None:
verify_recovery_reference(transaction, context, action)
require(not os.path.lexists(BASE / ('recovery-' + action['native_recovery']['previous_grant_id'] + '.json')),
'RECOVERY_ALREADY_RECORDED')
return
require(not path.exists(), 'ACCEPTANCE_ALREADY_RECORDED')
return
proof = json_bytes(sealed_read(path))
@@ -486,6 +511,92 @@ def validate_retry_reference(ref):
token(ref['bootstrap_marker_sha256'], HASH, 'RETRY_MARKER_HASH')
def validate_recovery_reference(ref):
exact(ref, 'schema_version previous_grant_id previous_attempt_id partial_proof_sha256')
require(type(ref['schema_version']) is int and ref['schema_version'] == 1, 'RECOVERY_SCHEMA')
for key in ('previous_grant_id', 'previous_attempt_id'):
value = ref[key]
require(type(value) is str and str(uuid.UUID(value)) == value and uuid.UUID(value).int != 0,
'RECOVERY_ID')
token(ref['partial_proof_sha256'], HASH, 'RECOVERY_PROOF_HASH')
def validate_partial_proof(proof):
exact(proof, 'schema_version type transaction_sha256 job_payload_sha256 effect_armed_ledger_id '
'grant_id job_id attempt_id authorization_id plan_sha256 original_evidence_sha256 '
'original_baseline_sha256 observed_snapshot_sha256 status_fingerprint fixture_payload_sha256 '
'snapshot checked_at_ms partial_effect postconditions_passed reboot_required')
require(type(proof['schema_version']) is int and proof['schema_version'] == 1 and
proof['type'] == 'rmm.apt.partial-reconciliation' and proof['partial_effect'] is True and
proof['postconditions_passed'] is False and proof['reboot_required'] is False and
type(proof['checked_at_ms']) is int and proof['checked_at_ms'] > 0, 'RECOVERY_PROOF_TYPE')
for key in ('transaction_sha256', 'job_payload_sha256', 'plan_sha256', 'original_evidence_sha256',
'original_baseline_sha256', 'observed_snapshot_sha256', 'status_fingerprint', 'fixture_payload_sha256'):
token(proof[key], HASH, 'RECOVERY_PROOF_HASH')
for key in ('grant_id','job_id','attempt_id','authorization_id'):
value = proof[key]
require(type(value) is str and str(uuid.UUID(value)) == value and uuid.UUID(value).int != 0,
'RECOVERY_PROOF_ID')
token(proof['effect_armed_ledger_id'], IDENT, 'RECOVERY_PROOF_LEDGER')
require(type(proof['snapshot']) is dict and
digest(canonical(proof['snapshot'])) == proof['observed_snapshot_sha256'] and
proof['snapshot'].get('rmm-mvp-test:all') == {'version':'1.0','status':'install ok unpacked'} and
proof['fixture_payload_sha256'] == digest(b'1.0\n'), 'RECOVERY_PROOF_SNAPSHOT')
def verify_recovery_reference(transaction, context, action):
"""Only immutable linkage here; current state is checked before the hook.
RootHelper additionally requires this proof in its original shared SQLite
ledger with terminal classified failure and the original verified Request.
Caller-provided JSON or a root-owned file alone never grants authority.
"""
ref = action['native_recovery']; validate_recovery_reference(ref)
require(context.action == 'apt-native-acceptance' and context.execution_profile == 'dev-test' and
action['schema_version'] == 4 and transaction.schema_version == 2 and
transaction.operation == 'configure_only', 'RECOVERY_DEDICATED_ACTION')
fixture_scope(transaction)
raw_proof = sealed_read(ACTIVE / 'partial-proof.json')
proof = json_bytes(raw_proof); validate_partial_proof(proof)
require(raw_proof == canonical(proof) and digest(raw_proof) == ref['partial_proof_sha256'] and
proof['grant_id'] == ref['previous_grant_id'] and proof['attempt_id'] == ref['previous_attempt_id'],
'RECOVERY_IMMUTABLE_PROOF_BINDING')
require(context.grant_id != proof['grant_id'] and context.attempt_id != proof['attempt_id'] and
context.job_id != proof['job_id'] and context.authorization_id != proof['authorization_id'] and
context.plan_sha256 != proof['plan_sha256'], 'RECOVERY_NEW_APPROVAL_REQUIRED')
require(transaction.baseline_sha256 == proof['observed_snapshot_sha256'] and
transaction.status_fingerprint == proof['status_fingerprint'] and
sealed_read(ACTIVE / 'baseline.json') == canonical(proof['snapshot']), 'RECOVERY_BASELINE_BINDING')
previous = BASE / 'history' / ref['previous_grant_id']
secure_path(previous, 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')
historical = {name: sealed_read(previous / name) for name in names}
for prefix in ('bootstrap-attempt-', 'bootstrap-retry-'):
name = prefix + 'rmm-apt-fixture-install-1.0.json'
historical[name] = sealed_read(BASE / name)
require(digest(canonical({name:digest(raw) for name,raw in historical.items()})) ==
proof['original_evidence_sha256'], 'RECOVERY_HISTORY_CHANGED')
old = VerifiedHelperContext.parse(json_bytes(historical['context.json']))
require(all(getattr(old, key) == proof[key] for key in
('transaction_sha256','job_payload_sha256','effect_armed_ledger_id','grant_id',
'job_id','attempt_id','authorization_id','plan_sha256')) and
digest(historical['signed-action.json']) == proof['job_payload_sha256'] and
digest(historical['expectation.json']) == proof['transaction_sha256'] and
digest(historical['baseline.json']) == proof['original_baseline_sha256'],
'RECOVERY_ORIGINAL_CONTEXT_BINDING')
old_job = json_bytes(historical['signed-action.json'])
new_job = json_bytes(sealed_read(ACTIVE / 'signed-action.json'))
require(all(old_job[key] == new_job[key] for key in
('tenant_id','asset_id','agent_id','enrollment_generation','assignment_version')) and
digest(sealed_read(previous / 'apt.conf')) == old_job['action']['apt_manifest']['apt_config_sha256'],
'RECOVERY_ORIGINAL_TARGET_OR_CONFIG')
require(not os.path.lexists(BASE / 'acceptance-rmm-apt-fixture-install-1.0.json') and
not os.path.lexists(BASE / 'pending-acceptance-rmm-apt-fixture-install-1.0.json'),
'RECOVERY_NOT_INSTALL_ACCEPTANCE')
return proof
def historical_retry_evidence(transaction, context, action):
"""Recheck immutable no-handoff evidence, never turn unknown into failed.
@@ -549,6 +660,10 @@ def historical_retry_evidence(transaction, context, action):
def bootstrap_binding(transaction, context, action):
binding = attempt_binding(context)
if action.get('native_recovery') is not None:
verify_recovery_reference(transaction, context, action)
binding.update(native_recovery=action['native_recovery'])
return BASE / ('recovery-attempt-' + action['native_recovery']['previous_grant_id'] + '.json'), binding
if action.get('native_retry') is not None:
binding.update(native_retry=action['native_retry'], previous_evidence_sha256=
historical_retry_evidence(transaction, context, action))
@@ -664,8 +779,16 @@ def complete_acceptance(transaction, context, action, runtime, evidence):
'completed_at_ms': time.time_ns() // 1000000}
# Stage+fsync complete bytes before publishing. Failed writes never leave a
# parseable final partial record. An existing final record is never replaced.
path = record_path(transaction)
staged = BASE / ('pending-acceptance-' + transaction.recipe_id + '.json')
recovery = action.get('native_recovery')
if recovery is not None:
verify_recovery_reference(transaction, context, action)
proof.update(schema_version=1, type='rmm.apt.native-recovery', operation='configure_only',
native_recovery=recovery)
path = BASE / ('recovery-' + recovery['previous_grant_id'] + '.json')
staged = BASE / ('pending-recovery-' + recovery['previous_grant_id'] + '.json')
else:
path = record_path(transaction)
staged = BASE / ('pending-acceptance-' + transaction.recipe_id + '.json')
durable_once(staged, proof)
linked = False
try:
@@ -681,6 +804,11 @@ def complete_acceptance(transaction, context, action, runtime, evidence):
path.unlink()
raise
# Retain staged bytes as an immutable record witness; never reset attempts.
if recovery is not None:
return {'test_acceptance': True, 'noProductionEvidence': True, 'native_recovery': True,
'recovery_record_sha256': digest(canonical(proof)),
'partial_proof_sha256': recovery['partial_proof_sha256'],
'test_result_id': action['test_result_id']}
return {'test_acceptance': True, 'noProductionEvidence': True,
'native_record_sha256': digest(canonical(proof)), 'test_result_id': action['test_result_id']}
@@ -747,6 +875,12 @@ def parse_protocol3(data):
def validate_actions(transaction, actions):
if transaction.operation == 'configure_only':
fixture_scope(transaction)
require(len(actions) == 1 and actions[0] == Action(
'rmm-mvp-test', '1.0', 'all', 'none', '=', '1.0', 'all', 'none', '**CONFIGURE**'),
'RECOVERY_CONFIGURE_ACTION_ONLY')
return
expected = {(p.name, p.architecture): p for p in transaction.packages}
seen = set()
for action in actions:
@@ -876,7 +1010,13 @@ def installed_snapshot():
def check_current_baseline(transaction, baseline):
require(digest(canonical(baseline)) == transaction.baseline_sha256, 'BASELINE_HASH')
require(status_fingerprint() == transaction.status_fingerprint, 'STATUS_FINGERPRINT')
require(installed_snapshot() == baseline, 'STATUS_BASELINE_CHANGED')
snapshot = partial_installed_snapshot() if transaction.operation == 'configure_only' else installed_snapshot()
require(snapshot == baseline, 'STATUS_BASELINE_CHANGED')
if transaction.operation == 'configure_only':
fixture_scope(transaction)
require(baseline.get('rmm-mvp-test:all') == {'version': '1.0', 'status': 'install ok unpacked'} and
sealed_read(Path('/usr/share/rmm-mvp-test/version'), limit=32) == b'1.0\n',
'RECOVERY_PARTIAL_PRECONDITION')
def check_preconditions(transaction, baseline):
@@ -884,7 +1024,8 @@ def check_preconditions(transaction, baseline):
for p in transaction.packages:
current = baseline.get(p.name + ':' + p.architecture)
require((current is None if p.old_version is None else
current == {'version': p.old_version, 'status': 'install ok installed'}),
current == {'version': p.old_version, 'status':
'install ok unpacked' if transaction.operation == 'configure_only' else 'install ok installed'}),
'PACKAGE_PRECONDITION')
@@ -933,6 +1074,10 @@ DPkg::Tools::Options::/usr/lib/rmm-apt-transaction/hook::InfoFD "0";
def apt_argv(transaction):
if transaction.operation == 'configure_only':
fixture_scope(transaction)
return ['/usr/bin/apt-get', '--yes', '--no-remove', '--no-install-recommends',
'install', '--', 'rmm-mvp-test=1.0']
# APT's --no-download also prevents the local file method from resolving
# its Install filename (v3 emits **ERROR**). Permit local acquisition of
# the already sealed/hash-checked archive. Empty sources, fixed paths and
@@ -1445,7 +1590,10 @@ def execute(request, native_acceptance=False):
check_current_baseline(transaction, baseline)
for package in transaction.packages:
verify_archive(package)
require(run_read(['/usr/bin/dpkg', '--audit']) == b'', 'DPKG_AUDIT')
# The exact bound unpacked fixture is the declared recovery input;
# ordinary jobs continue to require a clean audit before mutation.
if transaction.operation != 'configure_only':
require(run_read(['/usr/bin/dpkg', '--audit']) == b'', 'DPKG_AUDIT')
context.check_deadline()
if not native_acceptance:
evidence = verified_no_change(transaction, baseline, context)
@@ -1475,7 +1623,8 @@ def execute(request, native_acceptance=False):
if not armed:
# Trusted fixed config makes a missing hook a veto, not an
# after-the-fact substitute for pre-dpkg validation.
require(installed_snapshot() == baseline, 'MISSING_HOOK_WITH_CHANGE')
current = partial_installed_snapshot() if transaction.operation == 'configure_only' else installed_snapshot()
require(current == baseline, 'MISSING_HOOK_WITH_CHANGE')
return {'effect_state': 'known_failed', 'code': 'HOOK_NOT_HANDED_OFF',
'evidence': {'test_acceptance': True, 'noProductionEvidence': True}
if native_acceptance else {}}
@@ -1561,7 +1710,38 @@ def prepare_baseline_store():
'native_acceptance_created': False}
def recovery_planning(request):
"""Fresh passive projection of one ledger-verified, closed partial failure.
Rust verifies the signed original request, terminal failure and immutable
SQLite proof before invoking this fixed mode. No job or execution is made.
"""
exact(request, 'native_recovery proof')
ref, proof = request['native_recovery'], request['proof']
validate_recovery_reference(ref)
validate_partial_proof(proof)
require(digest(canonical(proof)) == ref['partial_proof_sha256'] and
proof['grant_id'] == ref['previous_grant_id'] and
proof['attempt_id'] == ref['previous_attempt_id'], 'RECOVERY_PLANNING_PROOF_BINDING')
fields = ('transaction_sha256 job_payload_sha256 effect_armed_ledger_id grant_id '
'job_id attempt_id authorization_id plan_sha256')
current = verify_partial({key: proof[key] for key in fields.split()})['proof']
require({key: value for key, value in current.items() if key != 'checked_at_ms'} ==
{key: value for key, value in proof.items() if key != 'checked_at_ms'},
'RECOVERY_PLANNING_STATE_CHANGED')
require(not os.path.lexists(BASE / ('recovery-attempt-' + ref['previous_grant_id'] + '.json')) and
not os.path.lexists(BASE / ('recovery-' + ref['previous_grant_id'] + '.json')),
'RECOVERY_ALREADY_ATTEMPTED')
result = _planning_status(proof)
result['native_recovery'] = ref
return result
def planning_status():
return _planning_status()
def _planning_status(recovery_proof=None):
"""Fixed passive fixture projection; complete dpkg state remains root-private.
Only content-addressed, fsynced helper metadata may be created here. No
@@ -1574,7 +1754,11 @@ def planning_status():
require(not observe_host_frontend_lock() and
not observe_host_frontend_lock(Path('/var/lib/dpkg/lock')), 'FOREIGN_PACKAGE_LOCK')
fingerprint = status_fingerprint() # Vetoes dirty updates/pending triggers.
snapshot = installed_snapshot()
snapshot_reader = partial_installed_snapshot if recovery_proof is not None else installed_snapshot
snapshot = snapshot_reader()
if recovery_proof is not None:
require(snapshot == recovery_proof['snapshot'] and fingerprint == recovery_proof['status_fingerprint'],
'RECOVERY_PLANNING_STATE_CHANGED')
runtime = runtime_identity()
prefetch = {}
for version in ('1.0', '1.1'):
@@ -1590,7 +1774,7 @@ def planning_status():
type(receipt['sealed_at_ms']) is int and 0 < receipt['sealed_at_ms'] <= time.time_ns() // 1000000,
'PREFETCH_RECEIPT')
prefetch[sha] = receipt
require(status_fingerprint() == fingerprint and installed_snapshot() == snapshot,
require(status_fingerprint() == fingerprint and snapshot_reader() == snapshot,
'PLANNING_STATE_CHANGED')
require(not observe_host_frontend_lock() and
not observe_host_frontend_lock(Path('/var/lib/dpkg/lock')), 'FOREIGN_PACKAGE_LOCK')
@@ -1615,7 +1799,7 @@ def planning_status():
else:
durable_once(path, snapshot)
# Do not publish a stale baseline if state changed during fsync.
require(status_fingerprint() == fingerprint and installed_snapshot() == snapshot,
require(status_fingerprint() == fingerprint and snapshot_reader() == snapshot,
'PLANNING_STATE_CHANGED')
return {'observed_at': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
'fixture_package': snapshot.get('rmm-mvp-test:all'),
@@ -1839,6 +2023,8 @@ def main():
sys.stdout.buffer.write(canonical(prepare_baseline_store()) + b'\n')
elif mode == 'planning-status':
sys.stdout.buffer.write(canonical(planning_status()) + b'\n')
elif mode == 'recovery-planning':
sys.stdout.buffer.write(canonical(recovery_planning(json_bytes(sys.stdin.buffer.read(MAX_INPUT + 1)))) + b'\n')
elif mode == 'probe-native':
sys.stdout.buffer.write(canonical(probe_native()) + b'\n')
elif mode == 'probe-worker':