hyperhive/hive-priv
Repository files (latest commit first)
Filename Latest commit message Latest commit date
atlas 9eaf66546b fix(priv): redact secrets by shape, not by the word "password"
`forgejo admin user generate-access-token` prints

    Access token was successfully created: <40 hex>

and that line reached the host journal verbatim, for every agent
provisioned within journal retention. `read_host_journal` is a grantable
agent capability, so any agent holding it could read every other agent's
forge token and act fully as them.

The redactor missed it for a reason worth keeping. It matched the
substring "password", and its doc comment explains that choice: broad on
purpose, not pinned to forgejo's exact phrasing, so a *reworded* password
line still gets caught. That reasoning is sound and it guarded the wrong
axis -- the leak was a different KIND of secret on a differently worded
line. A denylist of one keyword fails open, and it failed open silently
while looking deliberate.

So there are now two independent rules, and the second matches on shape
rather than vocabulary: a whitespace-delimited run of >=32 characters
from the hex/base64url alphabet. A new secret type is caught by default
instead of by someone remembering to add a word.

It deliberately over-matches -- a nix store hash is also a long opaque
run and will redact its line. That is the correct direction to be wrong
in: a false positive costs one log line, a false negative costs a live
credential.

Two further sites, because fixing one of three is how these survive:

- stdout drops from INFO to DEBUG. On the success path that stream *is*
  the product of the command (the freshly minted token) and nothing an
  operator needs at default verbosity. Level and redaction are separate
  layers; neither alone is sufficient.
- the failure path interpolated raw stderr into the `bail!` string, which
  is propagated to the caller and logged. Redacting the log but not the
  error leaves the same hole one step downstream.

`redact_password_line` is renamed to `redact_secret_line`. The old name
had become part of the problem: it read as "this line is safe" when it
only ever meant "this line has no password in it".

The regression test asserts its fixture contains no "password" before
asserting redaction -- otherwise it would pass under the old code and
prove nothing.

Rotating the already-exposed tokens is an operator action and is only
worth doing after this lands, or the new ones go into the journal too.
2026-08-09 20:02:18 +02:00
..
src fix(priv): redact secrets by shape, not by the word "password" 2026-08-09 20:02:18 +02:00
Cargo.toml docs(#2627): add READMEs for the remaining infra crates 2026-07-23 13:16:29 +02:00
README.md docs(#2627): add READMEs for the remaining infra crates 2026-07-23 13:16:29 +02:00

hive-priv

The minimal root privileged-helper for hive-c0re. It runs as root and exposes a narrow unix socket at /run/hive/priv.sock that accepts PrivRequest JSON lines and performs only the handful of operations that genuinely require root — bind-mount edits, nsenter into a container, btrfs subvolume ops. All coordination logic (broker, HTTP, scheduling) stays in the unprivileged hive-c0re process, which delegates here.

Why it exists

Privsep. hive-c0re runs as the unprivileged hive-core user so a bug or a prompt-injection in the large daemon can't directly wield root. The few root operations it needs are funnelled through this small, auditable helper instead. See docs/boundary.md and docs/security.md for the privilege boundary.

Security model

  • Strict allowlist. Every request is validated against a container-name allowlist before any filesystem or process operation — only names matching the hive convention (h-*, the manager container, known sibling service containers) are accepted.
  • No pass-through. Every PrivRequest variant maps to a single known operation; there is no arbitrary-command escape hatch.
  • Socket-activated, always. systemd binds /run/hive/priv.sock (SocketGroup=hive-core, 0660) and passes the listener as fd 3 (LISTEN_FDS); the helper requires this and has no self-bind fallback, so dev and prod take the identical path and the group grant always holds.

The wire contract (PrivRequest / response types) lives in the separate hive-priv-sock crate so this root binary depends on just the protocol shapes, not the whole daemon-shared crate.