Use script-only execution on Linux and preserve the enrolled helper through updates

This commit is contained in:
2026-11-18 12:01:02 +01:00
parent c692316abe
commit adc04f0148
9 changed files with 494 additions and 1010 deletions
+61 -90
View File
@@ -41,16 +41,12 @@ fn map(s: &root::Snapshot) -> reconcile::HelperSnapshot {
.collect(),
}
}
fn general(binding: &Binding, full: bool) -> Result<control::Response> {
let (socket_name, pin_name, profile) = if full {
(
"RMM_FULL_MAINTENANCE_HELPER_SOCKET",
"RMM_FULL_MAINTENANCE_POLICY_FILE",
"full_maintenance_v1",
)
} else {
("RMM_HELPER_SOCKET", "RMM_HELPER_POLICY_FILE", "general")
};
fn script_helper(binding: &Binding) -> Result<control::Response> {
let (socket_name, pin_name, profile) = (
"RMM_FULL_MAINTENANCE_HELPER_SOCKET",
"RMM_FULL_MAINTENANCE_POLICY_FILE",
"full_maintenance_v1",
);
let socket = std::env::var_os(socket_name).context("NO_GENERAL_HELPER")?;
let path = std::env::var_os(pin_name).context("GENERAL_POLICY_PIN_REQUIRED")?;
let pin = control::GeneralPin::read(Path::new(&path), binding)?;
@@ -207,97 +203,72 @@ impl Helpers {
Ok(applied.as_ref().map(map))
}
}
pub fn general_capabilities(binding: &Binding) -> Vec<String> {
let mut caps = profile_capabilities(binding, false);
caps.extend(profile_capabilities(binding, true));
caps.sort();
caps.dedup();
caps
}
fn profile_capabilities(binding: &Binding, full: bool) -> Vec<String> {
pub fn script_capabilities(binding: &Binding) -> Vec<String> {
(|| -> Result<Vec<String>> {
let response = general(binding, full)?;
let policy = response.policy.context("NO_GENERAL_POLICY")?;
let response = script_helper(binding)?;
let binary = response
.helper_binary_sha256
.context("SCRIPT_HELPER_BINARY_PROOF_REQUIRED")?;
ensure!(
rmm_agent_linux::actions::Interpreter::PosixSh.available(),
"SCRIPT_INTERPRETER_UNAVAILABLE"
);
let mut caps = vec![
"run_script".into(),
"root:run_script".into(),
"helper.root.v1".into(),
rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY.into(),
format!("helper.policy.sha256:{}", response.policy_sha256),
format!("helper.binary.sha256:{binary}"),
];
if full {
ensure!(
policy.schema_version == 2
&& policy.profile == "full_maintenance_v1"
&& policy.allowed_script_profiles.as_deref()
== Some(&[rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1]),
"FULL_MAINTENANCE_POLICY_REQUIRED"
);
let binary = policy
.helper_binary_sha256
.as_ref()
.context("FULL_MAINTENANCE_BINARY_PIN_REQUIRED")?;
ensure!(
response.helper_binary_sha256.as_ref() == Some(binary),
"FULL_MAINTENANCE_BINARY_PROOF_REQUIRED"
);
caps.push(format!("helper.binary.sha256:{binary}"));
caps.push(rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY.into());
}
let mut actions = vec![];
if policy.allow_root_scripts && rmm_agent_linux::actions::Interpreter::PosixSh.available() {
actions.push("run_script");
}
if !policy.allowed_services.is_empty() {
actions.extend(["set_service_state", "query_logs"]);
}
if policy.allow_reboot {
actions.push("reboot");
}
for action in actions {
caps.push(action.into());
caps.push(format!("root:{action}"));
if let Some(release) = std::env::var("RMM_SCRIPT_HELPER_RELEASE")
.ok()
.and_then(|value| Uuid::parse_str(&value).ok())
.filter(|id| !id.is_nil())
{
caps.push(format!("script.helper.release:{release}"));
}
Ok(caps)
})()
.unwrap_or_default()
}
pub fn general_supported(binding: &Binding, job: &rmm_domain::jobs::JobPayload) -> bool {
(|| -> Result<bool> {
let p = general(binding, job.action.full_maintenance())?
.policy
.context("NO_GENERAL_POLICY")?;
Ok(match &job.action {
rmm_domain::jobs::Action::RunScript { interpreter, .. } => {
p.allow_root_scripts
&& job.action.valid_execution_identity(&job.execution_identity)
&& job
.action
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes)
&& (!job.action.full_maintenance()
|| p.allowed_script_profiles.as_ref().is_some_and(|v| {
v.contains(
&rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1,
)
}))
&& match interpreter.as_str() {
"posix_sh" => rmm_agent_linux::actions::Interpreter::PosixSh.available(),
"bash" => rmm_agent_linux::actions::Interpreter::Bash.available(),
_ => false,
}
}
rmm_domain::jobs::Action::SetServiceState { unit, state } => {
p.allowed_services.contains(unit)
&& matches!(state.as_str(), "running" | "stopped")
&& job.max_runtime_seconds >= 180
}
rmm_domain::jobs::Action::QueryLogs { unit, .. } => {
p.allowed_services.contains(unit) && job.max_runtime_seconds >= 20
}
rmm_domain::jobs::Action::Reboot { .. } => {
p.allow_reboot && job.max_runtime_seconds >= 60
}
pub fn script_supported(binding: &Binding, job: &rmm_domain::jobs::JobPayload) -> bool {
let rmm_domain::jobs::Action::RunScript { interpreter, .. } = &job.action else {
return false;
};
job.execution_identity == "root"
&& job.action.full_maintenance()
&& job.action.valid_execution_identity(&job.execution_identity)
&& job
.action
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes)
&& match interpreter.as_str() {
"posix_sh" => rmm_agent_linux::actions::Interpreter::PosixSh.available(),
"bash" => rmm_agent_linux::actions::Interpreter::Bash.available(),
_ => false,
})
})()
.unwrap_or(false)
}
&& script_helper(binding).is_ok()
}
pub fn invoke_script(
binding: &Binding,
job: &rmm_domain::jobs::JobPayload,
request: &rmm_privileged_helper::Request,
observe: impl FnMut() -> Result<()>,
) -> Result<rmm_privileged_helper::Outcome> {
ensure!(
script_supported(binding, job),
"SCRIPT_HELPER_POLICY_REQUIRED"
);
let socket = std::env::var_os("RMM_FULL_MAINTENANCE_HELPER_SOCKET")
.context("SCRIPT_HELPER_SOCKET_REQUIRED")?;
rmm_privileged_helper::invoke_controlled(
Path::new(&socket),
request,
job.max_runtime_seconds,
observe,
)
}
impl Helpers {