Add gated agent update planning, preserved handoff and Linux worker ports
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-14 21:48:21 +01:00
parent dc9cb1b096
commit 1e89c4577f
82 changed files with 25052 additions and 69 deletions
+163
View File
@@ -0,0 +1,163 @@
//! Held state identities without reading/exporting private key contents.
//! Paths must come from independently provisioned LOCAL policy, never IPC/jobs.
use anyhow::{Context, Result, ensure};
use rmm_domain::jobs::hash;
use rmm_updater_linux::files::{Directory, Identity};
use serde::{Deserialize, Serialize};
use std::{
fs::File,
os::unix::fs::{MetadataExt, OpenOptionsExt},
path::{Path, PathBuf},
};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Retention {
/// Journal content is expected to advance, but the actual file stays held.
MutableDatabase,
/// Keys/configs remain byte-unread: additionally bind size/mtime/ctime.
ImmutableMetadata,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RetainedFileSpec {
pub path: PathBuf,
pub parent_uid: u32,
pub identity: Identity,
pub retention: Retention,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
struct Stamp {
size: u64,
mtime: i64,
mtime_nsec: i64,
ctime: i64,
ctime_nsec: i64,
}
impl Stamp {
fn of(meta: &std::fs::Metadata) -> Self {
Self {
size: meta.len(),
mtime: meta.mtime(),
mtime_nsec: meta.mtime_nsec(),
ctime: meta.ctime(),
ctime_nsec: meta.ctime_nsec(),
}
}
}
struct HeldState {
spec: RetainedFileSpec,
directory: Directory,
file: File,
stamp: Stamp,
}
pub struct RetainedSet {
files: Vec<HeldState>,
digest: String,
}
impl RetainedSet {
pub fn capture(specs: Vec<RetainedFileSpec>) -> Result<Self> {
ensure!(
!specs.is_empty() && specs.len() <= 64,
"UPDATE_RETAINED_FILESET_LIMIT"
);
let mut files = Vec::new();
for spec in specs {
ensure!(
spec.path.is_absolute()
&& spec.path.components().all(|c| matches!(
c,
std::path::Component::RootDir | std::path::Component::Normal(_)
))
&& !files.iter().any(|v: &HeldState| v.spec.path == spec.path),
"UPDATE_RETAINED_PATH"
);
// No state-reset/namespace substitution and no effect code files in
// this preservation set. Historical bound hardlinks are allowed.
ensure!(
![
rmm_updater_linux::files::Role::Agent,
rmm_updater_linux::files::Role::Helper,
rmm_updater_linux::files::Role::FullConfig,
rmm_updater_linux::files::Role::FullPin
]
.iter()
.any(|role| Path::new(role.target()) == spec.path),
"UPDATE_RETAINED_CODE_PATH"
);
let parent = spec.path.parent().context("UPDATE_RETAINED_PARENT")?;
let directory = Directory::open(parent, spec.parent_uid, false)?;
let file = std::fs::OpenOptions::new()
.read(true)
.custom_flags(libc::O_NOFOLLOW | libc::O_NONBLOCK | libc::O_CLOEXEC)
.open(&spec.path)?;
let stamp = Stamp::of(&file.metadata()?);
let held = HeldState {
spec,
directory,
file,
stamp,
};
held.verify()?;
files.push(held);
}
let serial: Vec<_> = files
.iter()
.map(|f| {
(
&f.spec,
if f.spec.retention == Retention::ImmutableMetadata {
Some(&f.stamp)
} else {
None
},
)
})
.collect();
let digest = hash(&serde_json::to_vec(&serial)?);
Ok(Self { files, digest })
}
pub fn sha256(&self) -> &str {
&self.digest
}
pub fn verify(&self) -> Result<()> {
for file in &self.files {
file.verify()?;
}
Ok(())
}
}
fn identity(meta: &std::fs::Metadata) -> Identity {
Identity {
device: meta.dev(),
inode: meta.ino(),
uid: meta.uid(),
gid: meta.gid(),
mode: meta.mode(),
links: meta.nlink(),
}
}
impl HeldState {
fn verify(&self) -> Result<()> {
self.directory.verify()?;
let held = self.file.metadata()?;
let named = std::fs::symlink_metadata(&self.spec.path)?;
ensure!(
held.is_file()
&& named.is_file()
&& !named.file_type().is_symlink()
&& identity(&held) == self.spec.identity
&& identity(&named) == self.spec.identity
&& held.mode() & 0o022 == 0
&& held.nlink() > 0,
"UPDATE_RETAINED_IDENTITY_CHANGED"
);
if self.spec.retention == Retention::ImmutableMetadata {
ensure!(
Stamp::of(&held) == self.stamp && Stamp::of(&named) == self.stamp,
"UPDATE_RETAINED_METADATA_CHANGED"
);
}
self.directory.verify()
}
}