feat: qualify bound configure-only recovery runtime on cloud VM
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -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)),
|
||||
|
||||
Reference in New Issue
Block a user