From 55fad073273c44c4cac4003ae2b10c9d89653ffe Mon Sep 17 00:00:00 2001 From: Kevin Janssen Date: Wed, 18 Nov 2026 12:17:52 +0100 Subject: [PATCH] Apply the script-only capability and start contract to every Windows profile --- Cargo.lock | 2 +- crates/agent-windows/Cargo.toml | 2 +- crates/agent-windows/src/helper_runtime.rs | 2 +- crates/agent-windows/src/helper_system.rs | 4 +- crates/agent-windows/src/runtime.rs | 61 +++++++---------- .../agent-windows/src/system_capabilities.rs | 67 +++---------------- .../src/update_observation_runtime.rs | 6 +- 7 files changed, 41 insertions(+), 103 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 43e708f..2a3f7fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2213,7 +2213,7 @@ dependencies = [ [[package]] name = "rmm-agent-windows" -version = "0.1.13" +version = "0.1.14" dependencies = [ "anyhow", "base64 0.22.1", diff --git a/crates/agent-windows/Cargo.toml b/crates/agent-windows/Cargo.toml index 53d1542..283a6cc 100644 --- a/crates/agent-windows/Cargo.toml +++ b/crates/agent-windows/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rmm-agent-windows" -version = "0.1.13" +version = "0.1.14" edition.workspace = true license.workspace = true diff --git a/crates/agent-windows/src/helper_runtime.rs b/crates/agent-windows/src/helper_runtime.rs index a399f52..743bc99 100644 --- a/crates/agent-windows/src/helper_runtime.rs +++ b/crates/agent-windows/src/helper_runtime.rs @@ -505,7 +505,7 @@ impl Client { self.check_pin()?; // 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 qualification=crate::system_capabilities::qualified(pin,true); 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. diff --git a/crates/agent-windows/src/helper_system.rs b/crates/agent-windows/src/helper_system.rs index 1e23540..6b804ba 100644 --- a/crates/agent-windows/src/helper_system.rs +++ b/crates/agent-windows/src/helper_system.rs @@ -1153,9 +1153,7 @@ impl SystemHelper { request, } => { let job = self.settings.binding.job(&request.job_bytes)?; - if self.settings.managed_scripts() { - ensure!(self.settings.permits_script(&job), "MANAGED_SYSTEM_SCRIPT_REQUIRED"); - } + ensure!(self.settings.permits_script(&job), "SYSTEM_SCRIPT_REQUIRED"); if matches!(job.action, Action::UpdateAgent { .. }) { ensure!( self.pending_update_activation.is_none(), diff --git a/crates/agent-windows/src/runtime.rs b/crates/agent-windows/src/runtime.rs index 9ef85cf..225b11d 100644 --- a/crates/agent-windows/src/runtime.rs +++ b/crates/agent-windows/src/runtime.rs @@ -92,19 +92,19 @@ fn rotation_file_id(path: &Path) -> Result<[u32; 3]> { ]) } impl Config { - fn allows_enrolled_action(&self, action: &Action, identity: &str) -> bool { - if self.localservice_time_policy.is_none() { - return true; - } + fn allows_script_action(&self, action: &Action, identity: &str) -> bool { let Action::RunScript { interpreter, windows_execution_profile, .. } = action else { 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" && windows_execution_profile.is_none_or(|p| self.profile_enabled(p)) && action.valid_execution_identity(identity) - && (identity == "agent_service" || (identity == "system" - && ((self.managed_script_helper && action.full_maintenance()) - || (self.windows_update_helper && action.windows_update_or_identity_probe())))) + && (identity == "agent_service" || (identity == "system" && system)) } fn profile_enabled(&self, profile: rmm_domain::jobs::WindowsExecutionProfile) -> bool { self.enable_jobs @@ -1423,7 +1423,7 @@ impl Agent { Ok(()) } 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; } if self.config.windows_echo_probe_only @@ -1575,9 +1575,6 @@ impl Agent { && native::require_local_service().is_ok() { 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() { caps.extend(["run_script", "script.powershell/1"].map(str::to_string)); if self.config.profile_enabled( @@ -1590,25 +1587,11 @@ impl Agent { if !self.config.windows_echo_probe_only && let Some(helper) = &self.helper { - let enrolled = self.config.localservice_time_policy.is_some(); - if enrolled { - 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 { + if self.config.job_binding_file.is_some() + || self.config.managed_script_helper || self.config.windows_update_helper + { 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 @@ -2671,7 +2654,7 @@ impl Agent { 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)?; 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. self.record(generation, &offer, "", jobs::no_start("failed", "LEGACY_ACTION_RETIRED"))?; needs_sync = true; @@ -3133,18 +3116,26 @@ mod tests { "action":"run_script","interpreter":"powershell","script_utf8":"Write-Output 1", "arguments":[],"expected_stdout":null,"windows_execution_profile":"powershell_51_remote_signed" })).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() }; - assert!(!config.allows_enrolled_action(&legacy, "agent_service")); - assert!(!config.allows_enrolled_action(&script,"system")); + assert!(!config.allows_script_action(&legacy, "agent_service")); + assert!(!config.allows_script_action(&script,"system")); let Action::RunScript { ref mut privileged_script_profile, .. } = script else { unreachable!() }; *privileged_script_profile = Some(rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1); 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.managed_script_helper = true; - assert!(config.allows_enrolled_action(&script, "system")); - assert!(!config.allows_enrolled_action(&legacy, "system")); + assert!(config.allows_script_action(&script, "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")] #[tokio::test] diff --git a/crates/agent-windows/src/system_capabilities.rs b/crates/agent-windows/src/system_capabilities.rs index 39e5df6..c4b6d38 100644 --- a/crates/agent-windows/src/system_capabilities.rs +++ b/crates/agent-windows/src/system_capabilities.rs @@ -34,7 +34,6 @@ struct Qualification { pub fn qualified( pin: &Pin, clock_qualified: bool, - reboot_privilege_available: Option, ) -> Result> { if !clock_qualified { return Ok(vec![]); @@ -92,67 +91,21 @@ pub fn qualified( && settings.enable_effects, "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![ "helper.system.v1".into(), format!("helper.binary.sha256:{}", pin.helper.binary_sha256), format!("helper.policy.sha256:{}", pin.policy_sha256), + "system:run_script".into(), ]; - for action in q.actions { - match action.as_str() { - "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"), - } - } + if general { caps.push(rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY.into()); } + if windows_update { caps.push(rmm_domain::jobs::WINDOWS_UPDATE_LONG_CAPABILITY.into()); } Ok(caps) } fn read(path: &Path, max: u64) -> Result> { diff --git a/crates/agent-windows/src/update_observation_runtime.rs b/crates/agent-windows/src/update_observation_runtime.rs index efea9d9..58bf00c 100644 --- a/crates/agent-windows/src/update_observation_runtime.rs +++ b/crates/agent-windows/src/update_observation_runtime.rs @@ -49,9 +49,5 @@ impl Observer { 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())) } - pub fn capabilities(&self)->Vec{ - 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)] - } + }