Skip to content

実装: control-plane preflight 用 sanitized Git subprocess 実行基盤を新設する #2196

Closed

Description

@squne121

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: code

Parent Issue

#2190

Parent Goal Ref

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>.pushInsteadOf rewrite の 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-checkout hook が発火しないことに加え、GIT_CONFIG split-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_directory

Remaining Parent Gaps

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-checkout hook 非発火の 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>.pushInsteadOf rewrite 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

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-checkout hook が 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-local insteadOf を適用する 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 -q

Allowed 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

Scope Delta(任意)

N/A

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Aug 16, 2026
  2. squne121 commented on Aug 16, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-08-16)

    • PR: feat: sanitized Git subprocess execution utility for control-plane preflight (#2196) #2201
    • Worktree: .claude/worktrees/issue-2196-git-subprocess-sanitize
    • Branch: worktree-issue-2196-git-subprocess-sanitize
    • Verification: 全項目 PASS(typecheck / lint / test 1872件 / build / 新規 pytest 18件 / 既存 agent-guards pytest 1320件回帰なし / model_routing pytest 24件)
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions