Retain bounded SYSTEM script failure metadata and verified execution context; keep historical Unknown unchanged
Rust development slice / linux (push) Failing after 10s

This commit is contained in:
2026-11-16 23:59:50 +01:00
parent 24211a1ac0
commit 0733be2736
5 changed files with 109 additions and 21 deletions
+23 -2
View File
@@ -1292,6 +1292,17 @@ impl SystemHelper {
);
self.recheck()?;
peer.check()?;
let mut context_helper=ipc::PeerProof::for_service(&self.pin.helper,std::process::id())?;
context_helper.check()?;
let agent_identity=peer.identity();
agent_identity.validate(&self.pin.agent,agent_identity.pid)?;
let helper_identity=context_helper.identity();
let execution_context=serde_json::json!({"schema_version":1,"tenant_id":self.pin.binding.tenant_id,
"asset_id":self.pin.binding.asset_id,"agent_id":self.pin.binding.agent_id,
"agent_binary_sha256":agent_identity.image_sha256,"helper_binary_sha256":helper_identity.image_sha256,
"policy_sha256":self.pin.policy_sha256,"agent_process_id":agent_identity.pid,
"agent_creation_ticks":agent_identity.creation_ticks,"helper_process_id":helper_identity.pid,
"helper_creation_ticks":helper_identity.creation_ticks,"binding_sha256":ipc::binding_hash(&self.pin.binding)?});
let (_, fresh, recorded_at) =
verified_window(&self.settings.binding, request, &self.clock)?;
ensure!(
@@ -1338,13 +1349,23 @@ impl SystemHelper {
Ok(())
},
);
let mut outcome =
result.unwrap_or_else(|_| Outcome::unknown("SYSTEM_SCRIPT_EFFECT_UNRESOLVED"));
let mut outcome = result.unwrap_or_else(|error| {
let mut value = Outcome::unknown("SYSTEM_SCRIPT_EFFECT_UNRESOLVED");
value.evidence["script_error"] = crate::system_script::diagnostic(&error);
value
});
if outcome.state == "succeeded" && self.clock.reading().is_err() {
outcome.state = "unknown".into();
outcome.error_code = "SYSTEM_FINAL_CLOCK_UNTRUSTED".into();
outcome.evidence["postconditions_passed"] = false.into();
}
let context_rechecked=self.recheck().and_then(|_|peer.check()).and_then(|_|context_helper.check()).is_ok();
if outcome.state=="succeeded" && !context_rechecked {
outcome.state="unknown".into();outcome.error_code="SYSTEM_FINAL_CONTEXT_UNCONFIRMED".into();
outcome.evidence["postconditions_passed"]=false.into();
}
outcome.evidence["execution_context"]=execution_context;
outcome.evidence["execution_context"]["rechecked_at_finish"]=context_rechecked.into();
ledger::persist_outcome(&self.db, permit, &outcome)?;
self.guard.check(&self.db)?;
ledger::finish(&self.db, permit, &outcome)?;
+6 -6
View File
@@ -1,7 +1,7 @@
//! Bounded Windows child process trees. No authorization is conferred here.
//! The caller must commit the verified grant/attempt consumption before run.
//! Job and handle lists are applied atomically by CreateProcessW (Windows 10+).
use anyhow::{Result, ensure};
use anyhow::{Context, Result, ensure};
use std::{
ffi::{OsStr, OsString},
mem::{size_of, size_of_val, zeroed},
@@ -316,8 +316,7 @@ pub(crate) fn run_observed(
!cancel.load(Ordering::SeqCst),
"PROCESS_CANCELLED_BEFORE_START"
);
ensure!(
unsafe {
let created = unsafe {
CreateProcessW(
application.as_ptr(),
command.as_mut_ptr(),
@@ -330,9 +329,10 @@ pub(crate) fn run_observed(
&startup.StartupInfo,
&mut process,
)
} != 0,
"PROCESS_CREATION_REFUSED"
);
};
if created == 0 {
return Err(std::io::Error::last_os_error()).context("PROCESS_CREATION_REFUSED");
}
let process_handle = owned(process.hProcess)?;
let _thread = owned(process.hThread)?;
// Handles not explicitly listed (including job, DB and keys) are never inherited.
+44 -13
View File
@@ -1,6 +1,6 @@
//! Exact approved SYSTEM script bytes, created only after helper consumption.
use crate::helper_ipc::PinnedFile;
use anyhow::{Result, ensure};
use anyhow::{Context, Result, ensure};
use rmm_agent_core::auth::Outcome;
use rmm_domain::jobs::{Action, JobPayload, WindowsExecutionProfile, hash};
use std::{
@@ -12,6 +12,34 @@ use std::{
time::{Duration, Instant},
};
/// Static breadcrumbs only. They never classify absence of effects or grant
/// authority to retry. No path, command, argument or arbitrary error text exits.
#[derive(Clone, Copy, Debug)]
enum Stage { Root, Create, Write, Flush, Pin, Bytes, Executable, Arguments, Process, BeforeStart, DuringProcess }
impl Stage {
fn name(self) -> &'static str { match self {
Self::Root => "root_directory", Self::Create => "create_script", Self::Write => "write_script",
Self::Flush => "flush_script", Self::Pin => "pin_script", Self::Bytes => "read_script",
Self::Executable => "powershell_path", Self::Arguments => "script_arguments",
Self::Process => "process", Self::BeforeStart => "observe_before_start", Self::DuringProcess => "observe_running",
}}
}
impl std::fmt::Display for Stage { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(self.name()) } }
/// Sanitized passive failure evidence. Even a preparation-stage error remains
/// unknown after consumption; it never authorizes a re-execution or nonstart.
pub(crate) fn diagnostic(error: &anyhow::Error) -> serde_json::Value {
const CODES: &[&str] = &["SYSTEM_SCRIPT_PROFILE_REQUIRED", "SYSTEM_SCRIPT_REQUIRED", "SYSTEM_SCRIPT_BYTES_CHANGED",
"SYSTEM_SCRIPT_PREPARATION_TIMEOUT", "SYSTEM_SCRIPT_CANCELLED", "SYSTEM_SCRIPT_START_FENCED",
"PROCESS_CREATION_REFUSED", "PROCESS_PIPE", "PROCESS_JOB_LIMITS", "PROCESS_ATTRIBUTES",
"PROCESS_ATTRIBUTE_BINDING", "PROCESS_CANCELLED_BEFORE_START", "PROCESS_ARGUMENT_LIMIT",
"TIME_STALE_RESPONSE", "TIME_RUNTIME_NO_EVIDENCE", "TIME_RUNTIME_GENERATION", "TIME_RUNTIME_CONNECTION_CHANGED"];
let ipc = crate::helper_ipc::diagnostic(error);
let code = error.chain().find_map(|e| CODES.iter().copied().find(|c| *c == e.to_string())).unwrap_or(ipc.code);
let stage = error.downcast_ref::<Stage>().copied().map_or("unclassified", Stage::name);
let native = error.chain().filter_map(|e| e.downcast_ref::<std::io::Error>()).find_map(|e| e.raw_os_error()).and_then(|v| u32::try_from(v).ok()).or(ipc.win32);
serde_json::json!({"stage":stage,"code":code,"native_win32":native,"diagnostic_only":true,"effect_status":"unknown","automatic_retry":false})
}
pub(crate) fn execute(
job: &JobPayload,
grant: uuid::Uuid,
@@ -40,16 +68,16 @@ pub(crate) fn execute(
};
let directory = Path::new(crate::helper_system::STATE_ROOT);
let writers = [helper_sid.to_owned()];
let mut root = PinnedFile::open_read_shared(directory, true, &[], &writers)?;
let mut root = PinnedFile::open_read_shared(directory, true, &[], &writers).context(Stage::Root)?;
let path = directory.join(format!("script-{}-{}.ps1", job.attempt_id, grant));
let mut file = OpenOptions::new()
.create_new(true)
.read(true)
.write(true)
.share_mode(windows_sys::Win32::Storage::FileSystem::FILE_SHARE_READ)
.open(&path)?;
file.write_all(script_utf8.as_bytes())?;
file.sync_all()?;
.open(&path).context(Stage::Create)?;
file.write_all(script_utf8.as_bytes()).context(Stage::Write)?;
file.sync_all().context(Stage::Flush)?;
drop(file);
struct Cleanup(std::path::PathBuf);
impl Drop for Cleanup {
@@ -58,13 +86,13 @@ pub(crate) fn execute(
}
}
let _cleanup = Cleanup(path.clone());
let mut pinned = PinnedFile::open(&path, false, &[], &writers, false)?;
let mut pinned = PinnedFile::open(&path, false, &[], &writers, false).context(Stage::Pin)?;
ensure!(
std::fs::read(&path)? == script_utf8.as_bytes(),
std::fs::read(&path).context(Stage::Bytes)? == script_utf8.as_bytes(),
"SYSTEM_SCRIPT_BYTES_CHANGED"
);
let executable = crate::actions::powershell()?;
let arguments = crate::actions::script_arguments(job, &path)?;
let executable = crate::actions::powershell().context(Stage::Executable)?;
let arguments = crate::actions::script_arguments(job, &path).context(Stage::Arguments)?;
let timeout = Duration::from_secs(job.max_runtime_seconds.into());
let remaining = timeout
.checked_sub(began.elapsed())
@@ -79,13 +107,16 @@ pub(crate) fn execute(
job.max_output_bytes as usize,
&AtomicBool::new(false),
|| {
root.check()?;
pinned.check()?;
observe(first)?;
let stage = if first { Stage::BeforeStart } else { Stage::DuringProcess };
root.check().context(stage)?;
pinned.check().context(stage)?;
observe(first).context(stage)?;
first = false;
Ok(())
},
)?;
).map_err(|error| {
if error.downcast_ref::<Stage>().is_some() { error } else { error.context(Stage::Process) }
})?;
let expected = expected_stdout
.as_ref()
.is_none_or(|s| output.stdout == s.as_bytes());
@@ -0,0 +1,21 @@
{
"schema_version": 1,
"observed_at": "2026-11-16T22:59:50.788486+00:00",
"scope": "necessary_SYSTEM_script_execution_context_and_sanitized_error_evidence_only",
"candidate_source_sha256": {
"crates/agent-windows/src/helper_system.rs": "eef861d34b57b5296860c076703c78ac3feaa9556b99ce2c7f4b301e26e07187",
"crates/agent-windows/src/system_script.rs": "de0ecdb832013deaaf49653d2c0cdbd67e1055bf363e07572cec77ed2fa0f323",
"crates/agent-windows/src/process.rs": "106e53af2f8afa819e0e6c886fa0e780e1a09c1a7fc11f745ca812859e769ec6"
},
"independently_reviewed": true,
"strict_windows_all_targets_clippy_exit_code": 0,
"release_link_performed": false,
"new_tests_added_or_run": false,
"new_native_vm_job_run": false,
"deployed_to_vm": false,
"old_unknown_or_history_changed": false,
"new_execution_or_retry_authority_added": false,
"root_cause_of_original_failure_established": false,
"old_working_tree_preserved": true,
"independent_review_receipt_sha256": "251bea40d23274ffe831607f41784c06a1f3bd95d5a29936635a03d465f20c18"
}
+15
View File
@@ -1,3 +1,18 @@
**Vorwärtspatch, noch keine neue VM-Abnahme:** Fehlenden tatsächlichen
Agent-/Helper-Ausführungskontext in den reproduzierbaren Quellenstand übernommen;
Fehlerphasen, feste erlaubte Fehlercodes und gegebenenfalls erfassten Win32-Code
beibehalten, ohne beliebige Fehlermeldungen/Pfade auszugeben. Ein
CreateProcessW-Fehler verliert seinen nativen Code nicht mehr. Unabhängige
Quellprüfung und genau eine tatsächliche strenge Windows-All-target-Clippyprüfung
bestanden. Ein früherer Cargo-Aufruf scheiterte davor an einem veralteten
Operator-Mountpfad und führte Clippy nicht aus; separat im privaten Originalbeleg
erhalten. Keine neuen Tests, Release-Links, VM-Installation oder Jobs.
[Quellenprüfung](evidence/windows-system-script-error-context-source.json).
Dies behebt die fehlende Fehlerdiagnose und Kontextlücke **für zukünftigen Code**;
es erklärt den alten Sammelfehler nicht nachträglich und löst den gespeicherten
Unknown nicht auf. S2 bleibt unabgenommen. Die neue Ausnahme ist nur
[Vorschlag](windows-system-unknown-357-decision.md), noch nicht freigegeben.
**22:45:55 UTC – maßgeblicher aktueller Stand:** S0 und der native
historienerhaltende Abschluss221 sind abgeschlossen. S2 ist **nicht bestanden**.
MCP-Antrag und tatsächliche WebUI-Genehmigung des neuen Jobs7d756c34… sind