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:
@@ -40,6 +40,11 @@ struct SystemScope {
|
||||
#[serde(default, deserialize_with = "strict_optional_hashes")]
|
||||
allowed_msi_recipe_sha256: Option<Vec<String>>,
|
||||
max_runtime_seconds: u32,
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "rmm_domain::jobs::deserialize_script_profiles"
|
||||
)]
|
||||
allowed_script_profiles: Option<Vec<rmm_domain::jobs::PrivilegedScriptProfile>>,
|
||||
}
|
||||
fn strict_optional_hashes<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
|
||||
where
|
||||
@@ -106,6 +111,10 @@ impl SystemScope {
|
||||
.len()
|
||||
== hashes.len()
|
||||
})
|
||||
&& self
|
||||
.allowed_script_profiles
|
||||
.as_deref()
|
||||
.is_none_or(|v| v == [rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1])
|
||||
&& (1..=120).contains(&self.max_runtime_seconds)
|
||||
}
|
||||
fn permits(
|
||||
@@ -114,6 +123,7 @@ impl SystemScope {
|
||||
job: &JobPayload,
|
||||
capabilities: &[String],
|
||||
allow_msi: bool,
|
||||
allow_scripts: bool,
|
||||
) -> bool {
|
||||
let has = |cap: &str| capabilities.iter().any(|c| c == cap);
|
||||
self.valid()
|
||||
@@ -145,6 +155,20 @@ impl SystemScope {
|
||||
&& has("system:set_service_state")
|
||||
&& has("set_service_state")
|
||||
}
|
||||
Action::RunScript { .. } => {
|
||||
allow_scripts
|
||||
&& job.action.full_maintenance()
|
||||
&& self.allowed_script_profiles.as_ref().is_some_and(|v| {
|
||||
v.contains(
|
||||
&rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1,
|
||||
)
|
||||
})
|
||||
&& job.action.validate()
|
||||
&& job
|
||||
.action
|
||||
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes)
|
||||
&& job.action.available_for("system", capabilities)
|
||||
}
|
||||
_ if allow_msi => job.action.windows_msi().is_some_and(|m| {
|
||||
job.action.validate()
|
||||
&& job
|
||||
@@ -164,12 +188,17 @@ impl SystemScope {
|
||||
}
|
||||
impl SystemPolicy {
|
||||
fn valid(&self, now: DateTime<Utc>) -> bool {
|
||||
matches!(self.schema_version, 1 | 2)
|
||||
&& (self.schema_version == 2
|
||||
matches!(self.schema_version, 1..=3)
|
||||
&& (self.schema_version >= 2
|
||||
|| self
|
||||
.scopes
|
||||
.iter()
|
||||
.all(|scope| scope.allowed_msi_recipe_sha256.is_none()))
|
||||
&& (self.schema_version == 3
|
||||
|| self
|
||||
.scopes
|
||||
.iter()
|
||||
.all(|scope| scope.allowed_script_profiles.is_none()))
|
||||
&& self.profile == "development"
|
||||
&& self.expires_at > now
|
||||
&& !self.scopes.is_empty()
|
||||
@@ -184,10 +213,15 @@ impl SystemPolicy {
|
||||
now: DateTime<Utc>,
|
||||
) -> bool {
|
||||
self.valid(now)
|
||||
&& self
|
||||
.scopes
|
||||
.iter()
|
||||
.any(|scope| scope.permits(principal, job, capabilities, self.schema_version == 2))
|
||||
&& self.scopes.iter().any(|scope| {
|
||||
scope.permits(
|
||||
principal,
|
||||
job,
|
||||
capabilities,
|
||||
self.schema_version >= 2,
|
||||
self.schema_version == 3,
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
fn disabled() -> Error {
|
||||
@@ -310,6 +344,9 @@ pub async fn authorize(
|
||||
}
|
||||
// Independent DB permission; root:execute never implies this scope.
|
||||
crate::permissions::require(tx, principal, "system:execute").await?;
|
||||
if matches!(job.action, Action::RunScript { .. }) {
|
||||
crate::permissions::require(tx, principal, "scripts:execute").await?;
|
||||
}
|
||||
let policy = load()?;
|
||||
let caps:serde_json::Value=sqlx::query_scalar("SELECT capabilities FROM agent_installations WHERE tenant_id=$1 AND agent_id=$2 AND asset_id=$3 AND revoked_at IS NULL AND enrollment_generation=$4 AND assignment_version=$5").bind(job.tenant_id).bind(job.agent_id).bind(job.asset_id).bind(i64::try_from(job.enrollment_generation).map_err(|_|Error(StatusCode::CONFLICT,"BINDING_MISMATCH"))?).bind(i64::try_from(job.assignment_version).map_err(|_|Error(StatusCode::CONFLICT,"BINDING_MISMATCH"))?).fetch_optional(&mut **tx).await?.ok_or(Error(StatusCode::CONFLICT,"AUTHORIZATION_REVOKED"))?;
|
||||
let capabilities: Vec<String> = serde_json::from_value(caps)?;
|
||||
@@ -422,6 +459,42 @@ mod tests {
|
||||
assert!(!policy.permits("selected", &job, &caps, policy.expires_at));
|
||||
}
|
||||
#[test]
|
||||
fn full_script_requires_v3_explicit_scope_and_does_not_inherit_scm_or_msi() {
|
||||
let (mut policy, mut job, mut caps) = fixture();
|
||||
job.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,
|
||||
),
|
||||
};
|
||||
caps.extend([
|
||||
"run_script".into(),
|
||||
"system:run_script".into(),
|
||||
"script.powershell/1".into(),
|
||||
rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY.into(),
|
||||
]);
|
||||
for version in [1, 2, 3] {
|
||||
policy.schema_version = version;
|
||||
assert!(!policy.permits("selected", &job, &caps, Utc::now()));
|
||||
}
|
||||
policy.scopes[0].allowed_script_profiles = Some(vec![
|
||||
rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1,
|
||||
]);
|
||||
for version in [1, 2] {
|
||||
policy.schema_version = version;
|
||||
assert!(!policy.permits("selected", &job, &caps, Utc::now()));
|
||||
}
|
||||
policy.schema_version = 3;
|
||||
assert!(policy.permits("selected", &job, &caps, Utc::now()));
|
||||
assert!(!policy.permits("foreign", &job, &caps, Utc::now()));
|
||||
caps.retain(|c| c != rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY);
|
||||
assert!(!policy.permits("selected", &job, &caps, Utc::now()));
|
||||
}
|
||||
#[test]
|
||||
fn narrow_scm_ceiling_denies_unreviewed_effects_and_provider_inputs() {
|
||||
let (mut policy, mut job, caps) = fixture();
|
||||
let now = Utc::now();
|
||||
@@ -443,6 +516,7 @@ mod tests {
|
||||
arguments: vec![],
|
||||
expected_stdout: None,
|
||||
windows_execution_profile: None,
|
||||
privileged_script_profile: None,
|
||||
};
|
||||
assert!(!policy.permits("selected", &job, &caps, now));
|
||||
job.action = Action::SetServiceState {
|
||||
|
||||
Reference in New Issue
Block a user