Skip to content

fix(tools): derive HTTPS identity from the host grant, drop provider tables - #412

Merged
github-actions[bot] merged 2 commits into
mainfrom
fix/sandbox-git-writes-provider-free
Aug 20, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
fix/sandbox-git-writes-provider-free

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Follow-up to #411. Removes the last provider-specific tables from confined-spawn credential projection, and fixes two .git policy bugs found while verifying gh against the real sandbox.

Identity is derived from the granted host

https_cli_env mapped hosts to credential env vars with a hardcoded table (github.com → GH_TOKEN/GITHUB_TOKEN, gitlab.com → GITLAB_TOKEN, everything else → nothing). Replaced by token_env_name, which uppercases the first DNS label of the granted host: example.com → EXAMPLE_TOKEN, my-git.internal → MY_GIT_TOKEN, bare IPs → none. Self-hosted forges now get a token env var; GitHub gets GITHUB_TOKEN as a consequence of the rule rather than a special case.

Also isolates XDG_CONFIG_HOME / XDG_CACHE_HOME / XDG_STATE_HOME into the spawn-local identity dir, so an HTTPS CLI does not fall through to the host config and OS secret store — which is blocked in-sandbox and produced a confusing half-authenticated state.

No provider name drives behavior anywhere in the codebase after this.

.git writes are detected per command segment

needs_git_writes keyed off the leading executable of the whole command line, so a git write in any later segment was denied — make release && git push lost the carve-out because make led the line. It now scans every segment, split on the shell operators that start a new command.

Frontends that shell out to git are deliberately not enumerated. Verified against real gh in the sandbox: a frontend needs .git writes only to auto-push a branch, which it cannot do without a TTY to prompt on. The working shape is an explicit git push, which this rule already covers, including chained in one command line.

.git/hooks stays read-only even for publish spawns

Hooks are the one part of .git that is executed rather than read, and one written inside the sandbox runs with the user's full privileges the next time they use git outside it. Publishing never writes a hook, so the carve-out now stops short of them. This closes a hole that was open before this branch too.

Verification

Driven against real gh 2.97 through the actual sandbox and egress proxy with a **.github.com grant. Pushes went to a local bare remote; nothing was sent to GitHub and no PR was created by the probes.

Probe Result
gh auth status ✓ Logged in to github.com account … (GITHUB_TOKEN) — projected, not host keyring
gh api user --jq .login authenticated
git commit --allow-empty ok — local git unaffected with no grant needed
git push -u local HEAD ok, upstream tracking set (.git/config write)
gh pr create --head feature --dry-run Would have created a Pull Request with: …
git push local HEAD && gh pr create … --dry-run both succeed — segment scan sees the git
gh --version && printf x > .git/refs/heads/sneak denied
printf x > .git/hooks/post-checkout denied

cargo fmt --all -- --check clean, cargo clippy --all-targets zero warnings, cargo test --workspace 2211 passed / 0 failed.

Known gap

GITHUB_PERSONAL_ACCESS_TOKEN reaches confined spawns via host environment inheritance rather than projection. That is an inheritance question in PROVIDER_CREDENTIAL_ENV, unrelated to the tables removed here, and is left for a separate change.

Spawn policy no longer keys off gh or github.com. A host(...) allow
fills HTTPS credentials on the host via git credential, rewrites
git@<host>: remotes to HTTPS (SSH cannot use CONNECT), and serves
those hosts through a spawn-local git helper. Git-dir writes follow
git frontends, not a forge name. GH_TOKEN remains only as an adapter
for HTTPS CLIs that do not speak git-credential.
`needs_git_writes` keyed off the leading executable of the command line,
so a git write in any later segment was denied: `make release && git
push` lost the carve-out because `make` led the line. Scan every segment
instead, split on the shell operators that start a new command.

Frontends that shell out to git are deliberately still not enumerated.
Verified against real `gh` in the sandbox: a frontend needs `.git` writes
only to auto-push a branch, which it cannot do without a TTY to prompt
on, so the working shape is an explicit `git push` — which this rule
already covers, including when the two are chained in one command line.

Also stop `.git/hooks` being writable when the carve-out is lifted. Hooks
are the one part of `.git` that is executed rather than read, and one
written inside the sandbox runs with the user's full privileges the next
time they use git on the host. Publishing never writes one.
@github-actions
github-actions Bot enabled auto-merge (squash) August 20, 2026 08:23
@github-actions
github-actions Bot merged commit 5e2d4a4 into main Aug 20, 2026
8 checks passed
mohitranka added a commit that referenced this pull request Aug 21, 2026
…tables (#412)

* refactor(tools): project HTTPS identity from the host grant

Spawn policy no longer keys off gh or github.com. A host(...) allow
fills HTTPS credentials on the host via git credential, rewrites
git@<host>: remotes to HTTPS (SSH cannot use CONNECT), and serves
those hosts through a spawn-local git helper. Git-dir writes follow
git frontends, not a forge name. GH_TOKEN remains only as an adapter
for HTTPS CLIs that do not speak git-credential.

* fix(tools): detect git writes per command segment, protect .git/hooks

`needs_git_writes` keyed off the leading executable of the command line,
so a git write in any later segment was denied: `make release && git
push` lost the carve-out because `make` led the line. Scan every segment
instead, split on the shell operators that start a new command.

Frontends that shell out to git are deliberately still not enumerated.
Verified against real `gh` in the sandbox: a frontend needs `.git` writes
only to auto-push a branch, which it cannot do without a TTY to prompt
on, so the working shape is an explicit `git push` — which this rule
already covers, including when the two are chained in one command line.

Also stop `.git/hooks` being writable when the carve-out is lifted. Hooks
are the one part of `.git` that is executed rather than read, and one
written inside the sandbox runs with the user's full privileges the next
time they use git on the host. Publishing never writes one.
mohitranka added a commit that referenced this pull request Sep 11, 2026
…tables (#412)

* refactor(tools): project HTTPS identity from the host grant

Spawn policy no longer keys off gh or github.com. A host(...) allow
fills HTTPS credentials on the host via git credential, rewrites
git@<host>: remotes to HTTPS (SSH cannot use CONNECT), and serves
those hosts through a spawn-local git helper. Git-dir writes follow
git frontends, not a forge name. GH_TOKEN remains only as an adapter
for HTTPS CLIs that do not speak git-credential.

* fix(tools): detect git writes per command segment, protect .git/hooks

`needs_git_writes` keyed off the leading executable of the command line,
so a git write in any later segment was denied: `make release && git
push` lost the carve-out because `make` led the line. Scan every segment
instead, split on the shell operators that start a new command.

Frontends that shell out to git are deliberately still not enumerated.
Verified against real `gh` in the sandbox: a frontend needs `.git` writes
only to auto-push a branch, which it cannot do without a TTY to prompt
on, so the working shape is an explicit `git push` — which this rule
already covers, including when the two are chained in one command line.

Also stop `.git/hooks` being writable when the carve-out is lifted. Hooks
are the one part of `.git` that is executed rather than read, and one
written inside the sandbox runs with the user's full privileges the next
time they use git on the host. Publishing never writes one.
mohitranka added a commit that referenced this pull request Sep 11, 2026
…tables (#412)

* refactor(tools): project HTTPS identity from the host grant

Spawn policy no longer keys off gh or github.com. A host(...) allow
fills HTTPS credentials on the host via git credential, rewrites
git@<host>: remotes to HTTPS (SSH cannot use CONNECT), and serves
those hosts through a spawn-local git helper. Git-dir writes follow
git frontends, not a forge name. GH_TOKEN remains only as an adapter
for HTTPS CLIs that do not speak git-credential.

* fix(tools): detect git writes per command segment, protect .git/hooks

`needs_git_writes` keyed off the leading executable of the command line,
so a git write in any later segment was denied: `make release && git
push` lost the carve-out because `make` led the line. Scan every segment
instead, split on the shell operators that start a new command.

Frontends that shell out to git are deliberately still not enumerated.
Verified against real `gh` in the sandbox: a frontend needs `.git` writes
only to auto-push a branch, which it cannot do without a TTY to prompt
on, so the working shape is an explicit `git push` — which this rule
already covers, including when the two are chained in one command line.

Also stop `.git/hooks` being writable when the carve-out is lifted. Hooks
are the one part of `.git` that is executed rather than read, and one
written inside the sandbox runs with the user's full privileges the next
time they use git on the host. Publishing never writes one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant