Add gated agent update planning, preserved handoff and Linux worker ports
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
//! Exact protected Full raw files and the independently provisioned public
|
||||
//! signing-key record. This is a closed renderer, never a JSON patch/ACL change.
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use ed25519_dalek::VerifyingKey;
|
||||
use rmm_domain::{
|
||||
agent_update::{PeerPinTransition, ResolvedAgentUpdate},
|
||||
jobs::hash,
|
||||
};
|
||||
use rmm_updater_handoff::{LinuxFullTransition, render_linux_full};
|
||||
use rmm_updater_linux::{
|
||||
Budget,
|
||||
files::{Directory, HeldFile, Role, StageDescriptor, Staged},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
ffi::OsStr,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct SigningKeyRecord {
|
||||
key_id: String,
|
||||
algorithm: String,
|
||||
schema_version: u32,
|
||||
public_key_hex: String,
|
||||
}
|
||||
pub struct FullFiles {
|
||||
directory: Directory,
|
||||
config: HeldFile,
|
||||
pin: HeldFile,
|
||||
key_directory: Directory,
|
||||
key_file: HeldFile,
|
||||
key_path: PathBuf,
|
||||
rendered: LinuxFullTransition,
|
||||
}
|
||||
impl FullFiles {
|
||||
/// `job_key_path` and `job_key_raw_sha256` come from independently protected
|
||||
/// LOCAL policy, not an update job, IPC request or manifest. The exact key
|
||||
/// identity is additionally bound to the approved Full transition proof.
|
||||
pub fn open(
|
||||
update: &ResolvedAgentUpdate,
|
||||
job_key_path: &Path,
|
||||
job_key_raw_sha256: &str,
|
||||
budget: &Budget,
|
||||
) -> Result<Self> {
|
||||
budget.check()?;
|
||||
ensure!(
|
||||
update.validate() && job_key_path.is_absolute(),
|
||||
"UPDATE_FULL_INPUT"
|
||||
);
|
||||
let PeerPinTransition::LinuxGeneralFullV1 { full, .. } = &update.peer_pin_transition else {
|
||||
anyhow::bail!("UPDATE_FULL_REQUIRED")
|
||||
};
|
||||
let key_directory = Directory::open(
|
||||
job_key_path.parent().context("UPDATE_FULL_KEY_PARENT")?,
|
||||
0,
|
||||
false,
|
||||
)?;
|
||||
let mut key_file = key_directory.inspect(
|
||||
job_key_path.file_name().context("UPDATE_FULL_KEY_NAME")?,
|
||||
0,
|
||||
4096,
|
||||
)?;
|
||||
ensure!(
|
||||
key_file.proof().sha256 == job_key_raw_sha256,
|
||||
"UPDATE_FULL_KEY_RAW_HASH"
|
||||
);
|
||||
let key: SigningKeyRecord = serde_json::from_slice(&key_file.bytes(4096)?)?;
|
||||
let raw = hex::decode(&key.public_key_hex)?;
|
||||
ensure!(
|
||||
key.schema_version == 1
|
||||
&& key.algorithm == "Ed25519"
|
||||
&& key.key_id == hash(&raw)
|
||||
&& key.key_id == full.effective_signing_key_id,
|
||||
"UPDATE_FULL_KEY_IDENTITY"
|
||||
);
|
||||
let key = VerifyingKey::from_bytes(
|
||||
&raw.try_into()
|
||||
.map_err(|_| anyhow::anyhow!("UPDATE_FULL_KEY_SIZE"))?,
|
||||
)?;
|
||||
ensure!(!key.is_weak(), "UPDATE_FULL_WEAK_KEY");
|
||||
let directory = Directory::open(Path::new("/etc/rmm-remote"), 0, false)?;
|
||||
let mut config = directory.inspect(OsStr::new("helper-full-maintenance.json"), 0, 16384)?;
|
||||
let mut pin =
|
||||
directory.inspect(OsStr::new("full-maintenance-helper-proof.json"), 0, 8192)?;
|
||||
ensure!(
|
||||
config.proof().sha256 == full.old_config_sha256
|
||||
&& pin.proof().sha256 == full.old_pin_sha256,
|
||||
"UPDATE_FULL_OLD_RAW_CHANGED"
|
||||
);
|
||||
let config_bytes = config.bytes(16384)?;
|
||||
// The renderer authenticates the effective public key but deliberately
|
||||
// does not load it. Bind the actual raw Config's key path independently.
|
||||
let value: serde_json::Value = serde_json::from_slice(&config_bytes)?;
|
||||
if let Some(path) = value.get("signing_key_file").and_then(|v| v.as_str()) {
|
||||
ensure!(
|
||||
Path::new(path) == job_key_path,
|
||||
"UPDATE_FULL_KEY_PATH_CHANGED"
|
||||
);
|
||||
} else {
|
||||
ensure!(
|
||||
value["binding"]["public_key_hex"].as_str() == Some(&hex::encode(key.as_bytes())),
|
||||
"UPDATE_FULL_INLINE_KEY_CHANGED"
|
||||
);
|
||||
}
|
||||
let rendered = render_linux_full(
|
||||
&config_bytes,
|
||||
&pin.bytes(8192)?,
|
||||
&full.new_helper_sha256,
|
||||
&key,
|
||||
)?;
|
||||
ensure!(
|
||||
serde_json::to_vec(rendered.proof())? == serde_json::to_vec(full)?,
|
||||
"UPDATE_FULL_RENDER_DIFFERS_FROM_APPROVED"
|
||||
);
|
||||
budget.check()?;
|
||||
Ok(Self {
|
||||
directory,
|
||||
config,
|
||||
pin,
|
||||
key_directory,
|
||||
key_file,
|
||||
key_path: job_key_path.to_owned(),
|
||||
rendered,
|
||||
})
|
||||
}
|
||||
pub fn verify_original(&mut self, budget: &Budget) -> Result<()> {
|
||||
budget.check()?;
|
||||
self.directory.verify()?;
|
||||
self.key_directory.verify()?;
|
||||
self.config.verify(16384)?;
|
||||
self.pin.verify(8192)?;
|
||||
self.key_file.verify(4096)?;
|
||||
self.directory.file(
|
||||
OsStr::new("helper-full-maintenance.json"),
|
||||
self.config.proof(),
|
||||
16384,
|
||||
)?;
|
||||
self.directory.file(
|
||||
OsStr::new("full-maintenance-helper-proof.json"),
|
||||
self.pin.proof(),
|
||||
8192,
|
||||
)?;
|
||||
self.key_directory.file(
|
||||
self.key_path.file_name().context("UPDATE_FULL_KEY_NAME")?,
|
||||
self.key_file.proof(),
|
||||
4096,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
/// Only after real WebUI approval and independent live original-grant /
|
||||
/// download checks by the enclosing admission path. No activation here.
|
||||
pub fn stage(&mut self, owner_nonce: Uuid, budget: &Budget) -> Result<[Staged; 2]> {
|
||||
self.verify_original(budget)?;
|
||||
let mut config = self.rendered.new_config_bytes();
|
||||
let mut pin = self.rendered.new_pin_bytes();
|
||||
let config = Staged::write(
|
||||
&self.directory,
|
||||
StageDescriptor {
|
||||
role: Role::FullConfig,
|
||||
nonce: owner_nonce,
|
||||
original: self.config.proof(),
|
||||
expected_sha: &self.rendered.proof().new_config_sha256,
|
||||
length: config.len() as u64,
|
||||
},
|
||||
&mut config,
|
||||
budget,
|
||||
)?;
|
||||
let pin = Staged::write(
|
||||
&self.directory,
|
||||
StageDescriptor {
|
||||
role: Role::FullPin,
|
||||
nonce: owner_nonce,
|
||||
original: self.pin.proof(),
|
||||
expected_sha: &self.rendered.proof().new_pin_sha256,
|
||||
length: pin.len() as u64,
|
||||
},
|
||||
&mut pin,
|
||||
budget,
|
||||
)?;
|
||||
Ok([config, pin])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user