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:
@@ -9,6 +9,7 @@ struct Endpoint {
|
||||
socket: PathBuf,
|
||||
profile: String,
|
||||
hash: String,
|
||||
binary_hash: Option<String>,
|
||||
}
|
||||
#[derive(Clone)]
|
||||
pub struct Helpers {
|
||||
@@ -39,24 +40,44 @@ fn map(s: &root::Snapshot) -> reconcile::HelperSnapshot {
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
fn general(binding: &Binding) -> Result<control::Response> {
|
||||
let socket = std::env::var_os("RMM_HELPER_SOCKET").context("NO_GENERAL_HELPER")?;
|
||||
let path = std::env::var_os("RMM_HELPER_POLICY_FILE").context("GENERAL_POLICY_PIN_REQUIRED")?;
|
||||
fn general(binding: &Binding, full: bool) -> Result<control::Response> {
|
||||
let (socket_name, pin_name, profile) = if full {
|
||||
(
|
||||
"RMM_FULL_MAINTENANCE_HELPER_SOCKET",
|
||||
"RMM_FULL_MAINTENANCE_POLICY_FILE",
|
||||
"full_maintenance_v1",
|
||||
)
|
||||
} else {
|
||||
("RMM_HELPER_SOCKET", "RMM_HELPER_POLICY_FILE", "general")
|
||||
};
|
||||
let socket = std::env::var_os(socket_name).context("NO_GENERAL_HELPER")?;
|
||||
let path = std::env::var_os(pin_name).context("GENERAL_POLICY_PIN_REQUIRED")?;
|
||||
let pin = control::GeneralPin::read(Path::new(&path), binding)?;
|
||||
ensure!(pin.profile == profile, "HELPER_PROFILE_ROUTE_MISMATCH");
|
||||
control::general_probe(Path::new(&socket), binding, &pin)
|
||||
}
|
||||
impl Helpers {
|
||||
pub fn configured(binding: &Binding) -> Result<Self> {
|
||||
let mut endpoints = vec![];
|
||||
if let Some(socket) = std::env::var_os("RMM_HELPER_SOCKET") {
|
||||
let path = std::env::var_os("RMM_HELPER_POLICY_FILE")
|
||||
.context("GENERAL_POLICY_PIN_REQUIRED")?;
|
||||
let pin = control::GeneralPin::read(Path::new(&path), binding)?;
|
||||
endpoints.push(Endpoint {
|
||||
socket: socket.into(),
|
||||
profile: "general".into(),
|
||||
hash: pin.policy_sha256,
|
||||
});
|
||||
for (socket_name, pin_name, profile) in [
|
||||
("RMM_HELPER_SOCKET", "RMM_HELPER_POLICY_FILE", "general"),
|
||||
(
|
||||
"RMM_FULL_MAINTENANCE_HELPER_SOCKET",
|
||||
"RMM_FULL_MAINTENANCE_POLICY_FILE",
|
||||
"full_maintenance_v1",
|
||||
),
|
||||
] {
|
||||
if let Some(socket) = std::env::var_os(socket_name) {
|
||||
let path = std::env::var_os(pin_name).context("GENERAL_POLICY_PIN_REQUIRED")?;
|
||||
let pin = control::GeneralPin::read(Path::new(&path), binding)?;
|
||||
ensure!(pin.profile == profile, "HELPER_PROFILE_ROUTE_MISMATCH");
|
||||
endpoints.push(Endpoint {
|
||||
socket: socket.into(),
|
||||
profile: profile.into(),
|
||||
hash: pin.policy_sha256,
|
||||
binary_hash: pin.helper_binary_sha256,
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Some(socket) = std::env::var_os("RMM_APT_HELPER_SOCKET") {
|
||||
ensure!(
|
||||
@@ -70,6 +91,7 @@ impl Helpers {
|
||||
socket: socket.into(),
|
||||
profile: "apt_only".into(),
|
||||
hash: pin.provider_stack_sha256,
|
||||
binary_hash: None,
|
||||
});
|
||||
}
|
||||
Ok(Self {
|
||||
@@ -79,7 +101,9 @@ impl Helpers {
|
||||
}
|
||||
fn validate(&self, e: &Endpoint, r: &control::Response) -> Result<()> {
|
||||
ensure!(
|
||||
r.profile == e.profile && r.policy_sha256 == e.hash,
|
||||
r.profile == e.profile
|
||||
&& r.policy_sha256 == e.hash
|
||||
&& r.helper_binary_sha256 == e.binary_hash,
|
||||
"HELPER_PIN_PROFILE_MISMATCH"
|
||||
);
|
||||
Ok(())
|
||||
@@ -153,13 +177,39 @@ impl Helpers {
|
||||
}
|
||||
}
|
||||
pub fn general_capabilities(binding: &Binding) -> Vec<String> {
|
||||
let mut caps = profile_capabilities(binding, false);
|
||||
caps.extend(profile_capabilities(binding, true));
|
||||
caps.sort();
|
||||
caps.dedup();
|
||||
caps
|
||||
}
|
||||
fn profile_capabilities(binding: &Binding, full: bool) -> Vec<String> {
|
||||
(|| -> Result<Vec<String>> {
|
||||
let response = general(binding)?;
|
||||
let response = general(binding, full)?;
|
||||
let policy = response.policy.context("NO_GENERAL_POLICY")?;
|
||||
let mut caps = vec![
|
||||
"helper.root.v1".into(),
|
||||
format!("helper.policy.sha256:{}", response.policy_sha256),
|
||||
];
|
||||
if full {
|
||||
ensure!(
|
||||
policy.schema_version == 2
|
||||
&& policy.profile == "full_maintenance_v1"
|
||||
&& policy.allowed_script_profiles.as_deref()
|
||||
== Some(&[rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1]),
|
||||
"FULL_MAINTENANCE_POLICY_REQUIRED"
|
||||
);
|
||||
let binary = policy
|
||||
.helper_binary_sha256
|
||||
.as_ref()
|
||||
.context("FULL_MAINTENANCE_BINARY_PIN_REQUIRED")?;
|
||||
ensure!(
|
||||
response.helper_binary_sha256.as_ref() == Some(binary),
|
||||
"FULL_MAINTENANCE_BINARY_PROOF_REQUIRED"
|
||||
);
|
||||
caps.push(format!("helper.binary.sha256:{binary}"));
|
||||
caps.push(rmm_domain::jobs::FULL_MAINTENANCE_CAPABILITY.into());
|
||||
}
|
||||
let mut actions = vec![];
|
||||
if policy.allow_root_scripts && rmm_agent_linux::actions::Interpreter::PosixSh.available() {
|
||||
actions.push("run_script");
|
||||
@@ -180,10 +230,22 @@ pub fn general_capabilities(binding: &Binding) -> Vec<String> {
|
||||
}
|
||||
pub fn general_supported(binding: &Binding, job: &rmm_domain::jobs::JobPayload) -> bool {
|
||||
(|| -> Result<bool> {
|
||||
let p = general(binding)?.policy.context("NO_GENERAL_POLICY")?;
|
||||
let p = general(binding, job.action.full_maintenance())?
|
||||
.policy
|
||||
.context("NO_GENERAL_POLICY")?;
|
||||
Ok(match &job.action {
|
||||
rmm_domain::jobs::Action::RunScript { interpreter, .. } => {
|
||||
p.allow_root_scripts
|
||||
&& job.action.valid_execution_identity(&job.execution_identity)
|
||||
&& job
|
||||
.action
|
||||
.valid_job_limits(job.max_runtime_seconds, job.max_output_bytes)
|
||||
&& (!job.action.full_maintenance()
|
||||
|| p.allowed_script_profiles.as_ref().is_some_and(|v| {
|
||||
v.contains(
|
||||
&rmm_domain::jobs::PrivilegedScriptProfile::FullMaintenanceV1,
|
||||
)
|
||||
}))
|
||||
&& match interpreter.as_str() {
|
||||
"posix_sh" => rmm_agent_linux::actions::Interpreter::PosixSh.available(),
|
||||
"bash" => rmm_agent_linux::actions::Interpreter::Bash.available(),
|
||||
|
||||
Reference in New Issue
Block a user