Implement guarded Linux updater runtime and compatible baseline tooling
Rust development slice / linux (push) Failing after 8s
Rust development slice / linux (push) Failing after 8s
This commit is contained in:
@@ -15,7 +15,7 @@ use std::{
|
||||
net::{UnixListener, UnixStream},
|
||||
},
|
||||
},
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
@@ -133,6 +133,7 @@ impl Config {
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum Incoming {
|
||||
UpdateObserve(rmm_privileged_helper::update_observer::Request),
|
||||
NativeUpdate(rmm_agent_core::update_handoff::NativeControlRequest),
|
||||
Control(control::Request),
|
||||
Probe(rmm_privileged_helper::readiness::Request),
|
||||
@@ -170,6 +171,17 @@ fn policy(config: &Config, job: &rmm_domain::jobs::JobPayload) -> Result<()> {
|
||||
job.execution_identity == "root",
|
||||
"HELPER_REQUIRES_EXPLICIT_ROOT_IDENTITY"
|
||||
);
|
||||
if matches!(job.action, Action::UpdateAgent { .. }) {
|
||||
ensure!(
|
||||
config.profile == HelperProfile::FullMaintenanceV1
|
||||
&& config.agent_uid == 993
|
||||
&& config.socket
|
||||
== std::path::Path::new("/run/rmm-helper-maintenance/control.sock")
|
||||
&& std::path::Path::new("/etc/rmm-agent-updater/policy.json").try_exists()?,
|
||||
"UPDATE_REQUIRES_SEPARATELY_PROVISIONED_FULL"
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
if rmm_privileged_helper::apt::is_apt_action(job) {
|
||||
ensure!(
|
||||
config.profile == HelperProfile::AptOnly,
|
||||
@@ -386,6 +398,44 @@ fn handle(
|
||||
ensure!(size <= 512 * 1024, "JOB_REQUEST_SIZE");
|
||||
request
|
||||
}
|
||||
Incoming::UpdateObserve(request) => {
|
||||
peer_allowed(stream, config.agent_uid)?;
|
||||
ensure!(
|
||||
size <= 65536
|
||||
&& config.profile == HelperProfile::FullMaintenanceV1
|
||||
&& config.agent_uid == 993
|
||||
&& config.socket == Path::new("/run/rmm-helper-maintenance/control.sock"),
|
||||
"UPDATE_OBSERVER_ONLY_FULL"
|
||||
);
|
||||
let guard = reconcile::ExecutorGuard::acquire(&config.state, 0)?;
|
||||
let key_path = config
|
||||
.signing_key_file
|
||||
.as_deref()
|
||||
.unwrap_or(Path::new("/etc/rmm-agent-updater/job-signing-key.json"));
|
||||
let policy = config.general_policy()?.sha256()?;
|
||||
let response = rmm_privileged_helper::update_observer::collect(
|
||||
db,
|
||||
rmm_privileged_helper::update_observer::Local {
|
||||
executor: &guard,
|
||||
binding: &config.binding,
|
||||
clock: update_clock.ok_or_else(|| anyhow::anyhow!("UPDATE_NOT_CONFIGURED"))?,
|
||||
sync,
|
||||
sync_clock,
|
||||
key_path,
|
||||
policy_sha256: &policy,
|
||||
helper_sha256: binary_sha256
|
||||
.as_deref()
|
||||
.ok_or_else(|| anyhow::anyhow!("UPDATE_FULL_BINARY_PIN_REQUIRED"))?,
|
||||
},
|
||||
&request,
|
||||
)?;
|
||||
peer_allowed(stream, config.agent_uid)?;
|
||||
let bytes = serde_json::to_vec(&response)?;
|
||||
ensure!(bytes.len() <= 192 * 1024, "UPDATE_OBSERVER_REPLY_LIMIT");
|
||||
stream.write_all(&u32::try_from(bytes.len())?.to_be_bytes())?;
|
||||
stream.write_all(&bytes)?;
|
||||
return Ok(());
|
||||
}
|
||||
Incoming::Control(request) => {
|
||||
peer_allowed(stream, config.agent_uid)?;
|
||||
let (challenge, identity) = request.binding();
|
||||
@@ -534,6 +584,65 @@ fn handle(
|
||||
// Both profiles use these exact same inodes, locked per effect rather than
|
||||
// daemon lifetime so the dedicated and general helper can coexist.
|
||||
let resource = reconcile::ExecutorGuard::acquire(&config.state, 0)?;
|
||||
if matches!(job.action, Action::UpdateAgent { .. }) {
|
||||
let consumed: bool = db.query_row("SELECT EXISTS(SELECT 1 FROM consumed WHERE grant_id=?1 OR (agent=?2 AND generation=?3 AND job=?4 AND attempt=?5))",
|
||||
rusqlite::params![permit.grant_id.to_string(),permit.agent_id.to_string(),permit.enrollment_generation,permit.job_id.to_string(),permit.attempt_id.to_string()],|r|r.get(0))?;
|
||||
ensure!(!consumed, "UPDATE_ALREADY_CONSUMED_NO_REDISPATCH");
|
||||
let key_path = config
|
||||
.signing_key_file
|
||||
.clone()
|
||||
.unwrap_or_else(|| PathBuf::from("/etc/rmm-agent-updater/job-signing-key.json"));
|
||||
private_path(&key_path, 0, false)?;
|
||||
ensure!(
|
||||
fs::metadata(&key_path)?.len() <= 4096,
|
||||
"UPDATE_JOB_KEY_RECORD_LIMIT"
|
||||
);
|
||||
let key = rmm_privileged_helper::SigningKey::read(&key_path, 0)?;
|
||||
ensure!(
|
||||
key.public_key_hex == config.binding.public_key_hex,
|
||||
"UPDATE_LOCAL_JOB_KEY_CHANGED"
|
||||
);
|
||||
let key_hash = rmm_domain::jobs::hash(&fs::read(&key_path)?);
|
||||
let prepared = rmm_privileged_helper::update_admission::Prepared::new(
|
||||
db,
|
||||
rmm_privileged_helper::update_admission::Local {
|
||||
executor: &resource,
|
||||
binding: &config.binding,
|
||||
clock: update_clock.ok_or_else(|| anyhow::anyhow!("UPDATE_NOT_CONFIGURED"))?,
|
||||
job_key_path: &key_path,
|
||||
job_key_raw_sha256: &key_hash,
|
||||
},
|
||||
&request,
|
||||
)?;
|
||||
peer_allowed(stream, config.agent_uid)?;
|
||||
let mut probe = 0u8;
|
||||
// Preparation may copy sizeable exact artifacts. Recheck the actual
|
||||
// caller at the original consumption boundary without consuming bytes.
|
||||
// SAFETY: live socket and a writable byte; MSG_PEEK leaves input intact.
|
||||
let available = unsafe {
|
||||
libc::recv(
|
||||
stream.as_raw_fd(),
|
||||
(&mut probe as *mut u8).cast(),
|
||||
1,
|
||||
libc::MSG_PEEK | libc::MSG_DONTWAIT,
|
||||
)
|
||||
};
|
||||
ensure!(
|
||||
available < 0
|
||||
&& std::io::Error::last_os_error().kind() == std::io::ErrorKind::WouldBlock,
|
||||
"UPDATE_CALLER_CANCELLED_OR_DISCONNECTED"
|
||||
);
|
||||
let accepted = prepared.consume(db, sync, sync_clock)?;
|
||||
let bytes = serde_json::to_vec(&accepted)?;
|
||||
ensure!(bytes.len() <= 4096, "UPDATE_HANDOFF_ACK_LIMIT");
|
||||
stream.write_all(&u32::try_from(bytes.len())?.to_be_bytes())?;
|
||||
stream.write_all(&bytes)?;
|
||||
stream.flush()?;
|
||||
// Full resumes its listener immediately after this once-only Activate
|
||||
// reply. The worker then reads this same original ledger via Full before
|
||||
// it may stop Agent/General/Full. This is never a final job Outcome.
|
||||
return prepared.dispatch_after_reply();
|
||||
}
|
||||
let previous: Option<Option<Vec<u8>>> = db
|
||||
.query_row(
|
||||
"SELECT COALESCE(result,(SELECT outcome FROM execution_evidence WHERE execution_evidence.grant_id=consumed.grant_id)) FROM consumed WHERE grant_id=?1",
|
||||
|
||||
Reference in New Issue
Block a user