Bind approved Windows PowerShell process policy and prove Linux-first contracts
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -191,6 +191,7 @@ pub async fn event(
|
||||
ensure!(r.stdout == expected.as_bytes(), "expected output mismatch");
|
||||
}
|
||||
}
|
||||
script_profile_evidence(&payload.action, &evidence)?;
|
||||
if matches!(payload.action, Action::Reboot { .. }) {
|
||||
crate::synchronization::verify_reboot_success(
|
||||
tx, tenant, agent, e, &payload, r, &evidence,
|
||||
@@ -224,6 +225,74 @@ pub async fn event(
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
// The profile records the requested process option, never an effective GPO policy.
|
||||
fn script_profile_evidence(action: &Action, evidence: &Value) -> Result<()> {
|
||||
if let Action::RunScript {
|
||||
script_utf8,
|
||||
windows_execution_profile: Some(WindowsExecutionProfile::PowerShell51RemoteSigned),
|
||||
..
|
||||
} = action
|
||||
{
|
||||
ensure!(
|
||||
evidence.get("windows_execution_profile")
|
||||
== Some(&json!("powershell_51_remote_signed"))
|
||||
&& evidence.get("execution_policy")
|
||||
== Some(&json!("process_remote_signed_requested"))
|
||||
&& evidence.get("execution_policy_requested") == Some(&json!("RemoteSigned"))
|
||||
&& evidence.get("execution_policy_scope") == Some(&json!("process"))
|
||||
&& evidence.get("script_sha256") == Some(&json!(hash(script_utf8.as_bytes()))),
|
||||
"requested Windows process profile evidence mismatch"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod script_profile_tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn requested_profile_success_evidence_is_exact_without_effective_policy_claim() {
|
||||
let mut action = Action::RunScript {
|
||||
interpreter: "powershell".into(),
|
||||
script_utf8: "Write-Output 'hi'\r\n".into(),
|
||||
arguments: vec![],
|
||||
expected_stdout: None,
|
||||
windows_execution_profile: Some(WindowsExecutionProfile::PowerShell51RemoteSigned),
|
||||
};
|
||||
let evidence = json!({"windows_execution_profile":"powershell_51_remote_signed",
|
||||
"execution_policy":"process_remote_signed_requested", "execution_policy_requested":"RemoteSigned",
|
||||
"execution_policy_scope":"process", "script_sha256":hash(b"Write-Output 'hi'\r\n")});
|
||||
script_profile_evidence(&action, &evidence).unwrap();
|
||||
for field in [
|
||||
"windows_execution_profile",
|
||||
"execution_policy",
|
||||
"execution_policy_requested",
|
||||
"execution_policy_scope",
|
||||
"script_sha256",
|
||||
] {
|
||||
let mut changed = evidence.clone();
|
||||
changed.as_object_mut().unwrap().remove(field);
|
||||
assert!(
|
||||
script_profile_evidence(&action, &changed).is_err(),
|
||||
"{field}"
|
||||
);
|
||||
changed[field] = json!("different");
|
||||
assert!(
|
||||
script_profile_evidence(&action, &changed).is_err(),
|
||||
"{field}"
|
||||
);
|
||||
}
|
||||
if let Action::RunScript {
|
||||
windows_execution_profile,
|
||||
..
|
||||
} = &mut action
|
||||
{
|
||||
*windows_execution_profile = None;
|
||||
}
|
||||
script_profile_evidence(&action, &json!({})).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
async fn locked_job(
|
||||
tx: &mut Transaction<'_, Postgres>,
|
||||
agent: Uuid,
|
||||
|
||||
Reference in New Issue
Block a user