Integrate strict Windows MSI manifests tenant catalog and SYSTEM package policy
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -37,8 +37,16 @@ struct SystemScope {
|
||||
// Administrative evidence pin, never an approval or authorization ID.
|
||||
acceptance_evidence_id: Uuid,
|
||||
allowed_services: Vec<String>,
|
||||
#[serde(default, deserialize_with = "strict_optional_hashes")]
|
||||
allowed_msi_recipe_sha256: Option<Vec<String>>,
|
||||
max_runtime_seconds: u32,
|
||||
}
|
||||
fn strict_optional_hashes<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
Vec::<String>::deserialize(deserializer).map(Some)
|
||||
}
|
||||
fn digest(value: &str) -> bool {
|
||||
value.len() == 64
|
||||
&& value
|
||||
@@ -86,9 +94,27 @@ impl SystemScope {
|
||||
.collect::<std::collections::BTreeSet<_>>()
|
||||
.len()
|
||||
== self.allowed_services.len()
|
||||
&& self
|
||||
.allowed_msi_recipe_sha256
|
||||
.as_ref()
|
||||
.is_none_or(|hashes| {
|
||||
hashes.len() <= 2
|
||||
&& hashes.iter().all(|h| digest(h))
|
||||
&& hashes
|
||||
.iter()
|
||||
.collect::<std::collections::BTreeSet<_>>()
|
||||
.len()
|
||||
== hashes.len()
|
||||
})
|
||||
&& (1..=120).contains(&self.max_runtime_seconds)
|
||||
}
|
||||
fn permits(&self, principal: &str, job: &JobPayload, capabilities: &[String]) -> bool {
|
||||
fn permits(
|
||||
&self,
|
||||
principal: &str,
|
||||
job: &JobPayload,
|
||||
capabilities: &[String],
|
||||
allow_msi: bool,
|
||||
) -> bool {
|
||||
let has = |cap: &str| capabilities.iter().any(|c| c == cap);
|
||||
self.valid()
|
||||
&& job.execution_identity == "system"
|
||||
@@ -110,17 +136,40 @@ impl SystemScope {
|
||||
"helper.binary.sha256:{}",
|
||||
self.helper_binary_sha256
|
||||
))
|
||||
&& has("system:set_service_state")
|
||||
&& has("set_service_state")
|
||||
&& (1..=self.max_runtime_seconds).contains(&job.max_runtime_seconds)
|
||||
&& (1..=65536).contains(&job.max_output_bytes)
|
||||
&& matches!(&job.action,Action::SetServiceState{unit,state}
|
||||
if self.allowed_services.contains(unit) && matches!(state.as_str(),"running"|"stopped"))
|
||||
&& match &job.action {
|
||||
Action::SetServiceState { unit, state } => {
|
||||
self.allowed_services.contains(unit)
|
||||
&& matches!(state.as_str(), "running" | "stopped")
|
||||
&& has("system:set_service_state")
|
||||
&& has("set_service_state")
|
||||
}
|
||||
_ if allow_msi => job.action.windows_msi().is_some_and(|m| {
|
||||
job.action.validate()
|
||||
&& job
|
||||
.action
|
||||
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes)
|
||||
&& self
|
||||
.allowed_msi_recipe_sha256
|
||||
.as_ref()
|
||||
.is_some_and(|hashes| hashes.contains(&m.recipe_sha256))
|
||||
&& has("ensure_package")
|
||||
&& has("system:ensure_package")
|
||||
&& has(rmm_domain::windows_execution::MSI_CAPABILITY)
|
||||
}),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl SystemPolicy {
|
||||
fn valid(&self, now: DateTime<Utc>) -> bool {
|
||||
self.schema_version == 1
|
||||
matches!(self.schema_version, 1 | 2)
|
||||
&& (self.schema_version == 2
|
||||
|| self
|
||||
.scopes
|
||||
.iter()
|
||||
.all(|scope| scope.allowed_msi_recipe_sha256.is_none()))
|
||||
&& self.profile == "development"
|
||||
&& self.expires_at > now
|
||||
&& !self.scopes.is_empty()
|
||||
@@ -138,7 +187,7 @@ impl SystemPolicy {
|
||||
&& self
|
||||
.scopes
|
||||
.iter()
|
||||
.any(|scope| scope.permits(principal, job, capabilities))
|
||||
.any(|scope| scope.permits(principal, job, capabilities, self.schema_version == 2))
|
||||
}
|
||||
}
|
||||
fn disabled() -> Error {
|
||||
@@ -410,6 +459,29 @@ mod tests {
|
||||
assert!(serde_json::from_value::<SystemPolicy>(invalid).is_err());
|
||||
}
|
||||
#[test]
|
||||
fn only_explicit_v2_hash_scope_and_package_caps_allow_fixed_msi() {
|
||||
let (mut policy, mut job, mut caps) = fixture();
|
||||
let m = crate::windows_msi_catalog::test_manifest(Uuid::new_v4(), &"ab".repeat(32), 32);
|
||||
job.action = crate::windows_msi_catalog::test_action(m.clone());
|
||||
caps.extend([
|
||||
"ensure_package".into(),
|
||||
"system:ensure_package".into(),
|
||||
rmm_domain::windows_execution::MSI_CAPABILITY.into(),
|
||||
]);
|
||||
assert!(!policy.permits("selected", &job, &caps, Utc::now()));
|
||||
policy.scopes[0].allowed_msi_recipe_sha256 = Some(vec![m.recipe_sha256.clone()]);
|
||||
assert!(!policy.permits("selected", &job, &caps, Utc::now())); // v1 remains SCM-only
|
||||
policy.schema_version = 2;
|
||||
assert!(policy.permits("selected", &job, &caps, Utc::now()));
|
||||
for index in caps.len() - 3..caps.len() {
|
||||
let mut short = caps.clone();
|
||||
short.remove(index);
|
||||
assert!(!policy.permits("selected", &job, &short, Utc::now()));
|
||||
}
|
||||
policy.scopes[0].allowed_msi_recipe_sha256 = Some(vec!["cd".repeat(32)]);
|
||||
assert!(!policy.permits("selected", &job, &caps, Utc::now()));
|
||||
}
|
||||
#[test]
|
||||
fn policy_file_refuses_symlinks_public_mode_wrong_owner_and_writable_parent() {
|
||||
use std::os::unix::fs::symlink;
|
||||
let directory = std::env::temp_dir().join(format!("rmm-windows-policy-{}", Uuid::new_v4()));
|
||||
|
||||
Reference in New Issue
Block a user