Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#2190"
goal_ref: "#2190 AC2(一部)・AC8: control-plane preflight が使う専用Git subprocessの環境sanitization基盤を新設し、後続child issueの前提とする"
change_kind: codeParent Issue
Parent Goal Ref
- Goal: 実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190(親)は production preflight profile 群を remote default-ref OID に fail-closed で束縛した detached dedicated linked worktree lifecycle へ移行する。本Issueはその最初の基盤フェーズ(sanitized Git subprocess 実行環境)を担う。
- Desired Destination: 実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 の Allowed Paths のうち
scripts/agent-guards/skill_runtime_command_policy.py/scripts/agent-guards/skill_runtime_exec.pyおよび対応テストのみを扱う。
Current Validated Scope
scripts/agent-guards/skill_runtime_exec.pyに、専用Git subprocessが参照するGIT_DIR/GIT_WORK_TREE/GIT_COMMON_DIR/GIT_INDEX_FILE/GIT_OBJECT_DIRECTORY/GIT_ALTERNATE_OBJECT_DIRECTORIES/GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM/GIT_CONFIG_COUNT/GIT_CONFIG/GIT_CONFIG_PARAMETERS/GIT_EXEC_PATH/GIT_CEILING_DIRECTORIES/GIT_SSL_NO_VERIFY系環境変数の unset、PATHの trusted allowlist 固定、git executable 絶対パスの一度解決・再利用、core.hooksPathの trusted empty directory 固定(絶対 realpath・symlink 拒否)、prompt/credential helper/interactive SSH 無効化、stdin=DEVNULL+ bounded timeout の既定適用、--no-replace-objectsの常時付与を実装するscripts/agent-guards/skill_runtime_command_policy.pyに、url.<base>.insteadOf/url.<base>.pushInsteadOfrewrite の fail-closed 拒否ポリシー(name-only・NUL区切り・regexp限定のgit config検査、probe失敗時は fail-closed で停止)を追加する- 呼び出し側が任意の Git global option(
-c/--config-env/-C/--git-dir/--work-tree/--exec-path/--namespace)を注入できない、closed な command builder API(run_control_plane_git_ls_remote等の allowlist されたサブコマンドのみを受理する型付き関数群)を提供する。汎用list[str]argv を直接渡す API は本Issueの完了時点で production 経路から除去する scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py/scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.pyを新設し、post-checkouthook が発火しないことに加え、GIT_CONFIGsplit-execution・後置 global option・=を含む insteadOf subsection・config probe 非ゼロ終了・helper/askpass/ssh marker executable 非実行を fixture で実証する
Control Plane Git Subprocess Contract(PR #2201 owner adversarial review 反映、詳細契約)
## Current Validated Scope の記述を置き換えない補助ブロック。実装・レビュー・テストはこの契約を正本として参照する。
control_plane_git_subprocess_contract:
unset_env_exact_set:
- GIT_DIR
- GIT_WORK_TREE
- GIT_COMMON_DIR
- GIT_INDEX_FILE
- GIT_OBJECT_DIRECTORY
- GIT_ALTERNATE_OBJECT_DIRECTORIES
- GIT_CONFIG_GLOBAL
- GIT_CONFIG_SYSTEM
- GIT_CONFIG_COUNT
- GIT_CONFIG
- GIT_CONFIG_PARAMETERS
- GIT_EXEC_PATH
- GIT_CEILING_DIRECTORIES
- GIT_SSL_NO_VERIFY
path_authority:
inherited_path: forbidden
safe_path_allowlist: required
transport_environment:
git_ssl_no_verify: forbidden
ssh_executable: absolute_trusted_path_or_https_only
object_identity:
replace_objects: disabled
fixed_global_option: "--no-replace-objects"
command_api:
raw_argv_list_str: forbidden_in_production_callsite
closed_builders_required:
- run_control_plane_git_ls_remote
- run_control_plane_git_fetch
- run_control_plane_git_cat_file
- run_control_plane_git_update_ref
- run_control_plane_git_worktree
subcommand_prefix_global_options: rejected
config_inspection:
method: name_only_nul_delimited_regexp_limited
target_keys:
- "^url\\..*\\.insteadof$"
- "^url\\..*\\.pushinsteadof$"
probe_failure_disposition: fail_closed_stop
probe_and_real_command_authority: identical
subprocess_boundary:
stdin: DEVNULL
timeout: required_bounded
hooks_containment:
path_form: absolute_realpath
symlink: component_wise_no_follow_rejected
scope: per_invocation_directoryRemaining Parent Gaps
- remote default-ref OID の observe/fetch/pin/verify プロトコル(実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 AC4)は Child 2(後続 Issue)で扱う
- lifecycle lock(実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 AC7)は Child 3(後続 Issue)で扱う
- identity probe・command class 分離・primary invariant・4 production profile 移行(実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 AC1/AC3/AC5/AC9/AC10)は Child 4(後続 Issue)で扱う
- artifact confinement・実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 全AC最終検証(AC6/AC11/AC12)は Child 5(後続 Issue)で扱う
Outcome
scripts/agent-guards/skill_runtime_exec.py と scripts/agent-guards/skill_runtime_command_policy.py に、専用Git subprocess実行のための環境sanitization(14変数のGIT_* 環境変数unset、trusted PATH allowlist、git executable絶対パス一度解決・再利用、core.hooksPath trusted empty directory固定、insteadOf/pushInsteadOf rewrite拒否、prompt/credential helper/interactive SSH無効化、closed command builder API、config probe fail-closed、stdin=DEVNULL+bounded timeout、--no-replace-objects)が実装され、新規 pytest(scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py / test_skill_runtime_control_plane_exec.py)が post-checkout hook 非発火・GIT_CONFIG split-execution 拒否・後置 global option 拒否・helper/askpass/ssh marker 非実行を含め全て PASS している状態(PR #2201 owner adversarial review の P1-1〜P1-5 指摘を反映)。
Runtime Verification Applicability
decision: immediate
reason: "isolated fixture(tmp git repo + core.hooksPath配線)でsanitizeされたsubprocess環境がhookを発火させないこと、GIT_*環境変数injectionをfail-closedで拒否することを実証する。production primary checkoutを操作しない。"
applicable_acs:
- AC1
- AC2
- AC3
- AC4
- AC5
- AC6
- AC7
- AC8
- AC9
- AC10
- AC11
execution_environment:
cli_tools:
- python3
- uv
- git
auth_required: false
network_required: false
skip_conditions:
- "isolated tmp git repo fixture(`git init` + `core.hooksPath` 配線)を構築できない実行環境ではSKIPではなくenvironment blockedとして扱う"
fallback_policy:
fallback_success_is_pass: false
notes: "fallback経由(例: 未sanitize環境での成功や継承環境をそのまま許容する経路)での成功をPASSに変換しない。fail-closedな拒否はPASSと区別する。"
artifact_requirements:
- "pytest output(test_skill_runtime_control_plane_policy.py / test_skill_runtime_control_plane_exec.py 全件)"
- "post-checkout hook 非発火の fixture ログ(AC3)"
- "GIT_CONFIG split-execution 拒否・後置 global option 拒否・helper/askpass/ssh marker 非実行の fixture ログ(AC6-AC8)"In Scope
scripts/agent-guards/skill_runtime_exec.pyへの GIT_* 環境変数 unset ロジックの追加(control_plane_git_subprocess_contract.unset_env_exact_setの14変数)PATHを trusted allowlist から構成し、継承PATHをそのまま使わない(GIT_EXEC_PATH除去と合わせ、git-remote-https等の補助実行ファイル・sshの差し替えを防ぐ)- git executable 絶対パスの一度解決・再利用(
shutil.which等での解決結果キャッシュ) core.hooksPathを trusted empty directory へ固定する配線(絶対 realpath・component-wise no-follow・per-invocation directory)と、post-checkouthook 非発火の fixture 実証- prompt/credential helper/interactive SSH の無効化(
GIT_TERMINAL_PROMPT=0等)と、credential helper/askpass/ssh の marker executable が一度も起動されないことの直接実証 stdin=subprocess.DEVNULLの既定適用と、bounded timeout の必須化- 全 subprocess 呼び出しへの
--no-replace-objects固定 - 汎用
list[str]argv API を廃止し、allowlist されたサブコマンドのみを受理する closed command builder(control_plane_git_subprocess_contract.command_api.closed_builders_required)へ置き換える。呼び出し側は-c/--config-env/-C/--git-dir/--work-tree/--exec-path/--namespace等のサブコマンド前 global option を注入できない scripts/agent-guards/skill_runtime_command_policy.pyへのurl.<base>.insteadOf/url.<base>.pushInsteadOfrewrite fail-closed 拒否ポリシー追加。検査はgit configの人間可読 line format を独自 split せず、name-only・NUL区切り・regexp限定の構造化クエリで行い、probe と実コマンドが同一の config authority(GIT_CONFIGを含む)を参照することを保証する- config probe が非ゼロ終了・timeout・decode/I/O error のいずれかを返した場合は fail-closed で停止する(「rewriteなし」と「検査不能」を区別する)
- threat model(「誤った継承環境・通常のlocal configによるmisroutingをfail-closedする。same-UIDの能動的攻撃者には耐えない」)のコード内コメントまたはdocstring明記
Out of Scope
- remote default-ref OID の observe/fetch/pin/verify プロトコル(実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 AC4、Child 2 で扱う)
- lifecycle lock(実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 AC7、Child 3 で扱う)
- identity probe・command class 分離・4 production profile 移行(実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 AC1/AC3/AC5/AC9/AC10、Child 4 で扱う)
- artifact confinement(実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 AC6/AC11、Child 5 で扱う)
WORKTREE_CATALOG_ENTRY_V1スキーマ変更contract_update.run.with_anchor/contract_update.run.with_human_contextの dedicated worktree 化
Acceptance Criteria
- AC1: 専用Git subprocess実行前に
control_plane_git_subprocess_contract.unset_env_exact_setの14変数(GIT_DIR/GIT_WORK_TREE/GIT_COMMON_DIR/GIT_INDEX_FILE/GIT_OBJECT_DIRECTORY/GIT_ALTERNATE_OBJECT_DIRECTORIES/GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM/GIT_CONFIG_COUNT/GIT_CONFIG/GIT_CONFIG_PARAMETERS/GIT_EXEC_PATH/GIT_CEILING_DIRECTORIES/GIT_SSL_NO_VERIFY)が環境から unset されることをテストで実証する(実装: fix: bind issue-refinement control-plane preflight to a dedicated linked worktree #2190 AC2/AC8 相当) - AC2: git executable の絶対パスが一度だけ解決され、以降の全 subprocess 呼び出しで同一の絶対パス文字列が再利用されることをテストで実証する
- AC3:
core.hooksPathが絶対 realpath・symlink 非追従・per-invocation directory として trusted empty directory に固定され、fixture repo に配置したpost-checkouthook が checkout 相当操作で発火しないことを実証する。relative/symlink な scratch root が拒否されることも実証する - AC4:
url.<base>.insteadOf/url.<base>.pushInsteadOfによるorigin URL rewriteが設定された fixture 環境で、専用Git subprocess実行が fail-closed で拒否することを実証する。検査は name-only・NUL区切り・regexp限定の構造化git configクエリで行い、=を含む合法な subsection 名(例:url.https://evil.example/?x=y.insteadof=...)でも見逃さないことを実証する - AC5: prompt/credential helper/interactive SSH が無効化された状態(
GIT_TERMINAL_PROMPT=0等)で subprocess が起動し、かつ credential helper/askpass/ssh の marker executable が一度も実行されないことを直接実証する(HTTP 401 での非ハングだけでは不十分) - AC6:
GIT_CONFIG等により config probe と実コマンドが異なる config authority を参照できないことを実証する。probe を空 config へ向けつつ実コマンドが repository-localinsteadOfを適用する fixture(GIT_CONFIG split-execution)が fail-closed で拒否される - AC7: 継承
PATH/GIT_EXEC_PATHを汚染し、偽のgit-remote-httpsを配置した fixture で、closed command API 経由の実行が偽 helper を起動しないことを実証する。PATHは trusted allowlist から構成される - AC8: closed command builder API(
run_control_plane_git_ls_remote等)が、呼び出し側から渡された-c/--config-env/-C/--git-dir/--work-tree/--exec-path/--namespace等のサブコマンド前 global option を受理しないことを実証する。汎用list[str]argv を直接渡す production API が存在しないことも実証する - AC9: config probe が非ゼロ終了・timeout・decode/I/O error を返した場合、「rewriteなし」と誤判定せず fail-closed で停止することを実証する
- AC10: closed command builder 経由の全 subprocess 呼び出しで
stdin=subprocess.DEVNULLが既定適用され、bounded timeout が必須であることを実証する - AC11: closed command builder 経由の全 subprocess 呼び出しに
--no-replace-objectsが固定付与されることを実証する
Verification Commands
# AC1
# AC3
# AC6
# AC9
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py -q# AC2
# AC5
# AC7
# AC10
# AC11
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q# AC4
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_policy.py -q -k insteadof# AC8
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q -k global_option$ pnpm typecheck$ pnpm lint$ pnpm test$ pnpm build$ uv run --locked pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -qAllowed Paths
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
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- 本child issueのAllowed Paths外への波及が必要と判明した場合
Required Skills
なし
Required Design References
- docs/dev/agent-skill-boundaries.md
- docs/dev/workflow.md
- https://git-scm.com/docs/git-config(`GIT_CONFIG_*` / repository discovery authority /
insteadOf/pushInsteadOf) - https://git-scm.com/docs/githooks(`post-checkout` hook /
core.hooksPath) - https://git-scm.com/docs/git(global option 一覧
-c/--config-env/-C/--git-dir/--work-tree/--exec-path/--namespace/--no-replace-objects) - https://docs.python.org/3.9/library/subprocess.html(`stdin` 既定継承・
timeout既定Noneの挙動)
Scope Delta(任意)
N/A
Activity
squne121 commentedon Aug 16, 2026
implement-issue: 実装完了 (2026-08-16)
.claude/worktrees/issue-2196-git-subprocess-sanitizeworktree-issue-2196-git-subprocess-sanitizefix: 所有権レビュー P1 指摘を反映しGit subprocess sanitizationを強化する (#2196)
feat: sanitized Git subprocess execution utility for control-plane pr…