Preserve exact staged file identities when reopening updater witnesses
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -329,7 +329,73 @@ pub struct StageDescriptor<'a> {
|
||||
pub expected_sha: &'a str,
|
||||
pub length: u64,
|
||||
}
|
||||
/// Original immutable proof bytes from the protected consumed handoff bundle.
|
||||
/// Reopening them supplies held observations only, never dispatch/resume.
|
||||
pub struct BoundStage<'a> {
|
||||
pub role: Role,
|
||||
pub nonce: Uuid,
|
||||
pub original: &'a FileProof,
|
||||
pub staged: &'a FileProof,
|
||||
}
|
||||
impl Staged {
|
||||
pub fn reopen_bound(dir: &Directory, bound: BoundStage<'_>, budget: &Budget) -> Result<Self> {
|
||||
ensure!(
|
||||
Path::new(bound.role.target()).parent() == Some(dir.path.as_path()),
|
||||
"UPDATE_FIXED_ROLE_DIRECTORY"
|
||||
);
|
||||
Self::reopen_held(dir, bound, budget)
|
||||
}
|
||||
fn reopen_held(dir: &Directory, bound: BoundStage<'_>, budget: &Budget) -> Result<Self> {
|
||||
budget.check()?;
|
||||
dir.verify()?;
|
||||
ensure!(
|
||||
!bound.nonce.is_nil()
|
||||
&& valid_digest(&bound.original.sha256)
|
||||
&& valid_digest(&bound.staged.sha256)
|
||||
&& bound.original.bytes > 0
|
||||
&& bound.original.bytes <= 256 * 1024 * 1024
|
||||
&& bound.staged.bytes > 0
|
||||
&& bound.staged.bytes <= 256 * 1024 * 1024
|
||||
&& bound.original.identity.uid == 0
|
||||
&& bound.original.identity.mode & 0o022 == 0
|
||||
&& bound.staged.identity.uid == bound.original.identity.uid
|
||||
&& bound.staged.identity.gid == bound.original.identity.gid
|
||||
&& bound.staged.identity.mode == bound.original.identity.mode
|
||||
&& bound.staged.identity.links == 1
|
||||
&& bound.staged.identity.device == bound.original.identity.device
|
||||
&& bound.staged.identity.inode != bound.original.identity.inode,
|
||||
"UPDATE_REOPEN_PROOF_SHAPE"
|
||||
);
|
||||
let target = Path::new(bound.role.target())
|
||||
.file_name()
|
||||
.context("UPDATE_TARGET")?
|
||||
.to_str()
|
||||
.context("UPDATE_TARGET")?
|
||||
.to_owned();
|
||||
let basename = format!(".rmm-update-{}-{}.stage", bound.nonce, bound.role.label());
|
||||
dir.file(OsStr::new(&target), bound.original, 256 * 1024 * 1024)?;
|
||||
let file = dir.file(OsStr::new(&basename), bound.staged, 256 * 1024 * 1024)?;
|
||||
// A partially applied prior pass is never reconstructed as a stage.
|
||||
dir.absent(OsStr::new(&format!(
|
||||
".rmm-update-{}-{}.previous",
|
||||
bound.nonce,
|
||||
bound.role.label()
|
||||
)))?;
|
||||
dir.absent(OsStr::new(&format!(
|
||||
".rmm-update-{}-{}.rejected",
|
||||
bound.nonce,
|
||||
bound.role.label()
|
||||
)))?;
|
||||
budget.check()?;
|
||||
Ok(Self {
|
||||
role: bound.role,
|
||||
nonce: bound.nonce,
|
||||
basename,
|
||||
file,
|
||||
target,
|
||||
original: bound.original.clone(),
|
||||
})
|
||||
}
|
||||
/// Stage only after the embedding agent has a real fixed approved job and
|
||||
/// authorized download. This function alone grants no stop/swap authority.
|
||||
pub fn write(
|
||||
@@ -611,3 +677,102 @@ impl Drop for LedgerGuard<'_> {
|
||||
unsafe { libc::flock(self.lock.as_raw_fd(), libc::LOCK_UN) };
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod reopen_tests {
|
||||
use super::*;
|
||||
use std::{
|
||||
fs,
|
||||
os::unix::fs::{OpenOptionsExt, PermissionsExt},
|
||||
time::Duration,
|
||||
};
|
||||
struct Fixture(PathBuf);
|
||||
impl Drop for Fixture {
|
||||
fn drop(&mut self) {
|
||||
fs::remove_dir_all(&self.0).unwrap();
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn bound_reopen_rejects_same_byte_name_substitution_and_added_stage_hardlink() {
|
||||
assert_eq!(
|
||||
unsafe { libc::geteuid() },
|
||||
0,
|
||||
"Use isolated Root unit fixture; never a host daemon"
|
||||
);
|
||||
let path = PathBuf::from(format!("/run/rmm-stage-reopen-unit-{}", Uuid::new_v4()));
|
||||
fs::create_dir(&path).unwrap();
|
||||
fs::set_permissions(&path, fs::Permissions::from_mode(0o700)).unwrap();
|
||||
let fixture = Fixture(path);
|
||||
let dir = Directory::open(&fixture.0, 0, true).unwrap();
|
||||
let nonce = Uuid::new_v4();
|
||||
let stage = format!(".rmm-update-{nonce}-agent.stage");
|
||||
for (name, bytes) in [
|
||||
("rmm-agent-remote", b"old public fixture".as_slice()),
|
||||
(stage.as_str(), b"new public fixture".as_slice()),
|
||||
] {
|
||||
let mut file = fs::OpenOptions::new()
|
||||
.create_new(true)
|
||||
.write(true)
|
||||
.mode(0o600)
|
||||
.open(fixture.0.join(name))
|
||||
.unwrap();
|
||||
file.write_all(bytes).unwrap();
|
||||
file.sync_all().unwrap();
|
||||
}
|
||||
let old = dir
|
||||
.inspect(OsStr::new("rmm-agent-remote"), 0, 1024)
|
||||
.unwrap()
|
||||
.proof()
|
||||
.clone();
|
||||
let new = dir
|
||||
.inspect(OsStr::new(&stage), 0, 1024)
|
||||
.unwrap()
|
||||
.proof()
|
||||
.clone();
|
||||
let bound = || BoundStage {
|
||||
role: Role::Agent,
|
||||
nonce,
|
||||
original: &old,
|
||||
staged: &new,
|
||||
};
|
||||
let boot = fs::read_to_string("/proc/sys/kernel/random/boot_id")
|
||||
.unwrap()
|
||||
.trim()
|
||||
.parse()
|
||||
.unwrap();
|
||||
let budget = Budget::new(boot, Duration::from_secs(10)).unwrap();
|
||||
// Public API always enforces the real fixed parent. The shared private
|
||||
// FD-validation core is exercised only below this NEW /run fixture.
|
||||
assert!(Staged::reopen_bound(&dir, bound(), &budget).is_err());
|
||||
let held = Staged::reopen_held(&dir, bound(), &budget).unwrap();
|
||||
assert_eq!(held.proof(), &new);
|
||||
fs::rename(
|
||||
fixture.0.join(&stage),
|
||||
fixture.0.join("held-original-stage"),
|
||||
)
|
||||
.unwrap();
|
||||
let mut replacement = fs::OpenOptions::new()
|
||||
.create_new(true)
|
||||
.write(true)
|
||||
.mode(0o600)
|
||||
.open(fixture.0.join(&stage))
|
||||
.unwrap();
|
||||
replacement.write_all(b"new public fixture").unwrap();
|
||||
replacement.sync_all().unwrap();
|
||||
assert!(Staged::reopen_held(&dir, bound(), &budget).is_err());
|
||||
assert_eq!(held.proof(), &new);
|
||||
drop(replacement);
|
||||
fs::remove_file(fixture.0.join(&stage)).unwrap();
|
||||
fs::rename(
|
||||
fixture.0.join("held-original-stage"),
|
||||
fixture.0.join(&stage),
|
||||
)
|
||||
.unwrap();
|
||||
fs::hard_link(
|
||||
fixture.0.join(&stage),
|
||||
fixture.0.join("unexpected-stage-alias"),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(Staged::reopen_held(&dir, bound(), &budget).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,3 +204,36 @@ wird bytegleich übernommen: [Native Linux-OS5](agent-updater-linux-native-resul
|
||||
Das ist ein nativer OS-Unitnachweis, ausdrücklich **keine Qualifikation des
|
||||
restriktiven tatsächlichen Generalhelper-Dienstkontexts**, der konkreten
|
||||
IPC-Peers, Engine/Fence oder Releaseaktivierung. Diese Gates bleiben offen.
|
||||
|
||||
## Enges additives Stage-Reopen: lokal6/6, native Folgeprüfung offen
|
||||
|
||||
Nach dem erhaltenen nativen5er-Stand wurde ausschließlich `files.rs` erweitert.
|
||||
`Staged::reopen_bound` rekonstruiert gehaltene Beobachtungen aus dem geschützten
|
||||
Originalhandoffbundle: feste Rollenzielverzeichnisse, ursprüngliche Rootdatei,
|
||||
exakte Stageidentität mit nlink1, gleiche Metadaten und Originalhashes. Bereits
|
||||
vorhandene previous-/rejected-Namen verweigern; es wird weder geschrieben noch
|
||||
ein teilweiser früherer Austausch als neuer Stageversuch interpretiert.
|
||||
|
||||
Die zusätzliche echte lokale OSprobe verwendet nur neue öffentliche Dummydateien
|
||||
in einem eigenen privaten `/run`-Verzeichnis des isolierten Rootcontainers.
|
||||
Der öffentliche Einstieg verweigert dieses fremde Rollenzielverzeichnis; die
|
||||
private gemeinsame FD-Prüfung besteht zunächst. Eine namensgleiche Stagekopie
|
||||
mit gleichen Bytes und anderer Dateiidentität sowie danach ein zusätzlicher
|
||||
Stagehardlink verweigern jeweils. Kein Agent/Helperdienst, Fremdprozess, Host-
|
||||
Packageupdate oder RMM-Job wurde dafür gestartet.
|
||||
|
||||
Tatsächlich lokal aus eingefrorenem Quellpaket ausgeführt: Release6/6 ohne
|
||||
Skips/Filter, Clippy mit -D warnings und Formatprüfung PASS. Neuer Originalbeleg:
|
||||
`devstate/agent-updater-linux/qualification-os6-0b3c8018-b08f-4917-80b8-0e3169a0f813/receipt.json`,
|
||||
SHA256 `c3e1ee619ef01630b296aaf7669d04f39ea952b1ec2d7adc1a791f69f6a6ee08`.
|
||||
Finale Unitexe `qualified-os6-tests`:1555392Bytes, SHA256
|
||||
`c78d24d9b3f543fc4eba3fa1d02bf82e72aea26493ae689f2fc82ee1067d33fc`.
|
||||
OSquellsatzSHA256 `5ad19b05dbc1277d6fdbf29fa3bb852ac00b34d43af94fca3220617662ed45a3`.
|
||||
Die einzige geänderte OSdatei `files.rs` hat27138Bytes und SHA256
|
||||
`f29a89d5e1a6fda9d24e74a0c0d4f2949d82e2e80c0052a11d1e3891467a69b7`.
|
||||
|
||||
Die frühere native5er-Abnahme bleibt historisch und qualifiziert diese neue
|
||||
Quelle nicht. Für genau diesen neuen6er-Stand ist der tatsächliche Cloud-
|
||||
VMnachweis noch offen; ebenso tatsächlicher Full-/Updater-Dienstkontext,
|
||||
geschlossene Readercensus, konkrete Engine und Apply. Ein erfolgreicher lokaler
|
||||
Reopen verleiht keine Start-, Retry-, Restore- oder allgemeine Readyautorität.
|
||||
|
||||
Reference in New Issue
Block a user