feat(#702): PrivRequest/PrivResponse wire types
This commit is contained in:
parent
ab861dd8dc
commit
c8ea28b218
1 changed files with 69 additions and 0 deletions
69
hive-sh4re/src/priv_proto.rs
Normal file
69
hive-sh4re/src/priv_proto.rs
Normal file
|
|
@ -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 <args>`.
|
||||||
|
///
|
||||||
|
/// 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<String> },
|
||||||
|
|
||||||
|
/// Run `systemctl daemon-reload`.
|
||||||
|
DaemonReload,
|
||||||
|
|
||||||
|
/// Overwrite `/etc/nixos-containers/<container>.conf` with new content.
|
||||||
|
WriteNspawnConf { container: String, content: String },
|
||||||
|
|
||||||
|
/// Write a file into the drop-in dir for `container@<container>.service`.
|
||||||
|
///
|
||||||
|
/// Creates `/run/systemd/system/container@<container>.service.d/<filename>`.
|
||||||
|
WriteSystemdDropin {
|
||||||
|
container: String,
|
||||||
|
filename: String,
|
||||||
|
content: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
/// Remove the drop-in dir for `container@<container>.service`, if present.
|
||||||
|
///
|
||||||
|
/// Removes `/run/systemd/system/container@<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<String> },
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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<String>,
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue