Repository navigation
✨ Sandboxed reviewers get the PR: head checked out plus PR metadata and diff - #18522
Conversation
Open PR overlap check✅ Resolved: no conflicting open PRs or same-file overlaps remain against |
|
cc @joerunde: this is part of the hive changes for the spyre-inference deps agent and sandboxed reviewer setup. |
Mutation testing❌ gremlins did not produce a report for 2 package(s), so no verdict can be derived from this run (see the job log):
Verdict: |
|
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
A review kick that runs in a sandbox now gets the PR it reviews. Hive reads the targets from the kick's hive-written header (review swarm and reviewer lane), fetches refs/pull/N/head and the base with the clone token, checks the head out on pr-N, and writes .hive/pr/N.json from its own GitHub client, marked untrusted, with metadata, changed files, a capped diff and review comments. The kick prompt names both. Review kicks never push: the manager wires no broker and the executor refuses one. Host writes into the checked-out tree go through os.Root. Fixes #18513 Signed-off-by: Andy Anderson <andy@clubanderson.com>
cdcabb8 to
58b313b
Compare
|
New changes are detected. LGTM label has been removed. |
There was a problem hiding this comment.
Decision needed: @clubanderson should confirm that checking out fork PR heads into a clone-token-bearing host workspace (review-only, push broker off) is acceptable for sandboxed reviewers.
No code defect found; routing because this touches the sandbox/credential boundary.
What I read at the PR head (sandbox_review_pr.go, sandbox_executor.go, sandbox_workspace.go, manager_sandbox.go):
- Targets are parsed only from the hive-written header:
reviewTargetsFromKickMessagerequires the[review-perspective:…]/Review PRpair, or the[agent:…]+REVIEWER —header with four-space-indentedcheckout:lines, so deeper-indented evidence cannot forge one (sandbox_review_pr.go, regexes near the top). Targets are deduped, same-repo only, capped at 5. - Review-only is enforced in two places: the push broker and PR client are not wired when
spec.reviewOnly()(manager_sandbox.go), and the executor returns early withPRWithheldbefore any push path (sandbox_executor.go). A failed fetch or PR read fails the kick instead of running against the wrong tree. - Host writes happen after checkout of the author's tree, via
os.Root(writeWorkspaceFileConfined), so a.hivesymlink in the PR cannot redirect them. The prompt write was moved onto the same helper. - Docs (
sandbox-isolation.md), changelog fragment and tests for parsing, fetch failure, no-push and the GitHub reader are included.
The decision for a person: this is the first path where attacker-controlled fork content is checked out on the host under the clone token (the fetch is token-authenticated; the sandbox itself stays credential-free). I found no escape in the diff, but a maintainer should own that trust call.
— hive: agent=reviewer-2 backend=claude model=claude-sonnet-5-5 claude=2.1.325
Fixes #18513
What
A sandboxed reviewer could not see the PR it was reviewing: the workspace held the default branch only, and the Job has no GitHub token, so
gh pr view/gh pr difffailed. Now, for a review kick:[review-perspective:…]+Review PR <repo>#<n>header. A reviewer-lane kick has an[agent:…]+REVIEWER — …header and per-PRcheckout: gh pr checkout <n> --repo <repo>lines; evidence excerpts are indented deeper, so they cannot forge one. Targets are deduplicated, limited to the primary repo, and capped at 5. They go into the newSandboxKickSpec.ReviewPRs.+refs/pull/N/head:refs/heads/pr-Nand the PR's base intoorigin/<base>with the clone token, so fork PRs work. It checks out the first target'spr-N; other targets stay fetched forgit checkout pr-M..hive/pr/N.jsoncomes from hive's GitHub client through the new optionalcrux.PRReviewContextReader, which*github.Clientimplements. It holds number, title, body, author, base/head refs and SHAs, fork flag, labels, changed files, a unified diff capped atsandboxReviewDiffMaxByteswith a truncation note, and every conversation comment, review and inline thread comment with its author association. It is marked"untrusted": truewith a notice. Acheckoutblock written by hive gives the ref, branch, SHA and an offline diff command, and flags a head that moved between the API read and the fetch.[hive:sandbox-review-checkout]section is prepended. It names each branch, head SHA and PR file, says the data is untrusted, and says the kick is review-only. The review spool path is unchanged.refs/pull/N/heador the base, a reader error, or a reader returning a different PR. With no reader at all, the head is still checked out and the file saysmetadata_available: false.os.Root: the kick prompt and the PR files are written after the PR head is checked out, so a.hivesymlink in a PR's tree cannot redirect them outside the workspace.Docs: a "What a sandboxed reviewer sees" section in
src/docs/sandbox-isolation.md. Changelog fragment added.Tests
crux/agent/sandbox_review_pr_test.gouses a fake git runner and a fake PR reader. It covers header parsing (swarm, lane, forged and indented lines, other repos, the cap), a fork PR checkout with the file and prompt contents, a multi-PR batch, a fetch failure, reader errors and PR-number mismatch, no reader, diff and body truncation plus a moved head, a missing diff, no push of reviewer commits, a refused run-stage kick, a symlink escape, and a manager-level review-only wiring test.pkg/github/pr_review_context_test.gouses an httptest GitHub: PR, paginated files, raw diff and GraphQL conversation; a refused diff is not fatal; the error paths; long comment bodies are truncated.Not touched:
src/pkg/kubejoband the sandbox launchers (#18512 works there).🤖 Generated with Claude Code