Share helper reconciliation and verify Linux and Windows native fixtures
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-14 01:14:11 +01:00
parent 31278bedec
commit a6c1f9accc
14 changed files with 2557 additions and 1293 deletions
+16
View File
@@ -138,3 +138,19 @@ impl Outcome {
}
}
}
/// Explicit configured privileged identity; never infer SYSTEM from Linux root.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum HelperIdentity {
#[default]
Root,
System,
}
impl HelperIdentity {
pub fn as_str(self) -> &'static str {
match self {
Self::Root => "root",
Self::System => "system",
}
}
}
+16
View File
@@ -3,6 +3,7 @@ use anyhow::Result;
use ed25519_dalek::{Signature, VerifyingKey};
pub trait Ed25519Verifier {
fn validate_key(&self, public_key: &[u8]) -> Result<bool>;
fn verify(&self, public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<bool>;
}
@@ -10,6 +11,13 @@ pub trait Ed25519Verifier {
pub struct DalekVerifier;
impl Ed25519Verifier for DalekVerifier {
fn validate_key(&self, public_key: &[u8]) -> Result<bool> {
let Ok(raw): Result<&[u8; 32], _> = public_key.try_into() else {
return Ok(false);
};
Ok(VerifyingKey::from_bytes(raw).is_ok_and(|key| !key.is_weak()))
}
fn verify(&self, public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<bool> {
let Ok(raw): Result<&[u8; 32], _> = public_key.try_into() else {
return Ok(false);
@@ -33,6 +41,14 @@ pub struct OpenSslVerifier;
#[cfg(all(unix, feature = "openssl-verifier"))]
impl Ed25519Verifier for OpenSslVerifier {
fn validate_key(&self, public_key: &[u8]) -> Result<bool> {
if public_key.len() != 32 {
return Ok(false);
}
openssl::pkey::PKey::public_key_from_raw_bytes(public_key, openssl::pkey::Id::ED25519)?;
Ok(true)
}
fn verify(&self, public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<bool> {
use openssl::{
pkey::{Id, PKey},
File diff suppressed because it is too large Load Diff
+1
View File
@@ -4,6 +4,7 @@
//! supply a qualified clock. A successful signature is never UI approval itself.
pub mod auth;
pub mod crypto;
pub mod helper_reconcile;
pub mod jobs;
pub mod ledger;
pub mod reconcile;
+21 -3
View File
@@ -3,6 +3,7 @@
//! Call only while holding the existing agent.lock. HelperSnapshot must come
//! from the independently authenticated root-helper IPC, never from the server.
use crate::auth::Binding;
pub use crate::auth::HelperIdentity;
use crate::crypto::{DefaultVerifier, Ed25519Verifier};
use anyhow::{Context, Result, ensure};
use chrono::{DateTime, Utc};
@@ -69,6 +70,7 @@ struct Gate {
pub struct ClientSync<V = DefaultVerifier> {
binding: Binding,
verifier: V,
helper_identity: HelperIdentity,
pending: Option<PreparedSync>,
channel: Option<Channel>,
gate: Option<Gate>,
@@ -84,11 +86,18 @@ impl<V: Ed25519Verifier> ClientSync<V> {
Self {
binding,
verifier,
helper_identity: HelperIdentity::Root,
pending: None,
channel: None,
gate: None,
}
}
/// Configure one explicit helper identity; changing it discards all leases.
pub fn with_helper_identity(mut self, identity: HelperIdentity) -> Self {
self.close();
self.helper_identity = identity;
self
}
/// Invoke on every authenticated/fenced ServerHello or transport loss.
pub fn close(&mut self) {
self.gate = None;
@@ -204,7 +213,15 @@ impl<V: Ed25519Verifier> ClientSync<V> {
ensure!(meta.helper_id.is_none(), "HELPER_JOURNAL_DISAPPEARED");
}
if let Some(h) = helper {
ingest_helper(&tx, ledger, &self.binding, &channel, h, now)?;
ingest_helper(
&tx,
ledger,
&self.binding,
&channel,
h,
now,
self.helper_identity,
)?;
}
archive_events(&tx)?;
tx.execute(
@@ -884,6 +901,7 @@ fn ingest_helper(
channel: &Channel,
helper: &HelperSnapshot,
now: DateTime<Utc>,
identity: HelperIdentity,
) -> Result<()> {
let mut statement = db.prepare("SELECT job,attempt,offer FROM job_attempts")?;
for row in statement.query_map([], |r| {
@@ -895,7 +913,7 @@ fn ingest_helper(
})? {
let (job, attempt, bytes) = row?;
let offer = JobOffer::decode(bytes.as_slice())?;
if binding.job(&offer.payload_bytes)?.execution_identity == "root" {
if binding.job(&offer.payload_bytes)?.execution_identity == identity.as_str() {
let consumed: bool = ledger.query_row(
"SELECT EXISTS(SELECT 1 FROM consumed WHERE job=?1 AND attempt=?2)",
params![job, attempt],
@@ -928,7 +946,7 @@ fn ingest_helper(
let offer = JobOffer::decode(bytes.as_slice())?;
let job = binding.job(&offer.payload_bytes)?;
ensure!(
job.execution_identity == "root"
job.execution_identity == identity.as_str()
&& h.job_payload_hash == offer.job_payload_hash
&& (grant.is_empty() || grant == h.grant_id),
"HELPER_ATTEMPT_BINDING"
+993
View File
@@ -0,0 +1,993 @@
//! Existing helper reconciliation semantic cases with portable test-only guard,
//! boot and signing adapters. Does not qualify OS locks, file IDs, IPC or SYSTEM.
use rmm_agent_core::helper_reconcile as reconcile;
use chrono::{DateTime, Duration, Utc};
use ed25519_dalek::{Signer, SigningKey};
use reconcile::*;
use rmm_agent_core::auth::{Binding, HelperIdentity, Request};
use rmm_domain::{jobs::*, reconciliation::*};
use rusqlite::{Connection, params};
use std::{fs, path::PathBuf};
use uuid::Uuid;
/// Test-only guard: identifies our fixture DB, not an OS lock qualification.
struct ExecutorGuard {
directory: PathBuf,
}
impl ExecutorLedgerGuard for ExecutorGuard {
fn check(&self, db: &Connection) -> anyhow::Result<()> {
let path: String = db.query_row(
"SELECT file FROM pragma_database_list WHERE name='main'",
[],
|r| r.get(0),
)?;
anyhow::ensure!(
PathBuf::from(path).canonicalize()?
== self.directory.join("consumption.sqlite").canonicalize()?,
"NOT_THE_SHARED_EXECUTOR_LEDGER"
);
Ok(())
}
}
struct TestClock {
now: DateTime<Utc>,
trusted: bool,
}
impl Clock for TestClock {
fn now(&self) -> anyhow::Result<DateTime<Utc>> {
anyhow::ensure!(self.trusted, "CLOCK_UNTRUSTED");
Ok(self.now)
}
}
struct TestBoot(Uuid);
impl BootSource for TestBoot {
fn current_boot(&self) -> anyhow::Result<Uuid> {
Ok(self.0)
}
}
struct Fixture {
dir: PathBuf,
db: Connection,
guard: ExecutorGuard,
binding: Binding,
key: SigningKey,
clock: TestClock,
boot: TestBoot,
agent_journal: Uuid,
identity: HelperIdentity,
}
#[test]
fn checkpoint_repair_verifies_complete_signed_history_and_detects_removed_predecessor() {
let mut f = Fixture::new();
let mut sync = f.sync();
let first = f.snapshot(&mut sync, 7);
let request = f.request(&first);
let d = f.decision(&first, &request, 7, false);
let signed = f.sign(&d);
sync.apply(&mut f.db, &f.guard, &signed, &request, &f.clock, &f.boot)
.unwrap();
f.clock.now += Duration::seconds(1);
let second = f.snapshot(&mut sync, 7);
let request = f.request(&second);
let d = f.decision(&second, &request, 7, false);
let signed = f.sign(&d);
sync.apply(&mut f.db, &f.guard, &signed, &request, &f.clock, &f.boot)
.unwrap();
verify_checkpoint_repair_history(&f.db, &f.binding, None).unwrap();
f.db.execute(
"DELETE FROM helper_sync_decisions WHERE checkpoint=?1",
[first.checkpoint],
)
.unwrap();
assert!(verify_checkpoint_repair_history(&f.db, &f.binding, None).is_err());
}
impl Drop for Fixture {
fn drop(&mut self) {
drop(std::mem::replace(
&mut self.db,
Connection::open_in_memory().unwrap(),
));
let _ = fs::remove_dir_all(&self.dir);
}
}
impl Fixture {
fn new() -> Self {
let dir = std::env::temp_dir().join(format!("helper-sync-{}", Uuid::new_v4()));
fs::create_dir(&dir).unwrap();
let guard = ExecutorGuard {
directory: dir.clone(),
};
let db = Connection::open(dir.join("consumption.sqlite")).unwrap();
rmm_agent_core::ledger::initialize_ledger(&db).unwrap();
let key = SigningKey::from_bytes(&[42; 32]);
let binding = Binding {
tenant_id: Uuid::new_v4(),
asset_id: Uuid::new_v4(),
agent_id: Uuid::new_v4(),
enrollment_generation: 1,
assignment_version: 3,
public_key_hex: hex::encode(key.verifying_key().to_bytes()),
};
let boot = TestBoot(Uuid::from_u128(1234));
Self {
dir,
db,
guard,
binding,
key,
clock: TestClock {
now: Utc::now(),
trusted: true,
},
boot,
agent_journal: Uuid::new_v4(),
identity: HelperIdentity::Root,
}
}
fn sync(&self) -> HelperSync {
HelperSync::new(self.binding.clone(), &self.clock)
.unwrap()
.with_helper_identity(self.identity)
}
fn snapshot(&mut self, sync: &mut HelperSync, generation: u64) -> Snapshot {
sync.snapshot(
&mut self.db,
&self.guard,
generation,
&self.clock,
&self.boot,
)
.unwrap()
}
fn request(&self, snapshot: &Snapshot) -> Vec<u8> {
request(
snapshot,
self.agent_journal,
100 + snapshot.checkpoint,
&snapshot.attempts,
)
}
fn decision(
&self,
snapshot: &Snapshot,
raw: &[u8],
generation: u64,
ready: bool,
) -> ReconcileDecisionPayload {
let mut d = ReconcileDecisionPayload {
domain: "rmm.reconciliation-decision".into(),
schema_version: 1,
decision_id: Uuid::new_v4(),
request_id: Uuid::nil(),
request_hash: hash(raw),
tenant_id: self.binding.tenant_id,
asset_id: self.binding.asset_id,
agent_id: self.binding.agent_id,
enrollment_generation: 1,
assignment_version: 3,
connection_generation: generation,
boot_id: self.boot.0,
journal_id: self.agent_journal,
checkpoint: 100 + snapshot.checkpoint,
helper_journal_id: Some(snapshot.journal_id),
helper_checkpoint: snapshot.checkpoint,
issued_at: self.clock.now,
valid_until: self.clock.now + Duration::seconds(60),
ready,
helper_ready: ready,
reason: if ready {
"CONSISTENT"
} else {
"ATTEMPT_RECONCILIATION_REQUIRED"
}
.into(),
attempts: snapshot
.attempts
.iter()
.map(|a| AttemptDecision {
job_id: a.job_id,
attempt_id: a.attempt_id,
job_payload_hash: a.job_payload_hash.clone(),
grant_id: Some(a.grant_id),
authorization_id: Some(a.authorization_id),
plan_hash: Some(a.plan_hash.clone()),
action: a.action.clone(),
execution_identity: self.identity.as_str().into(),
revision: a.revision + 1,
outcome_state: if matches!(
a.state.as_str(),
"succeeded" | "failed" | "cancelled" | "expired"
) {
a.state.clone()
} else {
"unknown".into()
},
previous_outcome_sha256: (!a.outcome_sha256.is_empty())
.then(|| a.outcome_sha256.clone()),
outcome_sha256: matches!(
a.state.as_str(),
"succeeded" | "failed" | "cancelled" | "expired"
)
.then(|| a.outcome_sha256.clone()),
outcome_bytes: vec![],
original_boot_id: Some(a.original_boot_id),
unlock: matches!(
a.state.as_str(),
"succeeded" | "failed" | "cancelled" | "expired"
),
reason: "TEST_SERVER_DECISION".into(),
})
.collect(),
acknowledged_message_ids: vec![],
key_id: hash(&self.key.verifying_key().to_bytes()),
};
// The fixture emits a canonical tag-1 request ID first, exactly as prost.
let len = usize::from(raw[1]);
d.request_id = Uuid::parse_str(std::str::from_utf8(&raw[2..2 + len]).unwrap()).unwrap();
d
}
fn sign(&self, d: &ReconcileDecisionPayload) -> SignedResponse {
let bytes = encode(d).unwrap();
SignedResponse {
signature: self.key.sign(&bytes).to_bytes().to_vec(),
decision_bytes: bytes,
}
}
fn apply(
&mut self,
sync: &mut HelperSync,
d: &ReconcileDecisionPayload,
raw: &[u8],
) -> anyhow::Result<Applied> {
let r = self.sign(d);
sync.apply(&mut self.db, &self.guard, &r, raw, &self.clock, &self.boot)
}
fn add(
&mut self,
action: Action,
outcome: Option<ReconciledOutcome>,
) -> ExecutionPermitPayload {
let job = JobPayload {
schema_version: 1,
tenant_id: self.binding.tenant_id,
asset_id: self.binding.asset_id,
agent_id: self.binding.agent_id,
enrollment_generation: 1,
assignment_version: 3,
job_id: Uuid::new_v4(),
attempt_id: Uuid::new_v4(),
action,
execution_identity: self.identity.as_str().into(),
not_before: self.clock.now - Duration::seconds(10),
start_before: self.clock.now + Duration::minutes(5),
max_runtime_seconds: 180,
max_output_bytes: 4096,
};
let permit = ExecutionPermitPayload {
domain: "rmm.execution-permit".into(),
schema_version: 1,
grant_id: Uuid::new_v4(),
authorization_id: Uuid::new_v4(),
tenant_id: job.tenant_id,
asset_id: job.asset_id,
agent_id: job.agent_id,
enrollment_generation: 1,
assignment_version: 3,
job_id: job.job_id,
attempt_id: job.attempt_id,
plan_hash: hash(b"approved fixed plan"),
job_payload_hash: hash(&encode(&job).unwrap()),
action: job.action.name().into(),
execution_identity: self.identity.as_str().into(),
not_before: self.clock.now - Duration::seconds(1),
start_before: self.clock.now + Duration::seconds(59),
max_runtime_seconds: 180,
key_id: hash(&self.key.verifying_key().to_bytes()),
};
let bytes = encode(&permit).unwrap();
let original = Request {
job_bytes: encode(&job).unwrap(),
permit_bytes: bytes.clone(),
signature: self.key.sign(&bytes).to_bytes().to_vec(),
plan_hash: permit.plan_hash.clone(),
authorization_id: permit.authorization_id,
};
rmm_agent_core::ledger::consume(&mut self.db, &permit).unwrap();
rmm_agent_core::ledger::save_start(
&self.db,
&permit,
&original,
self.boot.0,
self.clock.now,
)
.unwrap();
if let Some(o) = outcome {
self.db
.execute(
"UPDATE execution_evidence SET outcome=?2 WHERE grant_id=?1",
params![
permit.grant_id.to_string(),
canonical_outcome_bytes(&o).unwrap()
],
)
.unwrap();
}
permit
}
}
#[test]
fn general_and_apt_instances_share_fencing_but_never_inherit_a_process_gate() {
let mut f = Fixture::new();
let mut general = f.sync();
let first = f.snapshot(&mut general, 1);
let raw = f.request(&first);
let d = f.decision(&first, &raw, 1, true);
f.apply(&mut general, &d, &raw).unwrap();
assert!(general.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
let mut apt = f.sync();
assert!(!apt.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
let second = f.snapshot(&mut apt, 1);
assert!(!general.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
let raw = f.request(&second);
let d = f.decision(&second, &raw, 1, true);
f.apply(&mut apt, &d, &raw).unwrap();
assert!(apt.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
assert!(!general.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
}
#[test]
fn targeted_final_unlock_does_not_release_an_unrelated_unknown() {
let mut f = Fixture::new();
let known = f.add(script(), Some(success()));
let actual: rmm_agent_core::auth::Outcome =
serde_json::from_slice(&canonical_outcome_bytes(&success()).unwrap()).unwrap();
rmm_agent_core::ledger::finish(&f.db, &known, &actual).unwrap();
let uncertain = f.add(script(), Some(unknown()));
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, false);
let applied = f.apply(&mut sync, &d, &raw).unwrap();
assert_eq!(applied.unlocked_grants, vec![known.grant_id]);
assert!(!applied.ready);
assert!(!sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
let held: bool =
f.db.query_row(
"SELECT result IS NULL FROM consumed WHERE grant_id=?1",
[uncertain.grant_id.to_string()],
|r| r.get(0),
)
.unwrap();
assert!(held);
}
#[test]
fn independently_remembered_agent_journal_cannot_be_replaced_by_server_ready() {
let mut f = Fixture::new();
let mut sync = f.sync();
let first = f.snapshot(&mut sync, 1);
let raw = f.request(&first);
let d = f.decision(&first, &raw, 1, true);
f.apply(&mut sync, &d, &raw).unwrap();
let next = f.snapshot(&mut sync, 2);
f.agent_journal = Uuid::new_v4();
let raw = f.request(&next);
let d = f.decision(&next, &raw, 2, true);
assert!(f.apply(&mut sync, &d, &raw).is_err());
assert!(
sync.snapshot(&mut f.db, &f.guard, 2, &f.clock, &f.boot)
.is_err()
);
}
#[test]
fn missing_signed_checkpoint_history_closes_the_live_gate_stickily() {
let mut f = Fixture::new();
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
f.apply(&mut sync, &d, &raw).unwrap();
assert!(sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
f.db.execute("DELETE FROM helper_sync_decisions", [])
.unwrap();
assert!(!sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
assert!(
sync.snapshot(&mut f.db, &f.guard, 2, &f.clock, &f.boot)
.is_err()
);
}
#[test]
fn stale_process_connection_does_not_poison_a_new_fenced_process() {
let mut f = Fixture::new();
let mut general = f.sync();
let snapshot = f.snapshot(&mut general, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
f.apply(&mut general, &d, &raw).unwrap();
let mut apt = f.sync();
let snapshot = f.snapshot(&mut apt, 2);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 2, true);
f.apply(&mut apt, &d, &raw).unwrap();
assert!(
general
.snapshot(&mut f.db, &f.guard, 1, &f.clock, &f.boot)
.is_err()
);
assert!(apt.can_start(&f.db, &f.guard, 2, &f.clock, &f.boot));
}
#[test]
fn signed_noncanonical_outcome_bytes_do_not_unlock_root_consumption() {
let mut f = Fixture::new();
f.add(script(), Some(success()));
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let mut d = f.decision(&snapshot, &raw, 1, true);
d.attempts[0].outcome_bytes = serde_json::to_vec_pretty(&success()).unwrap();
d.attempts[0].outcome_sha256 = Some(hash(&d.attempts[0].outcome_bytes));
assert!(f.apply(&mut sync, &d, &raw).is_err());
assert_eq!(
f.db.query_row(
"SELECT count(*) FROM consumed WHERE result IS NULL",
[],
|r| r.get::<_, i64>(0)
)
.unwrap(),
1
);
}
#[test]
fn both_live_profiles_apply_one_signature_and_checkpoint_without_inheriting_readiness() {
let mut f = Fixture::new();
let mut general = f.sync();
let mut apt = f.sync();
let first = f.snapshot(&mut general, 1);
let second = f.snapshot(&mut apt, 1);
assert_eq!(first.checkpoint, second.checkpoint);
assert!(!general.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
assert!(!apt.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
let raw = f.request(&first);
let d = f.decision(&first, &raw, 1, true);
f.apply(&mut general, &d, &raw).unwrap();
f.apply(&mut apt, &d, &raw).unwrap();
assert!(general.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
assert!(apt.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
}
fn script() -> Action {
Action::RunScript {
interpreter: "posix_sh".into(),
script_utf8: "printf hello".into(),
arguments: vec![],
expected_stdout: Some("hello".into()),
}
}
fn success() -> ReconciledOutcome {
ReconciledOutcome {
state: "succeeded".into(),
stdout: b"hello".to_vec(),
stderr: vec![],
exit_code: Some(0),
output_truncated: false,
reboot_required: false,
evidence: serde_json::json!({"postconditions_passed":true}),
error_code: String::new(),
}
}
fn unknown() -> ReconciledOutcome {
ReconciledOutcome {
state: "unknown".into(),
stdout: vec![],
stderr: vec![],
exit_code: None,
output_truncated: false,
reboot_required: false,
evidence: serde_json::json!({"postconditions_passed":false}),
error_code: "EFFECT_UNKNOWN".into(),
}
}
// Test-only encoder for the actual existing prost field numbers. No substitute
// protocol dependency is added to the independently executable helper crate.
fn vi(mut n: u64, out: &mut Vec<u8>) {
loop {
let mut byte = (n & 127) as u8;
n >>= 7;
if n != 0 {
byte |= 128;
}
out.push(byte);
if n == 0 {
break;
}
}
}
fn num(tag: u64, n: u64, out: &mut Vec<u8>) {
if n != 0 {
vi(tag << 3, out);
vi(n, out);
}
}
fn blob(tag: u64, b: &[u8], out: &mut Vec<u8>) {
if !b.is_empty() {
vi((tag << 3) | 2, out);
vi(b.len() as u64, out);
out.extend_from_slice(b);
}
}
fn text(tag: u64, s: &str, out: &mut Vec<u8>) {
blob(tag, s.as_bytes(), out)
}
fn request(
snapshot: &Snapshot,
journal: Uuid,
checkpoint: u64,
attempts: &[LocalAttempt],
) -> Vec<u8> {
let mut out = vec![];
text(1, &Uuid::new_v4().to_string(), &mut out);
text(2, &journal.to_string(), &mut out);
num(3, checkpoint, &mut out);
text(
4,
&snapshot
.previous_decision_id
.map(|id| id.to_string())
.unwrap_or_default(),
&mut out,
);
num(5, 3, &mut out);
for a in attempts {
let mut row = vec![];
text(1, &a.job_id.to_string(), &mut row);
text(2, &a.attempt_id.to_string(), &mut row);
text(3, &a.job_payload_hash, &mut row);
text(4, &a.grant_id.to_string(), &mut row);
text(5, &a.consumption, &mut row);
text(6, &a.state, &mut row);
num(7, a.revision + 1, &mut row);
text(8, &a.original_boot_id.to_string(), &mut row);
text(11, &a.outcome_sha256, &mut row);
blob(12, &a.outcome_bytes, &mut row);
blob(6, &row, &mut out);
}
num(8, 1, &mut out);
text(9, &snapshot.journal_id.to_string(), &mut out);
num(10, snapshot.checkpoint, &mut out);
text(
11,
&snapshot
.previous_decision_id
.map(|id| id.to_string())
.unwrap_or_default(),
&mut out,
);
out
}
#[test]
fn clean_ready_shared_lock_and_reopen_start_closed() {
let mut f = Fixture::new();
let mut sync = f.sync();
assert!(!sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
let applied = f.apply(&mut sync, &d, &raw).unwrap();
assert!(applied.ready);
assert_eq!(sync.active_generation(), Some(1));
assert_eq!(applied.snapshot.previous_decision_id, Some(d.decision_id));
assert!(applied.unlocked_grants.is_empty());
assert!(sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
assert!(!sync.can_start(&f.db, &f.guard, 2, &f.clock, &f.boot));
let response = f.sign(&d);
let mut new_process = f.sync();
let mut reopened = Connection::open(f.dir.join("consumption.sqlite")).unwrap();
assert!(!new_process.can_start(&reopened, &f.guard, 1, &f.clock, &f.boot));
assert!(
new_process
.apply(&mut reopened, &f.guard, &response, &raw, &f.clock, &f.boot)
.is_err()
);
sync.close();
assert!(!sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
}
#[test]
fn exact_signatures_fake_key_wrong_domain_and_all_identity_bindings() {
let mut f = Fixture::new();
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
let base = serde_json::to_value(&d).unwrap();
for (field, value) in [
("domain", serde_json::json!("rmm.execution-permit")),
("schema_version", serde_json::json!(2)),
("tenant_id", serde_json::json!(Uuid::new_v4())),
("asset_id", serde_json::json!(Uuid::new_v4())),
("agent_id", serde_json::json!(Uuid::new_v4())),
("enrollment_generation", serde_json::json!(2)),
("assignment_version", serde_json::json!(4)),
("connection_generation", serde_json::json!(2)),
("boot_id", serde_json::json!(Uuid::new_v4())),
("journal_id", serde_json::json!(Uuid::new_v4())),
("checkpoint", serde_json::json!(1)),
("helper_journal_id", serde_json::json!(Uuid::new_v4())),
(
"helper_checkpoint",
serde_json::json!(snapshot.checkpoint + 1),
),
("request_id", serde_json::json!(Uuid::new_v4())),
("request_hash", serde_json::json!(hash(b"changed"))),
("key_id", serde_json::json!(hash(b"wrongkey"))),
] {
let mut changed = base.clone();
changed[field] = value;
let changed: ReconcileDecisionPayload = serde_json::from_value(changed).unwrap();
assert!(f.apply(&mut sync, &changed, &raw).is_err(), "{field}");
}
let mut response = f.sign(&d);
response.signature[0] ^= 1;
assert!(
sync.apply(&mut f.db, &f.guard, &response, &raw, &f.clock, &f.boot)
.is_err()
);
let mut response = f.sign(&d);
response.decision_bytes.push(b' ');
assert!(
sync.apply(&mut f.db, &f.guard, &response, &raw, &f.clock, &f.boot)
.is_err()
);
let fake = SigningKey::from_bytes(&[43; 32]);
let mut response = f.sign(&d);
response.signature = fake.sign(&response.decision_bytes).to_bytes().to_vec();
assert!(
sync.apply(&mut f.db, &f.guard, &response, &raw, &f.clock, &f.boot)
.is_err()
);
assert!(!sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
}
#[test]
fn definitive_unlock_is_transactional_idempotent_and_keeps_tombstones() {
let mut f = Fixture::new();
let grant = f.add(script(), Some(success()));
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
assert_eq!(snapshot.attempts[0].original_boot_id, f.boot.0);
assert_eq!(
snapshot.attempts[0].job_payload_hash,
grant.job_payload_hash
);
assert_eq!(snapshot.attempts[0].original_request_sha256.len(), 64);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
let applied = f.apply(&mut sync, &d, &raw).unwrap();
assert_eq!(applied.unlocked_grants, vec![grant.grant_id]);
assert!(applied.ready);
let again = f.apply(&mut sync, &d, &raw).unwrap();
assert!(again.ready);
assert!(again.unlocked_grants.is_empty());
assert_eq!(again.snapshot.checkpoint, snapshot.checkpoint);
let body: Vec<u8> =
f.db.query_row(
"SELECT result FROM consumed WHERE grant_id=?1",
[grant.grant_id.to_string()],
|r| r.get(0),
)
.unwrap();
assert_eq!(body, canonical_outcome_bytes(&success()).unwrap());
assert!(rmm_agent_core::ledger::consume(&mut f.db, &grant).is_err());
assert_eq!(
f.db.query_row("SELECT count(*) FROM consumed", [], |r| r.get::<_, i64>(0))
.unwrap(),
1
);
}
#[test]
fn omitted_unknown_root_row_is_sticky_despite_signed_ready() {
let mut f = Fixture::new();
f.add(script(), Some(unknown()));
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = request(&snapshot, f.agent_journal, 100 + snapshot.checkpoint, &[]);
let d = f.decision(&snapshot, &raw, 1, true);
assert!(f.apply(&mut sync, &d, &raw).is_err());
assert!(!sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
let mut restarted = f.sync();
assert!(
restarted
.snapshot(&mut f.db, &f.guard, 2, &f.clock, &f.boot)
.is_err()
);
}
#[test]
fn unknown_code_or_no_result_never_unlocks_even_signed_ready() {
for outcome in [None, Some(unknown())] {
let mut f = Fixture::new();
f.add(script(), outcome);
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
assert_eq!(snapshot.attempts[0].state, "unknown");
let raw = f.request(&snapshot);
let mut d = f.decision(&snapshot, &raw, 1, true);
let applied = f.apply(&mut sync, &d, &raw).unwrap();
assert!(!applied.ready);
assert!(!sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
d = f.decision(&snapshot, &raw, 1, true);
d.attempts[0].unlock = true;
d.attempts[0].outcome_state = "succeeded".into();
d.attempts[0].outcome_bytes = canonical_outcome_bytes(&success()).unwrap();
d.attempts[0].outcome_sha256 = Some(hash(&d.attempts[0].outcome_bytes));
assert!(f.apply(&mut sync, &d, &raw).is_err());
assert_eq!(
f.db.query_row(
"SELECT count(*) FROM consumed WHERE result IS NULL",
[],
|r| r.get::<_, i64>(0)
)
.unwrap(),
1
);
}
}
#[test]
fn old_process_response_fails_after_fresh_capture_even_inside_ttl() {
let mut f = Fixture::new();
let mut first = f.sync();
let snapshot = f.snapshot(&mut first, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
let response = f.sign(&d);
f.clock.now += Duration::seconds(5);
let mut second = f.sync();
let newer = f.snapshot(&mut second, 1);
assert!(newer.checkpoint > snapshot.checkpoint);
assert!(
second
.apply(&mut f.db, &f.guard, &response, &raw, &f.clock, &f.boot)
.is_err()
);
assert!(!second.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
}
#[test]
fn checkpoint_rollback_is_sticky_and_cannot_be_fixed_by_omission() {
let mut f = Fixture::new();
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
f.db.execute("UPDATE helper_sync_meta SET checkpoint=0", [])
.unwrap();
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
assert!(f.apply(&mut sync, &d, &raw).is_err());
f.db.execute(
"UPDATE helper_sync_meta SET checkpoint=?1",
[snapshot.checkpoint],
)
.unwrap();
assert!(
sync.snapshot(&mut f.db, &f.guard, 1, &f.clock, &f.boot)
.is_err()
);
}
#[test]
fn mutated_root_ledger_after_capture_is_not_the_signed_snapshot() {
let mut f = Fixture::new();
f.add(script(), Some(success()));
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
let mut changed = success();
changed.stdout = b"different".to_vec();
f.db.execute(
"UPDATE execution_evidence SET outcome=?1",
[canonical_outcome_bytes(&changed).unwrap()],
)
.unwrap();
assert!(f.apply(&mut sync, &d, &raw).is_err());
assert!(
sync.snapshot(&mut f.db, &f.guard, 1, &f.clock, &f.boot)
.is_err()
);
}
#[test]
fn unrelated_action_plan_and_previous_outcome_cannot_unlock() {
let mut f = Fixture::new();
f.add(script(), Some(success()));
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
let mut changed = d.clone();
changed.attempts[0].action = "reboot".into();
assert!(f.apply(&mut sync, &changed, &raw).is_err());
let mut changed = d.clone();
changed.attempts[0].plan_hash = Some(hash(b"changed plan"));
assert!(f.apply(&mut sync, &changed, &raw).is_err());
let mut changed = d;
changed.attempts[0].previous_outcome_sha256 = Some(hash(b"different outcome"));
assert!(f.apply(&mut sync, &changed, &raw).is_err());
}
#[test]
fn false_clock_expiry_and_invalid_independent_key_stay_closed() {
let mut f = Fixture::new();
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
f.clock.trusted = false;
assert!(f.apply(&mut sync, &d, &raw).is_err());
assert!(!sync.can_start(&f.db, &f.guard, 1, &f.clock, &f.boot));
f.clock.trusted = true;
f.clock.now += Duration::seconds(61);
assert!(f.apply(&mut sync, &d, &raw).is_err());
let mut invalid = f.binding.clone();
invalid.public_key_hex = "not a key".into();
assert!(HelperSync::new(invalid, &f.clock).is_err());
let mut changed = f.binding.clone();
changed.public_key_hex =
hex::encode(SigningKey::from_bytes(&[43; 32]).verifying_key().to_bytes());
let mut different = HelperSync::new(changed, &f.clock).unwrap();
assert!(
different
.snapshot(&mut f.db, &f.guard, 2, &f.clock, &f.boot)
.is_err()
);
}
#[test]
fn shared_database_only_and_missing_local_start_fail_closed() {
let mut f = Fixture::new();
let mut sync = f.sync();
let mut copy = Connection::open_in_memory().unwrap();
assert!(
sync.snapshot(&mut copy, &f.guard, 1, &f.clock, &f.boot)
.is_err()
);
let grant = f.add(script(), None);
f.db.execute(
"DELETE FROM execution_evidence WHERE grant_id=?1",
[grant.grant_id.to_string()],
)
.unwrap();
assert!(
sync.snapshot(&mut f.db, &f.guard, 1, &f.clock, &f.boot)
.is_err()
);
}
#[test]
fn real_local_boot_must_match_signed_reboot_completion() {
let mut f = Fixture::new();
let old = f.boot.0;
let mut awaiting = unknown();
awaiting.state = "awaiting_reboot".into();
awaiting.reboot_required = true;
f.add(
Action::Reboot {
reason: "mock reboot no native effect".into(),
reconnect_timeout_seconds: 120,
dependency_group: "acceptance".into(),
},
Some(awaiting),
);
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let mut d = f.decision(&snapshot, &raw, 1, true);
let mut done = success();
done.stdout.clear();
done.exit_code = None;
done.evidence = serde_json::json!({"postconditions_passed":true,"new_boot_id":Uuid::new_v4(),"reconciled_after_reboot":true,"inventory_message_id":Uuid::new_v4()});
d.attempts[0].unlock = true;
d.attempts[0].outcome_state = "succeeded".into();
d.attempts[0].outcome_bytes = canonical_outcome_bytes(&done).unwrap();
d.attempts[0].outcome_sha256 = Some(hash(&d.attempts[0].outcome_bytes));
assert!(f.apply(&mut sync, &d, &raw).is_err()); // native current boot is still old
f.boot.0 = Uuid::new_v4();
f.clock.now += Duration::seconds(1);
let snapshot = f.snapshot(&mut sync, 2);
let raw = f.request(&snapshot);
let mut d = f.decision(&snapshot, &raw, 2, true);
assert_eq!(snapshot.attempts[0].original_boot_id, old);
assert_ne!(f.boot.0, old);
done.evidence["new_boot_id"] = serde_json::json!(f.boot.0);
d.attempts[0].unlock = true;
d.attempts[0].outcome_state = "succeeded".into();
d.attempts[0].outcome_bytes = canonical_outcome_bytes(&done).unwrap();
d.attempts[0].outcome_sha256 = Some(hash(&d.attempts[0].outcome_bytes));
let applied = f.apply(&mut sync, &d, &raw).unwrap();
assert!(applied.ready);
assert_eq!(applied.snapshot.attempts[0].state, "succeeded");
assert!(sync.can_start(&f.db, &f.guard, 2, &f.clock, &f.boot));
}
#[test]
fn malformed_original_protobuf_or_digest_does_not_open_gate() {
let mut f = Fixture::new();
let mut sync = f.sync();
let snapshot = f.snapshot(&mut sync, 1);
let raw = f.request(&snapshot);
let d = f.decision(&snapshot, &raw, 1, true);
let mut malformed = raw.clone();
malformed.push(0);
assert!(f.apply(&mut sync, &d, &malformed).is_err());
let mut malformed = raw.clone();
text(1, &Uuid::new_v4().to_string(), &mut malformed);
let mut signed = d.clone();
signed.request_hash = hash(&malformed);
assert!(f.apply(&mut sync, &signed, &malformed).is_err());
let mut signed = d;
signed.request_hash.clear();
assert!(f.apply(&mut sync, &signed, &raw).is_err());
assert!(
sync.snapshot(&mut f.db, &f.guard, 1, &f.clock, &f.boot)
.is_err()
);
}
#[test]
fn root_and_system_are_distinct_explicit_helper_domains() {
let mut root = Fixture::new();
root.add(script(), Some(unknown()));
let before: Vec<u8> = root
.db
.query_row("SELECT start FROM execution_evidence", [], |r| r.get(0))
.unwrap();
let mut wrong = HelperSync::new(root.binding.clone(), &root.clock)
.unwrap()
.with_helper_identity(HelperIdentity::System);
assert!(
wrong
.snapshot(&mut root.db, &root.guard, 1, &root.clock, &root.boot)
.is_err()
);
assert_eq!(
before,
root.db
.query_row::<Vec<u8>, _, _>("SELECT start FROM execution_evidence", [], |r| r.get(0))
.unwrap()
);
assert_eq!(
root.db
.query_row::<u32, _, _>(
"SELECT count(*) FROM consumed WHERE result IS NULL",
[],
|r| r.get(0)
)
.unwrap(),
1
);
let mut system = Fixture::new();
system.identity = HelperIdentity::System;
system.add(script(), Some(success()));
let mut sync = system.sync();
let snapshot = system.snapshot(&mut sync, 1);
assert_eq!(snapshot.attempts[0].execution_identity, "system");
let raw = system.request(&snapshot);
let mut wrong = system.decision(&snapshot, &raw, 1, true);
wrong.attempts[0].execution_identity = "root".into();
assert!(system.apply(&mut sync, &wrong, &raw).is_err());
assert_eq!(
system
.db
.query_row::<u32, _, _>(
"SELECT count(*) FROM consumed WHERE result IS NULL",
[],
|r| r.get(0)
)
.unwrap(),
1
);
let mut system = Fixture::new();
system.identity = HelperIdentity::System;
system.add(script(), Some(success()));
let mut sync = system.sync();
let snapshot = system.snapshot(&mut sync, 1);
let raw = system.request(&snapshot);
let decision = system.decision(&snapshot, &raw, 1, true);
assert!(system.apply(&mut sync, &decision, &raw).unwrap().ready);
assert!(sync.can_start(&system.db, &system.guard, 1, &system.clock, &system.boot));
let changed = sync.with_helper_identity(HelperIdentity::Root);
assert!(!changed.can_start(&system.db, &system.guard, 1, &system.clock, &system.boot));
}
+91 -2
View File
@@ -31,6 +31,7 @@ struct Fixture {
binding: Binding,
channel: Channel,
clock: Clock,
helper_identity: HelperIdentity,
}
impl Drop for Fixture {
fn drop(&mut self) {
@@ -77,6 +78,7 @@ impl Fixture {
key,
binding,
channel,
helper_identity: HelperIdentity::Root,
clock: Clock {
now: Utc::now(),
trusted: true,
@@ -84,7 +86,7 @@ impl Fixture {
}
}
fn client(&self) -> ClientSync {
ClientSync::new(self.binding.clone())
ClientSync::new(self.binding.clone()).with_helper_identity(self.helper_identity)
}
fn prepare(&mut self, client: &mut ClientSync) -> PreparedSync {
client
@@ -216,7 +218,7 @@ impl Fixture {
action: Action,
) -> (JobOffer, Option<ExecutionPermitPayload>, Option<Envelope>) {
let execution_identity = if matches!(action, Action::SetServiceState { .. }) {
"root"
self.helper_identity.as_str()
} else {
"agent_service"
};
@@ -1143,3 +1145,90 @@ fn signed_attempt_mutation_or_terminal_regression_is_rejected() {
changed.attempts[0].previous_outcome_sha256 = Some(hash(b"other outcome"));
assert!(f.apply(&mut c, &changed).is_err());
}
#[test]
fn system_helper_import_requires_explicit_system_identity_and_never_root_alias() {
let mut f = Fixture::new();
f.helper_identity = HelperIdentity::System;
let mut unknown = success();
unknown.state = "unknown".into();
unknown.error_code = "HELPER_TRANSPORT_EFFECT_UNKNOWN".into();
unknown.evidence = serde_json::json!({"postconditions_passed":false});
let (offer, grant, old) = f.add(
"unknown",
true,
Some(unknown),
Action::SetServiceState {
unit: "rmm-acceptance.service".into(),
state: "running".into(),
},
);
let grant = grant.unwrap();
let mut definitive = success();
definitive.stdout.clear();
definitive.exit_code = None;
let bytes = canonical_outcome_bytes(&definitive).unwrap();
let mut helper = HelperSnapshot {
journal_id: Uuid::new_v4(),
checkpoint: 3,
previous_decision_id: None,
attempts: vec![SyncAttempt {
job_id: offer.job_id.clone(),
attempt_id: offer.attempt_id.clone(),
job_payload_hash: offer.job_payload_hash.clone(),
grant_id: grant.grant_id.to_string(),
consumption: "consumed".into(),
state: "succeeded".into(),
revision: 1,
original_boot_id: f.channel.boot_id.to_string(),
outcome_sha256: hash(&bytes),
outcome_bytes: bytes,
..Default::default()
}],
};
let mut wrong = ClientSync::new(f.binding.clone());
assert!(
wrong
.prepare(
&mut f.db,
&f.ledger,
f.channel.clone(),
Some(&helper),
&f.clock
)
.is_err()
);
let mut c = f.client();
let p = c
.prepare(
&mut f.db,
&f.ledger,
f.channel.clone(),
Some(&helper),
&f.clock,
)
.unwrap();
let imported = p.request.attempts[0].result_envelope.as_ref().unwrap();
assert_ne!(imported.message_id, old.unwrap().message_id);
assert_eq!(p.request.attempts[0].state, "succeeded");
assert_eq!(p.request.attempts[0].revision, 2);
let d = f.decision(&p, true);
let applied = f.apply(&mut c, &d).unwrap();
assert!(applied.helper_instruction.is_some());
c.apply_consumption(&mut f.ledger, &f.clock).unwrap();
assert!(!c.can_start(&f.channel, true, &f.clock));
helper.previous_decision_id = Some(d.decision_id);
c.confirm_helper(&helper).unwrap();
assert!(c.can_start(&f.channel, true, &f.clock));
let retained: i64 =
f.db.query_row("SELECT count(*) FROM reconcile_results", [], |r| r.get(0))
.unwrap();
assert_eq!(retained, 2);
let tombstones: i64 = f
.ledger
.query_row("SELECT count(*) FROM consumed", [], |r| r.get(0))
.unwrap();
assert_eq!(tombstones, 1);
let changed = c.with_helper_identity(HelperIdentity::Root);
assert!(!changed.can_start(&f.channel, true, &f.clock));
}
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -72,7 +72,7 @@ impl Drop for Fixture {
}
impl Fixture {
fn new() -> Self {
let dir = PathBuf::from("/tmp/opencode").join(format!("helper-sync-{}", Uuid::new_v4()));
let dir = std::env::temp_dir().join(format!("helper-sync-{}", Uuid::new_v4()));
fs::DirBuilder::new().mode(0o700).create(&dir).unwrap();
let uid = unsafe { libc::geteuid() };
let guard = ExecutorGuard::acquire(&dir, uid).unwrap();
+27
View File
@@ -1,5 +1,9 @@
# Native gemeinsame Core-Unitabnahme
**Helper-Sync-Profil tatsächlich ausgeführt, 2026-11-14:**
Fall `5704073c-a135-431c-aa84-fedc68a3de0b`, Linux 69/69 vor Windows 47/47,
keine Skips oder RMM-Wirkung. Auch dies ersetzt keine Windows-SYSTEM-Dienstprobe.
`shared_core_acceptance.py` führt ausschließlich die zwei source-/hashgebundenen
Testprogramme `contracts` und `reconcile` aus: eigene temporäre SQLite-Fixturen,
Testsignaturen, Fake-Clock und Fake-Channel. Keine RMM-Jobs, Hello-Wirkung,
@@ -45,3 +49,26 @@ Fehlt eine Quittung, bleibt die Abnahme unvollständig; kein automatisches Resum
keine Bereinigung oder Wiederholung. Native Unittests ersetzen weder den späteren
Linux-Dienst-Syncnachweis des extrahierten Kerns noch Windows-WebUI-/Clock-/
Prozess-/Jobabnahmen. Der aktuelle Windowsclient erhält dadurch keine Jobfähigkeit.
## Nachfolgendes festes Profil `helper-sync-v1`
Eigenständige neue Qualifikationsmanifeste/Artefakte unter
`devstate/shared-core/helper-sync-v1/` und `devstate/windows-core/helper-sync-v1/`;
Originalartefakte, Manifeste und deren native Fälle bleiben unverändert.
Das feste Profil prüft Linux **5+21+22+21=69** Fälle, zuletzt den bestehenden
Linuxhelper mit echtem Unix-ExecutorGuard und Bootquelle an eigenen Fixturen.
Erst dessen vollständiger Nativbeleg erlaubt Windows **4+21+22=47** Fälle.
Portable Helperfälle verwenden einen ausdrücklich simulierten Ledgerguard und
qualifizieren keine Windows-Pipe, Volume-/File-ID oder SYSTEM-Wirkung.
```sh
# GEPLANT, NICHT AUSGEFÜHRT: Parent übernimmt tatsächliche VM-Ausführung.
python3 deploy/shared_core_acceptance.py linux --profile helper-sync-v1
python3 deploy/shared_core_acceptance.py windows --profile helper-sync-v1 --case-id <UUID>
# Bei verlorener Antwort weiterhin nur lesen, mit demselben festen Profil:
python3 deploy/shared_core_acceptance.py finish-linux --profile helper-sync-v1 --case-id <UUID>
python3 deploy/shared_core_acceptance.py finish-windows --profile helper-sync-v1 --case-id <UUID>
```
Profil, Quellen und Artefakte sind an den privaten create-only Intent gebunden.
Es gibt weiterhin keinen frei wählbaren Programmpfad oder Argumentvektor.
+46 -24
View File
@@ -23,7 +23,11 @@ from windows import client_bootstrap as windows
ROOT = Path(__file__).resolve().parents[1]
STATE = ROOT / 'devstate/shared-core/acceptance'
KINDS = ('contracts', 'reconcile')
PROFILES = {
'original': {'linux': {'contracts':5, 'reconcile':20}, 'windows': {'contracts':4, 'reconcile':20}},
'helper-sync-v1': {'linux': {'contracts':5, 'reconcile':21, 'helper-reconcile':22, 'linux-helper':21}, 'windows': {'contracts':4, 'reconcile':21, 'helper-reconcile':22}},
}
KINDS = ('contracts', 'reconcile') # Historical original qualification only.
REMOTE_LINUX = '/var/lib/rmm-shared-core-acceptance'
@@ -36,25 +40,36 @@ def write_new(path, value):
contract.write_private(path, value)
def qualified(platform):
folder = ROOT/'devstate'/('shared-core' if platform == 'linux' else 'windows-core')
manifest = contract.protected_json(folder/'manifest.json')
def source_paths(profile):
contract.require(profile in PROFILES, 'fixed qualification profile')
sources = [ROOT/'Cargo.toml', ROOT/'Cargo.lock', ROOT/'rust-toolchain.toml']
for name in ('agent-core', 'domain', 'protocol'):
crates = ['agent-core', 'domain', 'protocol']
if profile == 'helper-sync-v1': crates.extend(('agent', 'agent-linux', 'privileged-helper'))
for name in crates:
sources.extend(p for p in (ROOT/'crates'/name).rglob('*') if p.is_file() and (p.suffix == '.rs' or p.name == 'Cargo.toml'))
sources.extend((ROOT/'proto').glob('*.proto'))
actual = {str(p.relative_to(ROOT)): sha(p.read_bytes()) for p in sources}
if profile == 'helper-sync-v1':
sources.extend(ROOT/p for p in ('tools/apt-transaction/apt_transaction.py', 'tools/apt-transaction/hook', 'deploy/linux/rmm-apt-helper.service', 'tests/apt_transaction/fixtures/planning-canonical.json'))
return sources
def qualified(platform, profile='original'):
folder = ROOT/'devstate'/('shared-core' if platform == 'linux' else 'windows-core')
if profile != 'original': folder = folder/profile
manifest = contract.protected_json(folder/'manifest.json')
contract.require(manifest.get('qualification_profile', 'original') == profile, 'bound qualification profile')
actual = {str(p.relative_to(ROOT)): sha(p.read_bytes()) for p in source_paths(profile)}
contract.require(manifest['source_files'] == actual and manifest['source_before_after_equal'] is True, 'qualified source bindings changed')
target = 'x86_64-unknown-linux-gnu' if platform == 'linux' else 'x86_64-pc-windows-gnu'
contract.require(manifest['schema_version'] == 1 and manifest['target'] == target and manifest['os_effects'] is False and manifest['native_vm_executed'] is False, 'fixed test-only qualification')
contract.require(all(manifest['checks'][n] is True for n in ('rustfmt_check', 'linux_all_target_clippy_warnings_denied', 'windows_all_target_clippy_warnings_denied')), 'qualified checks')
artifacts = {}
for kind, item in zip(KINDS, manifest['artifacts'], strict=True):
for kind, item in zip(PROFILES[profile][platform], manifest['artifacts'], strict=True):
path = folder/(kind + ('.exe' if platform == 'windows' else ''))
contract.require(item['path'] == str(path.relative_to(ROOT)) and not path.is_symlink() and path.is_file(), 'fixed artifact path')
contract.require(stat.S_IMODE(path.stat().st_mode) == 0o600 and path.stat().st_uid == os.getuid(), 'private artifact owner/mode')
contract.require(item['binary_sha256'] == sha(path.read_bytes()) and item['size_bytes'] == path.stat().st_size, 'artifact hash/size')
contract.require(item['test_count'] == (20 if kind == 'reconcile' else (5 if platform == 'linux' else 4)), 'fixed test count')
contract.require(item['test_count'] == PROFILES[profile][platform][kind], 'fixed test count')
artifacts[kind] = item
return dict(manifest_sha256=sha((folder/'manifest.json').read_bytes()), artifacts=artifacts)
@@ -67,10 +82,12 @@ def linux_case(payload):
ident = str(uuid.UUID(payload['id']))
require(ident == payload['id'] and payload['action'] in ('prepare', 'run', 'read'), 'fixed case')
entries = payload['artifacts']
require(set(entries) == {'contracts', 'reconcile'}, 'two fixed test artifacts')
profile=payload.get('profile','original')
profiles={'original':{'contracts':5,'reconcile':20},'helper-sync-v1':{'contracts':5,'reconcile':21,'helper-reconcile':22,'linux-helper':21}}
require(profile in profiles and set(entries)==set(profiles[profile]), 'fixed qualification artifacts')
for kind, item in entries.items():
require(len(item['binary_sha256']) == 64 and all(c in '0123456789abcdef' for c in item['binary_sha256']), 'fixed hash')
require(item['test_count'] == (5 if kind == 'contracts' else 20), 'fixed test count')
require(item['test_count'] == profiles[profile][kind], 'fixed test count')
require(os.geteuid() == 0, 'bootstrap root only')
def safe(path, directory):
m = path.lstat()
@@ -84,13 +101,13 @@ def linux_case(payload):
case = root/ident
if payload['action'] == 'prepare':
case.mkdir(mode=0o700)
save(case/'intent.json', dict(id=ident, artifacts=entries, linux_manifest_sha256=payload['linux_manifest_sha256'], windows_manifest_sha256=payload['windows_manifest_sha256'], test_only=True))
save(case/'intent.json', dict(id=ident, profile=profile, artifacts=entries, linux_manifest_sha256=payload['linux_manifest_sha256'], windows_manifest_sha256=payload['windows_manifest_sha256'], test_only=True))
for item in entries.values(): (case/item['binary_sha256']).mkdir(mode=0o700)
return dict(prepared=True)
safe(case, True); safe(case/'intent.json', False)
intent = json.loads((case/'intent.json').read_bytes())
require(intent['artifacts'] == entries and intent['linux_manifest_sha256'] == payload['linux_manifest_sha256'] and intent['windows_manifest_sha256'] == payload['windows_manifest_sha256'], 'same native intent')
kind = payload['kind']; require(kind in ('contracts', 'reconcile'), 'fixed test kind')
require(intent.get('profile','original') == profile and intent['artifacts'] == entries and intent['linux_manifest_sha256'] == payload['linux_manifest_sha256'] and intent['windows_manifest_sha256'] == payload['windows_manifest_sha256'], 'same native intent')
kind = payload['kind']; require(kind in profiles[profile], 'fixed test kind')
result_path = case/(kind+'-result.json')
if payload['action'] == 'read':
safe(result_path, False)
@@ -123,7 +140,10 @@ def linux_case(payload):
WINDOWS = r'''
$ErrorActionPreference='Stop'
$p=([Console]::In.ReadLine() | ConvertFrom-Json)
if ([string]([guid]$p.id) -cne $p.id -or $p.kind -notin @('contracts','reconcile') -or $p.action -notin @('run','read') -or $p.sha256 -notmatch '^[0-9a-f]{64}$' -or $p.linux_evidence_sha256 -notmatch '^[0-9a-f]{64}$') {throw 'Fixed native core case'}
if (!$p.profile) {$p | Add-Member -NotePropertyName profile -NotePropertyValue 'original'}
$kinds=@('contracts','reconcile');if ($p.profile -eq 'helper-sync-v1') {$kinds+=@('helper-reconcile')}
if ($p.profile -notin @('original','helper-sync-v1')) {throw 'Fixed qualification profile'}
if ([string]([guid]$p.id) -cne $p.id -or $p.kind -notin $kinds -or $p.action -notin @('run','read') -or $p.sha256 -notmatch '^[0-9a-f]{64}$' -or $p.linux_evidence_sha256 -notmatch '^[0-9a-f]{64}$') {throw 'Fixed native core case'}
$root='C:\ProgramData\RustDiscoveryBootstrap'
$case=Join-Path $root ('shared-core-'+$p.id)
function Safe([string]$path,[bool]$directory) {
@@ -144,11 +164,11 @@ Safe $root $true
if (!(Test-Path -LiteralPath $case)) {
if ($p.action -ne 'run' -or $p.kind -ne 'contracts') {throw 'Native intent missing'}
New-Item -ItemType Directory -Path $case | Out-Null
Write-New (Join-Path $case 'intent.json') @{id=$p.id;linux_evidence_sha256=$p.linux_evidence_sha256;test_only=$true}
Write-New (Join-Path $case 'intent.json') @{id=$p.id;profile=$p.profile;linux_evidence_sha256=$p.linux_evidence_sha256;test_only=$true}
}
Safe $case $true
$intent=Get-Content -LiteralPath (Join-Path $case 'intent.json') -Raw | ConvertFrom-Json
if ($intent.id -cne $p.id -or $intent.linux_evidence_sha256 -cne $p.linux_evidence_sha256) {throw 'Bound Linux-first evidence'}
if ((!$intent.profile -and $p.profile -ne 'original') -or ($intent.profile -and $intent.profile -cne $p.profile) -or $intent.id -cne $p.id -or $intent.linux_evidence_sha256 -cne $p.linux_evidence_sha256) {throw 'Bound Linux-first evidence'}
$result=Join-Path $case ($p.kind+'-result.json')
if ($p.action -eq 'read') {Safe $result $false;Get-Content -LiteralPath $result -Raw;exit 0}
Write-New (Join-Path $case ($p.kind+'-started.json')) @{kind=$p.kind;sha256=$p.sha256}
@@ -180,7 +200,7 @@ def upload_linux(case, kind, item):
def payload(intent, action, kind=None):
return dict(id=intent['id'], action=action, kind=kind, artifacts=intent['linux']['artifacts'], linux_manifest_sha256=intent['linux']['manifest_sha256'], windows_manifest_sha256=intent['windows']['manifest_sha256'])
return dict(id=intent['id'], profile=intent.get('profile','original'), action=action, kind=kind, artifacts=intent['linux']['artifacts'], linux_manifest_sha256=intent['linux']['manifest_sha256'], windows_manifest_sha256=intent['windows']['manifest_sha256'])
def verify_result(platform, kind, result, expected):
@@ -197,32 +217,34 @@ def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('action', choices=('linux', 'windows', 'finish-linux', 'finish-windows'))
parser.add_argument('--case-id')
parser.add_argument('--profile', choices=tuple(PROFILES), default='original')
args = parser.parse_args()
if args.action == 'linux':
contract.require(args.case_id is None, 'new Linux case chooses fresh UUID')
ident = str(uuid.uuid4()); case = STATE/ident
intent = dict(id=ident, linux=qualified('linux'), windows=qualified('windows'))
intent = dict(id=ident, linux=qualified('linux',args.profile), windows=qualified('windows',args.profile))
if args.profile != 'original': intent['profile']=args.profile
write_new(case/'intent.json', intent)
else:
contract.require(args.case_id is not None and str(uuid.UUID(args.case_id)) == args.case_id, 'fixed existing case UUID')
case = STATE/args.case_id
intent = contract.protected_json(case/'intent.json')
contract.require(intent['id'] == args.case_id and intent['linux'] == qualified('linux') and intent['windows'] == qualified('windows'), 'same qualified case source/artifacts')
contract.require(intent['id'] == args.case_id and intent.get('profile','original')==args.profile and intent['linux'] == qualified('linux',args.profile) and intent['windows'] == qualified('windows',args.profile), 'same qualified case source/artifacts')
platform = 'linux' if args.action.endswith('linux') else 'windows'
if platform == 'windows':
proof = contract.protected_json(case/'linux-passed.json')
contract.require(proof['id'] == intent['id'] and proof['passed'] is True and proof['qualification'] == intent['linux'], 'Linux-first native qualification required')
for kind in KINDS: verify_result('linux', kind, proof['results'][kind], intent['linux']['artifacts'][kind])
for kind in PROFILES[args.profile]['linux']: verify_result('linux', kind, proof['results'][kind], intent['linux']['artifacts'][kind])
linux_sha = sha((case/'linux-passed.json').read_bytes())
else: linux_sha = None
finish = args.action.startswith('finish-')
if not finish:
write_new(case/(platform+'-started.json'), dict(id=intent['id'], linux_evidence_sha256=linux_sha))
write_new(case/(platform+'-started.json'), dict(id=intent['id'], profile=args.profile, linux_evidence_sha256=linux_sha))
if args.action == 'linux':
linux.rpc('linux-vm.conf', linux_case, payload(intent, 'prepare'))
for kind in KINDS: upload_linux(case, kind, intent['linux']['artifacts'][kind])
for kind in PROFILES[args.profile]['linux']: upload_linux(case, kind, intent['linux']['artifacts'][kind])
results = {}
for kind in KINDS:
for kind in PROFILES[args.profile][platform]:
if platform == 'linux':
result = linux.rpc('linux-vm.conf', linux_case, payload(intent, 'read' if finish else 'run', kind))
else:
@@ -233,7 +255,7 @@ def main():
try:
with contextlib.redirect_stdout(captured):
if not finish: windows.upload(ROOT/item['path'], 'windows-core-'+kind+'.exe')
result = windows.powershell(WINDOWS, dict(id=intent['id'], kind=kind, action='read' if finish else 'run', sha256=item['binary_sha256'], linux_evidence_sha256=linux_sha), timeout=40)
result = windows.powershell(WINDOWS, dict(id=intent['id'], profile=args.profile, kind=kind, action='read' if finish else 'run', sha256=item['binary_sha256'], linux_evidence_sha256=linux_sha), timeout=40)
finally:
write_new(case/('windows-'+kind+'-transport-'+uuid.uuid4().hex+'.json'), dict(sanitized_bootstrap_output=captured.getvalue()))
write_new(case/(platform+'-'+kind+'-readback-'+uuid.uuid4().hex+'.json'), result)
+2 -2
View File
@@ -45,7 +45,7 @@ def powershell(script, payload=None, timeout=60, remote_signed=False):
UPLOAD = r'''
$ErrorActionPreference='Stop'
$p=([Console]::In.ReadLine() | ConvertFrom-Json)
if ($p.name -notmatch '^((rmm-agent-windows|windows-tests-(lib|bin|acl)|windows-core-(contracts|reconcile))\.exe|Install-PassiveClient\.ps1|PassiveStateProbe\.exe|WindowsTlsProbe\.exe)$') {throw 'Artifact allowlist'}
if ($p.name -notmatch '^((rmm-agent-windows|windows-tests-(lib|bin|acl)|windows-core-(contracts|reconcile|helper-reconcile))\.exe|Install-PassiveClient\.ps1|PassiveStateProbe\.exe|WindowsTlsProbe\.exe)$') {throw 'Artifact allowlist'}
$root='C:\ProgramData\RustDiscoveryBootstrap'
if (!(Test-Path -LiteralPath $root)) {
New-Item -ItemType Directory -Path $root | Out-Null
@@ -68,7 +68,7 @@ if (Test-Path -LiteralPath $path) {throw 'Artifact already exists'}
VERIFY_UPLOAD = r'''
$ErrorActionPreference='Stop'
$p=([Console]::In.ReadLine() | ConvertFrom-Json)
if ($p.sha256 -notmatch '^[0-9a-f]{64}$' -or $p.name -notmatch '^((rmm-agent-windows|windows-tests-(lib|bin|acl)|windows-core-(contracts|reconcile))\.exe|Install-PassiveClient\.ps1|PassiveStateProbe\.exe|WindowsTlsProbe\.exe)$') {throw 'Artifact allowlist'}
if ($p.sha256 -notmatch '^[0-9a-f]{64}$' -or $p.name -notmatch '^((rmm-agent-windows|windows-tests-(lib|bin|acl)|windows-core-(contracts|reconcile|helper-reconcile))\.exe|Install-PassiveClient\.ps1|PassiveStateProbe\.exe|WindowsTlsProbe\.exe)$') {throw 'Artifact allowlist'}
$path='C:\ProgramData\RustDiscoveryBootstrap\'+$p.sha256+'\'+$p.name
$hash=(Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash.ToLowerInvariant()
if ($hash -cne $p.sha256) {throw 'Artifact hash'}
+5
View File
@@ -63,6 +63,11 @@ Server/Domain/WebUI unterstützen lokal geprüft feste Plattformvarianten;
Clouddeployment steht noch aus. Vollständiger Restumfang:
[Windows-Gates](windows-gates.md), [Umsetzungsplan](windows-remaining-implementation.md).
Danach gemeinsamer Helper-Sync mit explizit getrennten Root-/Systembindungen
portiert: im eigenen Fall `5704073c-a135-431c-aa84-fedc68a3de0b` zuerst
69 Linux- und danach 47 Windows-Fixturen nativ bestanden, ohne RMM-Wirkung oder
Dienstersetzung. Windows-SYSTEM-Helper/Named-Pipe-Integration bleibt separat offen.
Der bestehende Windows-11-LocalService bleibt passiv: gleiche Geräteidentität,
Telemetriehistorie und Schlüssel; keine Jobs, Outbox oder Startgrants. Native
WSS-/Inventar-/Tenantnachweise und sieben Rusttests liegen vor. Explizites HTTPS
+17
View File
@@ -1,5 +1,22 @@
# Tatsächlicher Implementierungsstand
## Gemeinsamer Helper-Sync nativ geprüft — 2026-11-14
Der bisherige Linux-Helper-Sync ist jetzt ebenfalls Teil von `rmm-agent-core`.
Linux behält seine tatsächlichen Datei-/Lock-/Boot-/Clockadapter und den
OpenSSL-Verifier. Der gemeinsame Kern erhält explizite `Root`-/`System`-
Konfiguration; Windows wird niemals durch ein falsches `root`-Label dargestellt.
Historische Snapshot-/LocalAttempt-/SignedResponse-Codecs bleiben bytegleich.
Lokal bestanden: 174 betroffene Tests, Linux-/Windows-Clippy und Formatprüfung.
Im getrennten nativen Fall `5704073c-a135-431c-aa84-fedc68a3de0b` zuerst
69 Linuxfälle einschließlich 21 tatsächlicher Linux-Datei-/Lockadapter-Fixturen,
danach 47 portable Windowsfälle ohne Skip bestanden. Quell-/Artefaktbindungen
liegen separat unter `devstate/{shared-core,windows-core}/helper-sync-v1/`;
Rohbelege unter `devstate/shared-core/acceptance/<Fall>/`. Frühere Belege bleiben
unverändert. Keine Dienste ersetzt, keine RMM-Jobs, Systemaktionen oder neue
Grants. Dies ist kein nativer Windows-SYSTEM-/Named-Pipe-Nachweis.
## Gemeinsamer Jobkern nativ auf Linux und Windows geprüft — 2026-11-14
Der neue `rmm-agent-core` enthält die gemeinsame signierte Sync-/Checkpoint-