Skip to content

✨ Sandboxed reviewers get the PR: head checked out plus PR metadata and diff - #18522

Merged
kubestellar-prow[bot] merged 1 commit into
v5from
feat/18513-sandbox-reviewer-pr
Nov 16, 2026
Merged

kubestellar-prow[bot] merged 1 commit into
v5from
feat/18513-sandbox-reviewer-pr

Conversation

@clubanderson

Copy link
Copy Markdown
Member

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 diff failed. Now, for a review kick:

  • Targets come from the hive-written kick header, never from PR-supplied text. A review swarm kick has the [review-perspective:…] + Review PR <repo>#<n> header. A reviewer-lane kick has an [agent:…] + REVIEWER — … header and per-PR checkout: 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 new SandboxKickSpec.ReviewPRs.
  • Workspace prep fetches +refs/pull/N/head:refs/heads/pr-N and the PR's base into origin/<base> with the clone token, so fork PRs work. It checks out the first target's pr-N; other targets stay fetched for git checkout pr-M.
  • .hive/pr/N.json comes from hive's GitHub client through the new optional crux.PRReviewContextReader, which *github.Client implements. It holds number, title, body, author, base/head refs and SHAs, fork flag, labels, changed files, a unified diff capped at sandboxReviewDiffMaxBytes with a truncation note, and every conversation comment, review and inline thread comment with its author association. It is marked "untrusted": true with a notice. A checkout block 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.
  • Kick prompt: a [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.
  • Never pushes: the manager wires no push minter and no PR client for a kick with targets. The executor also returns before verify/broker for a review-only spec, so the guard holds even if a caller wires a push. Leftover commits are recorded as withheld.
  • Errors fail the kick with a clear message before the sandbox starts: a failed fetch of refs/pull/N/head or 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 says metadata_available: false.
  • Host writes go through os.Root: the kick prompt and the PR files are written after the PR head is checked out, so a .hive symlink 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.go uses 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.go uses 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/kubejob and the sandbox launchers (#18512 works there).

🤖 Generated with Claude Code

@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

✅ Resolved: no conflicting open PRs or same-file overlaps remain against v5.

@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Nov 16, 2026
@clubanderson

Copy link
Copy Markdown
Member Author

cc @joerunde: this is part of the hive changes for the spyre-inference deps agent and sandboxed reviewer setup.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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):

  • crux: gremlins exited 1
  • pkg/github: gremlins exited 137

Verdict: error (#17349).

@clubanderson clubanderson added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 16, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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>
@github-actions github-actions Bot removed the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Nov 16, 2026
@clubanderson
clubanderson force-pushed the feat/18513-sandbox-reviewer-pr branch from cdcabb8 to 58b313b Compare November 16, 2026 22:56
@kubestellar-prow kubestellar-prow Bot removed the lgtm Indicates that a PR is ready to be merged. label Nov 16, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@clubanderson clubanderson added the lgtm Indicates that a PR is ready to be merged. label Nov 16, 2026
@kubestellar-prow
kubestellar-prow Bot merged commit 91bfa2f into v5 Nov 16, 2026
93 of 95 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the feat/18513-sandbox-reviewer-pr branch November 16, 2026 23:14

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: reviewTargetsFromKickMessage requires the [review-perspective:…]/Review PR pair, or the [agent:…] + REVIEWER — header with four-space-indented checkout: 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 with PRWithheld before 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 .hive symlink 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Sandboxed reviewers get the PR: head checked out plus PR metadata and diff in the workspace

1 participant