Integrate signed agent catalog, tenant enrollment and HTTPS installers
This commit is contained in:
@@ -25,8 +25,11 @@ const PROBE_FILE: &str = "helper-probe.json";
|
||||
#[derive(Clone)]
|
||||
pub struct Client {
|
||||
pin: ipc::Pin,
|
||||
raw_pin_sha256: String,
|
||||
raw_settings_sha256: String,
|
||||
lane: Arc<Semaphore>,
|
||||
qualified_capabilities: Vec<String>,
|
||||
update_observer_configured:bool,
|
||||
probed_at: Option<std::time::Instant>,
|
||||
}
|
||||
pub struct ControlSnapshot {
|
||||
@@ -62,6 +65,28 @@ impl Client {
|
||||
file.file.read_to_end(&mut bytes)?;
|
||||
let pin: ipc::Pin = serde_json::from_slice(&bytes)?;
|
||||
pin.validate()?;
|
||||
let mut settings_file = ipc::PinnedFile::open(
|
||||
Path::new(crate::helper_system::CONFIG_PATH),
|
||||
false,
|
||||
&readers,
|
||||
&[],
|
||||
false,
|
||||
)?;
|
||||
ensure!(
|
||||
settings_file.file.metadata()?.len() <= 32768,
|
||||
"HELPER_SETTINGS_LIMIT"
|
||||
);
|
||||
let mut settings_raw = Vec::new();
|
||||
(&mut settings_file.file)
|
||||
.take(32769)
|
||||
.read_to_end(&mut settings_raw)?;
|
||||
ensure!(settings_raw.len() <= 32768, "HELPER_SETTINGS_LIMIT");
|
||||
let settings: crate::helper_system::Settings = serde_json::from_slice(&settings_raw)?;
|
||||
ensure!(
|
||||
serde_json::to_vec(&settings.pin()?)? == serde_json::to_vec(&pin)?,
|
||||
"HELPER_CURRENT_SETTINGS_PIN_BINDING"
|
||||
);
|
||||
settings_file.check()?;
|
||||
ensure!(
|
||||
pin.binding.agent_id.to_string() == agent_id
|
||||
&& pin.binding.asset_id.to_string() == asset_id
|
||||
@@ -75,7 +100,15 @@ impl Client {
|
||||
"HELPER_JOB_BINDING_MISMATCH"
|
||||
);
|
||||
}
|
||||
Ok(Some(Self { pin, lane, qualified_capabilities:vec![], probed_at:None }))
|
||||
Ok(Some(Self {
|
||||
raw_pin_sha256: rmm_domain::jobs::hash(&bytes),
|
||||
raw_settings_sha256: rmm_domain::jobs::hash(&settings_raw),
|
||||
pin,
|
||||
lane,
|
||||
qualified_capabilities: vec![],
|
||||
update_observer_configured:false,
|
||||
probed_at: None,
|
||||
}))
|
||||
}
|
||||
pub async fn refresh(
|
||||
agent_id: String,
|
||||
@@ -112,7 +145,9 @@ impl Client {
|
||||
)?
|
||||
.context("HELPER_PIN_REMOVED")?;
|
||||
ensure!(
|
||||
serde_json::to_vec(¤t.pin)? == serde_json::to_vec(&self.pin)?,
|
||||
serde_json::to_vec(¤t.pin)? == serde_json::to_vec(&self.pin)?
|
||||
&& current.raw_pin_sha256 == self.raw_pin_sha256
|
||||
&& current.raw_settings_sha256 == self.raw_settings_sha256,
|
||||
"HELPER_PIN_CHANGED"
|
||||
);
|
||||
Ok(())
|
||||
@@ -123,6 +158,32 @@ impl Client {
|
||||
pub fn helper_binary_hash(&self) -> &str {
|
||||
&self.pin.helper.binary_sha256
|
||||
}
|
||||
fn retained_intent_context(&self, intent: &intent::Intent, job: &JobPayload) -> bool {
|
||||
if intent.policy_sha256 == self.pin.policy_sha256
|
||||
&& intent.helper_binary_sha256 == self.pin.helper.binary_sha256
|
||||
{
|
||||
return true;
|
||||
}
|
||||
let Action::UpdateAgent { update } = &job.action else {
|
||||
return false;
|
||||
};
|
||||
let rmm_domain::agent_update::PeerPinTransition::WindowsCodePairV1 {
|
||||
new_pin_sha256,
|
||||
new_settings_sha256,
|
||||
time_profile: Some(_),
|
||||
..
|
||||
} = &update.peer_pin_transition
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
update.validate()
|
||||
&& intent.helper_binary_sha256 == update.predecessor.helper_sha256
|
||||
&& update
|
||||
.manifest()
|
||||
.is_ok_and(|manifest| manifest.artifacts[1].sha256 == self.pin.helper.binary_sha256)
|
||||
&& *new_pin_sha256 == self.raw_pin_sha256
|
||||
&& *new_settings_sha256 == self.raw_settings_sha256
|
||||
}
|
||||
/// Import only independently authenticated raw helper evidence. c+start is
|
||||
/// atomic through the existing core API. A crash before outcome persistence
|
||||
/// stays locked; the next fresh snapshot repairs that exact start idempotently.
|
||||
@@ -159,9 +220,9 @@ impl Client {
|
||||
let permit = intent.permit()?;
|
||||
ensure!(
|
||||
self.supports_system(&job)
|
||||
&& intent.policy_sha256 == self.pin.policy_sha256
|
||||
&& intent.helper_binary_sha256 == self.pin.helper.binary_sha256
|
||||
&& snapshot.boot_id == intent.original_boot_id
|
||||
&& self.retained_intent_context(&intent, &job)
|
||||
&& (snapshot.boot_id == intent.original_boot_id
|
||||
|| rmm_domain::windows_reboot::supported(&job))
|
||||
&& snapshot.journal_id == intent.anchor.journal_id()
|
||||
&& snapshot.checkpoint >= intent.anchor.checkpoint()
|
||||
&& observed_at >= intent.recorded_at
|
||||
@@ -176,8 +237,78 @@ impl Client {
|
||||
.next()
|
||||
.context("SYSTEM_DELEGATION_NO_HELPER_EVIDENCE")?;
|
||||
ensure!(matches.next().is_none(), "SYSTEM_DUPLICATE_HELPER_ATTEMPT");
|
||||
if matches!(job.action, Action::UpdateAgent { .. })
|
||||
&& !row.update_handoff_bytes.is_empty()
|
||||
{
|
||||
let proof = rmm_domain::agent_update::UpdateInflightProof::from_bytes(
|
||||
&row.update_handoff_bytes,
|
||||
)
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
let key = rmm_domain::agent_update::job_health_public_key(&job)
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
let (handoff, _) = rmm_domain::agent_update::verify_inflight_proof(&proof, key)
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
ensure!(
|
||||
rmm_domain::agent_update::handoff_matches_job(&handoff, &job)
|
||||
&& handoff.attempt.grant_id == permit.grant_id
|
||||
&& row.job_id == job.job_id
|
||||
&& row.attempt_id == job.attempt_id
|
||||
&& row.job_payload_hash == permit.job_payload_hash
|
||||
&& row.authorization_id == permit.authorization_id
|
||||
&& row.plan_hash == permit.plan_hash
|
||||
&& row.action == permit.action
|
||||
&& row.execution_identity == "system"
|
||||
&& row.grant_id == permit.grant_id
|
||||
&& row.original_request_sha256
|
||||
== rmm_domain::jobs::hash(&serde_json::to_vec(&intent.request)?)
|
||||
&& row.original_boot_id == intent.original_boot_id
|
||||
&& handoff.boot_id == intent.original_boot_id
|
||||
&& row.state == "running"
|
||||
&& row.consumption == "consumed"
|
||||
&& row.outcome_bytes.is_empty()
|
||||
&& row.outcome_sha256.is_empty()
|
||||
&& snapshot.journal_id == handoff.helper_journal_id,
|
||||
"UPDATE_MIRROR_ORIGINAL_INFLIGHT"
|
||||
);
|
||||
let start = core_ledger::start_witness_bytes(
|
||||
&permit,
|
||||
&intent.request,
|
||||
handoff.boot_id,
|
||||
proof.delegation.prepared_at,
|
||||
)?;
|
||||
ensure!(
|
||||
rmm_domain::jobs::hash(&start) == handoff.attempt.original_start_witness_sha256,
|
||||
"UPDATE_MIRROR_ORIGINAL_START"
|
||||
);
|
||||
let existing: Option<Vec<u8>> = ledger
|
||||
.query_row(
|
||||
"SELECT start FROM execution_evidence WHERE grant_id=?1",
|
||||
[permit.grant_id.to_string()],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.optional()?;
|
||||
if let Some(existing) = existing {
|
||||
ensure!(existing == start, "UPDATE_MIRROR_LOCAL_START_CONFLICT");
|
||||
} else {
|
||||
core_ledger::begin_execution(
|
||||
ledger,
|
||||
&permit,
|
||||
&intent.request,
|
||||
handoff.boot_id,
|
||||
proof.delegation.prepared_at,
|
||||
)?;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let outcome =
|
||||
verified_mirror_row(row, &job, &permit, &intent.request, intent.original_boot_id)?;
|
||||
if rmm_domain::windows_reboot::supported(&job) && outcome.state == "succeeded" {
|
||||
ensure!(
|
||||
snapshot.boot_id != intent.original_boot_id
|
||||
&& outcome.evidence["new_boot_id"] == snapshot.boot_id.to_string(),
|
||||
"SYSTEM_REBOOT_MIRROR_NEW_BOOT"
|
||||
);
|
||||
}
|
||||
let existing:Option<(String,u64,String,String,Vec<u8>)>=ledger.query_row("SELECT c.agent,c.generation,c.job,c.attempt,e.start FROM consumed c JOIN execution_evidence e USING(grant_id) WHERE c.grant_id=?1",[permit.grant_id.to_string()],|r|Ok((r.get(0)?,r.get(1)?,r.get(2)?,r.get(3)?,r.get(4)?))).optional()?;
|
||||
if let Some((agent, generation, j, a, start)) = existing {
|
||||
let start: serde_json::Value = serde_json::from_slice(&start)?;
|
||||
@@ -189,9 +320,16 @@ impl Client {
|
||||
&& a == job.attempt_id.to_string()
|
||||
&& serde_json::to_vec(&request)? == serde_json::to_vec(&intent.request)?
|
||||
&& start["previous_boot_id"] == intent.original_boot_id.to_string()
|
||||
&& serde_json::from_value::<chrono::DateTime<chrono::Utc>>(
|
||||
start["reserved_at"].clone()
|
||||
)? == intent.recorded_at,
|
||||
&& {
|
||||
let at = serde_json::from_value::<chrono::DateTime<chrono::Utc>>(
|
||||
start["reserved_at"].clone(),
|
||||
)?;
|
||||
if matches!(job.action, Action::UpdateAgent { .. }) {
|
||||
at >= permit.not_before && at < permit.start_before
|
||||
} else {
|
||||
at == intent.recorded_at
|
||||
}
|
||||
},
|
||||
"SYSTEM_MIRROR_LOCAL_START_CONFLICT"
|
||||
);
|
||||
} else {
|
||||
@@ -226,10 +364,9 @@ impl Client {
|
||||
== Some(row.outcome_sha256.as_str());
|
||||
ensure!(
|
||||
self.supports_system(&job)
|
||||
&& ((intent.policy_sha256 == self.pin.policy_sha256
|
||||
&& intent.helper_binary_sha256 == self.pin.helper.binary_sha256)
|
||||
|| mirrored)
|
||||
&& snapshot.boot_id == intent.original_boot_id
|
||||
&& (self.retained_intent_context(&intent, &job) || mirrored)
|
||||
&& (snapshot.boot_id == intent.original_boot_id
|
||||
|| rmm_domain::windows_reboot::supported(&job))
|
||||
&& snapshot.journal_id == intent.anchor.journal_id()
|
||||
&& snapshot.checkpoint >= intent.anchor.checkpoint(),
|
||||
"SYSTEM_MIRROR_CONTEXT"
|
||||
@@ -358,25 +495,48 @@ impl Client {
|
||||
ready,
|
||||
ledger,
|
||||
lock,
|
||||
reboot_privilege_available,
|
||||
update_observer_configured,
|
||||
} = reply.body
|
||||
else {
|
||||
anyhow::bail!("HELPER_PROBE_DENIED");
|
||||
};
|
||||
let value = json!({"schema_version":1,"source":"actual_local_service_runtime","agent_process_id":std::process::id(),"agent_service":crate::SERVICE_NAME,"agent_id":pin.binding.agent_id,"asset_id":pin.binding.asset_id,"challenge":reply.challenge,"observed_at":chrono::Utc::now(),"helper_service":ipc::HELPER_SERVICE,"verified_helper_user_sid":pin.helper.user_sid,"verified_helper_service_sid":pin.helper.service_sid,"helper_binary_sha256":reply.helper_binary_sha256,"policy_sha256":reply.policy_sha256,"authenticated_pipe_exchange":true,"client_service_pid_verified_by_helper":true,"ledger_file_id":ledger,"executor_lock_file_id":lock,"helper_clock_qualified":clock_qualified,"helper_ready":ready,"system_capability_advertised":false,"no_jobs":true});
|
||||
self.check_pin()?;
|
||||
// Advertise the static qualification independently of this connection's
|
||||
// clock warm-up: a capability change forces a reconnect, which resets the
|
||||
// per-generation clock again. Every start stays gated by helper readiness.
|
||||
let _ = clock_qualified;
|
||||
self.qualified_capabilities=crate::system_capabilities::qualified(pin,true)?;
|
||||
self.probed_at=Some(std::time::Instant::now());
|
||||
let mut value=value;
|
||||
value["system_capability_advertised"]=json!(!self.qualified_capabilities.is_empty());
|
||||
value["qualified_capabilities"]=json!(self.qualified_capabilities);
|
||||
// Static qualification only; a per-connection clock warm-up must not flap
|
||||
// advertised capabilities (each change forces a reconnect).
|
||||
let qualification=crate::system_capabilities::qualified(pin,true,reboot_privilege_available);
|
||||
let system_qualification_unavailable=qualification.is_err();
|
||||
// Capability evidence is deny-only. A missing/stale optional record
|
||||
// cannot remove the separately authenticated control/SignedSync lane.
|
||||
self.qualified_capabilities=qualification.unwrap_or_default();
|
||||
self.update_observer_configured=update_observer_configured==Some(true);
|
||||
self.probed_at = Some(std::time::Instant::now());
|
||||
let mut value = value;
|
||||
if system_qualification_unavailable {
|
||||
value["system_qualification_diagnostic"]="SYSTEM_QUALIFICATION_UNAVAILABLE".into();
|
||||
}
|
||||
value["system_capability_advertised"] = json!(!self.qualified_capabilities.is_empty());
|
||||
value["qualified_capabilities"] = json!(self.qualified_capabilities);
|
||||
if let Some(available) = reboot_privilege_available {
|
||||
value["reboot_privilege_available"] = json!(available);
|
||||
}
|
||||
write_current_probe(state, &value).context(ipc::Stage::ClientReport)
|
||||
}
|
||||
/// An actual recent authenticated Probe negotiates the passive method.
|
||||
/// Old helpers/missing local policy return false; never probe unknown IPC.
|
||||
pub fn update_observer_configured(&self)->bool {
|
||||
self.update_observer_configured && self.probed_at.is_some_and(|at|at.elapsed()<=Duration::from_secs(90))
|
||||
}
|
||||
pub fn qualified_capabilities(&self) -> Vec<String> {
|
||||
if self.probed_at.is_some_and(|at|at.elapsed()<=Duration::from_secs(90)) {self.qualified_capabilities.clone()} else {vec![]}
|
||||
if self
|
||||
.probed_at
|
||||
.is_some_and(|at| at.elapsed() <= Duration::from_secs(90))
|
||||
{
|
||||
self.qualified_capabilities.clone()
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
/// Pure admission shape only; no capability or qualification is asserted.
|
||||
pub fn supports_system(&self, job: &JobPayload) -> bool {
|
||||
@@ -394,13 +554,17 @@ impl Client {
|
||||
&self,
|
||||
intent: intent::Intent,
|
||||
admit: impl Fn() -> Result<()> + Send + 'static,
|
||||
) -> Result<()> {
|
||||
) -> Result<Option<crate::update_admission::Accepted>> {
|
||||
let job = self.pin.binding.job(&intent.request.job_bytes)?;
|
||||
ensure!(
|
||||
intent.connection_generation > 0 && self.supports_system(&job),
|
||||
"SYSTEM_TYPED_SERVICE_REQUIRED"
|
||||
);
|
||||
let timeout = execution_timeout(job.max_runtime_seconds)?;
|
||||
let timeout = if matches!(job.action, Action::UpdateAgent { .. }) {
|
||||
Duration::from_secs(60)
|
||||
} else {
|
||||
execution_timeout(job.max_runtime_seconds)?
|
||||
};
|
||||
let permit = self
|
||||
.lane
|
||||
.clone()
|
||||
@@ -438,6 +602,14 @@ impl Client {
|
||||
let call = ipc::Call::new(&client.pin, operation);
|
||||
let reply = ipc::exchange(&client.pin, &call, timeout)?;
|
||||
client.check_pin()?;
|
||||
if let ipc::ReplyBody::UpdateAccepted { accepted } = &reply.body {
|
||||
ensure!(
|
||||
matches!(job.action, Action::UpdateAgent { .. }),
|
||||
"UPDATE_ACK_FOR_NONUPDATE"
|
||||
);
|
||||
accepted.matches(&intent.request, intent.permit()?.grant_id)?;
|
||||
return Ok(Some(accepted.clone()));
|
||||
}
|
||||
let outcome = match reply.body {
|
||||
ipc::ReplyBody::Executed { outcome }
|
||||
| ipc::ReplyBody::Abandoned { outcome } => outcome,
|
||||
@@ -446,7 +618,7 @@ impl Client {
|
||||
checked_outcome(&job, &outcome)?;
|
||||
// A reply is never the consumption/mirror witness. Every outcome,
|
||||
// including a successful reply, requires a fresh raw snapshot.
|
||||
Ok::<_, anyhow::Error>(())
|
||||
Ok::<_, anyhow::Error>(None)
|
||||
}),
|
||||
)
|
||||
.await
|
||||
@@ -476,6 +648,101 @@ impl Client {
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
/// Independent passive measurements only; returned records grant no job.
|
||||
pub async fn observe_update(&self,request:crate::update_observer::Request)->Result<crate::update_observer::Response> {
|
||||
let permit=tokio::time::timeout(Duration::from_secs(5),self.lane.clone().acquire_owned()).await.context("UPDATE_OBSERVER_LANE_BUSY")??;
|
||||
let client=self.clone();
|
||||
tokio::task::spawn_blocking(move||->Result<crate::update_observer::Response>{
|
||||
let _permit=permit;client.check_pin()?;
|
||||
let reply=ipc::exchange(&client.pin,&ipc::Call::new(&client.pin,ipc::Operation::UpdateObserve{request:request.clone()}),Duration::from_secs(15))?;
|
||||
client.check_pin()?;
|
||||
let ipc::ReplyBody::UpdateObservation{response}=reply.body else {anyhow::bail!("UPDATE_OBSERVER_HELPER_DENIED");};
|
||||
response.validate(request.generation)?;
|
||||
ensure!(response.observation.predecessor.as_ref().is_some_and(|p|p.agent_sha256==client.pin.agent.binary_sha256 && p.helper_sha256==client.pin.helper.binary_sha256),"UPDATE_OBSERVER_ACTUAL_PAIR");
|
||||
Ok(*response)
|
||||
}).await?
|
||||
}
|
||||
/// Evidence-only metadata for the already consumed original Update job.
|
||||
/// No LocalService caller can claim Stop/Finalize through this route.
|
||||
pub async fn submit_update_health(
|
||||
&self,
|
||||
handoff: &rmm_updater_handoff::Handoff,
|
||||
key: [u8; 32],
|
||||
receipt: rmm_updater_handoff::SignedHealth,
|
||||
) -> Result<()> {
|
||||
use rmm_agent_core::update_handoff::{NativeControlOperation, NativeControlRequest};
|
||||
handoff.validate()?;
|
||||
let request = NativeControlRequest {
|
||||
operation: "agent_update_control_v1".into(),
|
||||
schema_version: 1,
|
||||
challenge: uuid::Uuid::new_v4(),
|
||||
tenant_id: handoff.attempt.tenant_id,
|
||||
asset_id: handoff.attempt.asset_id,
|
||||
agent_id: handoff.attempt.agent_id,
|
||||
enrollment_generation: handoff.attempt.enrollment_generation,
|
||||
assignment_version: handoff.attempt.assignment_version,
|
||||
grant_id: handoff.attempt.grant_id,
|
||||
owner_nonce: handoff.owner_nonce,
|
||||
handoff_sha256: rmm_domain::jobs::hash(&handoff.bytes()?),
|
||||
method: NativeControlOperation::Health { receipt },
|
||||
};
|
||||
let permit =
|
||||
tokio::time::timeout(Duration::from_secs(5), self.lane.clone().acquire_owned())
|
||||
.await
|
||||
.context("UPDATE_HEALTH_CONTROL_BUSY")??;
|
||||
let client = self.clone();
|
||||
tokio::task::spawn_blocking(move || -> Result<()> {
|
||||
let _permit = permit;
|
||||
client.check_pin()?;
|
||||
let reply = ipc::exchange(
|
||||
&client.pin,
|
||||
&ipc::Call::new(
|
||||
&client.pin,
|
||||
ipc::Operation::UpdateHealth {
|
||||
request: request.clone(),
|
||||
},
|
||||
),
|
||||
Duration::from_secs(5),
|
||||
)?;
|
||||
client.check_pin()?;
|
||||
let ipc::ReplyBody::UpdateHealth { reply } = reply.body else {
|
||||
anyhow::bail!("UPDATE_HEALTH_HELPER_DENIED");
|
||||
};
|
||||
ensure!(
|
||||
reply.schema_version == 1
|
||||
&& reply.challenge == request.challenge
|
||||
&& !reply.ready
|
||||
&& reply.grant_id == request.grant_id
|
||||
&& reply.owner_nonce == request.owner_nonce
|
||||
&& reply.handoff_sha256 == request.handoff_sha256
|
||||
&& reply.tenant_id == request.tenant_id
|
||||
&& reply.asset_id == request.asset_id
|
||||
&& reply.agent_id == request.agent_id
|
||||
&& reply.enrollment_generation == request.enrollment_generation
|
||||
&& reply.assignment_version == request.assignment_version
|
||||
&& reply.original_start_base64url.is_none()
|
||||
&& reply.pre_stop_sync_request_base64url.is_none()
|
||||
&& reply.pre_stop_sync_response_base64url.is_none()
|
||||
&& reply.claim.is_none()
|
||||
&& reply.original_outcome_base64url.is_none(),
|
||||
"UPDATE_HEALTH_REPLY_BINDING"
|
||||
);
|
||||
let proof = reply.proof.context("UPDATE_HEALTH_REPLY_PROOF")?;
|
||||
let (actual, journal) = rmm_domain::agent_update::verify_inflight_proof(&proof, key)
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
ensure!(
|
||||
rmm_domain::jobs::hash(&actual.bytes()?) == request.handoff_sha256
|
||||
&& matches!(
|
||||
journal.phase(),
|
||||
rmm_updater_handoff::Phase::HealthVerified
|
||||
| rmm_updater_handoff::Phase::RollbackHealthVerified
|
||||
),
|
||||
"UPDATE_HEALTH_ORIGINAL_PROOF"
|
||||
);
|
||||
Ok(())
|
||||
})
|
||||
.await?
|
||||
}
|
||||
pub async fn snapshot(&self, generation: u64, boot: uuid::Uuid) -> Result<ControlSnapshot> {
|
||||
let reply = self.call(ipc::Operation::Snapshot { generation }).await?;
|
||||
let ipc::ReplyBody::Snapshot { snapshot } = reply.body else {
|
||||
@@ -599,6 +866,18 @@ fn verified_mirror_row(
|
||||
Ok(outcome)
|
||||
}
|
||||
fn system_shape(job: &JobPayload) -> bool {
|
||||
if let Action::UpdateAgent { update } = &job.action {
|
||||
return job.execution_identity == "system"
|
||||
&& job.max_runtime_seconds == 600
|
||||
&& update.validate()
|
||||
&& update.execution_identity() == Some("system")
|
||||
&& job
|
||||
.action
|
||||
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes);
|
||||
}
|
||||
if matches!(job.action, Action::Reboot { .. }) {
|
||||
return rmm_domain::windows_reboot::supported(job);
|
||||
}
|
||||
if job.action.full_maintenance() {
|
||||
return job.execution_identity == "system"
|
||||
&& job.action.validate()
|
||||
@@ -627,6 +906,123 @@ fn execution_timeout(seconds: u32) -> Result<Duration> {
|
||||
Ok(Duration::from_secs(u64::from(seconds) + 5))
|
||||
}
|
||||
pub(super) fn checked_outcome(job: &JobPayload, outcome: &Outcome) -> Result<()> {
|
||||
if let Action::UpdateAgent { update } = &job.action {
|
||||
ensure!(
|
||||
system_shape(job)
|
||||
&& outcome.stdout.is_empty()
|
||||
&& outcome.stderr.is_empty()
|
||||
&& !outcome.output_truncated
|
||||
&& !outcome.reboot_required,
|
||||
"UPDATE_OUTCOME_SCOPE"
|
||||
);
|
||||
let evidence = &outcome.evidence;
|
||||
let data = &evidence["agent_update"];
|
||||
match outcome.state.as_str() {
|
||||
"succeeded" => {
|
||||
ensure!(
|
||||
outcome.exit_code == Some(0)
|
||||
&& outcome.error_code.is_empty()
|
||||
&& evidence["postconditions_passed"] == true
|
||||
&& data["schema_version"] == 1
|
||||
&& data["manifest_sha256"] == update.manifest_sha256
|
||||
&& data["predecessor_record_sha256"]
|
||||
== update.predecessor.installed_record_sha256
|
||||
&& data["rolled_back"] == false
|
||||
&& [
|
||||
"handoff_sha256",
|
||||
"installed_record_sha256",
|
||||
"signed_health_sha256"
|
||||
]
|
||||
.iter()
|
||||
.all(|k| data[*k]
|
||||
.as_str()
|
||||
.is_some_and(rmm_domain::agent_update::digest))
|
||||
&& data["activation_floor"]
|
||||
== update
|
||||
.manifest()
|
||||
.map_err(anyhow::Error::msg)?
|
||||
.release_sequence,
|
||||
"UPDATE_SUCCESS_EVIDENCE"
|
||||
);
|
||||
}
|
||||
"failed" if data["rolled_back"] == true => ensure!(
|
||||
outcome.exit_code.is_none()
|
||||
&& outcome.error_code == "AGENT_UPDATE_RETURNED_TO_PREDECESSOR"
|
||||
&& evidence["postconditions_passed"] == false
|
||||
&& data["schema_version"] == 2
|
||||
&& data["manifest_sha256"] == update.manifest_sha256
|
||||
&& data["predecessor_record_sha256"]
|
||||
== update.predecessor.installed_record_sha256
|
||||
&& data["installed_record_sha256"]
|
||||
== update.predecessor.installed_record_sha256
|
||||
&& ["handoff_sha256", "signed_health_sha256"]
|
||||
.iter()
|
||||
.all(|k| data[*k]
|
||||
.as_str()
|
||||
.is_some_and(rmm_domain::agent_update::digest)),
|
||||
"UPDATE_ROLLBACK_EVIDENCE"
|
||||
),
|
||||
"failed" | "cancelled" | "expired" => ensure!(
|
||||
evidence["not_started"] == true && !outcome.error_code.is_empty(),
|
||||
"UPDATE_NO_START_EVIDENCE"
|
||||
),
|
||||
"unknown" => ensure!(
|
||||
evidence["postconditions_passed"] != true && !outcome.error_code.is_empty(),
|
||||
"UPDATE_UNKNOWN_EVIDENCE"
|
||||
),
|
||||
_ => anyhow::bail!("UPDATE_NONTERMINAL_IS_NOT_OUTCOME"),
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if matches!(job.action, Action::Reboot { .. }) {
|
||||
ensure!(
|
||||
rmm_domain::windows_reboot::supported(job)
|
||||
&& outcome.stdout.is_empty()
|
||||
&& outcome.stderr.is_empty()
|
||||
&& outcome.exit_code.is_none()
|
||||
&& !outcome.output_truncated
|
||||
&& !outcome.reboot_required,
|
||||
"SYSTEM_REBOOT_OUTCOME_SCOPE"
|
||||
);
|
||||
let e = &outcome.evidence;
|
||||
match outcome.state.as_str() {
|
||||
"awaiting_reboot" => ensure!(
|
||||
e["provider"] == "windows.shutdown/1"
|
||||
&& e["native_request_accepted"] == true
|
||||
&& e["postconditions_passed"] == false
|
||||
&& e["force_apps_closed"] == false
|
||||
&& e["local_machine_only"] == true
|
||||
&& e["announcement_seconds"]
|
||||
== rmm_domain::windows_reboot::ANNOUNCEMENT_SECONDS
|
||||
&& e["automatic_retry"] == false
|
||||
&& e["previous_boot_id"]
|
||||
.as_str()
|
||||
.is_some_and(|s| uuid::Uuid::parse_str(s).is_ok_and(|id| !id.is_nil())),
|
||||
"SYSTEM_REBOOT_ACCEPTANCE_EVIDENCE"
|
||||
),
|
||||
"succeeded" => ensure!(
|
||||
e["postconditions_passed"] == true
|
||||
&& e["reconciled_after_reboot"] == true
|
||||
&& ["new_boot_id", "inventory_message_id"].iter().all(|k| e[k]
|
||||
.as_str()
|
||||
.is_some_and(|s| uuid::Uuid::parse_str(s).is_ok_and(|id| !id.is_nil()))),
|
||||
"SYSTEM_REBOOT_NEW_BOOT_EVIDENCE"
|
||||
),
|
||||
"failed" => ensure!(
|
||||
!outcome.error_code.is_empty() && e["not_started"] == true,
|
||||
"SYSTEM_REBOOT_NONSTART_EVIDENCE"
|
||||
),
|
||||
"unknown" => ensure!(
|
||||
!outcome.error_code.is_empty(),
|
||||
"SYSTEM_REBOOT_UNKNOWN_REASON"
|
||||
),
|
||||
"cancelled" | "expired" => {
|
||||
ensure!(e["not_started"] == true, "SYSTEM_REBOOT_NONSTART_EVIDENCE")
|
||||
}
|
||||
_ => anyhow::bail!("SYSTEM_REBOOT_OUTCOME_SCOPE"),
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
ensure!(
|
||||
matches!(
|
||||
outcome.state.as_str(),
|
||||
@@ -856,7 +1252,9 @@ pub fn record_verified_time(
|
||||
rmm_time_attestation::Role::SystemHelper => {
|
||||
("helper-time-sample.json", ".helper-time.pending")
|
||||
}
|
||||
rmm_time_attestation::Role::Updater => anyhow::bail!("TIME_UPDATER_OWN_PROFILE_REQUIRED"),
|
||||
rmm_time_attestation::Role::Updater => {
|
||||
anyhow::bail!("TIME_UPDATER_EVIDENCE_NOT_AGENT_OWNED")
|
||||
}
|
||||
};
|
||||
let value = json!({
|
||||
"schema_version": 1, "agent_pid": std::process::id(), "observed_at": observed_at,
|
||||
@@ -906,6 +1304,37 @@ fn write_report(state: &Path, name: &str, pending: &str, value: &serde_json::Val
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn reboot_acceptance_is_not_success_and_cannot_inherit_another_action() {
|
||||
let mut job = msi_test_job();
|
||||
job.action = Action::Reboot {
|
||||
reason: "Windows-MVP".into(),
|
||||
dependency_group: "windows-mvp".into(),
|
||||
reconnect_timeout_seconds: 180,
|
||||
};
|
||||
job.max_runtime_seconds = 60;
|
||||
let old = uuid::Uuid::new_v4();
|
||||
let mut o = Outcome {
|
||||
state: "awaiting_reboot".into(),
|
||||
stdout: vec![],
|
||||
stderr: vec![],
|
||||
exit_code: None,
|
||||
output_truncated: false,
|
||||
reboot_required: false,
|
||||
error_code: "EFFECT_REQUIRES_RECONCILIATION".into(),
|
||||
evidence: json!({"provider":"windows.shutdown/1","native_request_accepted":true,"postconditions_passed":false,"force_apps_closed":false,"local_machine_only":true,"announcement_seconds":5,"automatic_retry":false,"previous_boot_id":old}),
|
||||
};
|
||||
checked_outcome(&job, &o).unwrap();
|
||||
o.state = "succeeded".into();
|
||||
assert!(checked_outcome(&job, &o).is_err());
|
||||
o.evidence = json!({"postconditions_passed":true,"reconciled_after_reboot":true,"new_boot_id":uuid::Uuid::new_v4(),"inventory_message_id":uuid::Uuid::new_v4()});
|
||||
checked_outcome(&job, &o).unwrap();
|
||||
o.evidence["inventory_message_id"] = json!(null);
|
||||
assert!(checked_outcome(&job, &o).is_err());
|
||||
job.execution_identity = "agent_service".into();
|
||||
assert!(!system_shape(&job));
|
||||
assert!(checked_outcome(&job, &o).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn msi_scope_requires_bound_independent_postconditions_and_exact_noop_or_installer_exit() {
|
||||
let job = msi_test_job();
|
||||
assert!(system_shape(&job));
|
||||
|
||||
Reference in New Issue
Block a user