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
+11 -6
View File
@@ -319,10 +319,16 @@ fn local_manifest(installed: &Installed) -> Result<ReleaseManifest> {
// Only typed release UUIDs enter the fixed SCM command. The actual service path,
// LocalService account and absence of an independently provisioned helper are checked again on the target.
fn select(from: Uuid, to: Uuid) -> Result<()> {
fn select(from: &Installed, to: &Installed) -> Result<()> {
let manifest = local_manifest(to)?;
let [agent, helper] = manifest.artifacts.as_slice() else {
anyhow::bail!("incomplete installed release pair");
};
let script = include_str!("release_service_switch.ps1")
.replace("FROM_UUID", &from.to_string())
.replace("TO_UUID", &to.to_string());
.replace("FROM_UUID", &from.release_id.to_string())
.replace("TO_UUID", &to.release_id.to_string())
.replace("SELECTED_AGENT_SHA256", &agent.sha256)
.replace("SELECTED_HELPER_SHA256", &helper.sha256);
let windows = std::env::var_os("SystemRoot").context("Windows directory")?;
let ps = Path::new(&windows).join(r"System32\WindowsPowerShell\v1.0\powershell.exe");
let result = Command::new(ps)
@@ -338,8 +344,7 @@ fn select(from: Uuid, to: Uuid) -> Result<()> {
Ok(())
}
async fn rollback(t: &Transition) -> Result<()> {
local_manifest(&t.old)?;
select(t.new.release_id, t.old.release_id)?;
select(&t.new, &t.old)?;
write_record("rejected-release.json", &t.new)?;
fs::remove_file(record_path(INTENT))?;
Ok(())
@@ -494,7 +499,7 @@ async fn cycle() -> Result<()> {
let t = Transition { old: active, new };
write_record(INTENT, &t)?;
let start = chrono::Utc::now();
let selected = select(t.old.release_id, t.new.release_id);
let selected = select(&t.old, &t.new);
if selected.is_ok() {
for _ in 0..18 {
if let Ok(h) = device.health().await