Repository navigation
feat: sanitized Git subprocess execution utility for control-plane preflight (#2196) - #2201
Conversation
…eflight (#2196) #2190 の worktree migration を5分割した Child 1。専用Git subprocessが 参照するGIT_*環境変数のunset、git実行ファイル絶対パスの一度解決・再利用、 core.hooksPathのtrusted empty directory固定によるpost-checkout hook 非発火、url.<base>.insteadOf rewriteのfail-closed拒否、prompt/credential helper/interactive SSHの無効化を skill_runtime_exec.py / skill_runtime_command_policy.py に追加する。後続child issue(#2197-#2200) がこのutilityを消費する前提基盤。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URL✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2201/ The preview will be removed when this PR is closed. |
impl-review-loop Step 5 判定(自動投稿)Mergeability
Evidence Check
Blockersなし verdict: APPROVE
reviewed_head_sha: "412046dc09151424d555e8be8ecb7a1e970ec92c"
blockers: []
warnings: []本 PR は Delivery Rule により Draft のまま維持されています。マージ判断は人間が行います。 |
敵対的レビュー結果判定: 対象は head しかし、このPRが追加する 現時点では本番dispatch未配線なので、既存本番を直ちに破壊するP0ではありません。ただし #2197、#2198、#2199、#2200 は明示的にこのChild 1を前提としているため、基盤欠陥を後続実装へ伝播させるP1マージブロッカーです。 P1-1:
|
PR #2201 owner adversarial review (P1-1〜P1-5) を反映: - GIT_SUBPROCESS_UNSET_ENV_KEYS を14変数へ拡張(GIT_CONFIG/GIT_CONFIG_PARAMETERS/GIT_EXEC_PATH/GIT_CEILING_DIRECTORIES/GIT_SSL_NO_VERIFY追加) - PATHをtrusted allowlistのみで構成し継承PATHを排除、GIT_SSH_COMMANDをtrusted絶対パス解決に変更 - 汎用list[str] argv APIを廃止し、closed command builder(run_control_plane_git_*)群へ置換。global option注入を拒否 - insteadOf/pushInsteadOf検出をgit config --list行split解析からgit config --get-regexp --name-only -z構造化クエリへ置換(subsection内'='を正しく扱う) - config probe失敗(非ゼロ終了・timeout・decode失敗)をfail-closedに変更(rewrite無しと誤判定しない) - core.hooksPathをper-invocation trusted directoryへ変更、symlinked/relative scratch rootを拒否 - stdin=DEVNULL既定化・timeout必須化・--no-replace-objects固定付与 - helper/askpass/sshのmarker executable非実行を直接実証するfixtureテストを追加 Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
adversarial review の P1-1〜P1-5 をすべて修正しました(P2-1〜P2-6 も対応)。head を
全62件の新規テスト(policy 20件・exec 42件)が PASS、既存 |
impl-review-loop Step 5 判定(自動投稿・owner adversarial review 反映後の再判定)owner による敵対的セキュリティレビュー(P1-1〜P1-5、PoC付き)を受け、Issue #2196 の contract を改訂(AC1拡張・AC6-AC11新設)した上で実装を修正し、独立した pr-reviewer による再監査で全 P1 指摘の genuine な解消を確認しました。 Mergeability
P1 指摘の解消確認(reviewer 独立検証)
P2項目(hooksPath containment・stdin/timeout境界・credential marker非実行証明・--no-replace-objects・fixture環境分離)も対応済み。 Evidence Check
Blockersなし verdict: APPROVE
reviewed_head_sha: "367ec16e0b78f76c2499964ae58d034bf2b7ce2f"
blockers: []
warnings: []本 PR は Delivery Rule により Draft のまま維持されています。マージ判断は人間が行います。 |
Summary
本PRは Closes #2196(
#2190を5分割した Child 1)に対応する。#2190(親: production preflight profile群を remote default-ref OID に fail-closed で束縛した detached dedicated linked worktree lifecycle へ移行する大規模Issue)の最初の基盤フェーズとして、専用Git subprocessが安全に動作するための環境sanitization基盤を新設し、後続child issue(#2197remote-OID protocol、#2198lifecycle lock、#2199identity probe/profile migration、#2200artifact confinement)の前提とする。本PRは owner による adversarial security review(PR #2201 コメント、
REQUEST_CHANGES)を反映した fix delta である。初回実装は全AC/VCをPASSしていたが、owner レビューにより PoC 付きで5件のP1(must-fix)脆弱性が指摘され、Issue #2196 本文も AC1〜AC11・control_plane_git_subprocess_contractYAMLブロックへ改訂された。本コミットはその改訂後契約に基づき実装を全面的に作り直したものである。P1修正内容(owner adversarial review反映)
GIT_CONFIG/GIT_CONFIG_PARAMETERSを unset 対象へ追加(14変数化)。probe と実コマンドが同一の sanitized env(同一の unset 集合・同一の-cglobal option)を使うため、GIT_CONFIGを用いた probe/実コマンドの config authority 分離が構造的に不可能になった。GIT_EXEC_PATH/GIT_CEILING_DIRECTORIESを unset 対象へ追加。PATHを継承せず trusted allowlist のみで再構成し、GIT_SSH_COMMANDも同じ allowlist から解決した絶対パス(解決不能ならfalseにフォールバックし、素のsshは使わない)に変更。run_sanitized_git_subprocess(argv: list[str], ...)公開APIを廃止し、_run_sanitized_git_subprocess(private engine)+ 5つの closed command builder(run_control_plane_git_ls_remote/_fetch/_cat_file/_update_ref/_worktree)へ置き換えた。各builderは構造化パラメータのみを受け取り、-c/--config-env/-C/--git-dir/--work-tree/--exec-path/--namespaceを含むGit global optionを一切受理しない。=分割バグ):git config --listの行を独自split解析する実装を廃止し、git config --get-regexp --name-only -z <pattern>によるNUL区切り・name-only・regexp限定の構造化クエリへ置換。insteadOfだけでなくpushInsteadOfも対象化。subsection名に=を含む fixture(url.https://evil.example/?x=y.insteadOf)でも正しく検知することをbehavioral testで実証。GitSubprocessConfigProbeFailedを送出しfail-closedで停止するよう変更(従来は非ゼロ終了時に無条件でrewriteチェックをスキップしていた)。P2対応状況
core.hooksPathを固定名の使い回しからtempfile.mkdtempによるper-invocation・fresh・verified-emptyディレクトリへ変更し、realpath一致検証・symlinked/relative scratch root拒否を追加。subprocess.runにstdin=subprocess.DEVNULLを既定適用し、timeoutをkeyword-only必須パラメータ化(省略時TypeError、None/0以下はValueError)。--no-replace-objects固定): 対応済み。probe・実コマンド双方の argv に固定付与し、test_run_control_plane_git_worktree_applies_no_replace_objects_and_devnull_stdinでsubprocess.run呼び出しargvを直接検証。_init_fixture_repo)はHOME/XDG_CONFIG_HOME/GIT_AUTHOR_*/GIT_TERMINAL_PROMPTを分離したbase_envを使用し、marker系テストではHOME/GIT_ASKPASS/SSH_ASKPASSをwrapper呼び出し自体に対してmonkeypatchしている。Checks
以下の全コマンドをworktree内で実行し、すべてPASSしたことを確認した(head
367ec16e0b78f76c2499964ae58d034bf2b7ce2f)。uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py -q→ 結果は20件 PASS。uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q→ 結果は42件 PASS。uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py -q -k insteadof→ 結果は4件 PASS(16件 deselected)。uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q -k global_option→ 結果は8件 PASS(34件 deselected)。scripts/agent-guards/tests/全件との回帰有無を確認した:uv run --locked pytest scripts/agent-guards/tests/ -q→ 結果は1364件 PASS(1件 skipped、1件 deselected)。pnpm typecheck→ エラーなし。pnpm lint→ エラーなし。pnpm test→ 結果は1872件 PASS(112ファイル)。pnpm build→ 成功。uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -q→ 結果は24件 PASS。uv run ruff check scripts/agent-guards/skill_runtime_command_policy.py scripts/agent-guards/skill_runtime_exec.py scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py→ エラーなし(All checks passed!)。受け入れ条件の達成状況
GIT_SUBPROCESS_UNSET_ENV_KEYS(14変数)すべてが unset されることをtest_sanitized_git_subprocess_env_unsets_all_ac1_keys(test_skill_runtime_control_plane_exec.py)で実証している。test_resolve_git_subprocess_executable_is_cached_and_reused(test_skill_runtime_control_plane_exec.py)で実証している。core.hooksPathがper-invocation・verified-empty・realpath検証済みtrusted directoryに固定され、post-checkout hookが発火しないことをtest_run_sanitized_git_subprocess_prevents_post_checkout_hook_firing(baseline対照あり)で、relative/symlinked scratch rootの拒否をtest_git_subprocess_trusted_hooks_dir_rejects_relative_scratch_root/test_git_subprocess_trusted_hooks_dir_rejects_symlinked_scratch_rootで実証している(test_skill_runtime_control_plane_exec.py)。insteadOf/pushInsteadOf両方の拒否をtest_run_sanitized_git_subprocess_rejects_insteadof_rewrite/test_run_sanitized_git_subprocess_rejects_pushinsteadof_rewriteで、=を含むsubsection名での正しい検知をtest_run_sanitized_git_subprocess_rejects_insteadof_with_equals_in_subsectionで実証している(すべてtest_skill_runtime_control_plane_exec.py)。P2-6訂正: 前回本文はテストファイルを誤記していたが、これらのbehavioral testはすべてtest_skill_runtime_control_plane_exec.pyに存在する(test_skill_runtime_control_plane_policy.py側は正規表現の純粋なpythonロジックのunit testのみを担当)。test_run_sanitized_git_subprocess_never_invokes_credential_or_askpass_markersで直接実証している(test_skill_runtime_control_plane_exec.py、ローカルHTTP 401 fixtureサーバ + marker script)。GIT_CONFIGを空configへ向けたsplit-execution試行が、repo-local insteadOfをなお検知しfail-closed拒否することをtest_run_sanitized_git_subprocess_rejects_insteadof_despite_ambient_git_config_splitで実証している。PATH/GIT_EXEC_PATH上のfakegit-remote-httpsmarkerが実行されないことをtest_run_control_plane_git_ls_remote_ignores_poisoned_path_and_git_exec_pathで、poisonedPATH上のfakesshがGIT_SSH_COMMANDに採用されないことをtest_sanitized_git_subprocess_env_ssh_command_ignores_poisoned_pathで実証している。test_run_control_plane_git_ls_remote_rejects_global_option_like_repo_value(parametrize 7ケース)とtest_internal_engine_rejects_global_option_argv_defense_in_depthで、汎用raw argv production APIが存在しないことをtest_no_public_raw_argv_production_api_existsで実証している。GitSubprocessConfigProbeFailedでfail-closed停止することをtest_run_sanitized_git_subprocess_fails_closed_when_probe_cannot_be_evaluated/test_probe_insteadof_rewrite_keys_fails_closed_on_timeoutで実証している。stdin=subprocess.DEVNULL既定適用とtimeout必須化(省略時TypeError、None/0以下でValueError)をtest_run_control_plane_git_worktree_requires_timeout_kwarg/test_internal_engine_rejects_none_timeout/test_internal_engine_rejects_non_positive_timeout/test_run_control_plane_git_worktree_applies_no_replace_objects_and_devnull_stdinで実証している。--no-replace-objectsがprobe・実コマンド双方の実際のsubprocess.run呼び出しargvに含まれることをtest_run_control_plane_git_worktree_applies_no_replace_objects_and_devnull_stdin(subprocess.run spy)で実証している。対応するテストファイルと件数:
scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py(20件 PASS)、scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py(42件 PASS)。検証コマンド結果
すべて head
367ec16e0b78f76c2499964ae58d034bf2b7ce2fで実行し、以下の通り全てPASSした。$ pnpm typecheck # => exit 0, エラーなし$ pnpm lint # => exit 0, エラーなし$ pnpm build # => 成功$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -q # => 24 passedAllowed Paths 遵守
git diff --name-only(gh pr diff 2201 --name-only)で確認した本PRの変更ファイルは以下の4件のみであり、Issue #2196 の Allowed Paths と完全一致する。Allowed Paths 外の変更はない。scripts/agent-guards/skill_runtime_command_policy.pyscripts/agent-guards/skill_runtime_exec.pyscripts/agent-guards/tests/test_skill_runtime_control_plane_exec.pyscripts/agent-guards/tests/test_skill_runtime_control_plane_policy.pyRuntime Verification Evidence(動作検証証跡)
Issue #2196 の Runtime Verification Applicability は
decision: immediate(AC1〜AC11すべてruntime-verification: true)であり、以下の fixture ベースの実behavioral testで非vacuousな動作検証を行っている(SKIP経路やフォールバック経由の成功をPASSとして扱う設計は導入していない)。test_sanitized_git_subprocess_env_unsets_all_ac1_keys— 14変数すべてを汚染した環境を作り、sanitized_git_subprocess_env適用後の辞書にそれらのキーが存在しないことを直接アサートする。test_resolve_git_subprocess_executable_is_cached_and_reused—shutil.which呼び出し回数を計測し、複数回呼び出しても解決が1回のみであることを実証する。test_run_sanitized_git_subprocess_prevents_post_checkout_hook_firing(baseline対照あり)に加え、test_git_subprocess_trusted_hooks_dir_is_per_invocation/test_git_subprocess_trusted_hooks_dir_rejects_relative_scratch_root/test_git_subprocess_trusted_hooks_dir_rejects_symlinked_scratch_root/test_git_subprocess_trusted_hooks_dir_fails_closed_if_realpath_differs。=含みsubsection + GIT_CONFIG split-execution耐性):test_run_sanitized_git_subprocess_rejects_insteadof_rewrite/_rejects_pushinsteadof_rewrite/_rejects_insteadof_with_equals_in_subsection/_rejects_insteadof_despite_ambient_git_config_split— いずれもfixture repoの.git/configに実際にrewriteを設定しGitSubprocessRewriteRejectedの送出を実証する。test_run_sanitized_git_subprocess_never_invokes_credential_or_askpass_markers— ローカルHTTP 401サーバ + HOME配下のglobal credential.helper + GIT_ASKPASS/SSH_ASKPASSにmarker scriptを配線し、実行後にmarkerファイルが作られていないことを直接アサートする。test_run_control_plane_git_ls_remote_ignores_poisoned_path_and_git_exec_path/test_sanitized_git_subprocess_env_ssh_command_ignores_poisoned_path— fakegit-remote-https/sshmarkerをPATH先頭に配置しても採用/実行されないことを実証する。test_run_control_plane_git_ls_remote_rejects_global_option_like_repo_value(7パターンparametrize)/test_internal_engine_rejects_global_option_argv_defense_in_depth/test_no_public_raw_argv_production_api_exists。test_run_sanitized_git_subprocess_fails_closed_when_probe_cannot_be_evaluated(実際に.git/configを構文破壊)/test_probe_insteadof_rewrite_keys_fails_closed_on_timeout。--no-replace-objects固定):test_run_control_plane_git_worktree_applies_no_replace_objects_and_devnull_stdin(実際のsubprocess.run呼び出しargv/kwargsをspyで直接検証)/test_run_control_plane_git_worktree_requires_timeout_kwarg/test_internal_engine_rejects_none_timeout/test_internal_engine_rejects_non_positive_timeout。これらはいずれも production primary checkout を操作しない isolated fixture 環境での実証であり、CI green のみに依拠しない genuine な証跡である。
Schema Change Applicability
SKILL_RUNTIME_COMMAND_POLICY_V2等)のキー集合・型定義は一切変更していない。追加したのは新規Pythonシンボル(関数・定数・例外クラス)のみであり、いずれもまだ本番コマンドdispatchから参照されていない独立utilityであるため、スキーマ変更には該当しない。Schema Consumer Inventory
N/A
reason: スキーマ変更を伴わないため、Consumer調査は対象外とする。
Safety Claim Matrix
本PRの変更が実現する安全性主張を以下の表にまとめる。
test_sanitized_git_subprocess_env_unsets_all_ac1_keystest_resolve_git_subprocess_executable_is_cached_and_reusedtest_run_sanitized_git_subprocess_prevents_post_checkout_hook_firing他=含みsubsection・ambient GIT_CONFIG split試行を含む)でfail-closedに拒否する(AC4/AC6)test_run_sanitized_git_subprocess_rejects_insteadof_rewrite他4件test_run_sanitized_git_subprocess_never_invokes_credential_or_askpass_markerstest_run_control_plane_git_ls_remote_ignores_poisoned_path_and_git_exec_path他test_no_public_raw_argv_production_api_exists他test_run_sanitized_git_subprocess_fails_closed_when_probe_cannot_be_evaluated--no-replace-objects固定付与(AC10/AC11)test_run_control_plane_git_worktree_applies_no_replace_objects_and_devnull_stdin他Notes
#2190の5分割 Child 1 に対応する。Out of Scope(remote default-ref OIDプロトコル、lifecycle lock、identity probe/production profile移行、artifact confinement、WORKTREE_CATALOG_ENTRY_V1スキーマ変更、contract_update.run.with_anchor/contract_update.run.with_human_contextのdedicated worktree化)は、Issue本文の通り後続child issueで扱う。run_control_plane_git_ls_remote/_fetch/_cat_file/_update_ref/_worktree)は本Issueの完了時点でまだどの本番コマンドdispatchパスからも呼び出されていない。本PRはutility自体の正しさをfixtureで自己証明する範囲にとどめている。sibling issue 実装: control-plane preflight の remote default-ref OID observe/fetch/pin/verify プロトコルを実装する #2197〜実装: control-plane preflight の artifact confinement と #2190 全AC最終検証を実装する #2200 がこの5つのbuilderのうち自身が必要とするものを本番配線する予定。decision: immediateである。AC1〜AC11すべてに対応する実behavioral testを新設しており、SKIP経路やフォールバック経由の成功をPASSとして扱う設計は一切導入していない。証跡は本PRのChecksセクションおよび上記「Runtime Verification Evidence」セクションに記載した実行結果とする。#2201コメント)で指摘されたP1-1〜P1-5をすべて修正し、P2-1〜P2-6も含めて対応した。head SHAは412046dc09151424d555e8be8ecb7a1e970ec92cから367ec16e0b78f76c2499964ae58d034bf2b7ce2fへ更新されている。