Skip to content

fix: no-sudo local-dev 向け trusted uv resolver に standard user-local lane を復元する #2280

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "Issue #2276 の決定(no-sudo 制約下で標準 user-local `~/.local/bin/uv` を canonical local-dev trust lane として再許可する)を skill_runtime_exec.py の trusted uv resolver に実装する"
change_kind: code

Parent Issue

なし(Issue #2276 の decision record からの follow-up 実装 Issue)

Outcome

scripts/agent-guards/skill_runtime_exec.py の trusted uv resolver(_resolve_trusted_executable / _safe_path_entries)に、標準 account-local ~/.local/bin/uv を no-sudo local-dev 向け positive lane として再許可する。account-home の判定は ambient HOME 環境変数からではなく、pwd.getpwuid(os.getuid()).pw_dir(実行中プロセスの実 Unix account identity)から導出し、HOME spoofing で trust path を攻撃者側へ移動できないようにする。再許可した lane も既存の exact version pin(pyproject.toml の [tool.uv].required-version)による fail-closed 検証を通す。

Threat Model / Security Property

In Scope

  • scripts/agent-guards/skill_runtime_exec.py に real OS account home を解決する新ヘルパー(pwd.getpwuid(os.getuid()).pw_dir ベース、ambient HOME 不使用)を追加する。既存の .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py:2962 にある stale なドキュメント参照 `_os_account_home()` に合わせた命名を検討する。
  • _safe_path_entries() に、上記ヘルパーで解決した real account home 配下の .local/bin を候補として追加する。
  • 追加した lane も含め、uv の resolve は既存の _validate_trusted_executable_version(pyproject.toml の exact version pin)による fail-closed 検証を通す(非 hostedtoolcache 解決には既存コードが自動的に version check を要求する)。
  • _safe_path_entries() の docstring を、同一 UID attacker containment を主張しない形に書き換える(no-sudo local-dev convenience lane である旨、新しい dedicated trusted-bin / sudo / checksum authority を導入しない旨を明記)。
  • scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py の Issue fix: trusted uv resolver から account-home .local/bin を除外し CWE-427 search-selection risk を縮小する #2251 節(test_safe_path_entries_excludes_local_bin、test_local_bin_only_fails_closed 等)を新しい仕様に合わせて書き換える。
  • 新規 positive/negative テストを追加する(下記 Verification Commands 参照)。
  • docs/dev/workflow.md に「Controlled / Not Controlled」の区分を明記するセクションを追加・整理し、account-home 再許可の decision を反映する。

Out of Scope

Allowed Paths

  • scripts/agent-guards/skill_runtime_exec.py
  • scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py
  • docs/dev/workflow.md
  • .claude/skills/issue-refinement-loop/tests/test_operator_selected_scope_reframe.py(Scope Delta 2026-08-21: test_sanitize_env_trust_root_real_subprocess_ignores_home_override_ac3 のアサーション更新のみ)

Acceptance Criteria

  • AC1: scripts/agent-guards/skill_runtime_exec.py に real OS account identity(pwd.getpwuid(os.getuid()))から home を導出するヘルパーが存在し、ambient HOME 環境変数を参照していない
  • AC2: _safe_path_entries("uv") が real account home 配下の .local/bin を候補に含む(Scope Delta 2026-08-21: account-home lane は executable_name == "uv" のときのみ候補になるよう _safe_path_entries() を executable_name 引数付きに変更した。コメント参照)
  • AC3: real account home の .local/bin/uv が pyproject.toml の required-version と一致するバージョンの場合、_resolve_trusted_executable("uv", ...) が成功する(新規テストで検証)
  • AC4: HOME 環境変数を攻撃者制御のパスへ spoof しても、real account home 以外の .local/bin/uv は選択されない(新規テストで検証)
  • AC5: real account home の .local/bin/uv のバージョンが required-version と不一致の場合、fail-closed で拒否される(新規テストで検証)
  • AC6: project/CWD 配下の fake uv は引き続き選択されない(既存の project_root containment ロジックが維持されている)
  • AC7: hostedtoolcache および system 標準ディレクトリ(/usr/local/bin 等)の既存 lane が regression なく動作する(既存テストが pass する)
  • AC8: _safe_path_entries() の docstring が same-UID attacker containment を主張しておらず、明示的に否認する記述がある(Scope Delta 2026-08-21: 逐語 VC を same-UID attacker 文字列不在チェックから、否認文の存在チェックへ修正した。前者は docstring が拡張されてリスク説明文脈で same-UID attacker という語句自体は残るため false-negative になっていた)
  • AC9: scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py の test_safe_path_entries_excludes_local_bin 相当のテストが、新しい仕様(real account home の .local/bin は許可、isolated/spoofed HOME 由来の .local/bin は拒否)を検証する形に更新されている
  • AC10: docs/dev/workflow.md に Controlled / Not Controlled の区分と、本 Issue の決定(account-home 再許可)が明記されている
  • AC11(Scope Delta 2026-08-21 で新設・同日中に実装詳細を再修正済み): account-home lane は _resolve_trusted_executable 内で name == "uv" の場合のみ候補に追加され、共有の _safe_path_entries()(_sanitize_env/sanitized_git_subprocess_env/_resolve_trusted_ssh_command が使う、git/ssh を含む全 executable 名で共有される PATH リスト)には一切含まれないことが新規 adversarial regression テスト(test_safe_path_entries_never_includes_account_home / test_trusted_account_home_uv_dir_returns_real_account_home_local_bin / test_resolve_trusted_executable_uv_lane_includes_account_home_only_for_uv)で検証されている

Verification Commands

# AC1
# baseline-expect: fail (helper not yet added)
$ rg -n "pwd\.getpwuid\(os\.getuid\(\)\)" scripts/agent-guards/skill_runtime_exec.py

# AC2
# baseline-expect: fail
$ rg -n "_trusted_account_home" scripts/agent-guards/skill_runtime_exec.py

# AC3
# baseline-expect: fail (test not yet added)
$ uv run --locked pytest scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py -k account_home_local_bin_uv_correct_version -v

# AC4
# baseline-expect: fail (test not yet added)
$ uv run --locked pytest scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py -k fake_home_local_bin_never_selected -v

# AC5
# baseline-expect: fail (test not yet added)
$ uv run --locked pytest scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py -k account_home_local_bin_uv_wrong_version -v

# AC6/AC7 regression
# baseline-expect: pass
$ uv run --locked pytest scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py scripts/agent-guards/tests/test_skill_runtime_control_plane_exec.py -q

# AC8
# baseline-expect: fail
$ rg -n "does not claim to contain an attacker" scripts/agent-guards/skill_runtime_exec.py
# expect after fix: match found (exit 0), confirming the docstring explicitly disclaims
# same-UID attacker containment rather than merely omitting the old claim

# AC9
# baseline-expect: fail (old exclusion-only assertion still present)
$ rg -n "test_safe_path_entries_excludes_local_bin" scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py

# AC10
# baseline-expect: fail
$ rg -n "^### Controlled" docs/dev/workflow.md

# AC11
# baseline-expect: fail (test not yet added)
$ uv run --locked pytest scripts/agent-guards/tests/test_trusted_toolchain_isolated_home.py -k "safe_path_entries_never_includes_account_home or resolve_trusted_executable_uv_lane_includes_account_home_only_for_uv" -v

Runtime Verification Applicability

本 Issue の変更対象は agent 実行基盤スクリプト・テスト・docs のみです。ゲームの実行時動作には影響しません。

decision: not_applicable
reason: "Agent runtime trust boundary script and docs changes only. No game runtime behavior changed."

Dependencies

Stop Conditions

  • Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止
  • Allowed Paths 外への書き込みを試みた場合は即停止
  • 権限不足(permission denied)により操作が完了できない場合は即停止
  • 成果物の書き込みに失敗した場合(I/O エラー等)は即停止

Activity

  1. squne121 commented on Aug 21, 2026

    @squne121
    OwnerAuthor

    Scope Delta: Allowed Paths 拡張

    実装中、.claude/skills/issue-refinement-loop/tests/test_operator_selected_scope_reframe.py の test_sanitize_env_trust_root_real_subprocess_ignores_home_override_ac3(real subprocess で _safe_path_entries() を直接観測するテスト)が、旧設計(account-home .local/bin は常に全除外)を前提にしたアサーションを持っており、本 Issue の決定(real account home の .local/bin は許可、env-spoofed HOME 由来の .local/bin のみ拒否)と正しく矛盾することが判明しました。

    このテストは resolver の実際の security property を検証する regression test であり、削除ではなく アサーションを新しい仕様に合わせて修正 する必要があります。

    Allowed Paths に以下を追加します:

    • .claude/skills/issue-refinement-loop/tests/test_operator_selected_scope_reframe.py

    変更は該当テストのアサーション更新のみ(docstring・assertion の意味論修正)に限定し、テスト本体の削除は行いません。

  2. squne121 commented on Aug 21, 2026

    @squne121
    OwnerAuthor

    Scope Delta: account-home lane を uv 専用に限定する設計修正

    PR #2281 のレビューで、adversarial security reviewer が重大な指摘をした。_trusted_account_home_uv_dir() を共有の _safe_path_entries() リストへ無条件に追加していたため、_resolve_trusted_executable("git", ...)(_GIT_SUBPROCESS_EXECUTABLE_CACHE 経由で使用)等、uv 以外の executable 名の解決にも account-home .local/bin が候補として渡っていた。_validate_trusted_executable_version は uv 以外では no-op のため、real account home の .local/bin に同一 UID が置いた偽 git 等が無検証で trust されてしまう state だった。これは本 Issue の Out of Scope(「python3 等、uv 以外の executable の trust boundary ロジック変更」)に反する regression であり、Issue #2251 が閉じた CWE-427 exposure を git について再度開く。

    修正: _safe_path_entries(executable_name: str | None = None) とし、account-home lane は executable_name == "uv" のときのみ候補に含める。_resolve_trusted_executable は _safe_path_entries(name) を呼び、git/ssh 用の _sanitize_env / sanitized_git_subprocess_env / _resolve_trusted_ssh_command は引き続き _safe_path_entries()(account-home 不含)を呼ぶ。

    AC2 / AC9 の記述を以下のように修正する:

    • AC2: _safe_path_entries("uv") が real account home 配下の .local/bin を候補に含む(_safe_path_entries("git") や _safe_path_entries() は含まない)
    • AC9 を新設: git 等 uv 以外の名前の解決には account-home lane が一切含まれないことを新規テストで検証する(adversarial regression test)

    新規テスト test_safe_path_entries_excludes_account_home_for_non_uv_names / test_resolve_trusted_executable_git_never_selects_account_home_fake を追加済み。全 91 テスト pass、ruff clean。

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions