Repository navigation
feat(vetted-ops): run SSH push and worktree moves without leaving them to the user - #2161
Merged
Merged
Conversation
potiuk
force-pushed
the
vetted-ops-git-operations
branch
from
November 18, 2026 01:08
7993e8e to
22a4373
Compare
potiuk
enabled auto-merge (squash)
November 18, 2026 01:09
3 of 11 tasks
potiuk
force-pushed
the
vetted-ops-git-operations
branch
from
November 18, 2026 03:03
22a4373 to
6cb35c3
Compare
potiuk
disabled auto-merge
November 18, 2026 03:09
…m to the user A sandboxed session cannot push over SSH (the proxy gives it no TCP, and a hardware key's touch prompt never reaches the user) and cannot write the administrative directory of a linked worktree it did not create. Each of those steps ended in a command the user had to paste into their own terminal, or in a sandbox bypass, which is the wider and worse door. vetted-op-git runs exactly those steps as closed shapes behind the same confirmation as vetted-op, bounded by the approved policy's [git] table: a leased push to the policy's fork or upstream repository, and adding, moving or removing a clean linked worktree. Repository configuration and GIT_* environment that could steer git are refused or dropped. The push keeps the user's pre-push checks; skipping them is an explicit parameter for a hook that cannot run in this environment. Generated-by: Claude Opus 5
…before the git command acts The config check ran once, in one working tree, before several more git calls. A linked worktree's commands also read the main checkout's worktree config, and a key added between the check and the final command would have taken effect. Generated-by: Claude Opus 5
…t calls The repository check alone left gaps outside the sandbox: a .gitattributes could switch on a globally configured filter during a checkout, the caller's HOME or XDG_CONFIG_HOME could stand in a different global config, a key added right after the check could still take effect, and push.followTags would publish tags beside the one ref. The same pins the local tracker's git uses now apply here. Generated-by: Claude Opus 5
…quire git 2.42 A remote named exactly like the push URL would have applied its own pushurl to the push, and a git older than 2.42 ignores GIT_ATTR_SOURCE, so attributes could still switch on a filter. A failing pre-push hook's explanation on stdout was also dropped from the error. Generated-by: Claude Opus 5
…scriptor A directory the agent can write, such as a worktree root inside the checkout, could be swapped for a symlink between the checks and the command, sending git to write a new worktree somewhere outside the sandbox. A per-protocol setting in the repository could also override protocol.allow. Generated-by: Claude Opus 5
… git directory A copy of the main checkout whose .git file points at the main git directory passed as a linked worktree, so worktree-sync could reset the main branch through it. Git also finds .git by name, so the checkout's git directory could be swapped between validation and the command. Generated-by: Claude Opus 5
…ectory A linked worktree's .git file lives in the tree the agent can write, so it could be repointed after validation; git is now told the validated directory instead of reading that file. The checkout's .git is also looked up by name again before acting, so a swapped parent directory shows. And the touch overlay did not recognise a vetted-op-git push, so a push waiting for a key touch showed no window. Generated-by: Claude Opus 5
…ed-op-git agent-guard's empty-rebase guard stops a plain force-push of a branch with no commits over its base, because that push closes the pull request it heads. A push through vetted-op-git did not pass that guard. Generated-by: Claude Opus 5
The vetted-op-git permissions in .claude/settings.json and the agent-guard change are inputs to the secure-setup fingerprint, so the constant in setup_preflight needs regenerating (prek's isolated-setup-fingerprint hook). Generated-by: Claude Opus 5
…unapproved dry runs Three gaps in vetted-op-git, each a way to run or steer code outside the sandbox: - git-push-branch drops its hooks parameter and always pushes with --no-verify. A pre-push hook (.git/hooks/pre-push, or a hook manager reading its config from the working tree) is code the agent can write, and the confirmation shows the push, not what the hook executes. The pre-push checks run in the sandbox before the push instead. - The final check before the command re-reads the worktree's common and own git directory and refuses if either moved since validation: a linked worktree's commondir file can be rewritten in between. - A dry run against a policy that is not an approved copy validates the parameters and runs no git command at all. Generated-by: Claude Opus 5
…n main Generated-by: Claude Opus 5
potiuk
force-pushed
the
vetted-ops-git-operations
branch
from
November 18, 2026 05:06
3beed20 to
0d9ea56
Compare
…t holds Git.anchor ignored a passed descriptor when the path already had one, and that descriptor was never closed. It now takes ownership: a passed descriptor is kept until Git.close, or closed at once when the path is already anchored. Tests cover both cases. Generated-by: Claude Opus 5
| def test_anchor_closes_a_passed_descriptor_for_a_path_it_already_holds(git: Git, tmp_path: Path) -> None: | ||
| path = Path(os.path.realpath(tmp_path)) | ||
| first = git.anchor(path) | ||
| second = os.open(path, os.O_RDONLY | os.O_DIRECTORY) |
|
|
||
| def test_anchor_keeps_a_passed_descriptor_for_a_new_path_until_close(git: Git, tmp_path: Path) -> None: | ||
| path = Path(os.path.realpath(tmp_path)) | ||
| fd = os.open(path, os.O_RDONLY | os.O_DIRECTORY) |
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vetted-op-gitruns exactly those steps as closed shapes, outside the sandbox and behind the sameaskconfirmation asvetted-op, bounded by the approved policy's new[git]table:git-push-branch: a push to the policy'sforkorupstreamrepository, with--force-with-leaseon the full SHA the caller expects (ornew). Built-in protected branches are refused, and upstream accepts only theupstream_pushglobs.git-worktree-sync,git-worktree-add,git-worktree-remove: move, create or remove a clean linked worktree (reset --keep, never--force).--no-verifyalways, and the pre-push checks run inside the sandbox before it. A pre-push hook is code the agent can write, and the confirmation shows the push, not what the hook would run.expected.json,.claude/settings.json, sandbox-lint, the agent-guard spelling guard, the Codex rules, the touch-overlay matcher and the secure-setup docs.What keeps git safe to run unsandboxed, all in
tools/vetted-ops/src/vetted_ops/git_ops.py:SAFE_LOCAL_KEY; a remote name may not look like a URL). This is checked in every working tree git runs in, and again right before the acting command.core.fsmonitor, gc and maintenance off;httpsandsshtransports (protocol.allow=neverplusGIT_ALLOW_PROTOCOL);core.sshCommandset to the user's global value;GIT_ATTR_SOURCEset to the empty tree (git 2.42+ required);--no-follow-tagson push;--no-verifyon push.GIT_*is dropped,HOMEcomes from the password database andXDG_CONFIG_HOMEis dropped..gitfile is never read again. A new worktree is created through its root's descriptor.commondirfile can be rewritten in between).Type of change
tools/*/withpyproject.toml)docs/,README.md,CONTRIBUTING.md)Test plan
tools/vetted-ops: 61 new tests intests/test_git_ops.py. They run against real repositories in a temp directory, with bare repositories standing in for the forge. Every guard above has a test that fails without it, including a root swapped for a symlink mid-operation, a repointed.gitfile, a rewrittencommondir, a plantedfilter,core.sshCommand,url.*.insteadOf, a pre-push hook that must not run, and a dry run against an unapproved policy that must not start git.ruff check,ruff format --checkandmypypass fortools/vetted-ops.sandbox-lintpasses on the new.claude/settings.jsonagainst the newexpected.json. The old settings fail only on the four missingvetted-op-gitentries.prek run --all-filesand the rest of the vetted-ops, sandbox-lint and overlay suites were run in a sandboxed session. That sandbox denies writes to.apache-magpie-overrides/tools/vetted-opsand.claude/**paths and blockspgrep, so the tests that create those paths fail there before and after this change. CI runs them.RFC-AI-0004 compliance
permissions.askand never inallow, and sandbox-lint enforces the pairing.Notes for reviewers (optional)
prek run --hook-stage pre-pushin the sandbox first..gitand its config by name. Identity and config are re-checked right before the acting command, but closing the last instant relies on the harness keeping the git directory write-protected, as Claude Code's sandbox does for.git/configand.git/worktrees./dev/fd/Nas--git-dirdoes not work on macOS git..from inside its own directory, so git names its administrative directory-(-1, …).Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Claude Opus 5)
🤖 Generated with Claude Code
https://claude.ai/code/session_01NyQq9U7i5HhjDgrQ9qd3gq