Apply the script-only capability and start contract to every Windows profile

This commit is contained in:
2026-11-18 12:17:52 +01:00
parent 4afa6e4a12
commit 55fad07327
7 changed files with 41 additions and 103 deletions
Generated
+1 -1
View File
@@ -2213,7 +2213,7 @@ dependencies = [
[[package]] [[package]]
name = "rmm-agent-windows" name = "rmm-agent-windows"
version = "0.1.13" version = "0.1.14"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.22.1", "base64 0.22.1",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "rmm-agent-windows" name = "rmm-agent-windows"
version = "0.1.13" version = "0.1.14"
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true
+1 -1
View File
@@ -505,7 +505,7 @@ impl Client {
self.check_pin()?; self.check_pin()?;
// Static qualification only; a per-connection clock warm-up must not flap // Static qualification only; a per-connection clock warm-up must not flap
// advertised capabilities (each change forces a reconnect). // advertised capabilities (each change forces a reconnect).
let qualification=crate::system_capabilities::qualified(pin,true,reboot_privilege_available); let qualification=crate::system_capabilities::qualified(pin,true);
let system_qualification_unavailable=qualification.is_err(); let system_qualification_unavailable=qualification.is_err();
// Capability evidence is deny-only. A missing/stale optional record // Capability evidence is deny-only. A missing/stale optional record
// cannot remove the separately authenticated control/SignedSync lane. // cannot remove the separately authenticated control/SignedSync lane.
+1 -3
View File
@@ -1153,9 +1153,7 @@ impl SystemHelper {
request, request,
} => { } => {
let job = self.settings.binding.job(&request.job_bytes)?; let job = self.settings.binding.job(&request.job_bytes)?;
if self.settings.managed_scripts() { ensure!(self.settings.permits_script(&job), "SYSTEM_SCRIPT_REQUIRED");
ensure!(self.settings.permits_script(&job), "MANAGED_SYSTEM_SCRIPT_REQUIRED");
}
if matches!(job.action, Action::UpdateAgent { .. }) { if matches!(job.action, Action::UpdateAgent { .. }) {
ensure!( ensure!(
self.pending_update_activation.is_none(), self.pending_update_activation.is_none(),
+26 -35
View File
@@ -92,19 +92,19 @@ fn rotation_file_id(path: &Path) -> Result<[u32; 3]> {
]) ])
} }
impl Config { impl Config {
fn allows_enrolled_action(&self, action: &Action, identity: &str) -> bool { fn allows_script_action(&self, action: &Action, identity: &str) -> bool {
if self.localservice_time_policy.is_none() {
return true;
}
let Action::RunScript { interpreter, windows_execution_profile, .. } = action else { let Action::RunScript { interpreter, windows_execution_profile, .. } = action else {
return false; return false;
}; };
let system = match &self.localservice_time_policy {
Some(_) => (self.managed_script_helper && action.full_maintenance())
|| (self.windows_update_helper && action.windows_update_or_identity_probe()),
None => self.job_binding_file.is_some() && action.full_maintenance(),
};
interpreter == "powershell" interpreter == "powershell"
&& windows_execution_profile.is_none_or(|p| self.profile_enabled(p)) && windows_execution_profile.is_none_or(|p| self.profile_enabled(p))
&& action.valid_execution_identity(identity) && action.valid_execution_identity(identity)
&& (identity == "agent_service" || (identity == "system" && (identity == "agent_service" || (identity == "system" && system))
&& ((self.managed_script_helper && action.full_maintenance())
|| (self.windows_update_helper && action.windows_update_or_identity_probe()))))
} }
fn profile_enabled(&self, profile: rmm_domain::jobs::WindowsExecutionProfile) -> bool { fn profile_enabled(&self, profile: rmm_domain::jobs::WindowsExecutionProfile) -> bool {
self.enable_jobs self.enable_jobs
@@ -1423,7 +1423,7 @@ impl Agent {
Ok(()) Ok(())
} }
fn supported_job(&self, job: &rmm_domain::jobs::JobPayload) -> bool { fn supported_job(&self, job: &rmm_domain::jobs::JobPayload) -> bool {
if !self.config.allows_enrolled_action(&job.action, &job.execution_identity) { if !self.config.allows_script_action(&job.action, &job.execution_identity) {
return false; return false;
} }
if self.config.windows_echo_probe_only if self.config.windows_echo_probe_only
@@ -1575,9 +1575,6 @@ impl Agent {
&& native::require_local_service().is_ok() && native::require_local_service().is_ok()
{ {
caps.push("rmm.sync.v1".into()); caps.push("rmm.sync.v1".into());
if !self.config.windows_echo_probe_only && self.config.localservice_time_policy.is_none() {
caps.push("refresh_inventory".into());
}
if rmm_agent_windows::actions::powershell().is_ok() { if rmm_agent_windows::actions::powershell().is_ok() {
caps.extend(["run_script", "script.powershell/1"].map(str::to_string)); caps.extend(["run_script", "script.powershell/1"].map(str::to_string));
if self.config.profile_enabled( if self.config.profile_enabled(
@@ -1590,25 +1587,11 @@ impl Agent {
if !self.config.windows_echo_probe_only if !self.config.windows_echo_probe_only
&& let Some(helper) = &self.helper && let Some(helper) = &self.helper
{ {
let enrolled = self.config.localservice_time_policy.is_some(); if self.config.job_binding_file.is_some()
if enrolled { || self.config.managed_script_helper || self.config.windows_update_helper
if self.config.managed_script_helper || self.config.windows_update_helper { {
caps.extend(helper.qualified_capabilities().into_iter().filter(|cap| {
matches!(cap.as_str(), "helper.system.v1" | "system:run_script"
| rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY
| rmm_domain::jobs::WINDOWS_UPDATE_LONG_CAPABILITY)
|| cap.starts_with("helper.binary.sha256:")
|| cap.starts_with("helper.policy.sha256:")
|| cap.starts_with("script.helper.release:")
}));
}
} else {
caps.extend(helper.qualified_capabilities()); caps.extend(helper.qualified_capabilities());
} }
if !enrolled && helper.update_observer_configured()
&& self.update_observer.cached().is_some_and(|r|r.observation.predecessor.as_ref().is_some_and(|p|p.helper_sha256==helper.helper_binary_hash())) {
for cap in self.update_observer.capabilities(){if !caps.contains(&cap){caps.push(cap);}}
}
} }
} }
caps caps
@@ -2671,7 +2654,7 @@ impl Agent {
if let Ok(now)=self.clock.now() && let Some(offer)=jobs::next_at(self.journal.connection(),now)? { if let Ok(now)=self.clock.now() && let Some(offer)=jobs::next_at(self.journal.connection(),now)? {
let job=self.binding.as_ref().context("JOB_BINDING_REQUIRED")?.job(&offer.payload_bytes)?; let job=self.binding.as_ref().context("JOB_BINDING_REQUIRED")?.job(&offer.payload_bytes)?;
if now>=job.start_before {self.record(generation,&offer,"",jobs::no_start("expired","START_DEADLINE_EXPIRED"))?;needs_sync=true;} if now>=job.start_before {self.record(generation,&offer,"",jobs::no_start("expired","START_DEADLINE_EXPIRED"))?;needs_sync=true;}
else if !self.config.allows_enrolled_action(&job.action, &job.execution_identity) || !self.scope_permits(&offer, &job) { else if !self.config.allows_script_action(&job.action, &job.execution_identity) || !self.scope_permits(&offer, &job) {
// Only next_at's accepted row is known to have no reserved permit. // Only next_at's accepted row is known to have no reserved permit.
self.record(generation, &offer, "", jobs::no_start("failed", "LEGACY_ACTION_RETIRED"))?; self.record(generation, &offer, "", jobs::no_start("failed", "LEGACY_ACTION_RETIRED"))?;
needs_sync = true; needs_sync = true;
@@ -3133,18 +3116,26 @@ mod tests {
"action":"run_script","interpreter":"powershell","script_utf8":"Write-Output 1", "action":"run_script","interpreter":"powershell","script_utf8":"Write-Output 1",
"arguments":[],"expected_stdout":null,"windows_execution_profile":"powershell_51_remote_signed" "arguments":[],"expected_stdout":null,"windows_execution_profile":"powershell_51_remote_signed"
})).unwrap(); })).unwrap();
assert!(config.allows_enrolled_action(&script, "agent_service")); assert!(config.allows_script_action(&script, "agent_service"));
let legacy = Action::RefreshInventory { scope: "windows.base".into() }; let legacy = Action::RefreshInventory { scope: "windows.base".into() };
assert!(!config.allows_enrolled_action(&legacy, "agent_service")); assert!(!config.allows_script_action(&legacy, "agent_service"));
assert!(!config.allows_enrolled_action(&script,"system")); assert!(!config.allows_script_action(&script,"system"));
let Action::RunScript { ref mut privileged_script_profile, .. } = script else { unreachable!() }; let Action::RunScript { ref mut privileged_script_profile, .. } = script else { unreachable!() };
*privileged_script_profile = Some(rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1); *privileged_script_profile = Some(rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1);
config.windows_update_helper = true; config.windows_update_helper = true;
assert!(!config.allows_enrolled_action(&script,"system")); assert!(!config.allows_script_action(&script,"system"));
config.windows_update_helper = false; config.windows_update_helper = false;
config.managed_script_helper = true; config.managed_script_helper = true;
assert!(config.allows_enrolled_action(&script, "system")); assert!(config.allows_script_action(&script, "system"));
assert!(!config.allows_enrolled_action(&legacy, "system")); assert!(!config.allows_script_action(&legacy, "system"));
config.localservice_time_policy = None;
config.managed_script_helper = false;
config.job_binding_file = Some("job-binding.json".into());
assert!(!config.allows_script_action(&legacy, "agent_service"));
assert!(!config.allows_script_action(&legacy, "system"));
assert!(config.allows_script_action(&script, "system"));
config.job_binding_file = None;
assert!(!config.allows_script_action(&script, "system"));
} }
#[cfg(feature = "system-helper")] #[cfg(feature = "system-helper")]
#[tokio::test] #[tokio::test]
+10 -57
View File
@@ -34,7 +34,6 @@ struct Qualification {
pub fn qualified( pub fn qualified(
pin: &Pin, pin: &Pin,
clock_qualified: bool, clock_qualified: bool,
reboot_privilege_available: Option<bool>,
) -> Result<Vec<String>> { ) -> Result<Vec<String>> {
if !clock_qualified { if !clock_qualified {
return Ok(vec![]); return Ok(vec![]);
@@ -92,67 +91,21 @@ pub fn qualified(
&& settings.enable_effects, && settings.enable_effects,
"system qualification effective policy" "system qualification effective policy"
); );
if !q.actions.iter().any(|action| action == "run_script") {
return Ok(vec![]);
}
let general = settings.allowed_script_profiles.as_deref() ==
Some(&[rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1]);
let windows_update = settings.windows_update_max_runtime_seconds.is_some();
ensure!(settings.schema_version >= 3 && (general || windows_update), "system script qualification policy");
let mut caps = vec![ let mut caps = vec![
"helper.system.v1".into(), "helper.system.v1".into(),
format!("helper.binary.sha256:{}", pin.helper.binary_sha256), format!("helper.binary.sha256:{}", pin.helper.binary_sha256),
format!("helper.policy.sha256:{}", pin.policy_sha256), format!("helper.policy.sha256:{}", pin.policy_sha256),
"system:run_script".into(),
]; ];
for action in q.actions { if general { caps.push(rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY.into()); }
match action.as_str() { if windows_update { caps.push(rmm_domain::jobs::WINDOWS_UPDATE_LONG_CAPABILITY.into()); }
"run_script" => {
let general = settings.allowed_script_profiles.as_deref() ==
Some(&[rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1]);
let windows_update = settings.windows_update_max_runtime_seconds.is_some();
ensure!(settings.schema_version >= 3 && (general || windows_update), "system script qualification policy");
caps.push("system:run_script".into());
if general { caps.push(rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY.to_owned()); }
if windows_update { caps.push(rmm_domain::jobs::WINDOWS_UPDATE_LONG_CAPABILITY.to_owned()); }
}
"set_service_state" => {
ensure!(
!settings.allowed_services.is_empty(),
"system SCM qualification policy"
);
caps.extend(["set_service_state", "system:set_service_state"].map(str::to_string));
}
"ensure_package" => {
ensure!(
settings.schema_version >= 2
&& settings
.allowed_msi_recipe_sha256
.as_ref()
.is_some_and(|v| !v.is_empty())
&& crate::msi_cache::stage_configured(),
"system MSI qualification policy"
);
caps.extend(
[
"ensure_package",
"system:ensure_package",
rmm_domain::windows_execution::MSI_CAPABILITY,
]
.map(str::to_string),
);
}
"reboot" => {
ensure!(
settings.schema_version == 4
&& settings.allow_reboot
&& reboot_privilege_available == Some(true),
"system reboot qualification policy or live token"
);
caps.extend(
[
"reboot",
"system:reboot",
rmm_domain::windows_reboot::CAPABILITY,
]
.map(str::to_string),
);
}
_ => unreachable!("validated qualification action"),
}
}
Ok(caps) Ok(caps)
} }
fn read(path: &Path, max: u64) -> Result<Vec<u8>> { fn read(path: &Path, max: u64) -> Result<Vec<u8>> {
@@ -49,9 +49,5 @@ impl Observer {
pub fn observation(&self,generation:u64)->AgentUpdateObservation{ pub fn observation(&self,generation:u64)->AgentUpdateObservation{
self.cached().filter(|v|v.generation==generation).map(|v|v.observation.clone()).unwrap_or_else(||AgentUpdateObservation::not_configured(rmm_agent_windows::release_platform::WIRE,chrono::Utc::now())) self.cached().filter(|v|v.generation==generation).map(|v|v.observation.clone()).unwrap_or_else(||AgentUpdateObservation::not_configured(rmm_agent_windows::release_platform::WIRE,chrono::Utc::now()))
} }
pub fn capabilities(&self)->Vec<String>{
let Some(value)=self.cached() else{return vec![];};
let(Some(updater),Some(predecessor))=(&value.observation.updater,&value.observation.predecessor) else{return vec![];};
vec![rmm_domain::agent_update::APPLY_CAPABILITY.into(),rmm_domain::agent_update::CHECK_CAPABILITY.into(),"update_agent".into(),"system:update_agent".into(),"helper.system.v1".into(),format!("updater.binary.sha256:{}",updater.binary_sha256),format!("updater.policy.sha256:{}",updater.policy_sha256),format!("helper.binary.sha256:{}",predecessor.helper_sha256)]
}
} }