Enable per-order privileged scripts on managed devices

This commit is contained in:
2026-11-18 00:02:17 +01:00
parent 2aa460e337
commit ea87d8141c
20 changed files with 864 additions and 157 deletions
+58 -2
View File
@@ -38,6 +38,7 @@ pub struct Selection {
pub reason: String,
pub max_runtime_seconds: u32,
pub max_output_bytes: u32,
pub execution_identity: Option<String>,
}
fn script(interpreter: &str, identity: &str, body: String) -> Result<Action, Error> {
@@ -169,7 +170,9 @@ pub async fn plan(
version: row.get("version"),
script_sha256: hash(body.as_bytes()),
};
let identity: String = row.get("execution_identity");
let identity = input
.execution_identity
.unwrap_or_else(|| row.get("execution_identity"));
let action = script(row.get("interpreter"), &identity, body)?;
let plan = PlanInput {
targets: input.targets,
@@ -259,7 +262,59 @@ pub(crate) mod tests {
) {
let tenant = p.tenant;
let initial = list(s, p, tenant, PageQuery::default()).await.unwrap();
let template = &initial["items"][0];
let items = initial["items"].as_array().unwrap();
assert_eq!(items.len(), 13);
let template = items
.iter()
.find(|item| item["name"] == "Windows-Updates installieren")
.unwrap();
for (prefix, interpreter, asset) in [
("Linux · ", "posix_sh", linux),
("Windows · ", "powershell", windows),
] {
let revisions: Vec<_> = items
.iter()
.filter(|item| item["name"].as_str().unwrap().starts_with(prefix))
.collect();
assert_eq!(revisions.len(), 6);
for row in revisions {
let identity = if row["name"] == "Windows · Betriebssystem-Updatebedarf anzeigen" {
"system"
} else {
"agent_service"
};
assert_eq!(row["interpreter"], interpreter);
assert_eq!(row["execution_identity"], identity);
assert_eq!(row["version"], 1);
let id = Uuid::parse_str(row["revision_id"].as_str().unwrap()).unwrap();
let selection = Selection {
targets: Targets {
asset_ids: vec![asset],
},
schedule: Schedule {
not_before: Utc::now(),
start_before: Utc::now() + Duration::minutes(30),
},
rollout: Rollout {
max_parallel: 1,
halt_after_failures: 1,
},
reason: "standard diagnostic library contract".into(),
max_runtime_seconds: 120,
max_output_bytes: 65536,
execution_identity: None,
};
let planned = plan(s, p, tenant, id, selection).await;
if identity == "system" {
assert_eq!(planned.unwrap_err().0, StatusCode::FORBIDDEN);
} else {
assert_eq!(
planned.unwrap()["plan_payload"]["script_revision"]["script_sha256"],
row["script_sha256"]
);
}
}
}
assert_eq!(template["name"], "Windows-Updates installieren");
assert_eq!(template["interpreter"], "powershell");
let native = script(
@@ -343,6 +398,7 @@ pub(crate) mod tests {
reason: "isolated library contract".into(),
max_runtime_seconds: 60,
max_output_bytes: 4096,
execution_identity: None,
};
assert_eq!(
plan(s, p, tenant, id, selection(windows))