feat: add approval bound full maintenance script console and executors
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-14 16:35:11 +01:00
parent 287a784c8f
commit ff78b6a498
51 changed files with 8880 additions and 278 deletions
@@ -470,6 +470,14 @@ fn verified_mirror_row(
Ok(outcome)
}
fn system_shape(job: &JobPayload) -> bool {
if job.action.full_maintenance() {
return job.execution_identity == "system"
&& job.action.validate()
&& job.action.valid_execution_identity("system")
&& job
.action
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes);
}
if job.action.windows_msi().is_some() {
return job.execution_identity == "system"
&& job.action.validate()
@@ -544,6 +552,41 @@ pub(super) fn checked_outcome(job: &JobPayload, outcome: &Outcome) -> Result<()>
}
return Ok(());
}
if job.action.full_maintenance() {
let Action::RunScript {
script_utf8,
expected_stdout,
windows_execution_profile,
..
} = &job.action
else {
anyhow::bail!("SYSTEM_SCRIPT_REQUIRED")
};
let e = &outcome.evidence;
ensure!(
system_shape(job)
&& outcome.exit_code == Some(0)
&& !outcome.output_truncated
&& !outcome.reboot_required
&& e["postconditions_passed"] == true
&& e["privileged_script_profile"] == "full_maintenance_v1"
&& e["execution_sid"] == "S-1-5-18"
&& e["script_sha256"] == rmm_domain::jobs::hash(script_utf8.as_bytes())
&& expected_stdout
.as_ref()
.is_none_or(|s| outcome.stdout == s.as_bytes()),
"SYSTEM_SCRIPT_POSTCONDITION_BINDING"
);
if windows_execution_profile.is_some() {
ensure!(
e["windows_execution_profile"] == "powershell_51_remote_signed"
&& e["execution_policy_requested"] == "RemoteSigned"
&& e["execution_policy_scope"] == "process",
"SYSTEM_SCRIPT_PROCESS_PROFILE_BINDING"
);
}
return Ok(());
}
let Action::SetServiceState { unit, state } = &job.action else {
anyhow::bail!("SYSTEM_TYPED_SERVICE_REQUIRED");
};
@@ -585,6 +628,49 @@ pub fn map_snapshot(s: &Snapshot) -> HelperSnapshot {
.collect(),
}
}
#[cfg(test)]
mod script_tests {
use super::*;
#[test]
fn system_script_success_requires_exact_profile_identity_bytes_and_raw_output() {
let mut job = msi_test_job();
job.action = Action::RunScript {
interpreter: "powershell".into(),
script_utf8: "Write-Output 'hi'\r\n".into(),
arguments: vec![],
expected_stdout: Some("hi\r\n".into()),
windows_execution_profile: Some(
rmm_domain::jobs::WindowsExecutionProfile::PowerShell51RemoteSigned,
),
privileged_script_profile: Some(
rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1,
),
};
assert!(system_shape(&job));
let mut outcome = Outcome {
state: "succeeded".into(),
stdout: b"hi\r\n".to_vec(),
stderr: vec![],
exit_code: Some(0),
output_truncated: false,
reboot_required: false,
error_code: String::new(),
evidence: json!({"postconditions_passed":true,"privileged_script_profile":"full_maintenance_v1","execution_sid":"S-1-5-18","script_sha256":rmm_domain::jobs::hash(b"Write-Output 'hi'\r\n"),"windows_execution_profile":"powershell_51_remote_signed","execution_policy_requested":"RemoteSigned","execution_policy_scope":"process"}),
};
checked_outcome(&job, &outcome).unwrap();
outcome.evidence["execution_sid"] = "S-1-5-19".into();
assert!(checked_outcome(&job, &outcome).is_err());
outcome.evidence["execution_sid"] = "S-1-5-18".into();
outcome.stdout = b"other".to_vec();
assert!(checked_outcome(&job, &outcome).is_err());
outcome.state = "unknown".into();
outcome.evidence = serde_json::Value::Null;
checked_outcome(&job, &outcome).unwrap();
job.execution_identity = "root".into();
assert!(!system_shape(&job));
}
}
#[cfg(test)]
pub(crate) fn msi_test_job() -> JobPayload {
use rmm_domain::windows_execution::*;