Repository navigation
✨ feat: let a sandboxed reviewer post reviews through a workspace spool - #14989
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
|
@Danathar this PR is back in your court ( Failing checks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Your relay session received this as a |
A reviewer whose kicks run in a sandbox (Podman, or a Kubernetes Job on an accelerator node via sandbox.runtime: job) had no path to the pod-local review relay, so it could not post a verdict. Every sandbox kick now gets a review spool at .hive/review-requests in its workspace; hive-review writes there when HIVE_REVIEW_REQUEST_DIR is set. The executor registers the spool with a manifest under <work_dir>/sandbox-review-spools, outside every workspace and owner-only. The review-request watcher moves spooled requests into hive-owned staging through an os.Root at the workspace, runs them through the same handler as the pod-local drop box (per-head cap, pause, lane allowlist, sentinel block, audit unchanged), attributes them to the manifest's agent rather than the file's, and mirrors results back into the spool. A finished kick waits briefly for the relay to drain the spool before returning. Closes #14986 Hive-Run: #14986 Hive-Plan: issue-14986 proposal (relay accepts verdict files from the sandbox workspace) Hive-Spec: #14986#proposal-1-4 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Danathar <Danathar@users.noreply.github.com>
review_request_thread_test.go already declares readReviewResult with the same signature and behaviour, so the package failed to compile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Danathar <Danathar@users.noreply.github.com>
c373d38 to
eebe283
Compare
There was a problem hiding this comment.
Correctness review (head c373d38)
pkg/githubtest package does not compile — none of the relay tests in the PR body ran.src/pkg/github/review_request_sandbox_spool_test.go:61declaresreadReviewResult(t, reqPath), which already exists with the identical signature and body insrc/pkg/github/review_request_thread_test.go:35. CI:build-and-test,golangci-lint,test (rest 3/4)all fail withreadReviewResult redeclared in this block/FAIL github.com/hivecommons/hive/pkg/github [build failed]. Fix: delete the duplicate in the new file (lines 61–72); the existing helper is a drop-in.
--- a/src/pkg/github/review_request_sandbox_spool_test.go
+++ b/src/pkg/github/review_request_sandbox_spool_test.go
@@
-func readReviewResult(t *testing.T, reqPath string) ReviewResponse {
- t.Helper()
- b, err := os.ReadFile(strings.TrimSuffix(reqPath, ".json") + ".result.json")
- if err != nil {
- t.Fatalf("no result file mirrored into the spool: %v", err)
- }
- var resp ReviewResponse
- if err := json.Unmarshal(b, &resp); err != nil {
- t.Fatal(err)
- }
- return resp
-}
-- Sleep ratchet.
src/crux/agent/sandbox_review_spool_test.goadds twotime.Sleep(calls inTestSandboxExecutorWaitsForTheRelayToDrainTheSpool(the fake-relay goroutine).internal/testutil TestSleepRatchetfails intest (rest 2/4):200 "time.Sleep(" calls ... above the baseline of 198. Replace the busy-wait with a ticker:
go func() {
- deadline := time.Now().Add(5 * time.Second)
- for time.Now().Before(deadline) {
+ deadline := time.NewTimer(5 * time.Second)
+ defer deadline.Stop()
+ tick := time.NewTicker(time.Millisecond)
+ defer tick.Stop()
+ for {
matches, _ := filepath.Glob(filepath.Join(root, "*", crux.SandboxReviewSpoolRelPath, "r.json"))
if len(matches) == 1 {
- time.Sleep(50 * time.Millisecond)
+ <-time.After(50 * time.Millisecond)
consumed.Store(true)
_ = os.Remove(matches[0])
return
}
- time.Sleep(time.Millisecond)
+ select {
+ case <-deadline.C:
+ return
+ case <-tick.C:
+ }
}
}()Advisory (out of scope, non-blocking): hasSandboxReviewSpools (review_request_sandbox_spool.go) only checks for *.json in the manifest dir, while pruning of stale/untrusted manifests happens in loadSandboxReviewSpools. If the manifest dir is ever rejected by untrustedOwnerReason, nothing is pruned and the watcher stays on its short poll cadence indefinitely.
Checked and found sound: LaunchSpec.Env reaches both launchers (sandbox.go:113, kubejob.go:410); fileUID = 0 correctly skips the forge check in AuthorizeReviewRequest (manager.go:1701); nil reviewSpoolHandle is safe through sandboxEnv/awaitDrain/end.
— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. |
There was a problem hiding this comment.
HUMAN DECISION NEEDED — @Danathar: accept that any in-pod agent sharing hive's group can post a review as a sandboxed reviewer via its spool, or require the spool-file owner to be checked before attribution.
Security perspective. Read at head c373d38.
Spooled requests are attributed to the manifest's agent, but any group member can write the spool (high, in-scope)
The pod-local relay resists forgery by requiring the request file's owning UID to be the claimed agent (src/crux/agent/manager.go:1701-1708). This PR disables that for spooled requests — src/pkg/github/review_request_watcher.go:286 overwrites req.Agent with the manifest's agent and :353 sets fileUID = 0, which the authorizer treats as "no owning UID, skip the forge check". The PR body's safety argument is that the manifest is the proof. That holds for the manifest (0700, euid-checked). It does not hold for the spool the request is read from:
src/crux/agent/sandbox_review_spool.go:42creates the spool0o770, inside a workspace tree that is itself0o770(src/crux/agent/sandbox_executor.go:319,src/crux/sandbox/worktree.go:56) underwork_dir.src/pkg/github/review_request_sandbox_spool.go:261-276ingests every*.jsonin that spool and stages it under hive's uid; the owning uid returned byreadRootFile(fi) is discarded.
On a shared-uid host (the deployment the uid map exists for), all agents and hive share one primary group and work_dir is group-writable (/data/agents is drwxrwxr-x dev node here; agents have gid=1000(node)). So while reviewer R has a sandbox kick running, any in-pod agent A — including one whose ACMM level forbids reviewing — can echo '{"repo":…,"number":N,"event":"approve",…}' > <R-workspace>/.hive/review-requests/x.json and the relay posts it as R, passing R's authorization, lane allowlist, and audit attribution. This is a regression of the forge-resistance the review relay currently has, and it is the one property the #14986 contract calls out ("attributed to the owning agent … not from the file contents").
Suggested fix: keep the spool file's owning uid and deny a file owned by a different registered agent; hive's own euid (Podman --userns=keep-id) and an unregistered uid (Job image user) remain acceptable.
--- a/src/pkg/github/review_request_sandbox_spool.go
+++ b/src/pkg/github/review_request_sandbox_spool.go
@@ func (c *Client) ingestSandboxSpool(root *os.Root, rel, staging string, now time.Time) {
data, fi, err := readRootFile(root, src, requestMaxBytes)
...
+ // Forge check (mirrors the pod-local relay): the spool is group-writable,
+ // so a request owned by a registered in-pod agent other than the manifest's
+ // agent is a forgery, not a sandbox write. Hive's own uid (Podman keep-id)
+ // and an unregistered uid (the Job image's user) are the sandbox's.
+ if uid := fileOwnerUID(fi); uid != os.Geteuid() && c.reviewSpoolOwnerIsOtherAgent(uid) {
+ _ = root.Rename(src, src+".rejected")
+ c.logger.Warn("review-request watcher: REJECTED sandbox spool file (owned by another agent)",
+ slog.String("path", src), slog.Int("uid", uid))
+ continue
+ }reviewSpoolOwnerIsOtherAgent needs a hook into the manager's uidMap.LookupByUID (an extra authorizer or a func(uid int) (agent string, ok bool) on the Client), and the uid 0 test in review_request_sandbox_spool_test.go would then cover the owner path too. Alternatively, if the operators decide group-writable workspaces already make this moot (an in-pod agent can also inject commits into a sandbox worktree), say so in sandbox-isolation.md so the attribution claim in the PR/changelog is not stronger than the guarantee.
— hive: agent=adjudicator-3 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Decision needed: @clubanderson should decide whether review requests from sandboxed kicks may bypass the file-UID forge check and be attributed solely by the executor-written spool manifest (crux/agent/manager.go:1701 skips the check when fileUID is 0; review_request_watcher.go:353 forces 0 for spooled requests).
Read the relay half (src/pkg/github/review_request_sandbox_spool.go, the review_request_watcher.go diff) and the authorizer it lands in. The code is careful and I found no defect; what it changes is trust policy, which is a human call.
What this changes, concretely
review_request_watcher.go:350-354: a request drained from a sandbox spool hasfileUIDforced to0andreq.Agentoverwritten from the manifest (:283-286).crux/agent/manager.go:1701:AuthorizeReviewRequestruns the owner-UID forge check only whenfileUID > 0, so spooled requests skip it entirely. The push-capability gate, per-head caps, sentinel block and audit trail still apply because the samehandleOneReviewRequestruns (review_request_sandbox_spool.go:109).- Attribution therefore rests on the manifest in
crux.SandboxReviewSpoolsDir, which the sandbox cannot reach;loadSandboxReviewSpoolsrefuses manifests not owned by the relay's uid or group/world-writable (:206), and all spool I/O goes throughos.Rootopened at the workspace (:105-106) so a planted symlink cannot escape it. - Side effect worth knowing: while any manifest is registered, the watcher drops fsnotify and keeps the short poll cadence (
review_request_watcher.go:179,:206).
Why a human must decide: this is a new path by which a process the hive deliberately does not trust (a Podman/K8s Job) gets reviews posted under the App installation token, with identity asserted by a file the executor wrote rather than by the kernel. The mechanism is sound as written; whether the hive wants manifest-asserted identity for GitHub writes is a policy question, not a code one. I have not found anything that would block merging on correctness grounds.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
@Danathar this PR is back in your court ( Failing checks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (0 waiting): fixes are handed out before new work as soon as you have capacity. |
|
Triage of test (rest 2/4) at eebe283: 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
TestSleepRatchet failed: the spool drain test added two sleeps. Its relay goroutine now takes the request path from the fake launcher over a channel instead of polling the workspace; the one remaining hold is a deliberate negative wait and says so. The four poll loops in sandbox_executor_test.go use the package's ticker-based waitFor, and the ratchet baseline drops from 198 to 195. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Danathar <Danathar@users.noreply.github.com>
|
@Danathar this PR is back in your court ( Review asks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Your relay session received this as a |
There was a problem hiding this comment.
Decision needed: @clubanderson should decide whether the review relay (the hive's GitHub write gate) may accept requests from sandboxed reviewers authenticated by a per-run HMAC key that, on sandbox.runtime: job, is readable by anything with Pods/Jobs read in the namespace (src/docs/sandbox-isolation.md, "Posting reviews from a sandbox", last paragraph).
This extends the review relay — the hive's only GitHub write path — to accept requests from inside a sandbox. I found no defect in the parts I read; the trust decision is the part that needs a person, and the PR is also conflicting with v5 (mergeable_state=dirty) so it needs a rebase before it can land either way.
What I verified at head 59acb97 (I read the relay-side ingestion, the podman env change, the ratchet and the doc; I did not read all 1593 lines):
- Attribution is relay-owned, not sandbox-asserted.
src/pkg/github/review_request_sandbox_spool.go:162-200reads manifests only from<work_dir>/sandbox-review-spools/, anduntrustedOwnerReason(:221-233) rejects a manifest dir or file that is a symlink, not owned by the relay's euid, or group/world-writable. The request's ownagentfield is overridden by the manifest's (:84-90). - Spool reads are confined. Every spool access goes through an
os.Rootat the workspace;readRootFile(:432-465)Lstats first, sets aside symlinks/FIFOs, opens withO_NONBLOCK(read_untrusted_unix.go:54), and caps atrequestMaxBytes. - Replay/forgery.
sandboxSpoolEnvelope(:313) requires an HMAC over the request with this run's key (min length enforced at:244), andmarkSpoolMACSeen(:329) refuses a second copy of an accepted MAC. Manifests older thansandboxReviewSpoolMaxAgeare refused (:247). - Key never on a command line.
src/crux/sandbox/sandbox.go:113-120now passes--env NAMEonly; the value comes fromcmd.Env, whichRunsets from the samespec.Env(sandbox.go:66). Podman reads a name-only--envfrom its own environment, so this works. - Sleep ratchet moves down 198 → 195 (
src/internal/testutil/sleep_ratchet_test.go:24) — a tightening, not a bypass. - Doc states the residual exposures plainly: a group member can delete/alter a spooled request (loses the review, cannot post one), and on
runtime: jobthe key sits in the pod spec.
Open question for the owner, not a finding: whether "agents must not hold Pods read in the namespace" is an acceptable precondition to rely on for the write gate, or whether the key should be delivered another way (e.g. a mounted Secret) before this lands.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Decision needed: @clubanderson should decide whether the review relay may attribute sandbox-spooled reviews by executor manifest + per-kick HMAC key (delivered to the sandbox as the HIVE_REVIEW_SPOOL_KEY env var) in place of the file-owner UID forge check.
Code read looks sound; the trust-model change itself needs an owner's yes.
What I verified in src/pkg/github/review_request_sandbox_spool.go at 59acb97:
- The spool is only ever touched through an
os.Rootopened at the workspace (readRootFile/writeRootFile/root.Rename), withLstatrefusing symlinks and non-regular files, so a sandbox-planted symlink cannot redirect a read or write outside its own workspace. - The manifest dir and each manifest are checked with
untrustedOwnerReason: symlink, non-regular,fileOwnerUID != Geteuid(), or any group/other write bit → ignored. Manifests live under<work_dir>/sandbox-review-spools/(0700), outside every workspace. - A spooled request must be a
SandboxReviewEnvelopewhose HMAC verifies under the manifest's key (hmac.Equal), andmarkSpoolMACSeenrejects a replayed MAC; failures are renamed.rejected, never staged. The key is 256 random bits minted per kick (rand.Read) and the manifest refuses keys belowsandboxReviewSpoolKeyMinLen. - Staged requests then go through the existing
processReviewRequestDirwithreviewRequestSource{agent: manifest.Agent}overriding the file'sagent, somax_reviews_per_head, the lane allowlist, sentinel block, COMMENT-only guard and canary scan apply unchanged — the body's claim matches the code. sleep_ratchet_test.go: baseline lowered 198 → 195; no newtime.Sleepadded.
The decision a person owns: this is the first path where a review's attribution does not rest on the writing file's UID. It rests on (a) the relay's own 0700 manifest and (b) a secret the sandbox holds in its environment. For sandbox.runtime: job that env var is in the Pod spec, readable by anyone with pod-read in the namespace, and by anything inside the kick that dumps env. Blast radius is bounded to "post a COMMENT review as that one agent during that one kick" — but it is a new trust surface on the write gate, and the documented threat model (src/docs/github-write-surface.md) changes with it.
Also: the branch is CONFLICTING against v5 and sits at stage/072-returned-to-contributor; the rebase is on the author. I have not approved or changed anything.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Needs a decision, not a merge:
Head: verdict requires_human @59acb97, 63/63 checks green, DCO yes, soak 0s of 30m0s. How to release it:
Clear the cause and the hive re-evaluates on its next pass; the stage moves to |
Resolves the one conflict, src/docs/scale-envelope.md: v5 reworded the RankActionableIssues citation to "oldest first within each tier" while this branch had "descending `AgeMinutes`". Both describe the code at client.go:4780-4790 (tier, then descending AgeMinutes); kept the cited lines and combined the wording. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SnzFs53Qcer1xDySyxv1Vj Signed-off-by: Danathar <Danathar@users.noreply.github.com>
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
There was a problem hiding this comment.
HUMAN DECISION NEEDED — @Danathar / @clubanderson: accept the second review-relay ingress where sandbox-spooled requests are attributed by hive-owned manifest + per-kick HMAC (HIVE_REVIEW_SPOOL_KEY) with the file-owner UID check bypassed (fileUID = 0, src/pkg/github/review_request_watcher.go:350-357), in place of the pod-local file-owner forge check.
Delta re-review at bb49a5b (previous head 59acb97), intent-alignment perspective:
- The delta is solely
Merge branch 'v5'(11 v5 commits, 114 files); none of the PR's 20 files changed between heads, so no new scope entered the PR. Previous finding "branch conflicts with v5" is fixed (PR nowMERGEABLE). - Previous attribution finding (
src/pkg/github/review_request_sandbox_spool.go) is unchanged in code and remains the open policy question above. For the decider: #14986 item 2 explicitly asks for attribution "from the Job's sandbox manifest, not from the file contents", so the design matches the issue; what the issue did not pre-decide is dropping the UID check, which the HMAC envelope (bin/hive-review.sh,review_request_sandbox_spool.gosandboxSpoolEnvelope/markSpoolMACSeen) now substitutes for. - Diff covers all four bounded items of #14986 (workspace spool via
HIVE_REVIEW_REQUEST_DIR, manifest attribution, samehandleOneReviewRequestpolicy path,sandbox.runtime: jobdocumented insrc/docs/sandbox-isolation.md); quality/deps lanes untouched.sleep_ratchet_test.gobaseline 198→195 follows the sleeps removed fromsandbox_executor_test.go, not scope creep. - Advisory (non-blocking): the PR body's "Attribution" paragraph still says "the manifest is the proof instead" and omits the per-run MAC added in
59acb97; the changelog fragmentchangelog.d/added-14986-sandbox-review-spool.mdis current. Consider updating the body so the squash message describes the shipped trust model.
— hive: agent=adjudicator-3 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Security re-review (delta 59acb97→bb49a5b; read at head bb49a5b)
The delta is a Merge branch 'v5': the PR's own 20-file diff is byte-identical to 59acb97 (diff-of-diffs is empty) and the only conflict resolution is one doc line in src/docs/scale-envelope.md:37. It now merges clean onto v5.
Previous findings at the new head:
- Relay attribution without file-owner UID — addressed. Spooled files are only staged after the envelope MAC verifies against the per-run key (
src/pkg/github/review_request_sandbox_spool.go:289-321,hmac.Equal), with anO_EXCLseen-marker blocking replays (:329-343). The key is 32 random bytes minted per kick (src/crux/agent/sandbox_review_spool.go:59), stored only in the 0700/euid-owned manifest (:243drops manifests without a ≥32-byte key), and reaches Podman by name only (src/crux/sandbox/sandbox.go:119), so it is not in/proc/*/cmdline.isCredentialName(sandbox.go:154) does not stripHIVE_REVIEW_SPOOL_KEY, so it does reach the sandbox.fileUID = 0(review_request_watcher.go:356) is now only reachable post-MAC. Group members can still delete/garble a spooled request (DoS, not forgery), as the author documents. - Branch conflicts with v5 — fixed by the merge commit.
No new security findings in the delta.
— hive: agent=adjudicator-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Reviewed (docs-currency, delta re-review at bb49a5b) — no in-scope findings.
Delta since 59acb97 is the v5 merge (11 upstream commits + merge commit); the only PR-owned hunk it touched is src/docs/scale-envelope.md:37, a conflict resolution. Previous findings:
- [correctness] branch conflicts with v5 — fixed by merge commit
bb49a5b(mergeable: MERGEABLE; PR squash-merged as3e9edaec9). - [security]
review_request_sandbox_spool.go:42attribution not on file-owner UID — unchanged by the delta (file untouched); the manifest + per-run HMAC spool key design is documented as such insrc/docs/sandbox-isolation.md:217-223.
Docs verified against code at head: 24h manifest prune (review_request_sandbox_spool.go:72), .rejected + rejected: result (:280,:347,:354), poll cadence while a spool is registered (review_request_watcher.go, hasSandboxReviewSpools), 60s drain (crux/agent/sandbox_review_spool.go:24), <work_dir>/sandbox-review-spools wiring (manager_sandbox.go:156), env by name only in crux/sandbox/sandbox.go:113-119.
Advisory, out of scope: src/docs/scale-envelope.md:37 is an unrelated one-line rewording (oldest first within each tier → descending AgeMinutes within each tier); it is accurate (src/pkg/github/client.go:4788) and says the same thing, so no action needed.
— hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88
Summary
A reviewer whose kicks run in a sandbox couldn't post a review. That covers Podman, and on hardware spokes such as a1-vllm-spyre it covers
sandbox.runtime: jobon the card node. The sandbox never sees the pod-local relay dir (/var/run/hive-metrics/review-requests). This PR implements the bounded proposal in #14986:.hive/review-requestsin its workspace. The sandbox getsHIVE_REVIEW_REQUEST_DIR=/workspace/.hive/review-requests, andhive-reviewnow writes there when that variable is set. The schema is unchanged.<work_dir>/sandbox-review-spools/. That directory is outside every workspace and owner-only (0700). The relay attributes each spooled request to the manifest's agent and overwrites the file'sagentfield. It ignores a manifest dir or manifest file that isn't owned by its own uid or that others can write. The UID forge check is skipped for staged files, because hive owns them; the manifest is the proof instead.handleOneReviewRequest. Somax_reviews_per_head, repo pause, the lane write allowlist, the sentinel block, the contributor COMMENT-only guard, the canary scan, verdict validation and the audit all apply unchanged. Results are copied back into the spool so the agent can read them, for example to fix a bad--verdict-fileand resubmit within the same kick.sandbox.runtime: jobfor reviewers. No config gate refused it.sandbox-isolation.mdnow documents the setup and says the review runs on the card node.Hardening and lifecycle
os.Rootopened at the workspace. A planted symlink can't redirect a read, rename or result write outside the workspace. A request that is a symlink, FIFO or oversized is renamed to.rejected. All renaming, quarantine and retries happen in staging, which only hive can write.Out of scope, as the issue says: the quality and deps lanes are unchanged, and nothing inside a Job writes to GitHub directly.
Tests
pkg/github/review_request_sandbox_spool_test.go:.rejectedcrux/agent/sandbox_review_spool_test.go:Rununtil the relay takes the requestHIVE_WORK_DIRbin/test_hive_review.sh:HIVE_REVIEW_REQUEST_DIRredirects the request (run locally: 27 passed, 0 failed).Following AGENTS.md, I didn't run the Go tests locally; CI is the verdict.
gofmt -lis clean on every changed Go file.Closes #14986
🤖 Generated with Claude Code
— hive: backend=claude model=claude-opus-5-5
🐝 Hive Agent:
contributor| SHA:c373d3898