Skip to content

feat(settings): protect the agent gh config directory and let the gh guard rely on it - #290

Merged
furedea merged 6 commits into
mainfrom
feat/protect-agent-gh-config
Dec 1, 2026
Merged

furedea merged 6 commits into
mainfrom
feat/protect-agent-gh-config

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

エージェント用の gh 設定ディレクトリ ~/.config/agent-harness/gh を全 provider で書込み禁止にし,gh ガードはそれを根拠に「literal な --repo の読み取り + 同じ行の別コマンド」で確認を求めなくなる.
宣言は harness_roots.json を一般化した write_protected_paths.json(各項目に purpose)に移した.
判断事項: マージ前に下の「dotfiles が満たすべきこと」と「マージ後の確認」.

Refs #289(#282 の続き,#181 の暫定段階)

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 しない]
Loading
状況 変更前 変更後
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

検証

  • uv run pytest -q tests: 6658 passed, 2 skipped(git-lfs と gofmt が未インストール)
  • ruff check / ruff format --check / ty check / vulture / deptry / ls_lint / adr-check: 通過
  • Red を確認: 新しいテストは宣言ファイル未作成・新形式未対応・changes_directory による ask で失敗し,実装後に通過
  • rebase 後(ruff 0.17.6)に関連テスト 187 件と lint を再実行して通過
  • review 対応(1d974ef): claude-review P2「宣言内でも存在しない GH_CONFIG_DIR を信頼する」を修正.Red(新テスト失敗)→ Green,関連 57 件通過
  • review 対応(8ea5997): claude-review P2「harness 用の宣言(~/.hermes など)の中の GH_CONFIG_DIR も信頼する」を修正.hook しか持たない provider ではシェルがルートに書けるため,gh-config 用の宣言だけを信頼する.Red → Green
  • review 対応(b277803): claude-review P2「コマンド sandbox のない provider にも緩和が効く」を修正.Claude(provider なし)と Codex に限定.Red(5 provider が allow)→ Green,全テスト 6666 passed
  • bootstrap: 外部ダウンロードの失敗(curl の終了コード 22).ユーザーの rerun で通過
  • 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 の環境にも設定する.
設計・証拠・範囲
  • 宣言: 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 も対象に加えた.
  • 既存の gh guard: explain asks caused by other commands on the line, and teach lanes the prompt-free form #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 の変更(feat(nix): mint the agents' GitHub App token in dotfiles dotfiles#532),GitHub Gateway(feat(agent-runtime): build persistent, isolated, provider-neutral agent infrastructure #181),マージ.

🤖 Generated with Claude Code

…guard rely on it

Declare every path agents must not write in write_protected_paths.json, which
replaces harness_roots.json and gives each entry a purpose. The agent gh
configuration the host mints (~/.config/agent-harness/gh) joins the harness
roots: Claude denies it to file tools and in the sandbox's denyWrite, Codex
keeps it read-only, Antigravity denies it, and guard_file.py refuses it for
every provider with a host-specific reason.

The gh guard now lets a read that names its repository with a literal --repo
share its line with other commands when GH_CONFIG_DIR, and each gh config file
in it, really lies inside a declared path. Unset, relative, or linked-out
configuration still asks, as do assignments that change what gh reads.

Also fix the stale DESIGN note that said the source denyWrite is not in effect.

Refs #289

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@furedea

furedea commented Dec 1, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-01T07:50:05.380796Z
We couldn’t complete this review. Comment @codex review to try again.
046376c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/gh_environment.py Resolved
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Review summary

Read-only review of the generalized write_protected_paths.json declaration and the gh guard's new trust in a protected GH_CONFIG_DIR.

Findings: one P2, posted inline.

  • P2, gh_environment.py: config_is_protected passes when the declared gh config directory does not exist yet, because resolve() is non-strict and only existing files are checked. The exemption is then only as strong as the sandbox's ability to deny writes to a missing path. I'd require is_dir() and add a test for the missing-directory case.

What I checked and found fine:

  • Relative GH_CONFIG_DIR, .. detours, symlinked config files, and a declared path that is itself a link all fall back to ask.
  • Line-level environment assignments still ask before this code runs.
  • harness_roots.json references that remain are only in historical ADR text.
  • Test coverage for the new exemption is broad.

I did not run the test suite.

Minor, not posted as a finding: holds() compares a fully resolved target with the lexical declared path. If $HOME sits behind a symlink, the exemption never applies and every such line still asks. That fails safe.

A sandbox may not deny writes to a path that does not exist yet, so another
command on the line could create the declared directory with a socket.

Refs #289

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@furedea

furedea commented Dec 1, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Review summary: no blocking findings (no P0/P1, no inline comments).

I read the full diff, covering the new write_protected_paths module, the config_is_protected check, the _read_host_problem change, the provider settings and the tests. I did not run the test suite.

  • Fails closed. holds() compares the resolved target with the lexical declared path. A declared path that is a symlink, or one under a symlinked parent, therefore never counts as protected, and the guard asks as before. The tests cover this for the linked directory and linked config file cases.
  • Narrow trust condition. GH_CONFIG_DIR must be absolute and exist. The directory and each existing config.yml / hosts.yml must resolve inside a declared path. Anything else keeps the old "ask" behaviour.
  • Refactor is behaviour-preserving. guard_file still checks both the lexical and the resolved reading, and it now picks the refusal text from purpose.
  • Tests match the behaviour change. They cover the allow case, the ask cases (unset, relative, missing, out-of-declaration, linked) and the environment-assignment vectors.

Residual risk, which the ADR already lists as a "Bad" consequence and which I do not count against the merge. The gh guard's allowance rests on the provider sandbox really denying writes to ~/.config/agent-harness/gh. Claude (denyWrite) and Codex (guarded read-only) enforce that for shell commands. For Antigravity, Devin, Hermes, pi and dsh, only the file-tool guard enforces it, and a shell write is not blocked. Before this PR a config write in one Bash call followed by a standalone gh --repo read in the next already worked on those providers, so this PR adds no new hole. Still, the "全 provider で書込み禁止" wording in the PR description is accurate for file tools only, so check it against the host's actual sandbox before merging.

@furedea

furedea commented Dec 1, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/gh_environment.py Resolved
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Review summary (read-only)

I found one issue, a P2. I didn't run the test suite.

  • P2: config_is_protected trusts any declared entry, not only the gh-config one. The inline comment has the details and a suggested fix. The ADR already notes that the guarantee depends on how each provider is installed.

Checked and no problems found:

  • covers and holds handle .., symlinked declared paths and a missing GH_CONFIG_DIR safely. Each case fails closed to ask.
  • gh_rules now loads the declaration on every gh evaluation. A missing or invalid file raises ValueError, which the caller already handles by failing closed.
  • The harness_roots.json to write_protected_paths.json migration is consistent across the settings, the tests, and the new AGENT_WRITE_PROTECTED_PATHS override.

🤖 Generated with Claude Code

… root

Sandboxed commands of hook-only providers may write a harness root, so a
GH_CONFIG_DIR there could gain a socket from another command on the line.

Refs #289

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@furedea

furedea commented Dec 1, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Comment thread agents/hooks/lib/gh_environment.py Resolved
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Review summary

Read-only review of the diff. I did not run the test suite. Overall the change is careful: it fails closed on a relative or unset GH_CONFIG_DIR, a missing directory, a symlinked declared path and symlinked config files, and each of these has a test. The refactor from harness_roots.json to write_protected_paths.json is consistent across guard_file.py, guard_command.py and the provider settings. I found no certain breakage.

P2 (inline, gh_environment.py): The new allow path for a literal --repo read beside other commands assumes no agent can write the gh config directory. That is only enforced for Claude (denyWrite) and Codex (guarded read-only). Devin, Hermes, Pi, dsh and Antigravity have no command sandbox here, and guard_file.py harness covers file tools only. The guard doesn't check which provider is running, and no test covers a hook-only provider. ADR-0032 describes the risk as a provider whose sandbox ignores denyWrite, which doesn't cover a provider with no sandbox.

Not verified: The DESIGN.md and DESIGN_ja.md edits change "this sandbox rule is not in effect yet" to say agent-harness now keeps denyWrite (agent-harness#213). That is unrelated to the code change, and I could not check that the issue is fixed. If it isn't, the docs now overstate the protection, and the ADR's trust argument leans on denyWrite.

No other findings.

@furedea

furedea commented Dec 1, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

…mands

The file guard refuses the gh configuration for every provider, but only
Claude's denyWrite and Codex's guarded profile keep shell commands out of it,
so Antigravity and the hook-only providers keep asking.

Refs #289

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@furedea

furedea commented Dec 1, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Review of #290: no findings.

What I checked:

  • Provider trust. guard_command.py only treats commands as sandboxed for claude and codex. Claude's payload carries no provider field and defaults to claude. Every other adapter goes through provider_adapter.normalized() or translated(), which set provider explicitly. A hook-only provider therefore cannot pick up the sandbox trust by omission.
  • Sandbox escape. Claude has allowUnsandboxedCommands: false. The excludedCommands entries run outside the sandbox, but the allow rules already ask for any docker form that could reach host files, which the existing ADR and docs cover.
  • Fail-closed path checks. config_is_protected requires an absolute GH_CONFIG_DIR, an existing directory, and config.yml and hosts.yml (when present) resolving inside a declared gh-config path. holds() compares resolved paths against the lexical declaration, so a symlinked declared path, or a symlinked home, falls back to asking.
  • Declaration migration. harness_roots.json is gone and no code references the old AGENT_HARNESS_ROOTS_POLICY variable. The only remaining mentions are historical, in ADR-0031 and ADR-0032. A malformed declaration is handled the same way as the other rule files.
  • Tests. Coverage looks proportionate: the protected config, the unsafe variants (unset, relative, missing, outside the declaration, linked), and the hook-only providers that still ask.

I did not run the test suite.

@furedea

furedea commented Dec 1, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Review summary

No P0–P2 findings. I read the full diff and checked the following.

  • Provider trust. Every adapter path (normalized and translated in provider_adapter.py) sets provider, so the payload.get("provider", CLAUDE) default only applies to Claude's direct hook call. Antigravity, Devin, dsh, Hermes and Pi still ask.
  • Environment changes on the line. Any assignment on the line sets changes_environment, which asks in gh_policy.py. That is what makes the claim "the environment is the only other input" hold for PATH, GH_TOKEN, GH_ENTERPRISE_HOST and similar, not just the listed variables.
  • Path checks. config_is_protected requires an absolute GH_CONFIG_DIR that exists, with each existing config.yml or hosts.yml resolving inside a gh-config entry. A ~ that is itself a symlink makes holds return False, so it fails toward asking.
  • Provider settings. Claude's denyWrite and allowUnsandboxedCommands: false match the trust assumption. Codex read and Antigravity write_file deny entries are added.
  • Rename. No stale references remain to harness_roots, AGENT_HARNESS_ROOTS_POLICY, gh_policy.load or the removed guard_file helpers.
  • Tests. The new tests cover each ask and allow boundary in the PR table: unset, relative, missing, undeclared, linked file, linked directory, harness-purpose entry, and non-sandboxed providers.

P3, optional. COMMAND_SANDBOX_PROVIDERS is checked with a default of "claude" for a missing provider, so a future caller that forgets to set provider is trusted rather than asked. That is correct for Claude today. An explicit marker from the Claude hook entry would fail closed instead.

Not verified here: that Codex always runs the guarded permission profile, and that the host's dotfiles meet the "dotfiles must satisfy" list. Both are the PR's own merge checks.

@furedea
furedea merged commit 8dbb4bf into main Dec 1, 2026
27 of 29 checks passed
@furedea
furedea deleted the feat/protect-agent-gh-config branch December 1, 2026 08:06
furedea pushed a commit that referenced this pull request Dec 1, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.7.0](v0.6.0...v0.7.0)
(2026-12-01)


### Features

* **settings:** protect the agent gh config directory and let the gh
guard rely on it
([#290](#290))
([8dbb4bf](8dbb4bf))

---
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: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.com>
furedea-agent Bot pushed a commit to furedea/dotfiles that referenced this pull request Dec 1, 2026
…s unwritable

Update the agent-config input to 99f2ca3 (v0.7.0, furedea/agent-config#290), which
denies writes to ~/.config/agent-harness/gh for every agent and lets the gh guard
trust a protected GH_CONFIG_DIR for literal --repo reads. agent-harness is already
at its current main (249aeac).

Add contracts that the rendered Claude, Codex and Antigravity settings deny
writes to that directory.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
furedea added a commit to furedea/dotfiles that referenced this pull request Dec 1, 2026
…s unwritable (#536)

## 概要

`agent-config` を v0.7.0(`99f2ca3`)に更新します.これには furedea/agent-config#290
が含まれます.

- agent 用の gh 設定ディレクトリ `~/.config/agent-harness/gh` を,すべての agent
から書込み不可として宣言します.
- gh ガードは,保護された `GH_CONFIG_DIR` を,リテラルな `--repo` 付きの読み取りに限って信頼します.

`agent-harness` は dotfiles#532 の時点から現在の main(`249aeac`)のままで,更新はありません.

あわせて `nix/checks.nix` に契約を追加しました.描画された Claude / Codex / Antigravity
の設定が,いずれも `~/.config/agent-harness/gh` への書込みを拒否することを評価で確認します.

## 確認済み

- `nix flake check` が通ります.
- 追加した3つの契約はいずれも `true` です.

## マージ後の確認(ユーザー)

1. `sudo darwin-rebuild switch` を実行し,agent のセッションを再起動する.
2. 新しい Claude セッションで `git fetch -q origin && gh pr list --repo
furedea/dotfiles --limit 1` が承認プロンプトなしで実行できる.
3. Claude からの `~/.config/agent-harness/gh/config.yml` への Edit / Write
が拒否される.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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