[[Gitleaks]]でよく使う設定やコマンドについて。
## コマンド
### [[リポジトリ (Git)|リポジトリ]]のチェック
```console
gitleaks git <repository_path>
```
[[#ディレクトリ配下をチェック]]する場合との違いは、**コミット内容にシークレットが含まれていても検出できる**こと。
- `-v` オプションで問題の詳細も表示
### ディレクトリ配下をチェック
```console
gitleaks dir <directory_path>
```
- `-v` オプションで問題の詳細も表示
## 設定
### 特定のRuleIDを無視
`.gitleaks.toml` で `disabledRules` に指定する。
`.gitleaks.toml`
```toml
disabledRules = [ "generic-api-key"]
```
> [!note]
> `generic-api-key` は怪しいものを軒並み検出するので無効にするのもアリ。
### 特定の検出結果を除外
`.gitleaksignore` に検出結果の `Fingerprint` を追加する。以下は一例。
```
0aaf3ecd9203a780e9e87b736bbb862615db5139:docs/ja/getstarted/report/index.html:generic-api-key:1209
```
### すべてのリポジトリでコミット前に[[ステージング (Git)|ステージング]]された内容に対して実行
> [!caution]
> この方法はリポジトリレベルのhooksが設定されていると、動作しない可能性が高い。
`~/.config/git/hooks/pre-commit` に設定する。
```bash
#!/bin/sh
gitleaks git --staged
```
hooksの設定をして、実行権限をつける。
```console
git config --global core.hooksPath ~/.config/git/hooks
chmod +x ~/.config/git/hooks/pre-commit
```