Use script-only execution on Linux and preserve the enrolled helper through updates
This commit is contained in:
@@ -425,15 +425,8 @@ impl<C: reconcile::SyncClock> Agent<C> {
|
||||
|| binding.verify(&request, Utc::now()).is_err()
|
||||
{
|
||||
jobs::no_start("failed", "START_WINDOW_OR_CLOCK_INVALID_BEFORE_EFFECT")
|
||||
} else if matches!(job.action, rmm_domain::jobs::Action::UpdateAgent { .. }) {
|
||||
match agent_update_apply::handoff(&binding, &request, grant.grant_id) {
|
||||
// Full now owns this original. The stable updater may
|
||||
// stop us. Reconciliation alone supplies its final result.
|
||||
Ok(_) => return,
|
||||
Err(_) => rmm_privileged_helper::Outcome::unknown("UPDATE_HANDOFF_UNCONFIRMED"),
|
||||
}
|
||||
} else if job.execution_identity == "root" {
|
||||
apt::invoke_with_control(&binding, &job, &request, || {
|
||||
helper_sync::invoke_script(&binding, &job, &request, || {
|
||||
ensure!(
|
||||
!cancellation.load(Ordering::SeqCst)
|
||||
&& fence.running_generation.load(Ordering::SeqCst) == generation
|
||||
@@ -446,7 +439,7 @@ impl<C: reconcile::SyncClock> Agent<C> {
|
||||
rmm_privileged_helper::Outcome::unknown("HELPER_TRANSPORT_EFFECT_UNKNOWN")
|
||||
})
|
||||
} else {
|
||||
jobs::execute(&job)
|
||||
rmm_privileged_helper::script(&job).unwrap_or_else(|_| rmm_privileged_helper::Outcome::unknown("EXECUTOR_EFFECT_UNKNOWN"))
|
||||
};
|
||||
let _ = completed.blocking_send((offer, grant, outcome));
|
||||
});
|
||||
@@ -481,15 +474,7 @@ impl<C: reconcile::SyncClock> Agent<C> {
|
||||
if rmm_agent_linux::actions::Interpreter::PosixSh.available() {
|
||||
capabilities.push("run_script".into());
|
||||
}
|
||||
capabilities.push("refresh_inventory".into());
|
||||
if jobs::logs_available() {
|
||||
capabilities.push("query_logs".into());
|
||||
}
|
||||
capabilities.extend(apt::capabilities(binding));
|
||||
capabilities.extend(helper_sync::general_capabilities(binding));
|
||||
if self.clock.trusted() {
|
||||
capabilities.extend(self.update_observer.capabilities());
|
||||
}
|
||||
capabilities.extend(helper_sync::script_capabilities(binding));
|
||||
}
|
||||
capabilities.sort();
|
||||
capabilities.dedup();
|
||||
@@ -670,8 +655,6 @@ impl<C: reconcile::SyncClock> Agent<C> {
|
||||
let mut first_heartbeat = true;
|
||||
let mut health_task: Option<PendingUpdateHealth> = None;
|
||||
let mut health_inventory_prefix: Option<String> = None;
|
||||
let mut update_prefetch: Option<(JobOffer, agent_update_apply::Prefetch)> = None;
|
||||
let mut prefetched = std::collections::HashSet::new();
|
||||
loop {
|
||||
tokio::select! {
|
||||
Some(result) = self.inventory_rx.recv() => {
|
||||
@@ -748,7 +731,6 @@ impl<C: reconcile::SyncClock> Agent<C> {
|
||||
// First preserve the original completion without unlocking.
|
||||
// A startup can replay it if the journal transaction is lost.
|
||||
let state = outcome.state.clone();
|
||||
let refresh_capabilities=state=="succeeded" && serde_json::from_slice::<rmm_domain::jobs::JobPayload>(&offer.payload_bytes)?.action.name()=="apt_native_acceptance";
|
||||
rmm_privileged_helper::persist_outcome(&self.ledger,&grant,&outcome)?;
|
||||
let serialized = serde_json::to_vec(&outcome)?;
|
||||
self.record(generation, &offer, &grant.grant_id.to_string(), outcome)?;
|
||||
@@ -756,17 +738,9 @@ impl<C: reconcile::SyncClock> Agent<C> {
|
||||
rmm_privileged_helper::finish(&self.ledger, &grant, &outcome)?;
|
||||
if state == "unknown" { eprintln!("job effect unknown: device execution lock retained"); }
|
||||
needs_sync=true;self.replay(&ws, generation).await?;
|
||||
if refresh_capabilities {return Ok(());}
|
||||
}
|
||||
_ = tick.tick() => {
|
||||
self.replay(&ws, generation).await?;
|
||||
if update_prefetch.as_ref().is_some_and(|(_,task)|task.0.is_finished()) {
|
||||
let (offer, mut task)=update_prefetch.take().context("UPDATE_PREFETCH_REQUIRED")?;
|
||||
match (&mut task.0).await {
|
||||
Ok(Ok(())) => {prefetched.insert((offer.job_id.clone(),offer.attempt_id.clone()));},
|
||||
_ => {self.record(generation,&offer,"",jobs::no_start("failed","UPDATE_ARTIFACT_PREFETCH_FAILED"))?;needs_sync=true;}
|
||||
}
|
||||
}
|
||||
let busy:bool=self.db.query_row("SELECT EXISTS(SELECT 1 FROM job_attempts WHERE state IN ('requesting','running','verifying'))",[],|r|r.get(0))?;
|
||||
let update=self.update_proof()?;
|
||||
let pending_update=self.binding.as_ref().map(|binding|rmm_agent_core::jobs::needs_update_control(&self.db,&self.ledger,binding)).transpose()?.unwrap_or(false);
|
||||
@@ -802,18 +776,11 @@ impl<C: reconcile::SyncClock> Agent<C> {
|
||||
let job = self.binding.as_ref().context("binding")?.job(&offer.payload_bytes)?;
|
||||
if Utc::now() >= job.start_before {
|
||||
self.record(generation, &offer, "", jobs::no_start("expired", "START_DEADLINE_EXPIRED"))?;
|
||||
} else if !matches!(job.action,rmm_domain::jobs::Action::RunScript{..}) {
|
||||
self.record(generation, &offer, "", jobs::no_start("failed","LEGACY_ACTION_RETIRED"))?;
|
||||
} else if !self.ready(generation,job.execution_identity=="root") {
|
||||
needs_sync=true;
|
||||
} else if Utc::now() >= job.not_before {
|
||||
if matches!(job.action,rmm_domain::jobs::Action::UpdateAgent{..}) && !prefetched.contains(&(offer.job_id.clone(),offer.attempt_id.clone())) {
|
||||
if update_prefetch.is_none() {
|
||||
let identity=self.certificates.current(Utc::now().timestamp())?;
|
||||
let client=https_channel::mtls_client(self.address,&self.ca,&identity.certificate_pem,&identity.private_key_pem)?;
|
||||
let base=format!("https://{}:{}",https_channel::server_name()?,self.address.port());
|
||||
update_prefetch=Some((offer.clone(),agent_update_apply::Prefetch(tokio::spawn(agent_update_apply::prefetch(client,base,job)))));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Reserve before send. A lost response must never cause
|
||||
// a second permit request for this attempt.
|
||||
// The root updater holds this lock exclusively while it checks
|
||||
|
||||
Reference in New Issue
Block a user