Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1408"
goal_ref: "Issue #1450への人間の敵対的セキュリティレビュー(https://github.com/squne121/loop-protocol/issues/1450#issuecomment-4943281788)で指摘されたP1 Blocker「hash verifier/analyzer自体がcandidate-controlledであり、candidate repository内には信頼の起点となるexternal trust rootが存在しない」を解消する。さらに本Issue自身へのOWNER敵対的レビュー(https://github.com/squne121/loop-protocol/issues/1454#issuecomment-4944530037、REQUEST_CHANGES)で指摘されたP1 Blocker(managed hook registrationの欠如・working tree digestとpush対象commitの不一致・検査後command書換えの欠如)を解消する"
change_kind: codeParent Issue
Parent Goal Ref
- Goal: Issue #1408のpublish lane approval bridgeが、検証済み証跡に基づいてrtk git pushを許可しつつ、危険・不一致なpushをdenyし続ける状態を確立する
- Desired Destination: Issue 実装: publish laneのauthorization code(policy/adapter)の信頼境界をhash pinningでcandidate worktree外に確立する #1450(policy/adapterのhash pinningによるcandidate worktree内 trust boundary確立)に対する敵対的レビューで、「candidate repository内には信頼の起点が存在しない」ことが指摘された。本Issueはその信頼の起点(agentが書込み不能なexternal trust root)をPhase Aとして確立し、Issue #1450はこのtrust root上でcandidate integrity bindingを行うPhase Bとして本Issueに依存する
Current Validated Scope
- 現在のPreToolUse hook実行経路は
.codex/hooks.json→ candidate worktree内のcomposite → candidate worktree内のadapter → candidate worktree内のpolicy、という全段がcandidate repository内にあり、agentが書込み・改変可能である - Issue #1450への敵対的レビュー(OWNER, https://github.com/squne121/loop-protocol/issues/1450#issuecomment-4943281788)により、hash比較ロジックをcandidate側に置く設計では「改変対象自身に自分が改変されていないことを判定させる」ことになり信頼境界が成立しないことが指摘された
- 同レビューにより、
origin/mainを含むcandidate repository内のremote-tracking refは、candidate側でlocal ref・object database・Git設定・環境変数を操作できるためtrusted sourceたり得ないことが指摘された - codebase-investigator(gemini-cli-headless-delegation経由)の独立調査により、repository内にcandidate-controlledでないtrust entrypointが現状存在しないことが裏付けられた
- web-researcherのfact-checkにより、Codex
hooks.managed_dirの存在、origin/mainが共有mutable remote-tracking refであること、check-then-executeのTOCTOU race conditionの一般的存在、immutable trusted referenceのベストプラクティスが一次情報で検証済みである - 本Issue(初版)へのOWNER敵対的レビュー(https://github.com/squne121/loop-protocol/issues/1454#issuecomment-4944530037、REQUEST_CHANGES)により、初版の設計は「外部コピーが改変されていないこと」しか証明できず、次の3経路が閉じていないことが指摘された: (1)
.codex/hooks.jsonの登録自体がcandidate-controlledのままlauncherを呼ばない、(2) working tree digestを検査してもpushされるlocal_oidのtree/blobとは無関係、(3) 検査後にfakertk・PATH置換・HEAD移動でexecution-time TOCTOUが発生する。同レビューはCodex公式ドキュメント(hooks.managed_dir・requirements.toml・PreToolUseupdatedInput・Node/Python環境変数)、POSIX man page(chmod(2)・unlink(2)・rename(2)・openat2(2))、Git公式ドキュメント(git-push・git-config)を一次情報として引用している
Remaining Parent Gaps
- 本Issue完了後も、実際のpublish lane判定ロジックの統合(
.codex/hooks.jsonを本launcherへ実際に向ける本番切替、candidate側codex-hook-adapter.mjsのTCBからの完全分離、既存publish laneのpositive/negative regressionテストをtrusted launcher経由で再検証する統合作業)はIssue 実装: publish laneのauthorization code(policy/adapter)の信頼境界をhash pinningでcandidate worktree外に確立する #1450(Phase B、本Issueにblocked_byとして依存)で扱う - privileged operatorによる実機へのinstall実行(
install_trust_root.sh//etc/codex/requirements.tomlへの実登録)は本Issueでは行わず、installer scriptと手順書の提供までを本Issueの範囲とする - Node/pnpm session-recording adapter(
codex-hook-adapter.mjs・write-codex-session-manifest.mjs等)自体の再実装・security-critical pathからの完全分離実装は本Issueでは行わず、launcher側でNode component群を authorization TCBから除外する契約と検証のみを本Issueで扱う
Outcome
managed PreToolUse(/etc/codex/requirements.tomlにadmin-enforcedで登録されたhook)が捕捉した exact publish lane に対する local authorization TCB が、candidate worktree外の、agentが書込み不能な絶対パスに配置されたtrusted dispatcher/launcherのソース一式・external trust manifest schema(AUTHORIZATION_TCB_MANIFEST_V1)・privileged operator向けbootstrap/rotation installer scriptとしてscripts/trust-root/配下に追加される。launcherはproject-local .codex/hooks.jsonの削除・改変・無効化に依存せず作動し、push対象として確定したlocal_oidのtree/blobをmanifestと照合し、一致時のみupdatedInputでtrusted publisher(絶対パス・--force-with-lease固定)に置換して実行する。manifest欠落時・component改変時・symlink化時・origin/main等のremote-tracking ref書換え時・PATH偽装時・fake rtk実行時にはすべてfail-closedでdenyする。リポジトリ全体のremote-write security boundaryとは表現せず、GitHub branch protection / server-side rulesを最終防御として引き続き前提とすることをdocsに明記する。対応する実subprocess integration test(temporary external trusted directory + temporary candidate worktree + temporary bare Git repositoryを用いた改変検知テスト)がPASSしている状態。
In Scope
scripts/trust-root/trusted_hook_launcher.py(dispatcher): candidate repository外の絶対パスで動作するself-contained Python launcherのsource。managedPreToolUsepayloadを受け取り、外部manifestを読み込み、push対象として確定したlocal_oidの<local_oid>:<component-path>blob bytesをtrusted Git invocationで読みSHA-256をmanifestと照合する(working tree pathのlstatを正本にしない)。critical pathにuncommitted changeがある場合はcandidate_tree_ambiguousでdenyする。一致時のみ、allow時に元のBash commandをそのまま通すのではなく、updatedInput.commandで絶対パスのtrusted publisher(/usr/bin/git push --force-with-lease=<ref>:<expected-remote-oid> origin <local_oid>:<validated-ref>固定argv)に置換して実行する。Node/pnpm/composite/session-manifest producer(write-codex-session-manifest.mjs・codex-metadata-scan.mjs・codex-postrun-verifier.mjs等)はauthorization TCBから除外し、Pythonは固定absolute pathかつ-I(isolated mode)で実行するscripts/trust-root/manifest_schema.py:AUTHORIZATION_TCB_MANIFEST_V1のschema定義とバリデータ(manifest_version, repository, trusted_commit_oid(full 40-hex), components[].path/sha256, issued_by, generation(monotonic release epoch)を必須とし、unknown key・missing component・duplicate componentをdeny)。digest契約はsha256 / raw file bytes / lowercase hex / 64桁 / regular fileのみ / symlink deny / repository-relative posix path / line-ending正規化なし / unicode正規化なしに固定する。component digestはtrusted_commit_oidのtreeからinstallerが生成する契約とし、任意の手元ファイルからは生成できないことをdocsとinstallerロジックで明記する。issued_byはaudit metadataであり authenticity の根拠にしないことをschema docstringに明記するscripts/trust-root/install_trust_root.sh: privileged operatorが手動実行するinstaller(実行対象はrepo外のoperator指定ディレクトリ。既定値は/opt/loop-protocol/trust-rootのようなroot-owned anchorとし、「任意directory」を許容しない)。installerはrelease-based atomic layout(releases/<generation>-<manifest-digest>/配下にmanifest/authorization component、active.jsonはtmp+fsync+renameで単一原子的activation)を構築し、installer実行時のeuidがtrust root owner euidと同一の場合installationを拒否する(runtime_euid_must_differ_from_owner)。agentはこのスクリプトを実行しない- Git参照をtrust rootの入力として使う場合、
--no-replace-objectsの使用、明示的な--git-dir指定、GIT_DIR/GIT_COMMON_DIR/GIT_OBJECT_DIRECTORY/GIT_ALTERNATE_OBJECT_DIRECTORIES/GIT_CONFIG_COUNT等の環境変数除去、git rev-parse --verify <oid>^{commit} --end-of-optionsによるcommit型確認をlauncher内で実装する。Git subprocessは固定PATH・専用HOME・GIT_CONFIG_GLOBAL=/dev/null・GIT_CONFIG_SYSTEM=/dev/null・GIT_CONFIG_NOSYSTEM=1を明示し、env -i相当のallowlist方式で環境を構築する(blacklist方式は使わない) - publish evidence(
session_id/turn_id/tool_use_id/local_oid/remote_oid/issue_number/nonce/expiry)は inherited環境変数ではなく、trusted verifierが生成したversioned JSON/FDで launcher に渡す契約とする。LOOP_CANONICAL_REPO_URL_PATTERN/LOOP_DEFAULT_BRANCHは production launcherでは環境変数由来の値を信頼せず、test-only dependency injectionとしてのみ扱う - launcherのfail-closed reason code(
authorization_trust_root_missing/authorization_manifest_invalid/authorization_component_missing/authorization_component_type_invalid/authorization_component_digest_mismatch/authorization_reference_untrusted/authorization_runtime_untrusted/candidate_tree_ambiguous/candidate_commit_component_mismatch)を定義し、すべてgeneric allowでなくdenyする - featureはmanifestとtrusted directoryがprivileged operatorによってinstallされるまでdisabled(fail-closedでdeny)状態にする
- privileged bootstrap・manifest rotation・system-managed hook registration(
/etc/codex/requirements.tomlへの[features].hooks = true固定と managedPreToolUse登録手順)の手順(担当者・順序・failure/rollback)をdocsに明記する:bootstrap_executor: privileged_operator/manifest_update_authority: privileged_operator/rollback_policy: explicit_operator_approval/activation_order: [merge_trusted_code, install_trusted_runtime, install_manifest, register_managed_hook, enable_publish_lane]。managed hookはallow_managed_hooks_onlyを必須にせず、project-local hookの状態(削除・空化・無効化)に関わらずmanaged launcherが独立して作動する契約であることを明記する - 以下のtamperシナリオに対する実subprocess integration testを
scripts/trust-root/tests/に追加する: candidate adapter/policy/analyzer/composite改変(working tree改変とHEAD改変の両方を区別)、symlink化、origin/main書換え、refs/replace追加、偽python3/git/node/rtkをPATH先頭配置、.codex/hooks.jsonの削除・空化・別command変更、installer euidとowner euidの同一化、ancestor directoryのgroup-writable化
Out of Scope
.codex/hooks.jsonを本launcherへ実際に向ける本番切替、および candidate側のcodex-hook-adapter.mjs/git_mutation_command_policy.pyのTCB digest照合ロジックそのものの実装(Issue 実装: publish laneのauthorization code(policy/adapter)の信頼境界をhash pinningでcandidate worktree外に確立する #1450 Phase Bの対象)- 既存publish laneのpositive/negative regressionテストをtrusted launcher経由で再検証する統合作業(Issue 実装: publish laneのauthorization code(policy/adapter)の信頼境界をhash pinningでcandidate worktree外に確立する #1450 Phase Bの対象)
- Codex
hooks.managed_dir(admin-enforced領域)への本格移行そのもの。本Issueでは/etc/codex/requirements.tomlへの managedPreToolUse登録手順とfail-closed契約をdocsとinstallerに用意するに留め、hooks.managed_dir配下への完全移行は将来follow-upとする - 未mergeのpolicy変更を使ったbootstrap publishの検証テスト(Issue 実装: publish laneのauthorization code(policy/adapter)の信頼境界をhash pinningでcandidate worktree外に確立する #1450 Phase BのAC対象)
- privileged operatorによる実機への実際のinstall実行(installer script・managed hook登録手順書の提供までが本Issueの範囲。実行はOWNERが手動で行う)
- Node/pnpm session-recording adapter(
write-codex-session-manifest.mjs・codex-metadata-scan.mjs・codex-postrun-verifier.mjs)自体の再実装。本Issueでは launcher が これらを authorization TCB から除外する契約と検証のみを扱う
Runtime Verification Applicability
- reason: launcherのtrust boundaryはcandidate worktree外の実プロセス起動・実subprocess実行・実ファイルシステム操作(symlink・lstat・regular file判定)・実Git ref/object/config解決に依存するため、fixtureへの関数呼び出しだけのunit testでは「candidate verifierを消してもdenyされる」ことを証明できない。temporary external trusted directory + temporary candidate worktree + temporary bare Git repository + 実subprocessを用いた統合テストで検証する
decision: immediate
applicable_acs:
- AC1
- AC2
- AC3
- AC4
- AC5
- AC6
- AC7
- AC8
- AC9
- AC10
- AC11
- AC12
- AC13
- AC14
- AC15
- AC16
execution_environment:
cli_tools:
- python3
- uv
fixtures:
- temporary external trusted directory
- temporary candidate worktree
- temporary bare Git repository
auth_required: false
network_required: false
skip_conditions:
- "root-owned/EUID分離ファイルシステム操作(chmod/rename/openat相当)をサポートしないCI runner上では、privileged filesystemテストのみ skipif 可能とする(それ以外のtamperシナリオは skip 不可)"
fallback_policy:
fallback_success_is_pass: false
notes: "skip対象ACはPRコメントにskip理由と再現手順を明記し、privileged smokeを別artifactとして人間が実施した証跡(実行ログ・timestamp)を添付する。fallback経由の成功をPASSに変換しない"
artifact_requirements:
- "scripts/trust-root/tests/test_trusted_hook_launcher.py の pytest 出力"
- "scripts/trust-root/tests/test_manifest_schema.py の pytest 出力"Acceptance Criteria
- AC1: launcher entrypointがcandidate repository外の絶対パスに配置される設計になっており、
scripts/trust-root/trusted_hook_launcher.pyにその絶対パス解決・owner-only permission検証ロジックが実装されている - AC2:
scripts/trust-root/manifest_schema.pyがAUTHORIZATION_TCB_MANIFEST_V1のschema・full commit OID・全componentのSHA-256・generationを単一manifestで原子的にbindし、unknown key/missing component/duplicate componentをdenyすることがテストで確認できる - AC3: candidate側のadapter/policy/analyzer/compositeいずれかのファイル内容をworking tree上でのみ改変した状態でlauncherを実subprocessとして起動すると、
authorization_component_digest_mismatchでdenyする - AC4: candidate側のverifier/policyからintegrity checkの呼び出し自体を削除しても、external launcher(candidate側の実行に依存しない構成)がdenyを維持する
- AC5: 全component一致時、launcherはcandidate側のpolicy/analyzerファイルを実行せず、external trusted directory配下のtrusted copyのみを絶対パスで実行する
- AC6: candidate componentをsymlink化・非regular file化・欠落・manifest内duplicate entryにした場合、いずれもfail-closedでdenyする
- AC7: candidate repository内の
origin/main等のremote-tracking refを書き換えても、launcherのtrusted resolutionには影響しない - AC8:
refs/replaceを追加しても、--no-replace-objects相当のlauncher側処理によりtrusted resolutionに影響しない - AC9: PATHの先頭に偽
python3/git/node/rtkを配置しても、launcherおよびtrusted publisherは絶対パス実行のため影響を受けない - AC10: privileged bootstrap・manifest rotation・managed hook registrationの担当者・順序・failure/rollback動作がdocs(
docs/dev/hook-boundaries.md)にbootstrap_executor/manifest_update_authority/rollback_policy/activation_orderの語句付きで記載されている - AC11: manifestとtrusted directoryが未installの状態では、launcherはgeneric allowせずfail-closedで
authorization_trust_root_missingを返す - AC12:
scripts/trust-root/tests/test_trusted_hook_launcher.pyの実subprocess integration testが全tamperシナリオ(AC3, AC4, AC6-AC9, AC13-AC16相当)を含めてPASSする - AC13:
.codex/hooks.jsonを削除・空化・別commandに変更した状態でも、scripts/trust-root/install_trust_root.shが生成するmanaged hook登録設定(/etc/codex/requirements.toml相当のfixture)を経由したlauncher起動シナリオではdenyが維持されることを実subprocess integration testで確認できる - AC14: HEADにmalicious componentをcommitし working tree のみ approved bytes に戻した状態(
candidate_commit_component_mismatchシナリオ)でlauncherを起動すると、working tree検査ではなくlocal_oidのtree/blob検査によりdenyする - AC15: 全component一致時、launcherは元のBash commandをそのまま通さず、
updatedInput.commandで絶対パス・--force-with-lease=<ref>:<expected-remote-oid>固定のtrusted publisher argvに置換する(fakertk・PATH置換・HEADmovementの影響を受けない)ことをテストで確認できる - AC16: installer実行時のeuidがtrust root owner euidと同一の場合、installerがinstallationを拒否することをテストで確認できる
Verification Commands
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k external_absolute_path_permission # AC1
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_manifest_schema.py -k manifest_atomic_binding # AC2
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k tamper_component_denied # AC3
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k integrity_check_removed_still_denied # AC4
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k trusted_copy_executed_not_candidate # AC5
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k symlink_and_missing_denied # AC6
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k origin_main_rewrite_ignored # AC7
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k refs_replace_ignored # AC8
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k fake_path_binaries_ignored # AC9
# baseline-expect: fail
$ rg -n "bootstrap_executor" docs/dev/hook-boundaries.md # AC10
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k trust_root_missing_denied # AC11
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py # AC12
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k managed_registration_survives_local_hook_removal # AC13
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k committed_malicious_working_tree_clean_denied # AC14
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k trusted_publisher_command_rewrite # AC15
# baseline-expect: fail
$ uv run --locked pytest scripts/trust-root/tests/test_trusted_hook_launcher.py -k installer_same_euid_rejected # AC16Allowed Paths
- scripts/trust-root/trusted_hook_launcher.py
- scripts/trust-root/manifest_schema.py
- scripts/trust-root/install_trust_root.sh
- scripts/trust-root/tests/test_trusted_hook_launcher.py
- scripts/trust-root/tests/test_manifest_schema.py
- docs/dev/hook-boundaries.md
- docs/dev/session-recording-policy.md
- docs/dev/agent-runtime-ops.md
- .github/ci/python-test-plan.json
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
.codex/hooks.jsonを本launcherへ実際に向ける本番切替が必要と判明した場合- privileged operatorによる実機へのinstall実行・managed hook登録の実実行を本Issue内で行う必要が生じた場合
- Node/pnpm session-recording adapter自体の再実装が必要と判明した場合
Required Skills
- Python / pytest
- Bash installer script
- Git、SHA検証、trust boundary設計
- Codex
PreToolUse/ managed hook設定(requirements.toml)の仕様理解
Required Design References
- docs/dev/session-recording-policy.md
- docs/dev/hook-boundaries.md
- docs/dev/agent-runtime-ops.md
- Issue 実装: publish laneのauthorization code(policy/adapter)の信頼境界をhash pinningでcandidate worktree外に確立する #1450 敵対的レビューコメント(https://github.com/squne121/loop-protocol/issues/1450#issuecomment-4943281788)
- Issue 実装: publish lane authorization codeの信頼起点となるexternal trust root(trusted hook launcher・manifest・bootstrap/rotation手順)を確立する #1454 敵対的レビューコメント(OWNER, REQUEST_CHANGES, https://github.com/squne121/loop-protocol/issues/1454#issuecomment-4944530037)
- OpenAI Codex config reference(hooks.managed_dir): https://developers.openai.com/codex/config-reference/
- OpenAI Codex hooks reference(PreToolUse updatedInput・managed hook): https://developers.openai.com/codex/hooks/
Delivery Rule
- 1 Issue = 1 PR
- Dedicated worktreeを作成して実装する
- Draft PR既定
- 本Issue(Phase A: external trust root)はIssue 実装: publish laneのauthorization code(policy/adapter)の信頼境界をhash pinningでcandidate worktree外に確立する #1450(Phase B: candidate integrity binding)の前提となる。#1450は本Issueのmerge後に着手する
Scope Delta(任意)
- 本Issue初版に対するOWNER敵対的レビュー(https://github.com/squne121/loop-protocol/issues/1454#issuecomment-4944530037、REQUEST_CHANGES)を反映し、In Scope / Out of Scope / Acceptance Criteria / Allowed Paths / Verification Commands を更新した。追加された主な In Scope 項目: managed
PreToolUsehook登録(/etc/codex/requirements.toml)契約、working tree ではなくlocal_oidblob 検査への変更、allow 時のupdatedInputによる trusted publisher 置換、installer の euid 分離要件。 - 上記スコープ拡張は
issue-refinement-loopのANCHOR_SCOPE_REFRAME_V1構造化テンプレートを伴わない freeform な OWNER レビュー指摘(scope_delta_authority_evidence_v1)に基づく。deterministic scope guard(scope_signal_delta.py)の判定結果は本 Issue の refinement loop 終了コメントに記録する。 - PR feat: publish lane authorization の external trust root を確立する #1457 に対する pr-review-judge の REQUEST_CHANGES(iteration 1: feat: publish lane authorization の external trust root を確立する #1457 (comment) 、iteration 2 Allowed Paths gate: fail_closed)を反映し、
.github/ci/python-test-plan.jsonを Allowed Paths に追加した。CI のgenerate_ci_test_selection_artifact.py(uncovered_changed_test_filesゲート、Issue 実装: pytest target plan を SSOT 化し serial→xdist 段階移行と ci_test_selection fail-close 化を行う(python-test 並列化 migration) #1064 由来)が新規 test file 追加時に.github/ci/python-test-plan.jsonへの登録を必須としており(過去 precedent: fix(e501_migration_guard): TypeIgnore 意味論的正規化と full-scope completion モード追加(#1156 前提) #1163 / chore(ci): test_pr_body_validator.py を python-test plan に登録し #1156 を unblock する #1164 / 実装: issue-refinement-loop producer の fail-closed routing を固定する #1165 / 実装: hooks: publish_termination_report 用 controlled mutation policy を分離する #1166)、この登録なしには required CI checks(python-test/node-backed-hook-tests)が green にならないため、本 Issue の実装完了に不可欠な機械的追加としてスコープを拡張する。契約の他の固定要素(Outcome / In Scope / AC / VC)は変更しない。
Activity
squne121 commentedon Jul 11, 2026
create-issue transaction partial-failure
Issue: #1454
Failure stage: label-apply
Message: label-apply failed
Requested:
Completed steps: create
Failure context: command=gh issue edit --repo squne121/loop-protocol 1454 --add-label phase/implementation,agent/implementer,enhancement,triage-required,security
output=failed to update #1454: 'security' not found
failed to update 1 issue
matching_issue_numbers=[1454]
issue_number=1454
Recovery hint: stage 'label-apply' encountered an unexpected failure.
Generic guidance: verify the issue state manually and re-run the transaction if safe.
gh issue view 1454 --repo squne121/loop-protocol --json number,title,labels,state
idempotent re-run: depends on the specific failure
Please recover deterministically before re-running the create issue transaction.
squne121 commentedon Jul 11, 2026
判定:REQUEST_CHANGES
Issue #1454 は、#1450 の前回レビューで指摘された「candidate-controlled verifier」「可変 working tree の検査後に別物を実行する TOCTOU」「origin/main や replace ref 依存」をかなり正確に取り込んでいます。外部 manifest、trusted copy のみの実行、fail-closed installer、Git 環境の除去という方向性は妥当です。
ただし、現在の契約で証明できるのは主に**「外部コピーが改変されていないこと」**です。必要なのはそれより強い、次の end-to-end property です。
現状はこの連鎖が三か所で切れています。
P1 Blocker 1:launcher の登録元が依然として candidate-controlled
#1454 は external launcher を作りますが、実際の hook switch は #1450 に委譲し、
hooks.managed_dirは明示的に Out of Scope です。現在の.codex/hooks.jsonは repository 内の composite を直接起動しており、制御面そのものが candidate 側にあります。Codex の公式仕様では、project-local hook は定義が変更されると再信頼されるまでスキップされ、ユーザーから無効化もできます。一方、system・MDM・
requirements.toml由来の managed hook は policy-trusted で無効化できません。したがって、repository 内の.codex/hooks.jsonを絶対パス launcher に変更するだけでは trust root になりません。([OpenAI Developers]1)必要な修正
/etc/codex/requirements.tomlに managedPreToolUsehook を登録する。[features].hooks = trueを管理設定で固定する。hooks.managed_dirから root/admin-owned launcher を起動する。allow_managed_hooks_only = trueは既存 hook を全停止するため、移行完了までは必須ではない。ただし、security-critical な判定は managed hook 一つで完結させる。requirements.tomlはユーザーが上書きできない admin-enforced 設定であり、Unix の system location は/etc/codex/requirements.tomlです。([ChatGPT学習サイト]2)追加すべき negative test:
.codex/hooks.jsonを削除・空化・別 command に変更しても managed launcher が deny する。[features].hooks = falseを指定しても managed requirement が勝つ。P1 Blocker 2:「owner-only」は agent-nonwritable を意味しない
Issue は「任意の external absolute directory」「owner-only permission」を要件にしていますが、installer owner と agent runtime が同一 UID なら、そのプロセスは自分が所有するファイルの mode を変更できます。Linux では effective UID が owner と一致すれば
chmodが許可されます。([man7.org]3)また、ファイル自身が root-owned でも、親ディレクトリが agent-writable なら directory entry を
unlink・renameして別 inode に置き換えられます。削除・rename の権限は対象ファイルではなく、主に包含ディレクトリの write permission で決まります。([man7.org]4)必要な修正
agent-nonwritableを曖昧な形容ではなく、機械判定可能な invariant にしてください。少なくとも
/opt/loop-protocol/trust-rootのような root-owned anchor を既定値とし、「任意 directory」は削除すべきです。WSL 上で agent と operator が同じ Linux user の場合、chmod 700やchmod 600は保護ではありません。追加すべき test:
P1 Blocker 3:working tree の digest は、push される commit の証明にならない
現在の設計は candidate path を
lstatし、raw bytes の SHA-256 を manifest と比較します。しかし publish lane が送る対象は working tree ではなくHEADです。既存契約もrtk git push origin HEAD:refs/heads/<active-branch>を許可対象としています。したがって、次の攻撃が成立します。
HEADを publish する。これは AC3 の「candidate file tamper」試験では検出できません。
必要な修正
local_oidの tree/blob を検査する。<local_oid>:<component-path>の blob bytes を trusted Git invocation で読み、その SHA-256 を manifest と比較する。candidate_tree_ambiguousで deny。trusted_commit_oidの tree から installer が生成し、任意の手元ファイルから生成できないようにする。必須 negative test:
P1 Blocker 4:検査後に実行される
rtk・HEAD・remote state が固定されていない現在の adapter は policy が allow を返すと
nullを返し、元の Bash command をそのまま通します。つまり trusted policy が認可するのは文字列としての
ですが、その後に shell が解決する
rtkは PATH、shell function、alias、login-shell 環境などの影響を受けます。AC9 は fakepython3・git・nodeを対象にしていますが、実際の先頭 executable である fakertkを閉じていません。さらに検査後、実コマンドの開始前に別 process が
HEADを移動できます。必要な修正
allow 時に元 command を通すのではなく、managed launcher が
updatedInput.commandを返し、次のような trusted publisher に置換してください。Codex のPreToolUseは Bash command の書換えを公式にサポートしています。([OpenAI Developers]1)publisher 自身が絶対パスの Git を argv 配列で起動し、少なくとも次を固定します。
Git は
<src>に明示的 object expression を指定できます。また、expected value を明記した--force-with-lease=<ref>:<expect>は remote ref がその値でなければ失敗し、empty expect は ref 不在を要求します。([Git]5)policy 側で fast-forward/allowed-paths/head binding を確認したうえで、publisher が同一 OID と lease を使う形にすれば、次を同時に閉じられます。
rtkHEADmovementP1 Blocker 5:transitive TCB が manifest の component 集合を超えている
Issue は composite、adapter、policy、analyzer を主要 component としています。しかし現在の adapter は module load 時点で、少なくとも次の三ファイルを静的 import しています。
write-codex-session-manifest.mjscodex-metadata-scan.mjscodex-postrun-verifier.mjsさらに candidate policy/analyzer を path 解決し、PATH 上の
python3を起動しています。外部に adapter だけコピーすると import が失敗し、依存を全部コピーすれば TCB が暗黙に拡大します。現状の
authorization_runtime_untrustedreason code だけでは component closure を証明できません。推奨変更
security-critical path を session-recording adapter から分離してください。
PreToolUse専用の self-contained Python launcher。-Iは user site、script directory、全PYTHON*環境変数を import path から排除します。([Python documentation]6)Node を残す場合は少なくとも
NODE_OPTIONS、NODE_PATH、global module search を閉じる必要があります。NODE_OPTIONSは--requireを注入でき、NODE_PATHは module search path を前置できます。([Node.js]7)P1 Blocker 6:sanitized environment と現在の evidence protocol が矛盾している
現在の policy は authorization input の大部分を環境変数から読みます。
LOOP_PUBLISH_EXPECTED_REMOTE_HEADLOOP_PUBLISH_CURRENT_REMOTE_HEADLOOP_PUBLISH_DECLARED_PUBLISH_HEADLOOP_PUBLISH_VERIFIED_HEADLOOP_PUBLISH_ALLOWED_PATHS_GATE_*さらに canonical repository pattern と default branch まで environment override が可能です。
したがって「environment を sanitize する」だけでは不十分です。
LOOP_*を継承すると self-asserted evidence が残る。Git 自体も
GIT_CONFIG_COUNT、GIT_DIR、GIT_OBJECT_DIRECTORY、GIT_ALTERNATE_OBJECT_DIRECTORIES、GIT_SSH_COMMAND、config file location など多数の環境入力で動作が変わります。([Git]8)必要な修正
env -i相当の allowlist 構築。session_id、turn_id、tool_use_id、local_oid、remote_oid、issue_number、nonce/expiry を bind。LOOP_CANONICAL_REPO_URL_PATTERN、LOOP_DEFAULT_BRANCHは production では無効化し、test-only dependency injection に移す。GIT_CONFIG_GLOBAL=/dev/null、GIT_CONFIG_SYSTEM=/dev/null、GIT_CONFIG_NOSYSTEM=1等を明示。$HOME/.gitconfigやGIT_SSH_COMMAND継承に依存しない。P2 High findings
7. Manifest は
trusted_commit_oidと component digest の関係を証明していない現行 schema では、operator が無関係な commit OID と任意 bytes の digest を同じ manifest に書けます。
issued_byも単なる文字列で、認証情報ではありません。必要なのは schema validation ではなく provenance contract です。
trusted_commit_oidの blobs から components を抽出する。issued_byは audit metadata と明記し、authenticity の根拠にしない。generationまたは monotonic release epoch を追加し、意図しない rollback を拒否する。8. Rotation は file-by-file atomic ではなく release 単位で atomic にする
manifest、launcher、trusted components を個別に置換すると、crash 時に世代が混在します。
rename()は同一 filesystem 上の既存 pathname を atomic に置換できるため、staging release を完全検証してから active descriptor を一回だけ rename する構成が適切です。([man7.org]9)推奨 layout:
dispatcher.pyは小さく固定。active.json.tmpを fsync 後にrename。active.jsonを維持。9. path check は全 component と ancestor を対象にする
最終 path の
lstatだけでは、途中の symlink や path-resolution race を閉じられません。Linux ではopenat2()のRESOLVE_NO_SYMLINKSで全 path component の symlink 解決を拒否でき、RESOLVE_BENEATHで trusted root 外への escape を防げます。([man7.org]10)Python から直接
openat2を使わない場合も、openat(..., O_NOFOLLOW)fstatした同じ FD の bytes を hash・executeするという descriptor-based contract が必要です。
10. Hook 間の順序依存を明示的に禁止する
Codex は同一 event の matching command hooks を並行起動し、一つの hook が他の起動を止めることはできません。リポジトリ自身の SSOT も実行順序・short-circuit・handler 間依存がないと記載しています。([OpenAI Developers]1)
したがって trusted launcher は、次を他 hook に委譲してはいけません。
security-critical な判断は managed launcher/publisher 内で完結させる必要があります。
11. 「security boundary」の表現を修正する
Codex 公式仕様は
PreToolUseを完全な enforcement boundary ではなく guardrail と明記しており、shell interception も完全ではありません。リポジトリのhook-boundaries.mdと.codex/config.tomlも同じ制限を明示しています。([OpenAI Developers]1)Issue の Outcome は次のように限定すべきです。
リポジトリ全体の remote-write security boundary と表現してはいけません。最終防御は引き続き GitHub permissions、branch protection、server-side rules に置く必要があります。
推奨する修正版アーキテクチャ
この形なら trust chain は次の一方向になります。
Issue #1454 に追加すべき最低限の AC
Managed registration
repo-local hook の削除・変更・未信頼化・local feature disable 後も、system-managed launcher が作動する。
Different-owner boundary
installer owner と runtime EUID が同一なら installation を拒否する。全 ancestor が runtime-nonwritable。
Exact commit binding
working tree ではなく、publish 対象
local_oidの component blobs が manifest digest と一致する。Committed-malicious/working-tree-clean test
悪意ある HEAD+approved working tree を必ず deny する。
Trusted execution rewrite
allow 時に元の
rtk git push ...を通さず、absolute trusted publisher にupdatedInputで置換する。Exact source OID and lease
publisher は
HEADではなくlocal_oidを refspec source にし、remote expected OID を lease に使う。Executable substitution resistance
fake
rtk、fake Git、PATH、shell function、alias、BASH_ENV、NODE_OPTIONS、PYTHONPATHを注入しても trusted executable のみが使われる。Evidence provenance
inherited
LOOP_*だけでは allow されず、trusted evidence envelope と hook invocation ID の一致が必要。Transitive TCB closure
実行時に load/exec される全コード・interpreter・external binary が manifest または system trust に列挙される。
Atomic generation activation
crash injection の全地点で旧世代か新世代のどちらかだけが見え、混成状態にならない。
Concurrent hook independence
他の repository-local hook を削除・遅延・失敗させても、managed launcher の判定が変わらない。
Scope wording
PreToolUseの interception limitation と server-side enforcement 依存を normative documentation に明記する。総括
#1454 は前回の self-verifying hash pinning より大幅に改善されています。しかし、現契約では external launcher を作っても、
rtkまたは別HEADを実行するという三経路が残ります。
特に managed hook registration、exact commit blob binding、trusted publisher への command rewrite は #1454 自身の In Scope に戻すべきです。この三点を #1450 や後続 Issue に送ると、#1454 単体は「外部ファイル配布機構」にはなっても、publish lane の trust root にはなりません。
squne121 commentedon Jul 11, 2026
Contract Review Result
squne121 commentedon Jul 11, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 11, 2026
implement-issue: 実装完了
.claude/worktrees/issue-1454-trust-rootworktree-issue-1454-trust-rootscripts/trust-root/tests/)、ruff PASS、typecheck/lint/lint:md/lint:prose PASS.github/ci/python-test-plan.jsonへのscripts/trust-root/tests/登録が必要(Allowed Paths 外のため本 PR では未変更。PR 本文 Notes に記載)fix: python-test-plan.json に scripts/trust-root/tests/ を登録する (#1454)
fix: 実 Codex PreToolUse wire format と evidence binding を実装する (#1454)
feat: publish lane authorization の external trust root を確立する (#1457)
chore: 未配線の external trust root(scripts/trust-root/)を削除する (#1469) (#1471