Apply the script-only capability and start contract to every Windows profile
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user