Add reviewed Windows scope completion and idle certificate renewal; deploy completion API
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-16 10:25:25 +01:00
parent ebcad08731
commit bb4ffe518d
43 changed files with 5146 additions and 50 deletions
@@ -160,8 +160,134 @@ mod windows {
ensure!(bytes.len() as u64 <= max, "public file changed");
Ok(bytes)
}
fn complete_echo(apply: bool) -> Result<()> {
let readers = [ipc::service_sid(SERVICE_NAME)?];
let _root = PinnedFile::open(Path::new(ROOT), true, &readers, &[], false)?;
let mut pin = PinnedFile::open(
&Path::new(ROOT).join("binding.json"),
false,
&readers,
&[],
false,
)?;
let bytes = data(&mut pin.file, 8192)?;
ensure!(hash(&bytes) == BINDING_SHA256, "changed job binding");
let binding: Binding = serde_json::from_slice(&bytes)?;
let (settings, _pins) = helper_system::read_settings()?;
let mut config = PinnedFile::open(
&Path::new(ROOT).join("config.json"),
false,
&readers,
&[],
false,
)?;
ensure!(
config.sha256()? == PASSIVE && !settings.enable_effects && !settings.allow_reboot,
"restore original passive pair first"
);
let stopped = both_stopped()?;
ensure!(
!apply || stopped,
"both services must be stopped by the operator"
);
let mut locks = vec![];
if stopped {
for path in [
Path::new(STATE).join("agent.lock"),
Path::new(helper_system::STATE_ROOT).join("executor.lock"),
] {
let file = leaf(&path)?;
file.try_lock_exclusive().context("service lock busy")?;
locks.push(file);
}
ensure!(both_stopped()?, "service started during completion");
}
native::private_path(Path::new(STATE), true)?;
for p in [AGENT_DB, LOCAL_DB] {
native::private_path(Path::new(p), false)?;
}
let helper_sid = [ipc::service_sid(ipc::HELPER_SERVICE)?];
let _helper_state = PinnedFile::open_read_shared(
Path::new(helper_system::STATE_ROOT),
true,
&[],
&helper_sid,
)?;
let helper_file =
PinnedFile::open_read_shared(Path::new(HELPER_DB), false, &[], &helper_sid)?;
let mut agent = Db::open(AGENT_DB, apply, stopped)?;
let consumption = Db::open(LOCAL_DB, false, stopped)?;
let helper = Db::open(HELPER_DB, false, stopped)?;
let (ledger, lock, pin): (Vec<u8>, Vec<u8>, String) = helper.db.query_row(
"SELECT ledger,executor_lock,binding_sha256 FROM windows_helper_files WHERE id=1",
[],
|r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)),
)?;
ensure!(
serde_json::from_slice::<ipc::FileIdentity>(&ledger)? == helper_file.identity
&& pin == ipc::binding_hash(&settings.binding)?,
"helper journal or binding changed"
);
let witness = rmm_agent_windows::echo_completion::witness(
&agent.db,
&consumption.db,
&helper.db,
&binding,
&settings.binding,
)?;
println!("{}", serde_json::to_string(&witness)?);
if apply {
ensure!(
serde_json::from_slice::<ipc::FileIdentity>(&lock)?
== ipc::file_identity(&locks[1])?,
"helper lock identity changed"
);
let path =
Path::new(r"C:\ProgramData\RustDiscoveryBootstrap\windows-echo-completion.json");
let _folder = PinnedFile::open(
path.parent().context("completion folder")?,
true,
&[],
&[],
false,
)?;
let mut file = PinnedFile::open(path, false, &[], &[], false)?;
let receipt = data(&mut file.file, 131072)?;
let boot = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?
.block_on(native::boot_id())?;
let boot = uuid::Uuid::parse_str(&boot)?;
ensure!(both_stopped()?, "service started during completion");
let pair = rmm_agent_windows::echo_completion::LocalPair {
consumption: &consumption.db,
helper: &helper.db,
binding: &binding,
helper_binding: &settings.binding,
};
rmm_agent_windows::echo_completion::apply(
&mut agent.db,
pair,
&receipt,
boot,
chrono::Utc::now(),
)?;
println!(
"additional echo restriction retired; original history retained; ordinary signed pair sync and each WebUI job approval remain required"
);
}
Ok(())
}
pub fn run() -> Result<()> {
let args: Vec<_> = std::env::args().skip(1).collect();
if args.len() == 1
&& matches!(
args[0].as_str(),
"echo-completion-read" | "echo-completion-apply"
)
{
return complete_echo(args[0] == "echo-completion-apply");
}
ensure!(
args.len() == 1
&& matches!(