Repository navigation
Pin the GitHub Host for Every gh Child the Hub Scripts Start - #4502
Conversation
Most of the hub's gh calls named no host, so an exported GH_HOST moved an audit read, a review-loop read, or a merge to a host the registry never named. scripts/gh_graphql.py now gives every child it starts GH_HOST=github.com, through pinned_env(). spec/audit.py's gh() and scripts/handoff.py's run_gh() now run through that runner, and scripts/pr_review.py's _run(), which pr_merge.py's merge call also uses, passes the same environment. spec/audit_environments.py's names() duplicated spec/resolve_secrets.py's read_live_names(), and only the first pinned the host. Both now read through one resolve_secrets.read_names(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
spec/audit.py's check_secrets_names read the actions and dependabot secret names through one unpaginated gh() page, a third copy of the names reader. It now calls resolve_secrets.read_live_names, which paginates. gh() uses gh_graphql's HTTP_STATUS rather than a copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 52 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
A recorded local strict-review pass covers head |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, and the changes include regression coverage for host pinning across the affected subprocess call sites.
No open issues 🎉
What changed in this PR
This PR pins all hub-script gh subprocesses to github.com, preventing an inherited GH_HOST from redirecting reads or writes.
Changes:
- Add shared
pinned_env()handling inscripts/gh_graphql.py. - Route audit, secret, environment, handoff, review, policy, metrics, and merge operations through host-pinned subprocesses.
- Consolidate repository and environment name reads in
resolve_secrets.read_names. - Add regression tests covering host pinning across the affected call sites.
| File | Description |
|---|---|
| tests/test_resolve_secrets.py | Tests pinned secret-store reads and the consolidated names-reader behavior. |
| tests/test_pr_review.py | Tests host pinning for review and archive subprocesses. |
| tests/test_pr_merge.py | Tests host pinning for merge execution. |
| tests/test_handoff.py | Tests host pinning for handoff commands. |
| tests/test_gh_graphql.py | Tests pinned child environments, environment preservation, and GraphQL requests. |
| tests/test_backlog_metrics.py | Tests host pinning for backlog metric reads. |
| tests/test_audit.py | Updates audit fixtures for the shared environment-reader implementation. |
| tests/test_audit_helpers.py | Tests host pinning for audit REST reads. |
| tests/test_audit_environments.py | Updates environment-reader tests and pagination assertions for the shared reader. |
| tests/test_agent_policy.py | Tests host pinning for agent-policy reads. |
| spec/resolve_secrets.py | Adds the shared paginated names reader and routes secret reads through the pinned transport. |
| spec/audit.py | Routes audit reads through the pinned transport and shared live secret-name reader. |
| spec/audit_environments.py | Reuses the centralized names reader for environment checks. |
| scripts/pr_review.py | Applies the pinned environment to review subprocesses by default. |
| scripts/handoff.py | Uses the shared subprocess transport for pinned GitHub CLI calls. |
| scripts/gh_graphql.py | Adds the shared GitHub host pin and applies it to child processes. |
Review effort: Lite
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4502 +/- ##
========================================
Coverage 79.00% 79.01%
========================================
Files 50 50
Lines 16796 16795 -1
========================================
Hits 13270 13270
+ Misses 3526 3525 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
|
/review |
Action not completed
|
…4505) ## Summary The repo gate's one `gh` read named no host, and the Docker pin manifest had three parsers that disagreed. Both are fixed here. ### The gate's `gh` read is pinned to github.com `gh_read` ran `gh api` in the inherited environment. With `GH_HOST` exported to a reachable host that lacks the path, the 404 read as absent, so `sha-pin` could report a valid hub SHA as unresolvable. The child now runs under `gh_env()`, the process environment with `GH_HOST=github.com`. That is the same pin #4502's `gh_graphql.pinned_env()` sets. It is set in place rather than loaded from `gh_graphql.py` because one context cannot load it: a single-file fetch through `hub_fetch_run.py`. `repo_gate.py` has no companions there, and `gate_hub_root()` needs `spec/files.json`. That fallback would have to exist anyway, so loading the hub module elsewhere changed no behavior. The local review raised exactly that, and the first draft's two paths were collapsed into one. A test holds the gate's `GITHUB_HOST` equal to `gh_graphql.HOST`. Another sets `GH_HOST` to a constructed host and asserts the child still gets github.com. The existing read-only test read the 270-byte `scripts/repo_gate.py` shim rather than the gate, so it could never fail. It now reads the gate itself. ### The pin manifest has one parser `docker_lint.read_pins` is now the only parser of `.github/actions/docker-lint-pins/Dockerfile`. - The repo gate drops its `SHELLCHECK_PIN` regex and takes `read_pins(...)["shellcheck"]` from the hub's `docker_lint.py`. `check_composite_actions` loads that script and resolves the image once per run. It then hands both to `docker_unreachable`, for the pull, and the image to each body. A pin it cannot read, or a script that will not load, is one finding before docker is asked anything. `docker_lint.require_stages` is now the one check that a stage is pinned, used by `lint`, `--pin` and the gate. - The `docker-lint-pins` action drops its `sed`. `docker_lint.py` gains a small `--pin STAGE` mode that prints `STAGE=<image reference>` per stage. Where the manifest cannot be read, a stage is unpinned, or a stage is named twice, it prints nothing and exits 1. The action appends that to its outputs. On a failure, its one `::error::` annotation carries the script's reason. It calls the script it already locates, so the locate step now runs first. Before this, the `sed` accepted an empty tag (`FROM r.io/x:@sha256:... AS x`), which `read_pins` and the gate refused, and a failure left partial outputs written. Tests now run the empty-tag and duplicate-stage cases through all three readers, and the old action fails the new case. `scripts/README.md`'s `docker_lint.py` section documents `--pin`, and its repo-gate sentence now names the shellcheck pin as well as the pull. ### Where the action runs, and `python3` there `docker-lint-pins` has one user in the hub tree, `uses: $/.github/actions/docker-lint-pins` in `validate-task.yml`'s `lint` job (`Lint sources job`). A search of every tracked file found no other workflow, job or step that uses it. That job is `runs-on: ubuntu-latest` with no `container:`. Its own later steps already run `python3 "$DOCKER_LINT" --pull ...` (the EditorConfig, shell and PowerShell steps). In run 45877714910 on develop's head `f93f34a6`, `Validate sources job / Lint sources job` passed both `Read Docker lint pins step` and `Check EditorConfig step`, the second of which calls `python3`. On this pull request's head `1530a579`, the new `Read Docker lint pins step`, which calls `python3 "$DOCKER_LINT" --pin ...`, passed in run 45886897083, along with `Check EditorConfig step` and `Check shell scripts step`, which read its outputs. ## Test evidence - `uvx --with-requirements tests/requirements.txt coverage@latest run -m unittest`: `test_docker_lint` 74 OK, `test_repo_gate` 211 OK, `test_release_guards` 53 OK. - The new action-step cases fail against develop's `action.yml`. The empty tag exits 0 there, and every failing case left partial outputs written. - ruff check, ruff format --check and `uvx mypy@latest` are clean. The pre-commit hook passed. - `repo_gate.py --check composite-actions` ran live in Docker through the new pin path and found 0 issues. - With `GH_HOST=unresolvable.invalid`, `repo_gate.py --check sha-pin` resolved 8 of 8 same-owner pins. That held from the hub checkout and from a copy of `repo_gate.py` placed alone. Develop's file reported all 8 as "GitHub did not answer". - The action-step test is now skipped off POSIX, since it runs the runner's `python3`, which a Windows host may not have on PATH. ## Local review findings The first push listed four `introduced` findings that the local review's budget had left open. Copilot raised the same four on `1530a579`, plus a fifth on the read-once test. All are fixed in `acebe006` and `25129446`, and `eb2c231c` corrects the README sentence on a duplicate stage. - `check_composite_actions` resolved the shellcheck image a second time, outside any `try`. It now resolves it once and hands it on, and a pin it cannot read is a finding. - The read-once test mocked away the first read. `docker_unreachable` now takes the module and image rather than loading them. The test asserts one load and that `docker_unreachable` receives that module. It stubs the action read, so a host without PyYAML still runs it. - `require_stages` said a stage was not named where a line named it with a moving or empty tag. It now says the stage is pinned on no `FROM <image>:<tag>@sha256:<digest> AS <stage>` line. - `hub_script`'s docstring listed `gh_graphql.py`, which no gate check loads. That line is restored. Closes on promotion: #4504 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Chores** * Docker image pin checks now use the shared pin manifest and report clear errors for missing or invalid pins. * Repository shell checks use the pinned ShellCheck image, with Docker or pin-loading problems reported as reasons checks cannot run. * GitHub API reads consistently target GitHub.com, regardless of inherited host settings. * **Tests** * Expanded coverage for pin validation, error reporting, and reuse of the resolved ShellCheck image. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…s, Environment Secret Audit, and macOS Bash Floor (#4485) Promotes the 26 pull requests that landed on develop since the last promotion (#4428), from the away-mode backlog burndown run. - #4447: Bump markdownlint-cli2-action from 25.0.0 to 25.1.0. - #4449: Have the agent open and drive the promotion after an audit's file fix merges. - #4453: Pass over a signal handled as the prose gate's first handler starts. - #4456: Record a managed copy for claude and codex in install-agents and report any other copy as a stray. - #4457: Name the PowerShell suppression form and correct the Python CI backstop text. - #4458: Read the metrics report's reviewed heads from the gate's one filter (part of #3880, completed by #4481). - #4460: Cross-check Python directories against Dependabot's pip and uv entries (items 2 and 3 of #2286, which stays open for item 1). - #4461: Pin the Docker lint images by digest through a Dependabot-tracked manifest. - #4464: State the platform weighting and correct the hook-promotion worked example. - #4463: Key Qodo findings without links or commit hashes and ask dismissal by title and location. - #4465: Hand a caller's hook-input to the validate and resolve-upstream hooks. - #4466: Require an empty workflow-level permissions block on entry-point callers. - #4467: Remove the npm and bun upgrade paths no managed tool reaches. - #4469: Add a hub-hosted script that enables a clone's hook framework once. - #4472: Select each repository's Python line from its root `.python-version` (the part of #4187 needing no decision; #4187 stays open). - #4479: Report dotnet and powershell as unmanaged while Microsoft's feed is unconfigured. - #4477: Bound the shell trap's child wait and give the heading search a file. - #4480: Check deployment environment secret and variable names in the audit. - #4478: Add a macOS bash 4.4 floor with a platform-scoped host tool entry. - #4481: Build the gate's comment readers on one trusted-comment reader. - #4484: Record the measured absence of a git floor for `--end-of-options`. - #4496: Narrow the Qodo acknowledgment key's normalization to a link and a hash after `commit`. - #4500: Pass over a signal handled as the hook enabler's first handler starts. - #4502: Pin the GitHub host for every `gh` child the hub's Python scripts start. - #4503: Write the Docker pull retry once, with one backoff schedule. - #4505: Pin the repo gate's `gh` read and parse the Docker pin manifest once. ## Release notes for callers - #4472: A caller passing no `python-versions` input and carrying no root `.python-version` moves from Python 3.13 to 3.14 for its `unit-test` leg and its `lint` job's Python steps once its hub pin reaches this change. Its nested check name moves from `Unit test job (Python 3.13)` to `Unit test job (Python 3.14)`, and its Codecov flag from `python-3.13` to `python-3.14`, so a `.codecov.yml` naming the old flag stops matching. Its `lint` job warns on each run until it carries a selector. A caller whose `requires-python` or locked dependencies exclude 3.14 adds a `.python-version` before moving its pin. A `.python-version` naming no `X.Y` line, or an explicit `python-versions` whose first entry differs from the file's line, now fails validate. - #4479: The Linux `install-tools.sh --json` report schema moves from 1 to 2, because a not-installed `dotnet` or `powershell` can now read `unmanaged` with `installed: null`. A hand-installed amd64 `powershell` with no Microsoft feed now reads `unmanaged`. The Windows `-Json` report stays at schema 1. - #4466: Each entry-point caller must declare an empty workflow-level `permissions: {}` block. A site repository's `deploy-site.yml` carrying only job-level blocks now reports this as drift, and the fix belongs to that repository. - #4461: Dependabot's docker ecosystem listing tags on mirror.gcr.io for the shellcheck and shfmt lines is unconfirmed until its first docker run for that directory. - #4478: macOS now has a bash 4.4 floor, met by Homebrew's bash ahead of the system bash on `PATH`. Not yet verified on a native macOS host. - #4480: The audit gains the `secrets.environments` check. Registry `environments[]` entries may now declare their secret and variable names. - #4463 and #4496: The Qodo acknowledgment key changed. A `fleet-finding-ack` already posted on a still-open pull request stops matching its finding once a caller's hub pin reaches this change. Post it again, since `merge` refuses until then. - #4502: Every `gh` child the Python scripts under the hub's `scripts/` and `spec/` start now runs with `GH_HOST=github.com`, so an exported `GH_HOST` no longer moves their reads and writes. #4505 pins the repo gate's own `gh_read` the same way. The `gh-write-guard` hook (#4501) and the shell and PowerShell scripts are unchanged. - #4503: The `validate-task.yml` EditorConfig, shell, and PowerShell lint steps now pull their images through `docker_lint.py --pull`, with one retry schedule of 3 attempts waiting 15s, then 30s. The `docker-lint-pins` action gains a `docker-lint` output naming that script at the calling workflow's own ref. A caller pinned before this change keeps its inline retry. - #4505: The `docker-lint-pins` action now reads the pin manifest through `docker_lint.py --pin` rather than `sed`, so its step runs `python3`. It now refuses an empty tag or a stage named twice, which the old `sed` accepted, and on a failure it writes no outputs and one `::error::` annotation carrying the reason. - A fleet resync is owed, because carried text changed: AGENTS.md, GOVERNANCE.md, CODESTYLE.md, and several skills. ## Findings from the local strict review The attested local pass on c25ec49 (`main...develop`) raised five findings. Their outcomes: - Tracked: the hub's own `dependabot.ecosystems` DRIFT on `/tests` is the question #4459 holds, so it changes nothing here. - Fixed by #4500: `scripts/enable_hooks.py` `on_signal` now passes over a signal handled as its first handler starts. - Fixed by #4503: the bounded Docker pull retry is now written once, `scripts/docker_lint.py` `pull_image`, with one schedule. - Fixed by #4502: `spec/audit_environments.py` `names()` is gone, and both environment readers read through `spec/resolve_secrets.py` `read_names`. - Release note: the Qodo acknowledgment key change from #4463 and #4496 is stated under "Release notes for callers" above. The attested local pass on f93f34a (`main...develop`) raised 57 findings. Their outcomes: - Declined, 52 `prose_lint` `comment-added` lines: each comment was added by a feature pull request carrying the `comments` label (#4456, #4461, #4463, #4465, #4467, #4472, #4480), and the promotion re-carries them without that label. - Tracked: `spec/audit_dependabot.py:93`, the hub's own `/tests` pip drift, is the question #4459 holds. - Tracked: the nested-signal guard missing at `scripts/docker_lint.py:416`, `scripts/backlog_metrics.py:1290`, and `catalog/snippets/hub_fetch_run.py:193` is the class #4452 holds. - Release note: the Qodo key change at `scripts/pr_review_answers.py:158` is stated above. - Fixed by #4505: `.github/actions/repo-gate/repo_gate.py` `gh_read` now starts its `gh api` child under `gh_env()`, which pins `GH_HOST=github.com`. - Fixed by #4505: `scripts/docker_lint.py` `read_pins` is now the pin manifest's one parser. The repo gate dropped `SHELLCHECK_PIN`, and the `docker-lint-pins` action dropped its `sed` for `docker_lint.py --pin`. The attested local pass on 3183644 (`main...develop`) raised 53 findings. Their outcomes: - Declined, 51 `prose_lint` `comment-added` lines: the same comments the pass on f93f34a named, less the `docker-lint-pins` `action.yml` line #4505 removed, each added by a feature pull request carrying the `comments` label. - Tracked: the nested-signal guard missing at `scripts/docker_lint.py:448`, `scripts/backlog_metrics.py:1290`, `scripts/pr_review.py:2174`, and `catalog/snippets/hub_fetch_run.py:193` is the class #4452 holds. - `introduced`, design, `scripts/docker_lint.py:856`: `resolve_digest` runs one more `docker image inspect` per linter to read a digest the pin manifest's tag-and-digest reference already gives, since #4461 pins every image, and it takes `RepoDigests[0]`, which can name another repository holding the same image. Deferred to #4508 by the maintainer's decision, which is this finding's outcomes. Fixes #3468 Fixes #3880 Fixes #4408 Fixes #2070 Fixes #4473 Fixes #4474 Fixes #2594 Fixes #4327 Fixes #4450 Fixes #1783 Fixes #3325 Fixes #3917 Fixes #4448 Fixes #1164 Fixes #1613 Fixes #1727 Fixes #4403 Fixes #4407 Fixes #4158 Fixes #4210 Fixes #4429 Fixes #4406 Fixes #4488 Fixes #4498 Fixes #4489 Fixes #4499 Fixes #4504 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Summary
Most of the hub's
ghcalls named no host. So an exportedGH_HOSTmoved a read or a write to a host the registry never named. WithGH_HOST=other.example,spec/audit.pyreadrepos/ptr727/<repo>from that host. Its environment checks in the same run stayed on github.com. The registry names every repository on github.com, so the host is now pinned for everyghchild these scripts start.The pin is one mechanism in one place.
scripts/gh_graphql.pygainspinned_env(), the process environment withGH_HOST=github.com. Itsrun_subprocessnow passes that to every child. The pin goes in the child environment rather than in--hostname, since--hostnameexists ongh apialone.gh help environmentsaysGH_HOSTsets the host for a command that names none. Reads run withGH_HOSTset to an unresolvable constructed host confirmed it.gh apiREST and GraphQL calls follow it, and so dogh pr viewandgh issue listgiven--repo OWNER/REPO. Each failed witherror connecting tothat host. Each answered from github.com withGH_HOST=github.com.Each listed site now reaches the pin:
spec/resolve_secrets.py: all four reads go throughgh_run, which callsrun_subprocess.scripts/agent_policy.py,scripts/backlog_metrics.py,scripts/gh_graphql.py: already ran throughrun_subprocess.spec/audit.pygh(): now runs throughrun_subprocess. The file is at 2988 of its 3000.scripts/handoff.pyrun_gh(): now runs throughrun_subprocess, which does the same UTF-8 decode andOSErrormapping it did by hand.scripts/pr_review.py_run(): passespinned_env()unless a caller names its ownenv. That coversgh_rest, the escape-flag probe, the tarball read, andscripts/pr_merge.py'sgh pr merge, which runs throughcore._run. Noghcall passes its ownenv. The file stays at 2196 of its 2200.The trusted comment on the issue asked for one host-pinned names reader in place of the
spec/audit_environments.pynames()andspec/resolve_secrets.pyread_live_namespair. That reader is nowresolve_secrets.read_names(path, key).read_live_namesand the environment check both read through it, andnames()is gone. The argv the two built is unchanged, since--hostnameis no longer needed. Sotests/test_configure_secrets.py's stubghmatches as before.Closes on promotion: #4489
Out of Scope
Pre-existing findings, filed
host-setup/agent-safety/claude/gh-write-guard.py_live_branch_rules, correctness: its branch-rules read names no host, soGH_HOSTmoves it. Filed as Pin the GitHub Host for the Write Guard's Branch-Rules Read #4501.Local review findings
spec/audit.pycheck_secrets_namesread the repository stores through an unpaginatedgh()page, a third copy of the names reader. Fixed: it now callsresolve_secrets.read_live_names, which paginates.spec/audit.pykept its own copy ofHTTP_STATUS. Fixed:gh()usesgh_graphql's.audit.gh()ontoresolve_secrets.gh_runwas declined.gh_graphql's docstring says each caller maps a failed run to its own exit contract, since the contracts differ.gh_runnames a repository and raisesResolveError.audit.gh()also reads non-repository paths, and its callers catchRuntimeError. Both share the transport,run_subprocess.Tests
tests/test_gh_graphql.py: a real child started byrun_subprocessunderGH_HOST=ghe.example.invalidreadsgithub.com.pinned_env()keeps the rest of the environment, and a GraphQLrequestruns pinned.tests/test_pr_review.py: a real child started by_runreadsgithub.com, andgh_restandhead_carriesboth pass the pinned host.tests/test_audit_helpers.py,tests/test_resolve_secrets.py,tests/test_handoff.py,tests/test_agent_policy.py,tests/test_backlog_metrics.py,tests/test_pr_merge.py: each site run underGH_HOST=ghe.example.invalidpassesGH_HOST=github.comto its child.pinned_env()reduced to a plain copy of the environment, and passes with the pin.resolve_secrets.read_names.unittestsuite,ruff check,ruff format --check, andmypyare clean.🤖 Generated with Claude Code