Bind Windows script contexts to the installed signed helper

This commit is contained in:
2026-11-18 11:58:55 +01:00
parent ab20cb0778
commit c692316abe
10 changed files with 345 additions and 14 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "rmm-agent-windows"
version = "0.1.11"
version = "0.1.12"
edition.workspace = true
license.workspace = true
@@ -1153,6 +1153,9 @@ 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");
}
if matches!(job.action, Action::UpdateAgent { .. }) {
ensure!(
self.pending_update_activation.is_none(),
@@ -289,6 +289,25 @@ impl Device {
}
}
/// Report the signed release layout of the already authenticated live SCM/IPC pair.
/// The server independently verifies the pair's catalog release and helper digest.
pub(crate) fn managed_script_release(pin: &crate::helper_ipc::Pin) -> Result<Uuid> {
let dir = pin.helper.binary.parent().context("missing installed helper directory")?;
let release = dir.file_name().and_then(|n| n.to_str()).context("missing release directory")?;
let id = Uuid::parse_str(release)?;
ensure!(release == id.to_string() && dir == generation(id)
&& pin.agent.binary == dir.join(AGENT) && pin.helper.binary == dir.join(HELPER),
"managed scripts require a pinned release pair");
let path = dir.join("manifest.json");
let raw = protected(&path, rmm_updater::MAX_MANIFEST_BYTES)?;
let manifest: ReleaseManifest = serde_json::from_slice(&raw)?;
ensure!(manifest.platform == VERIFY && manifest.release_id == id
&& manifest.artifacts[0].sha256 == pin.agent.binary_sha256
&& manifest.artifacts[1].sha256 == pin.helper.binary_sha256,
"managed helper differs from installed release manifest");
Ok(id)
}
fn local_manifest(installed: &Installed) -> Result<ReleaseManifest> {
let root = generation(installed.release_id);
let raw = protected(&root.join("manifest.json"), rmm_updater::MAX_MANIFEST_BYTES)?;
@@ -51,12 +51,29 @@ if ($managed) {
$settingsPath = Join-Path $policyRoot 'helper.json'
$settings = Get-Content -LiteralPath $settingsPath -Raw | ConvertFrom-Json
if ($settings.schema_version -ne 5) { throw 'Managed helper settings required.' }
# Old renderers require this input; the successor preserves the complete
# existing scope, including an absent long Windows Update permission.
$longRuntime = 3600
if ($settings.PSObject.Properties['windows_update_max_runtime_seconds']) { $longRuntime = $settings.windows_update_max_runtime_seconds }
$rendered = ([ordered]@{binding=$settings.binding; release_id='TO_UUID'
agent_sha256='SELECTED_AGENT_SHA256'; helper_sha256='SELECTED_HELPER_SHA256'
max_runtime_seconds=$settings.windows_update_max_runtime_seconds; managed_scripts=$true} | ConvertTo-Json -Depth 6 -Compress) |
max_runtime_seconds=$longRuntime; managed_scripts=$true} | ConvertTo-Json -Depth 6 -Compress) |
& $helperExe --prepare-enrolled-windows-update
if ($LASTEXITCODE -ne 0) { throw 'Signed successor helper could not render its pins.' }
$pins = $rendered | ConvertFrom-Json
# Rollback may select an earlier renderer. Compare the complete protected
# policy, allowing only the two release image paths and digests to change.
$scope = $pins.helper_settings | ConvertFrom-Json
if ($scope.agent.binary -cne (Join-Path (Split-Path $helperExe) 'rmm-agent-windows.exe') -or
$scope.helper.binary -cne $helperExe -or $scope.agent.binary_sha256 -cne 'SELECTED_AGENT_SHA256' -or
$scope.helper.binary_sha256 -cne 'SELECTED_HELPER_SHA256') { throw 'Rendered helper image pins differ from the selected release.' }
foreach ($role in @('agent','helper')) {
$scope.$role.binary = $settings.$role.binary
$scope.$role.binary_sha256 = $settings.$role.binary_sha256
}
if (($scope | ConvertTo-Json -Depth 12 -Compress) -cne ($settings | ConvertTo-Json -Depth 12 -Compress)) {
throw 'Agent release cannot change the managed script authorization.'
}
Wait-Stopped 'RmmDiscoveryWindows'
Wait-Stopped 'RmmDiscoverySystemHelper'
Replace-Pin $settingsPath $pins.helper_settings
+22 -3
View File
@@ -1409,6 +1409,11 @@ impl Agent {
Ok(())
}
fn supported_job(&self, job: &rmm_domain::jobs::JobPayload) -> bool {
if self.config.localservice_time_policy.is_some()
&& !matches!(job.action, rmm_domain::jobs::Action::RunScript { .. })
{
return false;
}
if self.config.localservice_time_policy.is_some() && job.execution_identity != "agent_service"
&& !(job.execution_identity == "system"
&& (self.config.windows_update_helper && job.action.windows_update_or_identity_probe()
@@ -1564,7 +1569,7 @@ impl Agent {
&& native::require_local_service().is_ok()
{
caps.push("rmm.sync.v1".into());
if !self.config.windows_echo_probe_only {
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() {
@@ -1579,8 +1584,22 @@ impl Agent {
if !self.config.windows_echo_probe_only
&& let Some(helper) = &self.helper
{
caps.extend(helper.qualified_capabilities());
if helper.update_observer_configured()
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 {
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);}}
}
@@ -55,6 +55,9 @@ pub fn qualified(
}
if settings.managed_scripts() {
caps.push(rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY.into());
if let Ok(id) = crate::release_service::managed_script_release(pin) {
caps.push(format!("script.helper.release:{id}"));
}
}
return Ok(caps);
}
@@ -1,5 +1,4 @@
//! Render the two public configuration files for the narrowly scoped, enrolled
//! development helper. The operator installs them after reviewing the live pair.
//! Render the enrolled script helper settings and peer pin for installation or a signed pair update.
use crate::{
helper_ipc::{self as ipc, PeerPin},
helper_system::Settings,
@@ -49,7 +48,7 @@ pub fn render() -> Result<()> {
binary_sha256: digest,
})
};
let settings = Settings {
let mut settings = Settings {
schema_version: if data.managed_scripts { 5 } else { 3 },
binding: data.binding,
agent: role(
@@ -74,6 +73,17 @@ pub fn render() -> Result<()> {
}),
windows_update_max_runtime_seconds: Some(data.max_runtime_seconds),
};
if data.managed_scripts && std::path::Path::new(crate::helper_system::CONFIG_PATH).try_exists()? {
// Older fixed workers call this same renderer without a predecessor
// argument. Read the protected local settings before changing image pins.
let (previous, _pins) = crate::helper_system::read_settings()?;
ensure!(
previous.managed_scripts()
&& ipc::binding_hash(&previous.binding)? == ipc::binding_hash(&settings.binding)?,
"MANAGED_SCRIPT_PREDECESSOR_SCOPE"
);
settings = Settings { agent: settings.agent, helper: settings.helper, ..previous };
}
settings.validate()?;
let pin = settings.pin()?;
let result = serde_json::json!({"helper_settings":serde_json::to_string(&settings)?,