Add fresh device trust, installer recovery and scoped patch runtime
This commit is contained in:
@@ -1430,6 +1430,13 @@ impl Server {
|
||||
}
|
||||
}
|
||||
/// Blocking SDK call; run on the agent's bounded blocking worker, never heartbeat reactor.
|
||||
pub fn execution_timeout(action: &rmm_domain::jobs::Action, seconds: u32) -> Result<Duration> {
|
||||
ensure!(
|
||||
(1..=action.windows_system_runtime_limit(120, Some(rmm_domain::jobs::WINDOWS_UPDATE_MAX_SECONDS))).contains(&seconds),
|
||||
"SYSTEM_EXECUTION_TIMEOUT_BOUND"
|
||||
);
|
||||
Ok(Duration::from_secs(u64::from(seconds) + 5))
|
||||
}
|
||||
pub fn exchange(pin: &Pin, call: &Call, timeout: Duration) -> Result<Reply> {
|
||||
exchange_fixed(pin, call, timeout, false)
|
||||
}
|
||||
@@ -1443,10 +1450,17 @@ fn exchange_fixed(pin: &Pin, call: &Call, timeout: Duration, time_only: bool) ->
|
||||
);
|
||||
pin.validate()?;
|
||||
require_self(&pin.agent).context(Stage::ClientSelfRole)?;
|
||||
ensure!(
|
||||
(Duration::from_secs(1)..=Duration::from_secs(125)).contains(&timeout),
|
||||
"HELPER_CALL_TIMEOUT_BOUND"
|
||||
);
|
||||
if timeout > Duration::from_secs(125) {
|
||||
let Operation::Execute { request, .. } = &call.operation else {
|
||||
anyhow::bail!("HELPER_CALL_TIMEOUT_BOUND");
|
||||
};
|
||||
let job = pin.binding.job(&request.job_bytes)?;
|
||||
ensure!(job.execution_identity == "system" && job.action.is_windows_update_template()
|
||||
&& execution_timeout(&job.action, job.max_runtime_seconds)? == timeout,
|
||||
"HELPER_CALL_TIMEOUT_BOUND");
|
||||
} else {
|
||||
ensure!(timeout >= Duration::from_secs(1), "HELPER_CALL_TIMEOUT_BOUND");
|
||||
}
|
||||
let deadline = Instant::now() + timeout;
|
||||
let pipe = owned(unsafe {
|
||||
CreateFileW(
|
||||
|
||||
@@ -563,7 +563,7 @@ impl Client {
|
||||
let timeout = if matches!(job.action, Action::UpdateAgent { .. }) {
|
||||
Duration::from_secs(60)
|
||||
} else {
|
||||
execution_timeout(job.max_runtime_seconds)?
|
||||
ipc::execution_timeout(&job.action, job.max_runtime_seconds)?
|
||||
};
|
||||
let permit = self
|
||||
.lane
|
||||
@@ -898,13 +898,6 @@ fn system_shape(job: &JobPayload) -> bool {
|
||||
&& (1..=65536).contains(&job.max_output_bytes)
|
||||
&& matches!(&job.action,Action::SetServiceState{unit,state} if unit.starts_with("RmmDiscoveryFixture")&&unit.len()>"RmmDiscoveryFixture".len()&&unit.len()<=80&&unit.bytes().all(|b|b.is_ascii_alphanumeric()||b"_-".contains(&b))&&matches!(state.as_str(),"running"|"stopped"))
|
||||
}
|
||||
fn execution_timeout(seconds: u32) -> Result<Duration> {
|
||||
ensure!(
|
||||
(1..=120).contains(&seconds),
|
||||
"SYSTEM_EXECUTION_TIMEOUT_BOUND"
|
||||
);
|
||||
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!(
|
||||
@@ -1023,11 +1016,15 @@ pub(super) fn checked_outcome(job: &JobPayload, outcome: &Outcome) -> Result<()>
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
let windows_update = job.action.is_windows_update_template();
|
||||
let reboot_report = if windows_update && !outcome.output_truncated && matches!(outcome.state.as_str(), "succeeded" | "failed") {
|
||||
rmm_domain::jobs::windows_update_reboot_report(&outcome.stdout)
|
||||
} else { None };
|
||||
ensure!(
|
||||
matches!(
|
||||
outcome.state.as_str(),
|
||||
"succeeded" | "failed" | "cancelled" | "expired" | "unknown"
|
||||
) && (job.action.windows_msi().is_some() || !outcome.reboot_required)
|
||||
) && (job.action.windows_msi().is_some() || outcome.reboot_required == reboot_report.unwrap_or(false))
|
||||
&& outcome
|
||||
.stdout
|
||||
.len()
|
||||
@@ -1092,7 +1089,7 @@ pub(super) fn checked_outcome(job: &JobPayload, outcome: &Outcome) -> Result<()>
|
||||
system_shape(job)
|
||||
&& outcome.exit_code == Some(0)
|
||||
&& !outcome.output_truncated
|
||||
&& !outcome.reboot_required
|
||||
&& (!windows_update || (reboot_report.is_some() && e["windows_update_reboot_required"] == serde_json::json!(reboot_report)))
|
||||
&& e["postconditions_passed"] == true
|
||||
&& e["privileged_script_profile"] == "full_maintenance_v1"
|
||||
&& e["execution_sid"] == "S-1-5-18"
|
||||
@@ -1417,9 +1414,9 @@ mod tests {
|
||||
state: "stopped".into(),
|
||||
};
|
||||
assert!(!system_shape(&job));
|
||||
assert_eq!(execution_timeout(120).unwrap(), Duration::from_secs(125));
|
||||
assert!(execution_timeout(0).is_err());
|
||||
assert!(execution_timeout(121).is_err());
|
||||
assert_eq!(ipc::execution_timeout(&job.action, 120).unwrap(), Duration::from_secs(125));
|
||||
assert!(ipc::execution_timeout(&job.action, 0).is_err());
|
||||
assert!(ipc::execution_timeout(&job.action, 121).is_err());
|
||||
let mut outcome = Outcome::unknown("LOST_REPLY");
|
||||
assert!(checked_outcome(&job, &outcome).is_ok());
|
||||
outcome.reboot_required = true;
|
||||
|
||||
@@ -83,6 +83,8 @@ pub struct Settings {
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_script_profiles"
|
||||
)]
|
||||
pub allowed_script_profiles: Option<Vec<rmm_domain::jobs::PrivilegedScriptProfile>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub windows_update_max_runtime_seconds: Option<u32>,
|
||||
}
|
||||
fn strict_recipe_hashes<'de, D: serde::Deserializer<'de>>(
|
||||
d: D,
|
||||
@@ -113,7 +115,7 @@ impl Settings {
|
||||
&& job
|
||||
.action
|
||||
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes)
|
||||
&& job.max_runtime_seconds <= self.max_runtime_seconds
|
||||
&& job.max_runtime_seconds <= job.action.windows_system_runtime_limit(self.max_runtime_seconds, self.windows_update_max_runtime_seconds)
|
||||
&& self.allowed_script_profiles.as_deref()
|
||||
== Some(&[rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1])
|
||||
}
|
||||
@@ -144,6 +146,7 @@ impl Settings {
|
||||
|v| v == [rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1]
|
||||
)
|
||||
&& (self.schema_version == 4 || !self.allow_reboot)
|
||||
&& rmm_domain::jobs::valid_windows_update_limit(self.windows_update_max_runtime_seconds, self.allowed_script_profiles.as_deref())
|
||||
&& (1..=120).contains(&self.max_runtime_seconds)
|
||||
&& self.allowed_services.len() <= 16,
|
||||
"SYSTEM_POLICY_PROFILE"
|
||||
@@ -1167,8 +1170,8 @@ impl SystemHelper {
|
||||
&& ((job.max_runtime_seconds <= self.settings.max_runtime_seconds
|
||||
&& (matches!(&job.action,Action::SetServiceState{unit,state} if matches!(state.as_str(),"running"|"stopped")&&self.settings.allowed_services.iter().any(|r|r.name==*unit))
|
||||
|| self.settings.permits_msi(&job)
|
||||
|| self.settings.permits_script(&job)
|
||||
|| self.settings.permits_reboot(&job)))
|
||||
|| self.settings.permits_script(&job)
|
||||
|| crate::update_admission::permits_denial(
|
||||
&self.settings.binding,
|
||||
&job
|
||||
@@ -1974,6 +1977,7 @@ mod tests {
|
||||
allow_reboot: false,
|
||||
allowed_msi_recipe_sha256: None,
|
||||
allowed_script_profiles: None,
|
||||
windows_update_max_runtime_seconds: None,
|
||||
};
|
||||
let legacy = serde_json::to_value(&settings).unwrap();
|
||||
assert!(legacy.get("allowed_msi_recipe_sha256").is_none());
|
||||
@@ -2013,6 +2017,19 @@ mod tests {
|
||||
assert!(!settings.permits_script(&script));
|
||||
settings.schema_version = 3;
|
||||
assert!(settings.permits_script(&script));
|
||||
let generic_script = script.action.clone();
|
||||
script.max_runtime_seconds = 3600;
|
||||
settings.windows_update_max_runtime_seconds = Some(3600);
|
||||
assert!(!settings.permits_script(&script));
|
||||
if let Action::RunScript { script_utf8, windows_execution_profile, .. } = &mut script.action {
|
||||
*script_utf8 = rmm_domain::jobs::WINDOWS_UPDATE_SCRIPT_UTF8.into();
|
||||
*windows_execution_profile = Some(rmm_domain::jobs::WindowsExecutionProfile::PowerShell51RemoteSigned);
|
||||
}
|
||||
assert!(settings.permits_script(&script));
|
||||
settings.windows_update_max_runtime_seconds = None;
|
||||
assert!(!settings.permits_script(&script));
|
||||
script.action = generic_script;
|
||||
script.max_runtime_seconds = 30;
|
||||
script.execution_identity = "root".into();
|
||||
assert!(!settings.permits_script(&script));
|
||||
let mut null = legacy;
|
||||
|
||||
@@ -89,6 +89,9 @@ pub fn qualified(
|
||||
&& crate::actions::powershell().is_ok(),
|
||||
"system script qualification policy"
|
||||
);
|
||||
if settings.windows_update_max_runtime_seconds.is_some() {
|
||||
caps.push(rmm_domain::jobs::WINDOWS_UPDATE_LONG_CAPABILITY.to_owned());
|
||||
}
|
||||
caps.extend(["system:run_script", "script.full_maintenance/1"].map(str::to_string));
|
||||
}
|
||||
"set_service_state" => {
|
||||
|
||||
@@ -60,6 +60,8 @@ struct Settings {
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_script_profiles"
|
||||
)]
|
||||
allowed_script_profiles: Option<Vec<PrivilegedScriptProfile>>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
windows_update_max_runtime_seconds: Option<u32>,
|
||||
}
|
||||
fn strict_hashes<'de, D: serde::Deserializer<'de>>(
|
||||
d: D,
|
||||
@@ -213,6 +215,7 @@ pub fn render(input: Inputs<'_>) -> Result<CodePairTransition> {
|
||||
ensure!(
|
||||
matches!(settings.schema_version, 1..=4)
|
||||
&& (settings.schema_version == 4 || !settings.allow_reboot)
|
||||
&& rmm_domain::jobs::valid_windows_update_limit(settings.windows_update_max_runtime_seconds, settings.allowed_script_profiles.as_deref())
|
||||
&& (1..=120).contains(&settings.max_runtime_seconds)
|
||||
&& settings.allowed_services.len() <= 16
|
||||
&& (settings.schema_version >= 2 || settings.allowed_msi_recipe_sha256.is_none())
|
||||
|
||||
Reference in New Issue
Block a user