git secretsの基本操作

Homebrewでインストールする。

$ brew install git-secrets

git-secretsを利用するリポジトリでhookのインストールを行い、パターンを登録する。

$ git secrets --install
$ git secrets --register-aws

全リポジトリにまとめてパターンを設定できる。

# for AWS
$ git secrets --register-aws --global

# for GCP @see https://cloudplatform-jp.googleblog.com/2017/08/help-keep-your-Google-Cloud-service-account-keys-safe.html
git secrets --add 'private_key' --global
git secrets --add 'private_key_id' --global

init/clone時にgit secretsのインストールを行うにはinit.templatedirの設定をする。

$ git secrets --install ~/.git-templates/secrets
$ git config --global init.templatedir '~/.git-templates/secrets'

現在の選択肢

git-secretsは今も使えるが、コミット前に止める仕組みは他にも増えている。

  • GitHubのSecret scanningとPush protection。リポジトリ設定で有効化できる。
  • gitleaks。検出ルールが多くCIにも組み込みやすい。

参考