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
|
|
@ -4,11 +4,32 @@
|
|||
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::process::CommandExt as _;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
|
||||
use crate::util::agent_exists;
|
||||
|
||||
/// Refuse early when the caller isn't root.
|
||||
///
|
||||
/// `machinectl shell` needs root or a polkit grant, and hyperhive ships
|
||||
/// no polkit rules — so unprivileged callers hit an authentication
|
||||
/// prompt/refusal from systemd that says nothing about which hivectl
|
||||
/// verb wanted it. Naming the requirement here keeps the failure honest
|
||||
/// and points at the one thing that would fix it.
|
||||
fn require_root() -> Result<()> {
|
||||
// SAFETY: `geteuid` takes no arguments, reads a process attribute
|
||||
// the kernel always has, and cannot fail.
|
||||
let euid = unsafe { libc::geteuid() };
|
||||
if euid != 0 {
|
||||
bail!(
|
||||
"choom needs root: it runs `machinectl shell`, which requires root \
|
||||
(hyperhive ships no polkit rule granting it) - re-run with sudo"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Drop into an interactive Claude session in the agent container.
|
||||
///
|
||||
/// Execs `machinectl shell <name>@h-<name>` running claude as the agent
|
||||
|
|
@ -17,13 +38,19 @@ use crate::util::agent_exists;
|
|||
/// live harness session). See `docs/tools/hivectl.md` (Choom) for the
|
||||
/// full rationale. Inherits the caller's PTY; requires root + a running
|
||||
/// container.
|
||||
pub(crate) fn choom(name: &str, resume_session: Option<&str>) -> Result<()> {
|
||||
if !agent_exists(name)? {
|
||||
///
|
||||
/// The existence check goes over the daemon socket even though the exec
|
||||
/// itself doesn't need it: the agents root isn't readable by the
|
||||
/// operator group, so checking locally reported every rootless invocation
|
||||
/// as a permission problem with the state dir rather than with the shell.
|
||||
pub(crate) async fn choom(socket: &Path, name: &str, resume_session: Option<&str>) -> Result<()> {
|
||||
if !agent_exists(socket, name).await? {
|
||||
bail!(
|
||||
"no such agent: '{name}' (no state dir under {}/)",
|
||||
hive_host_sock::AGENTS_ROOT
|
||||
);
|
||||
}
|
||||
require_root()?;
|
||||
let container = hive_host_sock::container_name(name);
|
||||
// Enter as the agent's unix user (== agent name) so claude reads the
|
||||
// right `$HOME/.claude`.
|
||||
|
|
|
|||
Loading…
Reference in a new issue