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:
@@ -28,9 +28,19 @@ struct RootScope {
|
||||
assignment_version: u64,
|
||||
principals: Vec<String>,
|
||||
helper_policy_sha256: String,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_optional_sha256"
|
||||
)]
|
||||
helper_binary_sha256: Option<String>,
|
||||
acceptance_evidence_id: String,
|
||||
allowed_services: Vec<String>,
|
||||
allow_root_scripts: bool,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_script_profiles"
|
||||
)]
|
||||
allowed_script_profiles: Option<Vec<rmm_domain::jobs::PrivilegedScriptProfile>>,
|
||||
allow_reboot: bool,
|
||||
#[serde(default)]
|
||||
apt: Option<RootAptPolicy>,
|
||||
@@ -96,6 +106,9 @@ impl RootPolicy {
|
||||
}
|
||||
fn required_permissions(job: &JobPayload, sensitive_log: bool) -> Vec<&'static str> {
|
||||
let mut permissions = vec!["root:execute"];
|
||||
if matches!(job.action, Action::RunScript { .. }) {
|
||||
permissions.push("scripts:execute");
|
||||
}
|
||||
if matches!(job.action, Action::AptNativeAcceptance { .. }) {
|
||||
permissions.push("apt:native_acceptance");
|
||||
}
|
||||
@@ -205,7 +218,21 @@ impl RootScope {
|
||||
&& (20..=3600).contains(&job.max_runtime_seconds)
|
||||
&& (1..=65536).contains(&job.max_output_bytes)
|
||||
}
|
||||
Action::RunScript { .. } => self.allow_root_scripts && job.max_runtime_seconds <= 300,
|
||||
Action::RunScript { .. } => {
|
||||
self.allow_root_scripts
|
||||
&& job.max_runtime_seconds <= 300
|
||||
&& job.action.valid_execution_identity(&job.execution_identity)
|
||||
&& (!job.action.full_maintenance()
|
||||
|| (self.helper_binary_sha256.as_ref().is_some_and(|h| {
|
||||
capabilities.contains(&format!("helper.binary.sha256:{h}"))
|
||||
}) && self.allowed_script_profiles.as_ref().is_some_and(|v| {
|
||||
v.contains(
|
||||
&rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1,
|
||||
)
|
||||
}) && capabilities
|
||||
.iter()
|
||||
.any(|c| c == rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY)))
|
||||
}
|
||||
Action::SetServiceState { unit, state } => {
|
||||
self.allowed_services.contains(unit)
|
||||
&& matches!(state.as_str(), "running" | "stopped")
|
||||
@@ -265,7 +292,12 @@ fn load() -> Result<RootPolicy, Error> {
|
||||
}
|
||||
let policy: RootPolicy =
|
||||
serde_json::from_slice(&fs::read(path).map_err(|_| disabled())?).map_err(|_| disabled())?;
|
||||
if policy.schema_version != 1
|
||||
if !matches!(policy.schema_version, 1 | 2)
|
||||
|| (policy.schema_version == 1
|
||||
&& policy
|
||||
.scopes
|
||||
.iter()
|
||||
.any(|s| s.allowed_script_profiles.is_some() || s.helper_binary_sha256.is_some()))
|
||||
|| policy.profile != "development"
|
||||
|| policy.expires_at <= Utc::now()
|
||||
|| policy.scopes.is_empty()
|
||||
@@ -342,7 +374,7 @@ mod tests {
|
||||
fn no_capability_or_relabel_shortcut() {
|
||||
let id = Uuid::new_v4();
|
||||
let now = Utc::now();
|
||||
let job = JobPayload {
|
||||
let mut job = JobPayload {
|
||||
schema_version: 1,
|
||||
tenant_id: id,
|
||||
asset_id: id,
|
||||
@@ -357,6 +389,7 @@ mod tests {
|
||||
arguments: vec![],
|
||||
expected_stdout: None,
|
||||
windows_execution_profile: None,
|
||||
privileged_script_profile: None,
|
||||
},
|
||||
execution_identity: "root".into(),
|
||||
not_before: now,
|
||||
@@ -364,7 +397,7 @@ mod tests {
|
||||
max_runtime_seconds: 60,
|
||||
max_output_bytes: 1024,
|
||||
};
|
||||
let scope = RootScope {
|
||||
let mut scope = RootScope {
|
||||
tenant_id: id,
|
||||
asset_id: id,
|
||||
agent_id: id,
|
||||
@@ -372,9 +405,11 @@ mod tests {
|
||||
assignment_version: 1,
|
||||
principals: vec!["selected".into()],
|
||||
helper_policy_sha256: "ab".repeat(32),
|
||||
helper_binary_sha256: None,
|
||||
acceptance_evidence_id: "native-test-record".into(),
|
||||
allowed_services: vec![],
|
||||
allow_root_scripts: true,
|
||||
allowed_script_profiles: None,
|
||||
allow_reboot: false,
|
||||
apt: None,
|
||||
root_logs: None,
|
||||
@@ -389,6 +424,26 @@ mod tests {
|
||||
assert!(scope.permits("selected", &job, &caps, None));
|
||||
assert!(!scope.permits("automation", &job, &caps, None));
|
||||
assert!(!scope.permits("selected", &job, &caps[..4], None));
|
||||
if let Action::RunScript {
|
||||
privileged_script_profile,
|
||||
..
|
||||
} = &mut job.action
|
||||
{
|
||||
*privileged_script_profile =
|
||||
Some(rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1);
|
||||
}
|
||||
assert!(!scope.permits("selected", &job, &caps, None));
|
||||
scope.allowed_script_profiles = Some(vec![
|
||||
rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1,
|
||||
]);
|
||||
assert!(!scope.permits("selected", &job, &caps, None));
|
||||
let mut caps = caps;
|
||||
caps.push(rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY.into());
|
||||
assert!(!scope.permits("selected", &job, &caps, None));
|
||||
scope.helper_binary_sha256 = Some("cd".repeat(32));
|
||||
assert!(!scope.permits("selected", &job, &caps, None));
|
||||
caps.push(format!("helper.binary.sha256:{}", "cd".repeat(32)));
|
||||
assert!(scope.permits("selected", &job, &caps, None));
|
||||
let mut windows = caps;
|
||||
windows.push("windows.base/1".into());
|
||||
assert!(!scope.permits("selected", &job, &windows, None));
|
||||
|
||||
Reference in New Issue
Block a user