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

@ -1031,6 +1031,13 @@ pub enum Capability {
/// available on the agent socket even with this capability — use the
/// manager socket for swarm-wide scans.
QueryAgentState,
/// Agent can restart hive infrastructure containers (hive-ci,
/// hive-gateway, hive-forge) via the `restart` MCP tool. hive-c0re
/// checks this capability before routing the restart through
/// hive-priv; the concrete service allowlist lives root-side in
/// hive-priv. Deliberately generic ("infra admin") so future
/// privileged infra ops can hang off the same grant.
InfraAdmin,
}
impl Capability {
@ -1040,6 +1047,7 @@ impl Capability {
Self::ManageRootAgent,
Self::ReadHostJournal,
Self::QueryAgentState,
Self::InfraAdmin,
];
/// Canonical `snake_case` name for this capability (matches serde).
@ -1049,6 +1057,7 @@ impl Capability {
Self::ManageRootAgent => "manage_root_agent",
Self::ReadHostJournal => "read_host_journal",
Self::QueryAgentState => "query_agent_state",
Self::InfraAdmin => "infra_admin",
}
}
@ -1063,6 +1072,9 @@ impl Capability {
Self::QueryAgentState => {
"query non-child agents' loose ends and reminder state via get_loose_ends"
}
Self::InfraAdmin => {
"restart hive infrastructure containers (hive-ci, hive-gateway, hive-forge) via the restart tool"
}
}
}
}

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"));
}
}