fix(hivectl): ask the daemon whether an agent exists
The agents root is 0700 and owned by the daemon's user, so hivectl's client-side existence guard hit EACCES on traversal for anyone not root. It reported that as "this command needs root; re-run with sudo", which turned three verbs' pre-flight check into a permission error about the wrong thing: `choom`, `subvol upgrade` and `subvol snapshot create` all failed at the guard rather than at whatever they actually needed. The daemon runs as the owning user and already answers this question for its own provisioning paths, so expose it on the host socket as `AgentExists` and have hivectl ask. Operators reach that socket through the `hive-admin` group, so the guard now works without sudo. `choom` still needs root for `machinectl shell` — we ship no polkit rule granting those actions — so it now checks the effective uid and says so directly instead of failing later inside systemd's authorisation.
This commit is contained in:
parent
1bbc09e9dd
commit
170fd817ea
9 changed files with 119 additions and 36 deletions
|
|
@ -162,6 +162,10 @@ async fn dispatch(req: &HostRequest, coord: Arc<Coordinator>) -> HostResponse {
|
|||
HostResponse::dags(dags)
|
||||
}
|
||||
HostRequest::List => HostResponse::list(lifecycle::list().await?),
|
||||
// The agents root is ours and not world-traversable, so this
|
||||
// question is only answerable on this side of the socket —
|
||||
// see the request's doc comment for why the client asks.
|
||||
HostRequest::AgentExists { name } => HostResponse::agent_exists(agent_exists(name)?),
|
||||
HostRequest::AgentStatus => handle_agent_status(&coord).await,
|
||||
// The hive domain + per-surface public URLs are injected into
|
||||
// c0re's service env by hive-c0re.nix; surface them so the
|
||||
|
|
@ -380,7 +384,12 @@ fn matrix_http_client() -> Result<reqwest::Client> {
|
|||
}
|
||||
|
||||
/// True when `name` has a state dir under the agents root, i.e. it's a
|
||||
/// managed agent rather than a bare (operator/human) matrix account.
|
||||
/// managed agent rather than a bare (operator/human) account.
|
||||
///
|
||||
/// Used by the provisioning handlers below to tell an agent account from
|
||||
/// a human one, and exposed over the socket as
|
||||
/// [`HostRequest::AgentExists`] for clients that can't read the agents
|
||||
/// root themselves (it's `0700` and owned by the daemon's user).
|
||||
fn agent_exists(name: &hive_types::Ident) -> Result<bool> {
|
||||
crate::paths::agent_state_dir(name)
|
||||
.try_exists()
|
||||
|
|
|
|||
Loading…
Reference in a new issue