From c8ea28b21878d283b1edb292ce27c88c73dade93 Mon Sep 17 00:00:00 2001 From: damocles Date: Mon, 1 Jun 2026 16:34:01 +0200 Subject: [PATCH] feat(#702): PrivRequest/PrivResponse wire types --- hive-sh4re/src/priv_proto.rs | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 hive-sh4re/src/priv_proto.rs diff --git a/hive-sh4re/src/priv_proto.rs b/hive-sh4re/src/priv_proto.rs new file mode 100644 index 00000000..98e5f558 --- /dev/null +++ b/hive-sh4re/src/priv_proto.rs @@ -0,0 +1,69 @@ +//! Wire types for the `hive-priv` privileged-helper socket. +//! +//! Both `hive-priv` (server) and `hive-c0re` (client via `priv_client`) +//! import these so the shapes stay in sync. + +use std::path::PathBuf; + +use serde::{Deserialize, Serialize}; + +/// Default socket path for the privileged helper. +pub const PRIV_SOCK: &str = "/run/hive/priv.sock"; + +/// A request to the privileged helper. +/// +/// Wire format: one JSON object per line over `/run/hive/priv.sock`. +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(tag = "op", rename_all = "snake_case")] +pub enum PrivRequest { + /// Run `nixos-container `. + /// + /// The helper validates that the container argument (second positional + /// arg for verbs that take one) matches a hive-managed name + /// (`h-*`, the manager container, or a known sibling service container). + ContainerRun { args: Vec }, + + /// Run `systemctl daemon-reload`. + DaemonReload, + + /// Overwrite `/etc/nixos-containers/.conf` with new content. + WriteNspawnConf { container: String, content: String }, + + /// Write a file into the drop-in dir for `container@.service`. + /// + /// Creates `/run/systemd/system/container@.service.d/`. + WriteSystemdDropin { + container: String, + filename: String, + content: String, + }, + + /// Remove the drop-in dir for `container@.service`, if present. + /// + /// Removes `/run/systemd/system/container@.service.d/`. + RemoveSystemdDropin { container: String }, + + /// `chown(2)` a path under a hive-managed prefix + /// (`/run/hive-agent/` or `/var/lib/hyperhive/`). + Chown { path: PathBuf, uid: u32, gid: u32 }, + + /// `chmod(2)` a path under a hive-managed prefix. + Chmod { path: PathBuf, mode: u32 }, + + /// Run a command inside a machine container via `systemd-run --machine`. + /// + /// The machine name must be a hive-managed container. + SystemdRunMachine { machine: String, cmd: Vec }, +} + +/// Response from the privileged helper. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PrivResponse { + pub ok: bool, + #[serde(default)] + pub stdout: String, + #[serde(default)] + pub stderr: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub error: Option, +}