Repository navigation
feat(nix): mint the agents' GitHub App token in dotfiles - #532
Conversation
|
@codex review |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Review summary One blocking finding.
I found nothing else worth flagging. The permission scoping, atomic 0600 write, stdin-passed credentials and the key-deny checks look right. |
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Review summary: no P0–P2 findings. I read the full diff (the mint script, the Bats suite and helper, the Nix wiring, What I checked:
P3 notes, not inline comments:
|
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Review summaryRead-only review of the new Findings
Checked, no problem found
No P0 or P1 findings. |
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Review summaryNo P0 or P1 findings, and no inline comments. I read the whole diff and did not run the Bats suite or the Nix checks. The review is by reading only. What I checked
Residual notes, none blocking
|
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Review summaryNo P0–P2 findings. I read the full diff: the mint script, its Bats spec and helpers, the launchd job, the Nix checks, the ADR, and the lock bump. I did not run the tests or Checked and found sound:
P3 (optional, no change needed to merge): Known trade-off, already recorded in ADR-0055: a long-running 🤖 Generated with Claude Code |
Sign an RS256 App JWT, mint a token for the App's only installation, and replace the gh hosts.yml in the given config dir atomically with mode 0600, keeping the current file on any failure. Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…harness Add the agent-github-token launchd agent on both Macs, keeping the App ID, key path and gh config dir, and drop programs.agent-harness.github, which agent-harness no longer provides. Record the ownership move in ADR-0055. Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Request the token with an explicit permission list from the launchd job, so permissions later added to the App do not reach agents, and revoke the token of the previous hosts.yml once the new one is in place so at most one agent token is live. A 401 on revoke means it already expired; other failures are logged without any token. Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude, Codex and Antigravity must each deny reading the GitHub App key, and a newly rendered provider fails the check until it is covered. Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude Code env and Codex shell_environment_policy.set do not expand ~, so the agent source cannot name the config dir; dotfiles sets it next to NVIM_LOG_FILE. Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
agent-harness 2008c43 drops the github option and composedSettings; agent-config ac335be (furedea/agent-config#286) denies reading ~/.ssh for every provider. The checks now compose the provider settings the way the agent-harness module does, and the old option counts as removed when reading it fails. Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The launchd job's TOOLS_PATH has no sed, so every run after the first exited 127 before replacing hosts.yml. Read the previous token with bash instead, and run the Bats specification in a Nix check with only the job's pinned tools so a missing tool fails there. Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… key Claude Code reads Read(/path) relative to the project, so such an entry does not protect the key and must not satisfy the contract. Refs #531 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A gh process keeps the token it read at start, so revoking the previous token cut off a gh run watch that began just before a run. Keeping the replaced hosts.yml as hosts.previous.yml and revoking the token it held lets such a process run until the run after. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
agent-harness 0.10.0 renders MCP servers declared once in the source. Co-Authored-By: Claude Opus 5.5 <[email protected]>
4498810 to
775a3d0
Compare
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Review summaryI found no P0, P1 or P2 issues, so I posted no inline comments. I read the whole diff and traced these paths:
P3 (not tied to a line): the PR description is stale in two places.
Please update the description so it matches what merges. The owner-facing trade-off is described differently in the description and the ADR. I did not run the bats suite or |
…guard rely on it (#290) エージェント用の gh 設定ディレクトリ `~/.config/agent-harness/gh` を全 provider で書込み禁止にし,gh ガードはそれを根拠に「literal な `--repo` の読み取り + 同じ行の別コマンド」で確認を求めなくなる. 宣言は `harness_roots.json` を一般化した `write_protected_paths.json`(各項目に `purpose`)に移した. 判断事項: マージ前に下の「dotfiles が満たすべきこと」と「マージ後の確認」. Refs #289(#282 の続き,#181 の暫定段階) ```mermaid flowchart LR D[write_protected_paths.json] --> C[Claude: Edit deny + sandbox denyWrite] D --> X[Codex guarded: read] D --> A[Antigravity: write_file deny] D --> F[guard_file.py harness: 全 provider] D --> G[gh guard] G -->|GH_CONFIG_DIR と config.yml / hosts.yml の実体が gh-config 宣言内| R[--repo 読み取りは行の他コマンドで ask しない] ``` | 状況 | 変更前 | 変更後 | | --- | --- | --- | | Edit/Write で `~/.config/agent-harness/gh/config.yml` | 通る | 拒否(「ホストの dotfiles で変える」と案内) | | `git fetch -q origin && gh issue list --repo o/r`(保護された `GH_CONFIG_DIR`,Claude / Codex) | ask | allow | | 同上,Antigravity / Devin / dsh / Hermes / Pi | ask | ask(シェルの書込みを防ぐ sandbox 規則がない) | | 同上,`GH_CONFIG_DIR` 未設定・相対・存在しない・宣言外・設定ファイルが宣言外へ link・宣言パス自体が link | ask | ask | | 行に `export GH_HOST=…` / `HOME=… gh` / `XDG_CONFIG_HOME=… gh` / `export HTTPS_PROXY=…` | ask | ask | | `--repo` なしの読み取り + 別コマンド | ask | ask | ## 検証 - [x] `uv run pytest -q tests`: 6658 passed, 2 skipped(git-lfs と gofmt が未インストール) - [x] `ruff check` / `ruff format --check` / `ty check` / `vulture` / `deptry` / `ls_lint` / `adr-check`: 通過 - [x] Red を確認: 新しいテストは宣言ファイル未作成・新形式未対応・`changes_directory` による ask で失敗し,実装後に通過 - [x] rebase 後(ruff 0.17.6)に関連テスト 187 件と lint を再実行して通過 - [x] review 対応(1d974ef): claude-review P2「宣言内でも存在しない `GH_CONFIG_DIR` を信頼する」を修正.Red(新テスト失敗)→ Green,関連 57 件通過 - [x] review 対応(8ea5997): claude-review P2「`harness` 用の宣言(`~/.hermes` など)の中の `GH_CONFIG_DIR` も信頼する」を修正.hook しか持たない provider ではシェルがルートに書けるため,`gh-config` 用の宣言だけを信頼する.Red → Green - [x] review 対応(b277803): claude-review P2「コマンド sandbox のない provider にも緩和が効く」を修正.Claude(`provider` なし)と Codex に限定.Red(5 provider が allow)→ Green,全テスト 6666 passed - [x] bootstrap: 外部ダウンロードの失敗(curl の終了コード 22).ユーザーの rerun で通過 - [x] jev-lint(advisory): テストで繰り返していたコマンド文字列を定数にした.`check(mode: str)` と `AGENT_GH_POLICY` の文字列は既存のコードで今回の変更範囲ではなく,`entry without a path` は外側の `invalid write protection policy: <path>` が操作を示すので変えていない - [ ] codex-review: Codex の usage limit で review を完了できず失敗(コード起因ではない) ## dotfiles が満たすべきこと(#532 で既に満たす) - `GH_CONFIG_DIR` を **絶対パス** `$HOME/.config/agent-harness/gh` として Claude の `settings.env` と Codex の `shell_environment_policy.set` に渡す. - そのディレクトリ自体と `~/.config`,`~/.config/agent-harness` を symlink にしない(実体が宣言の外にあると gh ガードは ask に戻る).`config.yml` / `hosts.yml` を置くなら実体もこのディレクトリ内に置く. ## マージ後の確認(ユーザー) - [ ] agent-harness でレンダリングした `~/.claude/settings.json` に `Edit(~/.config/agent-harness/gh/**)` と `sandbox.filesystem.denyWrite` の `~/.config/agent-harness/gh` があること,Codex の `config.toml` に `"~/.config/agent-harness/gh" = "read"` があること. - [ ] Claude で `~/.config/agent-harness/gh/config.yml` への Write が拒否されること.sandbox の Bash で `touch ~/.config/agent-harness/gh/x` が失敗すること. - [ ] Claude で `git fetch -q origin && gh pr view <n> --repo furedea/agent-config` が確認なしで動くこと. - [ ] Codex の hook に `GH_CONFIG_DIR` が渡らない場合,その行は従来どおり ask になる(安全側).渡したい場合は dotfiles 側で hook の環境にも設定する. <details><summary>設計・証拠・範囲</summary> - 宣言: `agents/hooks/rules/write_protected_paths.json`(旧 `harness_roots.json`).`purpose` は `harness` と `gh-config`.テスト用の上書き変数は `AGENT_WRITE_PROTECTED_PATHS`(旧 `AGENT_HARNESS_ROOTS_POLICY`).別ファイルを並べず一般化したのは,provider 設定・file guard・gh guard が同じ問い(エージェントがそのパスを書けるか)を読むため.`guard_file.py harness` のモード名は hooks.json と全 adapter が参照するので据え置いた. - gh ガードは hook がユーザー権限で動くため書込み可否を自分で確かめられない.宣言を信頼する根拠は,`tests/test_harness_protection.py` が宣言と各 provider の設定を照合すること.作業ディレクトリと `$TMPDIR` は許可リストに関係なく書けるので,Claude の `denyWrite` と Codex の `read` も足した. - gh を逸らせる他の経路(`_read_host_problem` の docstring と `tests/hooks/test_gh_protected_config.py`): - `GH_HOST`,`GH_REPO`,`GH_CONFIG_DIR`,`HOME`,`XDG_CONFIG_HOME`,proxy,CA bundle は環境変数で,行の代入・`export` は既存の `changes_environment` で ask. - alias,pager,`http_unix_socket` は `config.yml` / `hosts.yml` にあり保護ディレクトリ内. - `--repo` があれば作業ディレクトリのリモートと git 設定は読まない. - extension は組み込みコマンドを上書きできず,state / cache ディレクトリはホストを選ばない. - PATH への gh / git の仕込みは `_stand_in_problem` が独立に判定する.既存テスト `cp x later/git; gh pr list -R …` は PATH に `later` がなく実際には仕込めていなかった(`changes_directory` だけで ask していた)ので,PATH に相対エントリを足して本当に仕込める形にし,gh も対象に加えた. - 既存の #282 テスト(`test_gh_line_asks.py`)は「gh の設定が保護されていない」前提を fixture で明示した.保護された `GH_CONFIG_DIR` の環境で実行すると allow になっていたため. - DESIGN.md / DESIGN_ja.md の「agent-harness が `denyWrite` を置き換えるので未適用」という注記は,agent-harness#213 が 2026-11-11 に close され,インストール済み設定にソースの項目が入っていることを確認して直した. - review の補足(finding ではない): `$HOME` が symlink の配下にあるホストでは `holds()` が一致せず常に ask になる.安全側なので変えていない. - ADR-0032 を追加し,ADR-0031 を `partly-superseded-by` にした. - 範囲外: トークン発行と dotfiles の変更(furedea/dotfiles#532),GitHub Gateway(#181),マージ. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
概要
furedea/agent-harness#264 でエージェント用 GitHub トークンの発行機能が agent-harness から削除されたため,発行を dotfiles に移した.
scripts/github-app-token/mint_github_app_token.sh(新規):openssl,curl,jqでトークンを発行する.jqは既存の依存.GET /app/installationsで App のインストールが 1 つだけであることを確かめ,POST /app/installations/{id}/access_tokensでトークンを発行する.<設定ディレクトリ>/hosts.ymlを一時ファイルからの rename で mode 0600 で書く.設定ディレクトリは 0700.config.ymlがなければversion: "1"を書く.hosts.ymlをそのまま残す.hosts.ymlを同じディレクトリのhosts.previous.yml(mode 0600,一時ファイルからの rename)に残す.新しいhosts.ymlに置き換えた後,hosts.previous.ymlにあったトークン(2 回前の実行で発行したもの)を,そのトークン自身でDELETE /installation/tokenして失効させる.gh run watchのような長いghも,その次の実行まで(少なくとも 15 分)動き続ける.hosts.ymlもhosts.previous.ymlも変えず,何も失効させない.nix/home/default.nix:programs.agent-harness.github.agentTokenを削除した.agent-github-tokenを両ホストに追加した(RunAtLoad,15 分ごとに実行,ログは~/Library/Logs/agent-github-token.log).~/.config/agent-harness/ghは旧版と同じ.envと Codex のshell_environment_policy.setにGH_CONFIG_DIRを設定した.source の設定は~を展開しないので,dotfiles が絶対パスで渡す.flake.lock: agent-harness を 249aeac(0.10.0,feat: render MCP servers declared once in the source agent-harness#268 を含む)に,agent-config を 4ea2075(0.6.0,feat(settings)!: declare the harness protection and the agent GitHub policy agent-config#286 を含む)に一緒に更新した.mcp_servers.jsonと Home Manager のmcpServersに宣言した MCP サーバーを,各プロバイダーの設定に生成する.darwin-rebuild後に Mac に現れるのは次の 2 つ.~/.gemini/config/mcp_config.json: 新しい activationagentHarnessAntigravityMcpServersが,なければ作る.~/.gemini/config/.agent-harness-managed.json: そのサイドカー({"mcpServers": []}).~/.codex/.agent-harness-managed.jsonに空のmcp_serversが加わる.Codex のconfig.tomlに[mcp_servers]は増えず,Claude の skills ツリーのファイル構成も変わらない.Devin は有効にしていないので~/.config/devinには何も書かれない.nix/checks.nix:composedSettingsを公開しないので,モジュールと同じ評価(source の設定に Home Manager のsettingsをrecursiveUpdateで重ねる)で生成後の設定を組み立てるようにした.githubオプションが削除済みであることGH_CONFIG_DIRRead(...)とdenyReadの両方default_permissionsのプロファイルの filesystem に"deny"read_file(...)~/.sshなどの親ディレクトリの拒否も鍵を含むものとして扱う.Closes #531
権限の選び方
GET /apps/furedea-agentで調べた App の権限はactions:read,contents:write,issues:write,metadata:read,pull_requests:writeだった.エージェントはどれも使うので,5 つすべてを明示して要求する.actions:readcontents:writeissues:writepull_requests:writemetadata:read絞り込みの効果は,後から App に権限を足しても,dotfiles に書き足すまでエージェントには渡らないこと.リポジトリは絞らなかった.インストールが所有者の全リポジトリを対象にしていて,エージェントは複数のリポジトリにまたがって作業するため.
マージ後の手順(各 Mac で)
トークンは表示しない.
sudo darwin-rebuild switch --flake ~/ghq/github.com/furedea/dotfiles#<host>で反映する.launchctl print gui/$(id -u)/org.nix-community.home.agent-github-token | grep -E 'state|last exit code'でlast exit code = 0になっている.~/Library/Logs/agent-github-token.logにエラーがない.GH_CONFIG_DIR=~/.config/agent-harness/gh gh api /installation/repositories --jq .total_countが数を返す.stat -f %Lp ~/.config/agent-harness/gh/hosts.ymlが600を返す.gh pr list --repo furedea/dotfilesが動く.~/.config/agent-harness/gh/agent_harness_token.jsonは不要なので消してよい.検証
bats tests/github-app-token: 22 件すべて成功.スクリプトを作る前,失効と権限を足す前,2 回前の失効に変える前の各段階で,テストが先に失敗することを確認した.nix flake check: 成功(all checks passed!).agent-harness-github-option-removed(旧agent-harness-has-no-github-option)github-app-key-unreadable-by-claude,-codex,-antigravityGH_CONFIG_DIRの 2 件は,dotfiles で設定した時点で通った.bats --recursive tests(137 件): 今回の変更による失敗はなし.ローカルのサンドボックスで zsh の ssh-agent の 8 件と nvim の lspmux の 1 件が失敗したが,原因は Unix ソケットの listen と~/.local/state/nvimへの書き込みの拒否で,今回の変更とは関係ない.agent-github-token-script(darwinOnly): bats の仕様を,launchd ジョブと同じ固定ツール(nix/agent_github_token.nix,curl のみ偽物)で実行し,22 件すべて成功.codex-reviewと,それに連動するall-green以外はすべて成功.codex-reviewは利用上限で実行されていない(Codex のコメントで確認).レビュー対応
TOOLS_PATHにsedがなく,2 回目以降の実行が exit 127 で失敗してトークンが更新されなくなる.sed: command not foundで失敗することを確認した.gh(gh run watchなど)が 401 になる.Read(/path)はプロジェクトからの相対パスとして読まれるので,鍵の契約が保護にならないエントリーを通しうる.Read(の絶対パスは//で始まるものだけを数える.hosts.ymlの値をそのまま使う点.指摘自身が問題なしとしている.エージェントがそのディレクトリに書けても,送られるのはエージェントがすでに持つトークンだけ.stat -fによって mode の確認がずれていた.テストの補助関数でstat -cを先に試すように直した.計画からの逸脱
jqを使った.インストール一覧の応答には入れ子のidがあり,sed では確実に読めないため.hosts.ymlだけで済む代わりに,1 台あたり毎時 4 回の発行と失効になる(ADR-0055).nix/checks.nixで agent-harness の合成を再現した.新しい agent-harness がcomposedSettingsを公開しなくなったため.🤖 Generated with Claude Code