feat(#1636): infra_admin capability — restart hive-ci/gateway/forge via restart tool

This commit is contained in:
damocles 2026-06-13 11:41:15 +02:00 committed by mara
commit f05031ebe3
6 changed files with 144 additions and 4 deletions

View file

@ -18,6 +18,15 @@ pub const AGENT_PREFIX: &str = "h-";
/// Sibling service containers managed by hive-c0re.
pub const SIBLING_CONTAINERS: &[&str] = &["hive-forge", "hive-matrix", "hive-gateway", "hive-ci"];
/// Infra containers an agent holding the `infra_admin` capability may
/// restart via the `restart` MCP tool. A deliberate subset of
/// [`SIBLING_CONTAINERS`]: hive-matrix is excluded (kicking the matrix
/// backend mid-sync is its own concern) and hive-c0re is excluded
/// entirely (a self-restart would sever the very socket the request
/// arrived on). hive-priv re-validates against this list root-side, so
/// it is the authoritative allowlist regardless of what the caller sends.
pub const RESTARTABLE_INFRA_CONTAINERS: &[&str] = &["hive-ci", "hive-gateway", "hive-forge"];
/// Host path of the meta flake. The flake ref for agent `<name>` is
/// `{META_DIR}#{name}`, derived by `hive-priv` — never passed over the wire.
pub const META_DIR: &str = "/var/lib/hyperhive/meta";
@ -287,6 +296,18 @@ pub enum PrivRequest {
/// Logical agent name (validated by `validate_agent_name`).
agent_name: String,
},
/// Restart a hive infrastructure container on the host via
/// `systemctl restart container@<container>.service`. hive-priv
/// validates `container` against [`RESTARTABLE_INFRA_CONTAINERS`]
/// before acting — the root-side allowlist is authoritative. Used
/// by hive-c0re to service a `restart` request from an agent that
/// holds the `infra_admin` capability.
RestartInfraContainer {
/// Infra container name (e.g. `hive-ci`); must be in
/// [`RESTARTABLE_INFRA_CONTAINERS`].
container: String,
},
}
/// Response from the privileged helper.
@ -341,3 +362,24 @@ pub enum PrivEvent {
/// Terminal event: the operation has finished.
Done(PrivResponse),
}
#[cfg(test)]
mod tests {
use super::{RESTARTABLE_INFRA_CONTAINERS, SIBLING_CONTAINERS};
#[test]
fn restartable_infra_is_a_safe_subset_of_siblings() {
// Every restartable infra container must be a known sibling.
for c in RESTARTABLE_INFRA_CONTAINERS {
assert!(
SIBLING_CONTAINERS.contains(c),
"{c} is not a managed sibling container"
);
}
// hive-matrix and hive-c0re are deliberately excluded: kicking the
// matrix backend mid-sync is its own concern, and a self-restart of
// c0re would sever the request socket.
assert!(!RESTARTABLE_INFRA_CONTAINERS.contains(&"hive-matrix"));
assert!(!RESTARTABLE_INFRA_CONTAINERS.contains(&"hive-c0re"));
}
}