feat: add approval bound full maintenance script console and executors
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
//! SYSTEM service with an independent signed-sync gate and durable ledger.
|
||||
//! Only fixed, policy-pinned SCM state changes exist; no arbitrary SYSTEM CLI.
|
||||
//! Versioned policy independently admits fixed SCM/MSI actions or the explicit
|
||||
//! full_maintenance_v1 SYSTEM script profile; none inherit another's authority.
|
||||
//!
|
||||
//! Bootstrap contract (not performed by this module): install exactly
|
||||
//! `RmmDiscoverySystemHelper` as an OWN_PROCESS LocalSystem service with its
|
||||
@@ -75,6 +76,12 @@ pub struct Settings {
|
||||
deserialize_with = "strict_recipe_hashes"
|
||||
)]
|
||||
pub allowed_msi_recipe_sha256: Option<Vec<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_script_profiles"
|
||||
)]
|
||||
pub allowed_script_profiles: Option<Vec<rmm_domain::jobs::PrivilegedScriptProfile>>,
|
||||
}
|
||||
fn strict_recipe_hashes<'de, D: serde::Deserializer<'de>>(
|
||||
d: D,
|
||||
@@ -83,7 +90,7 @@ fn strict_recipe_hashes<'de, D: serde::Deserializer<'de>>(
|
||||
}
|
||||
impl Settings {
|
||||
fn permits_msi(&self, job: &JobPayload) -> bool {
|
||||
self.schema_version == 2
|
||||
self.schema_version >= 2
|
||||
&& job.execution_identity == "system"
|
||||
&& job.action.validate()
|
||||
&& job
|
||||
@@ -96,10 +103,24 @@ impl Settings {
|
||||
.is_some_and(|h| h.contains(&m.recipe_sha256))
|
||||
})
|
||||
}
|
||||
fn permits_script(&self, job: &JobPayload) -> bool {
|
||||
self.schema_version == 3
|
||||
&& job.execution_identity == "system"
|
||||
&& job.action.full_maintenance()
|
||||
&& job.action.valid_execution_identity("system")
|
||||
&& job.action.validate()
|
||||
&& job
|
||||
.action
|
||||
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes)
|
||||
&& job.max_runtime_seconds <= self.max_runtime_seconds
|
||||
&& self.allowed_script_profiles.as_deref()
|
||||
== Some(&[rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1])
|
||||
}
|
||||
pub fn validate(&self) -> Result<()> {
|
||||
ensure!(
|
||||
matches!(self.schema_version, 1 | 2)
|
||||
&& (self.schema_version == 2 || self.allowed_msi_recipe_sha256.is_none())
|
||||
matches!(self.schema_version, 1..=3)
|
||||
&& (self.schema_version >= 2 || self.allowed_msi_recipe_sha256.is_none())
|
||||
&& (self.schema_version == 3 || self.allowed_script_profiles.is_none())
|
||||
&& self
|
||||
.allowed_msi_recipe_sha256
|
||||
.as_ref()
|
||||
@@ -112,6 +133,9 @@ impl Settings {
|
||||
.len()
|
||||
== hashes.len()
|
||||
})
|
||||
&& self.allowed_script_profiles.as_deref().is_none_or(
|
||||
|v| v == [rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1]
|
||||
)
|
||||
&& !self.allow_reboot
|
||||
&& (1..=120).contains(&self.max_runtime_seconds)
|
||||
&& self.allowed_services.len() <= 16,
|
||||
@@ -1018,7 +1042,8 @@ impl SystemHelper {
|
||||
job.execution_identity == "system"
|
||||
&& job.max_runtime_seconds <= self.settings.max_runtime_seconds
|
||||
&& (matches!(&job.action,Action::SetServiceState{unit,state} if matches!(state.as_str(),"running"|"stopped")&&self.settings.allowed_services.iter().any(|r|r.name==*unit))
|
||||
|| self.settings.permits_msi(&job)),
|
||||
|| self.settings.permits_msi(&job)
|
||||
|| self.settings.permits_script(&job)),
|
||||
"SYSTEM_ABANDON_POLICY_DENIED"
|
||||
);
|
||||
self.sync()?;
|
||||
@@ -1109,6 +1134,9 @@ impl SystemHelper {
|
||||
),
|
||||
"SYSTEM_SIGNED_SYNC_REQUIRED"
|
||||
);
|
||||
if job.action.full_maintenance() {
|
||||
return self.execute_script(generation, request, &job, &permit, peer);
|
||||
}
|
||||
if job.action.windows_msi().is_some() {
|
||||
return self.execute_msi(generation, request, &job, &permit, peer);
|
||||
}
|
||||
@@ -1150,6 +1178,78 @@ impl SystemHelper {
|
||||
ledger::finish(&self.db, &permit, &outcome)?;
|
||||
Ok(outcome)
|
||||
}
|
||||
fn execute_script(
|
||||
&mut self,
|
||||
generation: u64,
|
||||
request: &Request,
|
||||
job: &JobPayload,
|
||||
permit: &ExecutionPermitPayload,
|
||||
peer: &mut ipc::PeerProof,
|
||||
) -> Result<Outcome> {
|
||||
let began = Instant::now();
|
||||
ensure!(
|
||||
self.settings.permits_script(job),
|
||||
"SYSTEM_SCRIPT_POLICY_DENIED"
|
||||
);
|
||||
self.observe_unsettled_msi()?;
|
||||
ensure!(
|
||||
self.unsettled_msi.is_none(),
|
||||
"SYSTEM_MSI_PREVIOUS_PROCESS_UNSETTLED"
|
||||
);
|
||||
self.recheck()?;
|
||||
peer.check()?;
|
||||
let (_, fresh, recorded_at) =
|
||||
verified_window(&self.settings.binding, request, &self.clock)?;
|
||||
ensure!(
|
||||
&fresh == permit && !STOP.load(Ordering::SeqCst),
|
||||
"SYSTEM_SCRIPT_START_FENCED"
|
||||
);
|
||||
crate::helper_runtime::intent::Store::require_not_denied(
|
||||
request,
|
||||
self.boot.current_boot()?,
|
||||
generation,
|
||||
&self.pin.policy_sha256,
|
||||
&self.pin.helper.binary_sha256,
|
||||
)?;
|
||||
ledger::begin_execution(
|
||||
&mut self.db,
|
||||
permit,
|
||||
request,
|
||||
self.boot.current_boot()?,
|
||||
recorded_at,
|
||||
)?;
|
||||
self.sync.as_mut().unwrap().close();
|
||||
let helper_sid = self.settings.helper.service_sid.clone();
|
||||
let result = crate::system_script::execute(
|
||||
job,
|
||||
permit.grant_id,
|
||||
&helper_sid,
|
||||
began,
|
||||
|before_start| {
|
||||
self.recheck()?;
|
||||
peer.check()?;
|
||||
self.clock.now()?;
|
||||
ensure!(!STOP.load(Ordering::SeqCst), "SYSTEM_SCRIPT_CANCELLED");
|
||||
crate::helper_runtime::intent::Store::require_not_denied(
|
||||
request,
|
||||
self.boot.current_boot()?,
|
||||
generation,
|
||||
&self.pin.policy_sha256,
|
||||
&self.pin.helper.binary_sha256,
|
||||
)?;
|
||||
if before_start {
|
||||
verified_window(&self.settings.binding, request, &self.clock)?;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
let outcome =
|
||||
result.unwrap_or_else(|_| Outcome::unknown("SYSTEM_SCRIPT_EFFECT_UNRESOLVED"));
|
||||
ledger::persist_outcome(&self.db, permit, &outcome)?;
|
||||
self.guard.check(&self.db)?;
|
||||
ledger::finish(&self.db, permit, &outcome)?;
|
||||
Ok(outcome)
|
||||
}
|
||||
fn execute_msi(
|
||||
&mut self,
|
||||
generation: u64,
|
||||
@@ -1517,6 +1617,7 @@ mod tests {
|
||||
enable_effects: false,
|
||||
allow_reboot: false,
|
||||
allowed_msi_recipe_sha256: None,
|
||||
allowed_script_profiles: None,
|
||||
};
|
||||
let legacy = serde_json::to_value(&settings).unwrap();
|
||||
assert!(legacy.get("allowed_msi_recipe_sha256").is_none());
|
||||
@@ -1538,6 +1639,29 @@ mod tests {
|
||||
settings.max_runtime_seconds = 30;
|
||||
settings.allowed_msi_recipe_sha256 = Some(vec!["cd".repeat(32)]);
|
||||
assert!(!settings.permits_msi(&job));
|
||||
let mut script = job.clone();
|
||||
script.action = Action::RunScript {
|
||||
interpreter: "powershell".into(),
|
||||
script_utf8: "Write-Output 'hi'\r\n".into(),
|
||||
arguments: vec![],
|
||||
expected_stdout: None,
|
||||
windows_execution_profile: None,
|
||||
privileged_script_profile: Some(
|
||||
rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1,
|
||||
),
|
||||
};
|
||||
assert!(!settings.permits_script(&script));
|
||||
settings.allowed_script_profiles = Some(vec![
|
||||
rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1,
|
||||
]);
|
||||
assert!(!settings.permits_script(&script));
|
||||
settings.schema_version = 3;
|
||||
assert!(settings.permits_script(&script));
|
||||
script.execution_identity = "root".into();
|
||||
assert!(!settings.permits_script(&script));
|
||||
let mut null = legacy;
|
||||
null["allowed_script_profiles"] = serde_json::Value::Null;
|
||||
assert!(serde_json::from_value::<Settings>(null).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn service_adapter_exposes_only_implemented_states() {
|
||||
|
||||
Reference in New Issue
Block a user