Implement bounded Windows MSI delegation with deny-only cancellation and retained installer ownership
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-14 13:53:05 +01:00
parent 66c1855056
commit 66e77ad83e
9 changed files with 996 additions and 16 deletions
+85 -2
View File
@@ -367,6 +367,25 @@ struct Agent {
impl Agent {
fn close_gate(&mut self) {
self.fence.close();
#[cfg(feature = "system-helper")]
if let Some(running) = &self.running
&& running.grant.execution_identity == "system"
{
running.cancel.store(true, Ordering::SeqCst);
let denied = (|| -> Result<()> {
let mut store = rmm_agent_windows::helper_runtime::intent::Store::open(true)?;
let intent = store.by_grant(running.grant.grant_id)?;
ensure!(
intent.permit()? == running.grant,
"SYSTEM_CANCEL_GRANT_BINDING"
);
store.deny(&intent.request, Uuid::parse_str(&self.boot)?)
})();
if denied.is_err() {
self.helper_refused = true;
eprintln!("SYSTEM_CANCEL_PERSISTENCE_FAILED");
}
}
if let Some(sync) = &mut self.sync {
sync.close();
}
@@ -566,7 +585,11 @@ impl Agent {
}
#[cfg(feature = "system-helper")]
{
Path::new(rmm_agent_windows::helper_runtime::intent::DB).is_file()
(job.action.windows_msi().is_none()
|| (self.config.state_directory
== Path::new(rmm_agent_windows::msi_cache::AGENT_STATE)
&& rmm_agent_windows::msi_cache::stage_configured()))
&& Path::new(rmm_agent_windows::helper_runtime::intent::DB).is_file()
&& self
.helper
.as_ref()
@@ -983,9 +1006,69 @@ impl Agent {
let completed = self.completed_tx.clone();
let work_offer = offer.clone();
let work_grant = grant.clone();
let msi = job.action.windows_msi().cloned();
let address = self.config.connect_address;
let ca = self.ca.clone();
let state = self.config.state_directory.clone();
let request_for_stage = request.clone();
let binding_for_stage = binding.clone();
let worker = tokio::spawn(async move {
let staged = if let Some(m) = msi {
let result = async {
ensure!(
!worker_cancel.load(Ordering::SeqCst)
&& fence.allows_identity(generation, true, &clock),
"MSI_DOWNLOAD_FENCED"
);
verified_window(&binding_for_stage, &request_for_stage, &clock)?;
let cert = protected_read(&state.join("device.pem"), 32768)?;
let key = protected_read(&state.join("device.key"), 16384)?;
let tls = crate::https_channel::mtls_client(address, &ca, &cert, &key)?;
let response = tls
.get(format!(
"https://{}:{}/agent/v1/artifacts/{}?job_id={}&attempt_id={}",
crate::https_channel::server_name()?,
address.port(),
m.recipe.artifact.artifact_id,
work_grant.job_id,
work_grant.attempt_id
))
.send()
.await?;
ensure!(
response
.headers()
.get("x-artifact-sha256")
.and_then(|v| v.to_str().ok())
== Some(m.recipe.artifact.sha256.as_str()),
"MSI_DOWNLOAD_METADATA"
);
let bytes = crate::https_channel::bounded_body(
response,
m.recipe.artifact.bytes as usize,
"application/octet-stream",
)
.await?;
ensure!(
!worker_cancel.load(Ordering::SeqCst)
&& fence.allows_identity(generation, true, &clock),
"MSI_DOWNLOAD_FENCED"
);
verified_window(&binding_for_stage, &request_for_stage, &clock)?;
tokio::task::spawn_blocking(move || {
rmm_agent_windows::msi_cache::stage(&m, &bytes)
})
.await??;
Ok::<_, anyhow::Error>(())
}
.await;
result.is_ok()
} else {
true
};
let _result = helper
.delegate(intent, move || {
ensure!(staged, "MSI_DOWNLOAD_NOT_READY");
ensure!(
!worker_cancel.load(Ordering::SeqCst),
"CANCELLED_BEFORE_DISPATCH"
@@ -1298,7 +1381,7 @@ impl Agent {
#[cfg(feature="system-helper")]
if Path::new(rmm_agent_windows::helper_runtime::intent::DB).is_file() {
let mut store=rmm_agent_windows::helper_runtime::intent::Store::open(true)?;
if let Some(intent)=store.pending()?.first() && intent.permit()?.job_id.to_string()==cancel.job_id && intent.permit()?.attempt_id.to_string()==cancel.attempt_id {store.cancel_before_dispatch(intent.id)?;}
if let Some(intent)=store.pending()?.first() && intent.permit()?.job_id.to_string()==cancel.job_id && intent.permit()?.attempt_id.to_string()==cancel.attempt_id {store.deny(&intent.request,Uuid::parse_str(&self.boot)?)?;store.cancel_before_dispatch(intent.id)?;}
}
if state=="accepted" {self.record(generation,&JobOffer::decode(bytes.as_slice())?,&grant,jobs::no_start("cancelled","CANCELLED_BEFORE_START"))?;needs_sync=true;}
}