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:
@@ -162,6 +162,13 @@ pub struct Variant {
|
||||
#[derive(Clone, Deserialize, Serialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct WebParameters {
|
||||
#[serde(
|
||||
default,
|
||||
deserialize_with = "deserialize_privileged_script_profile",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
#[schemars(with = "PrivilegedScriptProfile")]
|
||||
privileged_script_profile: Option<PrivilegedScriptProfile>,
|
||||
execution_identity: String,
|
||||
timeout_seconds: u32,
|
||||
max_output_bytes: u32,
|
||||
@@ -230,6 +237,7 @@ impl PlanRequest {
|
||||
arguments: p.arguments.clone().unwrap_or_default(),
|
||||
expected_stdout: p.expected_stdout.clone(),
|
||||
windows_execution_profile: v.windows_execution_profile,
|
||||
privileged_script_profile: p.privileged_script_profile,
|
||||
}
|
||||
}
|
||||
"refresh_inventory" => Action::RefreshInventory {
|
||||
@@ -329,6 +337,7 @@ fn validate_variants(variants: &[Variant]) -> Result<()> {
|
||||
arguments: vec![],
|
||||
expected_stdout: None,
|
||||
windows_execution_profile: v.windows_execution_profile,
|
||||
privileged_script_profile: None,
|
||||
};
|
||||
if v.encoding != "utf-8"
|
||||
|| action.script_platform() != Some(v.os_family.as_str())
|
||||
@@ -346,6 +355,15 @@ fn capabilities(value: Value) -> Result<Vec<String>> {
|
||||
serde_json::from_value(value).map_err(|_| fail("UNSUPPORTED_CAPABILITY"))
|
||||
}
|
||||
fn target_action(input: &PlanInput, caps: &[String]) -> Result<Action> {
|
||||
if !input
|
||||
.action
|
||||
.valid_execution_identity(&input.execution_identity)
|
||||
|| (input.execution_identity == "system"
|
||||
&& matches!(input.action, Action::RunScript { .. })
|
||||
&& !input.action.full_maintenance())
|
||||
{
|
||||
return Err(fail("VALIDATION_ERROR"));
|
||||
}
|
||||
if input.script_variants.is_empty() {
|
||||
return Ok(input.action.clone());
|
||||
}
|
||||
@@ -356,6 +374,7 @@ fn target_action(input: &PlanInput, caps: &[String]) -> Result<Action> {
|
||||
arguments,
|
||||
expected_stdout,
|
||||
windows_execution_profile,
|
||||
privileged_script_profile,
|
||||
} = &input.action
|
||||
else {
|
||||
return Err(fail("VALIDATION_ERROR"));
|
||||
@@ -364,7 +383,7 @@ fn target_action(input: &PlanInput, caps: &[String]) -> Result<Action> {
|
||||
if interpreter != &first.interpreter
|
||||
|| script_utf8 != &first.script_utf8
|
||||
|| windows_execution_profile != &first.windows_execution_profile
|
||||
|| (input.execution_identity != "agent_service"
|
||||
|| (input.execution_identity == "root"
|
||||
&& input
|
||||
.script_variants
|
||||
.iter()
|
||||
@@ -391,6 +410,7 @@ fn target_action(input: &PlanInput, caps: &[String]) -> Result<Action> {
|
||||
arguments: arguments.clone(),
|
||||
expected_stdout: expected_stdout.clone(),
|
||||
windows_execution_profile: v.windows_execution_profile,
|
||||
privileged_script_profile: *privileged_script_profile,
|
||||
})
|
||||
}
|
||||
async fn policy(tx: &mut Transaction<'_, Postgres>) -> Result<()> {
|
||||
@@ -413,6 +433,9 @@ pub async fn plan(
|
||||
if input.targets.asset_ids.is_empty()
|
||||
|| input.targets.asset_ids.len() > 100
|
||||
|| !input.action.validate_plan_shape()
|
||||
|| !input
|
||||
.action
|
||||
.valid_execution_identity(&input.execution_identity)
|
||||
|| !matches!(
|
||||
input.execution_identity.as_str(),
|
||||
"agent_service" | "root" | "system"
|
||||
@@ -821,6 +844,9 @@ async fn authorize_http(
|
||||
return Err(fail("AUTHORIZATION_REVOKED"));
|
||||
}
|
||||
for job in &plan.jobs {
|
||||
if matches!(job.payload.action, Action::RunScript { .. }) {
|
||||
crate::permissions::require_principal(&mut tx, &p, "scripts:execute").await?;
|
||||
}
|
||||
if let Some(permission) =
|
||||
crate::root_policy::execution_permission(&job.payload.execution_identity)
|
||||
{
|
||||
@@ -1116,6 +1142,28 @@ mod windows_contract_tests {
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn full_maintenance_web_profile_is_action_wide_strict_and_identity_bound() {
|
||||
let request = serde_json::json!({"tenant_id":Uuid::nil(),"action":"run_script","targets":{"asset_ids":[Uuid::nil()]},"parameters":{"execution_identity":"system","timeout_seconds":30,"max_output_bytes":4096,"privileged_script_profile":"full_maintenance_v1","variants":[{"os_family":"windows","interpreter":"powershell","encoding":"utf-8","script_utf8":"Write-Output 'hi'\r\n","windows_execution_profile":"powershell_51_remote_signed"}]},"schedule":{"not_before":"2026-11-14T12:00:00Z","start_before":"2026-11-14T13:00:00Z","offline_policy":"wait_until_deadline"},"rollout":{"max_parallel":1,"halt_after_failures":1},"reason":"codec only"});
|
||||
let resolved = serde_json::from_value::<PlanRequest>(request.clone())
|
||||
.unwrap()
|
||||
.resolve(Uuid::nil())
|
||||
.unwrap();
|
||||
let action = target_action(&resolved, &["windows.base/1".into()]).unwrap();
|
||||
assert!(action.full_maintenance());
|
||||
let mut invalid = resolved.clone();
|
||||
invalid.execution_identity = "agent_service".into();
|
||||
assert!(target_action(&invalid, &["windows.base/1".into()]).is_err());
|
||||
for value in [
|
||||
serde_json::Value::Null,
|
||||
serde_json::json!("unknown"),
|
||||
serde_json::json!({"full_maintenance_v1":null}),
|
||||
] {
|
||||
let mut request = request.clone();
|
||||
request["parameters"]["privileged_script_profile"] = value;
|
||||
assert!(serde_json::from_value::<PlanRequest>(request).is_err());
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn remote_signed_fixed_variants_bind_profile_without_linux_inheritance() {
|
||||
let mut i = input();
|
||||
let legacy_linux = encode(&i.action).unwrap();
|
||||
@@ -1130,6 +1178,7 @@ mod windows_contract_tests {
|
||||
windows,
|
||||
Action::RunScript {
|
||||
windows_execution_profile: Some(WindowsExecutionProfile::PowerShell51RemoteSigned),
|
||||
privileged_script_profile: None,
|
||||
..
|
||||
}
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user