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:
@@ -124,13 +124,17 @@ pub fn save_start(
|
||||
}
|
||||
|
||||
pub fn script(job: &JobPayload) -> Result<Outcome> {
|
||||
use rmm_agent_linux::actions::{Interpreter, ScriptRequest, run_script};
|
||||
script_controlled(job, || Ok(()))
|
||||
}
|
||||
pub fn script_controlled(job: &JobPayload, observe: impl FnMut() -> Result<()>) -> Result<Outcome> {
|
||||
use rmm_agent_linux::actions::{Interpreter, ScriptRequest, run_script_controlled};
|
||||
let rmm_domain::jobs::Action::RunScript {
|
||||
interpreter,
|
||||
script_utf8,
|
||||
arguments,
|
||||
expected_stdout,
|
||||
windows_execution_profile: None,
|
||||
..
|
||||
} = &job.action
|
||||
else {
|
||||
anyhow::bail!("NOT_SCRIPT")
|
||||
@@ -147,14 +151,15 @@ pub fn script(job: &JobPayload) -> Result<Outcome> {
|
||||
std::time::Duration::from_secs(job.max_runtime_seconds.into()),
|
||||
job.max_output_bytes as usize,
|
||||
)?;
|
||||
let output = run_script(&request)?;
|
||||
let output = run_script_controlled(&request, observe)?;
|
||||
let passed = output.code == Some(0)
|
||||
&& !output.timed_out
|
||||
&& !output.interrupted
|
||||
&& expected_stdout
|
||||
.as_ref()
|
||||
.is_none_or(|s| !output.truncated && output.stdout == s.as_bytes());
|
||||
Ok(Outcome {
|
||||
state: if output.timed_out || output.code.is_none() {
|
||||
state: if output.timed_out || output.interrupted || output.code.is_none() {
|
||||
"unknown"
|
||||
} else if passed {
|
||||
"succeeded"
|
||||
@@ -167,9 +172,11 @@ pub fn script(job: &JobPayload) -> Result<Outcome> {
|
||||
exit_code: output.code,
|
||||
output_truncated: output.truncated,
|
||||
reboot_required: false,
|
||||
evidence: serde_json::json!({"postconditions_passed":passed}),
|
||||
evidence: serde_json::json!({"postconditions_passed":passed,"script_sha256":rmm_domain::jobs::hash(script_utf8.as_bytes()),"privileged_script_profile":if job.action.full_maintenance(){Some("full_maintenance_v1")}else{None},"execution_uid":unsafe{libc::geteuid()},"output_encoding":"raw_native_bytes","cancel_or_fence_observed":output.interrupted,"termination_does_not_prove_absence_of_effects":output.interrupted||output.timed_out}),
|
||||
error_code: if passed {
|
||||
""
|
||||
} else if output.interrupted {
|
||||
"CANCEL_OR_FENCE_EFFECT_UNKNOWN"
|
||||
} else if output.timed_out {
|
||||
"TIMEOUT_EFFECT_UNKNOWN"
|
||||
} else {
|
||||
@@ -210,6 +217,14 @@ pub struct TrustedClock {
|
||||
/// Local client authenticates the root process as well as the root-owned socket.
|
||||
/// A malicious same-user Unix server must not be able to forge helper success.
|
||||
pub fn invoke(socket: &Path, request: &Request, max_runtime_seconds: u32) -> Result<Outcome> {
|
||||
invoke_controlled(socket, request, max_runtime_seconds, || Ok(()))
|
||||
}
|
||||
pub fn invoke_controlled(
|
||||
socket: &Path,
|
||||
request: &Request,
|
||||
max_runtime_seconds: u32,
|
||||
mut observe: impl FnMut() -> Result<()>,
|
||||
) -> Result<Outcome> {
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
os::{
|
||||
@@ -256,16 +271,50 @@ pub fn invoke(socket: &Path, request: &Request, max_runtime_seconds: u32) -> Res
|
||||
stream.set_read_timeout(Some(Duration::from_secs(
|
||||
u64::from(max_runtime_seconds) + 10,
|
||||
)))?;
|
||||
observe()?;
|
||||
let bytes = serde_json::to_vec(request)?;
|
||||
ensure!(bytes.len() <= 512 * 1024, "HELPER_REQUEST_SIZE");
|
||||
stream.write_all(&(u32::try_from(bytes.len())?).to_be_bytes())?;
|
||||
stream.write_all(&bytes)?;
|
||||
stream.set_read_timeout(Some(Duration::from_millis(50)))?;
|
||||
let started = std::time::Instant::now();
|
||||
let mut closed = false;
|
||||
let mut read = |stream: &mut UnixStream, mut target: &mut [u8]| -> Result<()> {
|
||||
while !target.is_empty() {
|
||||
if !closed && observe().is_err() {
|
||||
// Half-close only this exact authenticated request stream. The
|
||||
// helper treats its EOF as cancellation; result reads continue.
|
||||
stream.shutdown(std::net::Shutdown::Write)?;
|
||||
closed = true;
|
||||
}
|
||||
ensure!(
|
||||
started.elapsed() < Duration::from_secs(u64::from(max_runtime_seconds) + 10),
|
||||
"HELPER_RESPONSE_TIMEOUT_EFFECT_UNKNOWN"
|
||||
);
|
||||
match stream.read(target) {
|
||||
Ok(0) => anyhow::bail!("HELPER_RESPONSE_CLOSED_EFFECT_UNKNOWN"),
|
||||
Ok(n) => target = &mut target[n..],
|
||||
Err(e)
|
||||
if matches!(
|
||||
e.kind(),
|
||||
std::io::ErrorKind::WouldBlock
|
||||
| std::io::ErrorKind::TimedOut
|
||||
| std::io::ErrorKind::Interrupted
|
||||
) =>
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
let mut length = [0; 4];
|
||||
stream.read_exact(&mut length)?;
|
||||
read(&mut stream, &mut length)?;
|
||||
let length = u32::from_be_bytes(length) as usize;
|
||||
ensure!(length <= 2 * 1024 * 1024, "HELPER_RESPONSE_SIZE");
|
||||
let mut bytes = vec![0; length];
|
||||
stream.read_exact(&mut bytes)?;
|
||||
read(&mut stream, &mut bytes)?;
|
||||
let outcome: Outcome = serde_json::from_slice(&bytes)?;
|
||||
ensure!(
|
||||
outcome.stdout.len() + outcome.stderr.len() <= 262144,
|
||||
|
||||
Reference in New Issue
Block a user