Skip to content

fix(security): give the GitHub token only to the calls that need it - #5266

Merged
dan-petty merged 12 commits into
mainfrom
fix/5265-github-token-scope
Nov 13, 2026
Merged

dan-petty merged 12 commits into
mainfrom
fix/5265-github-token-scope

Conversation

@dan-petty

@dan-petty dan-petty commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

The GitHub token of the session now reaches only the git and gh calls that need it.

  • Only a git call that reaches a remote gets the token.
  • A gh call reads the token from a private folder made for that call (GH_CONFIG_DIR, 0700/0600), not from its environment. No temp candidate is in the current folder. The folder goes after the call.
  • A child that gets the token starts in its own session, and a timeout kills its process group.
  • The implement Job runs each network git call in a new bare git folder that reads no global, system or clone configuration and no hook. An unknown git setting, attribute driver or alternates file in a runner, or a linked shallow file, stops the item (class git_config).
  • In a runner, leftover processes end before and after each child that gets the token.
  • A plan verification command runs git only as ! git grep.
  • SECURITY.md item 15 states the limits.

Closes #5265
Change: openspec/changes/archive/2026-11-12-5265-github-token-scope/

@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Details, checks and remaining risks (the PR body is the short squash message):

The GitHub token of the session now reaches only the git and gh calls that need it, in a place that no other program of the call reads.

Why: the process runner gave the token to each git child and to each gh child in the environment. A local git call (git add, git commit) needs no token, and a program that the configuration of its repository names runs as its child. The implement job ran its network git calls in the clone, so git read configuration, hook and attribute files that the agent of a step can write. gh gives its environment to each --jq filter. The private advisory of the repository holds the details.

What changes:

  • core/process.py: only a git child that reaches a remote (push, fetch, pull, ls-remote, clone, and remote set-head, show, update, prune) gets GH_TOKEN (git_reaches_remote). A gh child gets no token in its environment: each call gets a new private folder (0700) with the token in hosts.yml (0600), GH_CONFIG_DIR and GH_HOST=github.com, under $XDG_RUNTIME_DIR/gh-config or <data directory>/gh-config. The runner removes the folder after the child, also after an error or a timeout. build_subprocess_env accepts GIT_CONFIG_GLOBAL=/dev/null and GIT_CONFIG_NOSYSTEM=1, and only these values.
  • roadmap/implement/git_isolation.py (new): OriginGit runs each network git call of the implement job, also the reads of add_worktree, in a new bare git folder that links the objects of the clone. The call reads no global, system or clone configuration and no hook, has an empty home folder and an empty credential.helper before the trusted helper, and uses the URL of origin that the job read before its first item. The job ends every leftover process before it makes the folder and again just before the call. A push sends a commit and moves the remote-tracking ref of the branch.
  • check_settings: in a runner, when each turn of the agent ends and before each network call, a git key, an attribute driver or an alternates file that the job does not allow stops the item with the new failure class git_config (action wait). The stop names keys, not values, and pushes nothing.
  • roadmap/request_plan.py: the dry-run plan of devops roadmap implement shows the new push.
  • SECURITY.md (item 15), docs/ROADMAP_WORKFLOW.md, process_hardening.py, implement_run.py: the invariants. docs/ERRORS.md is generated again for GitSettingsError.

The two-container Job of #3700 stays the structural fix.

Plan: openspec/changes/archive/2026-11-12-5265-github-token-scope/.

Fail-to-pass (uv run devops ci fail-to-pass --base origin/main, exit 0): 17 tests fail on the base and pass on the branch, 933 pass on both, 2 modules do not collect on the base (they import names that the fix adds). The failures on the base include:

  • test_roadmap_implement_token_isolation::test_no_program_that_the_home_folder_names_sees_the_token and ::test_no_program_that_the_configuration_of_the_clone_names_sees_the_token: a hook that a turn of the agent writes into the home folder or the clone saw the token.
  • test_process::test_a_local_git_child_gets_no_token[add -A] and 5 more cases: a local git child got the token.
  • test_process::test_a_gh_child_gets_the_token_in_a_private_folder_that_goes_after_the_run[success|failure|timeout], ::test_a_gh_child_of_the_app_gets_the_installation_token_in_the_private_folder, ::test_a_gh_child_with_no_runtime_folder_gets_its_folder_in_the_data_directory: a gh child had the token in its environment.

Local checks (GitHub Actions do not run in this fork):

  • uv run devops ci --check --only lint,format,typecheck,docs,openspec: the 6 rows pass on the final tree.
  • uv run pytest on the changed and covering modules (tests/core/test_process.py, test_subprocess_env_boundary.py, test_roadmap_implement_planned_run.py, tests/roadmap/implement/test_roadmap_implement_{git_isolation,token_isolation,job}.py, tests/roadmap/test_roadmap_{failure,dry_runs}.py, tests/github/test_github_{app_identity,client,rate_limiter}.py, tests/git, tests/invariants/test_change_folders.py): 1303 passed.
  • uv run pytest tests/roadmap tests/commands tests/config tests/invariants tests/security tests/ai/mcp: 13959 passed, 1 failed. tests/core tests/roadmap/implement tests/github tests/git: 4803 passed after the fixes of this branch, 2 failed. The 3 failures (test_review_facts::test_the_facts_of_a_version_window, test_git_contract::...[review_window] twice) fail the same way on the base commit in this devcontainer.
  • The two Job-level isolation tests passed 3 runs in a row.
  • Live, through uv run devops gh api: a probe that reads only lengths found no token in the environment of a gh filter, and an authenticated call still worked.
  • Not run here: the Service Image Tests, which need a build of the Service image; this change starts no Python child and changes no image input.
  • Pending a person: one implement Job in the cluster, to see its pushes in the Job log; the live devops roadmap eval implement run of the advisory needs a model run.

@dan-petty
dan-petty force-pushed the fix/5265-github-token-scope branch 2 times, most recently from 9ccf46b to 64ab4e6 Compare November 12, 2026 23:14
…search

A plan can name a git call as a verification command. The step runs it in
the checkout, where git reads the configuration that the agent can write,
and the process runner gives a git call that reaches a remote the token.
The reader of a verification command now refuses git in any form other
than the negative search. The step, the stage gate, the plan reader and
the amendments read the same rule. No plan pull request of the Service in
the last 14 days uses git in another form.
… a network call

The network git call of the implement job checked the git settings of the
checkout before it ended the leftover processes. A refused setting stopped
the call before any sweep, and the job then went on to its GitHub writes.
The call now ends the leftover processes first. A refused setting at the
push of a wip: commit or of a checkpoint stops the item with the class
git_config at once, and a refused setting at the push of a stop gives the
stop that class.
…Hub token in a runner

In a runner, the process runner now ends every leftover process of the job
before a gh child or a git child that reaches a remote starts, before the
token folder of a gh child exists. A process that survives stops the item.
The job runs code of the checkout, such as tests and hooks, after the end
of a turn, so the end of a turn was not the last point where such a
process could start.

The private gh configuration folder no longer depends on the current
folder. It goes into the runtime folder of the user (platformdirs), else
into the temp folder of the system, else into the data directory when it
is absolute. When none works, the call stops with an error that names the
settings. An async call looks up the token in a thread and makes the
folder in the thread of the event loop, so a cancelled call leaves no
folder.
The new git folder of a network call linked the objects of the clone, but
not its shallow file, so a fetch in a shallow clone walked into parents
that the clone does not hold and failed. The folder now gets a copy of the
shallow file, and a fetch that changes it writes it back into the clone.
SECURITY.md item 15 and docs/ROADMAP_WORKFLOW.md now name where the
private gh configuration folder goes, the end of leftover processes before
each child with the token in a runner, the rule for git in a verification
command, and the limits: a repository with Git LFS or a driver of its own
cannot use the implement Job, a gh call reads no gh configuration of the
person, and the eval of the implement step runs only outside a runner.
…-back

- The private gh folder goes directly into the runtime folder, with no
  folder of devops-cli between them, so a link below the runtime folder
  cannot move it. A runtime or temp folder that resolves into the
  current folder is skipped.
- A child that gets the session's token starts in a session of its own,
  and a timeout kills its whole process group. In a runner, the sweep of
  leftover processes runs again after the child.
- The copy of the shallow file opens it with O_NOFOLLOW, and the
  write-back uses a new file with a random name and os.replace.
- The text of a surviving process names no step, and the dry-run fetch
  line says that it is the short form of the refspec.
@dan-petty
dan-petty force-pushed the fix/5265-github-token-scope branch from 64ab4e6 to cdc8b46 Compare November 13, 2026 00:27
@dan-petty

Copy link
Copy Markdown
Owner Author

Fix round 2 (head cdc8b46, rebased on origin/main f9ca1b4).

  • The gh folder goes directly into the checked runtime folder. A runtime or temp folder in the current folder is skipped (process.py _runtime_folder, _temp_folder, _check_outside_current_folder).
  • A child that gets the token starts in its own session, and a timeout kills its process group (_run_in_own_session). In a runner, the sweep runs again after the child (_pinned).
  • The shallow file is read with O_NOFOLLOW and written back with mkstemp and os.replace (git_isolation.py _read_shallow, keep_shallow).

Each new test failed on the previous head (64ab4e6) for the expected reason, and passes now.

  • uv run devops ci fail-to-pass --base origin/main: exit 0, 94 failed on base, 4 test modules do not collect on base.
  • Covering tests (tests/core, tests/github, tests/roadmap/implement, tests/roadmap/test_roadmap_plan_read.py, tests/invariants): 5438 passed.
  • uv run devops ci --check --only lint,format,typecheck,docs,openspec,security: all pass.

@dan-petty
dan-petty marked this pull request as ready for review November 13, 2026 00:42
@dan-petty
dan-petty merged commit 38266c7 into main Nov 13, 2026
30 checks passed
@dan-petty
dan-petty deleted the fix/5265-github-token-scope branch November 13, 2026 00:53
dan-petty pushed a commit that referenced this pull request Nov 13, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.125.1](v0.125.0...v0.125.1)
(2026-11-13)


### Bug Fixes

* **security:** give the GitHub token only to the calls that need it
([#5266](#5266))
([38266c7](38266c7)),
closes [#5265](#5265)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): give the GitHub token only to the calls that need it

1 participant