Talisman
gitで機微情報をアップしてしまって大変、という話は数多ありますがそういった事故を防いでくれるツールがTalismanです。
githookとして動作し、認証情報などが含まれる場合に警告を表示して中断します。開発元はあのThoughtworksです。
https://thoughtworks.github.io/talisman/
2019/10/02にバージョン 1.0.0に到達しました。
自分は個別のローカルレポジトリごとに導入しています。
curl https://thoughtworks.github.io/talisman/install.sh > ~/install-talisman.sh chmod +x ~/install-talisman.sh cd my-git-project ~/install-talisman.sh
以上でgit hookとしてTalismanが導入されます。グローバルに共通して導入する場合はGitHubのREADMEを参照してください。
検知ルールをカスタマイズする場合は、 https://github.com/thoughtworks/talisman/blob/master/detector/ 以下を編集してください。例えばファイル名や拡張子に関するルールは filename_detector.go に記述があります。
動作を見てみましょう。
ここでは拡張子 .pem の(空)ファイルを追加してpushを行ってみます。
$ git commit -m "add hoge.pem" [master d1e81ab] add hoge.pem 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 hoge.pem $ git push -u foo The following errors were detected in hoge.pem The file name "hoge.pem" failed checks against the pattern ^.+\.pem$ error: failed to push some refs to 'git@some:where/far.git'
検知されてpushはfailしました。
拡張子だけでなく、鍵ファイルの内容など様々なdetectorが用意されています。
githookで手前で防ぐことができ便利ですので、興味のある方はお試しください。