最終更新: 2026-03-13
対象: 開発者
タグ: category/security, layer/support, environment/cross-platform, audience/developer
Claude Rules: .claude/rules/security.md
- SSH 秘密鍵:
id_rsa,id_ed25519,*.pem - GPG 秘密鍵:
secring.gpg,*.key - API トークン: GitHub Personal Access Tokens, AWS Credentials
- パスワード: 平文パスワード、データベース認証情報
- 証明書秘密鍵:
*.key,*.p12,*.pfx
.gitignore パターン:
**/.ssh/*_rsa
**/.ssh/*_ed25519
**/.ssh/*.pem
**/.gnupg/private-keys-v1.d/
**/.gnupg/secring.gpg
**/.aws/credentials
**/.config/gh/hosts.yml- 環境変数ファイル:
.env,.env.local,.envrc - 設定ファイルのローカル上書き:
config.local,*.secret - セッショントークン
.env
.env.*
!.env.example
.envrc
*.local
*.secret- ビルド成果物:
result,result-*,dist/,build/ - 一時ファイル:
*.tmp,*.log,.DS_Store - 依存関係キャッシュ:
node_modules/,.venv/,__pycache__/
新しいツールや設定を追加する際の確認フロー:
- 秘密情報を含む可能性 →
.gitignoreに追加 - 環境固有の設定 →
.gitignoreに追加、.exampleファイルを提供 - 一時ファイル →
.gitignoreに追加
# 新ツール newtool の例
echo "**/.config/newtool/credentials" >> .gitignore
echo "**/.config/newtool/*.local" >> .gitignore
cp .config/newtool/config.local .config/newtool/config.local.example# .pre-commit-config.yaml
- repo: https://github.com/gitleaks/gitleaks
rev: v8.30.0
hooks:
- id: gitleaksmise install # pre-commit と gitleaks をインストール
sh ./scripts/setup-gitleaks.sh
sh ./scripts/setup-gitleaks.sh --create-baseline # ベースライン作成(既存の警告を無視)git commit -m "feat: add new feature" # 自動実行
pre-commit run gitleaks --all-files # 手動実行
pre-commit run --all-files # 全フック実行ベースラインに追加:
sh ./scripts/setup-gitleaks.sh --create-baseline個別に除外(コメント):
API_KEY = "example_key_for_documentation" # gitleaks:allowgit commit --no-verify -m "emergency fix" # 全フックスキップ(非推奨)
SKIP=gitleaks git commit -m "message" # gitleaks のみスキップ確認事項: なぜスキップするか?セキュリティリスクはないか?後でレビューする計画は?
pre-commit run gitleaks --all-files
git ls-files -o --exclude-standard | grep -E "\.(env|key|pem|credentials)$"
find ~/.ssh -type f -name "id_*" ! -name "*.pub" -exec ls -la {} \;
gpg --list-keys --with-colons | grep "^pub"
gh auth status
aws sts get-caller-identitygit diff --cached --name-only
git diff --cached
# 目視確認: パスワード、トークン、APIキー、個人情報、内部サーバー情報ls -la ~/.config/newtool/ | grep -E "(credential|secret|token|key)"
echo "**/.config/newtool/credentials" >> .gitignore
cp ~/.config/newtool/config.secret ~/.config/newtool/config.secret.example
sed -i '' 's/actual_secret/YOUR_SECRET_HERE/g' ~/.config/newtool/config.secret.examplegit reset --soft HEAD~1
rm path/to/secret/file # または .env へ移行
echo "path/to/secret/file" >> .gitignore
git add .gitignore
git commit -m "fix: remove secret and update .gitignore"- 秘密情報を即座に無効化(GitHub Token 削除、AWS Credentials 無効化、SSH Key 削除)
- プッシュしたブランチを削除(可能な場合):
git push origin --delete branch-name - チームに通知
brew install git-filter-repo
git filter-repo --path path/to/secret/file --invert-paths
git push --force-with-lease origin main # チーム全員に通知後
# チーム全員に再クローンを依頼(古いクローンには秘密情報が残る)- インシデントレポート(何が漏洩/いつ/誰がアクセス可能/どう無効化)
.gitignoreにパターン追加- pre-commit フックの強化
- チームへのセキュリティトレーニング
- すべての秘密情報を即座に無効化
- リポジトリを一時的にプライベートに変更(GitHub Settings → Danger Zone)
git filter-repo --path path/to/secret/file --invert-paths
git push --force-with-lease origin main
# GitHub Support に連絡してキャッシュ削除を依頼
# https://support.github.com/contact- 全設定ファイルのセキュリティ監査
.gitignore徹底見直し- pre-commit フック必須化
- GitHub Insights でクローン履歴確認
- アクセスログ確認・影響範囲調査
.gitignore— 除外パターン定義.pre-commit-config.yaml— pre-commit フック設定scripts/setup-gitleaks.sh— gitleaks セットアップスクリプト- GitHub: Removing sensitive data
- Gitleaks Documentation