fix(claude): credentials の deny 誤爆と mktemp の失敗を直す - #80
Merged
Conversation
#78 の設定を再起動後に実機で確認したところ、2つの問題が残っていた。 **credentials の deny が node_modules を巻き込む** ~/Repos 配下で `**/credentials` に該当する10件は、すべて node_modules 内の ディレクトリだった(@anthropic-ai/sdk, @azure/identity, @azure/storage-common のソース構成)。本物の認証情報は0件で、誤爆率100%。 これにより tree-walk するツールが途中で止まる。実測では `gofmt -l .` が終了コード 2 を返すため、フォーマット違反の検出と 権限エラーの区別がつかない状態だった。 拡張子つきの実在パターンに絞る。拡張子なしの `credentials` ファイルは 読めるようになるが、~/.aws や ~/.config/gcloud はディレクトリ単位で 別途 deny してあるため、実際に守りたい対象は落ちない。 **mktemp -d がサンドボックスで失敗する** macOS の mktemp は引数なしの場合 $TMPDIR を無視して confstr(_CS_DARWIN_USER_TEMP_DIR) すなわち /var/folders/*/*/T を使う。 ここが allowWrite に無いため mkdtemp が Operation not permitted になる。 自分で書くスクリプトは $TMPDIR を明示するので履歴上の発生はほぼ無いが、 このリポジトリの tests/pre-commit-hook.test.sh が mktemp -d を使っており ローカルでは TMP_BASE が空になって失敗する(CI では通る)。 OS のユーザ一時ディレクトリなので、$TMPDIR を許可しているのと同等のリスク。 **なお `**/secrets/**` は誤爆していなかった** dot_git-templates/secrets/ を塞いでいると疑ったが、実測では読めた。 `**/*.pem` が certifi の公開CAバンドルを塞ぐ件は確認したが、実際に 壊れた履歴が無く、絞ると server.pem のような命名を取りこぼすため 今回は手を入れない。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
#78 で入れた設定を Claude Code 再起動後に実機で確認したところ、2つの問題が残っていた。どちらも #78 と同じ「名前だけのグロブが、秘密ではなくソースを掴んでいる」型。
1.
**/credentialsの deny が node_modules を巻き込む~/Repos配下で**/credentialsに該当するパスを数えたところ、10件すべてが node_modules 内のディレクトリだった。本物の認証情報は0件、誤爆率100%。これにより tree-walk するツールが途中で止まる。実測では以下のとおり。
終了コード 2 が返るため、フォーマット違反の検出と権限エラーの区別がつかない。
対応: 拡張子つきの実在パターンに絞る。
**/credentials**/credentials.json**/credentials.yml**/credentials.yaml**/credentials.db拡張子なしの
credentialsファイルは読めるようになるが、~/.aws/と~/.config/gcloud/はディレクトリ単位で別途 deny してあるため、実際に守りたい対象は落ちない。2.
mktemp -dがサンドボックスで失敗するmacOS の
mktempは引数なしの場合$TMPDIRを無視してconfstr(_CS_DARWIN_USER_TEMP_DIR)(/var/folders/*/*/T)を使う。ここがallowWriteに無いため落ちる。対応:
allowWriteに/var/folders/*/*/Tを追加。OS のユーザ一時ディレクトリなので、すでに許可している$TMPDIRと同等のリスク。自分で書くスクリプトは
$TMPDIRを明示するため履歴上の発生はほぼ無いが、このリポジトリのtests/pre-commit-hook.test.shがmktemp -dを使っており、ローカルではTMP_BASEが空になって失敗する(CI では通る)。手を入れなかったもの
**/secrets/**:dot_git-templates/secrets/を塞いでいると疑ったが、実測では読めた。誤爆していない**/*.pem: certifi の公開CAバンドル(cacert.pem)が拒否されることは確認したが、実際に壊れた履歴が無い。絞るとserver.pemのように鍵を含む命名を取りこぼすため、保護を下げるトレードオフを取らない判断にした#78 の効果確認(参考)
再起動後、以下は意図どおりになっていた。
golangci-lint runのキャッシュ警告が消えた(従来58回失敗していた箇所)go vet ./...が承認プロンプトなしで終了コード 0.env.example/.envrc.example/.envrc_exampleは読める.env/.env_prod/.env_stg/.envrcは拒否~/.ssh/known_hosts/~/.config/gh/hosts.ymlは拒否検証状況
サンドボックス設定はセッション開始時に読まれるため、この PR の2点は次回の Claude Code 再起動後でないと実機確認できない。現時点で確認済みなのは JSON として valid であることと、意図したキーに入っていることだけ。
/var/folders/*/*/TのグロブがallowWriteで解釈されるかも未確認。🤖 Generated with Claude Code