AWSのキーなど万一にも漏洩すると大変なことになる情報をGitHubにプッシュすると、わずか数分で抜き取られるなんて怖い話があります。この話を聞いて、自分の過去のリポジトリは大丈夫なのかと焦った方も多いでしょう。 しかし過去のすべての状態において問題がなかったか確認するのは大変です。そこで使ってみたいのがgitleaksです。

gitleaksの使い方

gitleaksはリポジトリを指定して実行するだけです。例えばデモのリポジトリでは以下のような結果が返ってきます。

$ gitleaks --json https://github.com/zricethezav/gronit
Cloning https://github.com/zricethezav/gronit...
{
   "line": "+const AWS_KEY = \"AKIALALEMEL33243OLIAE\"",
   "commit": "cb5599aeed261b2c038aa4729e2d53ca050a4988",
   "string": "AKIALALEMEL33243OLIA",
   "reason": "AWS",
   "commitMsg": "fake key",
   "time": "2018-02-04 19:10:58 -0600",
   "author": "Zachary Rice",
   "file": "main.go",
   "repoURL": "https://github.com/zricethezav/gronit"
}
{
   "line": "-const AWS_KEY = \"AKIALALEMEL33243OLIAE\"",
   "commit": "eaeffdc65b4c73ccb67e75d96bd8743be2c85973",
   "string": "AKIALALEMEL33243OLIA",
   "reason": "AWS",
   "commitMsg": "remove fake key",
   "time": "2018-02-04 19:43:28 -0600",
   "author": "Zachary Rice",
   "file": "main.go",
   "repoURL": "https://github.com/zricethezav/gronit"
}
Report written to /path/to/.gitleaks/report/zricethezav/gronit_leaks.json

gitleaksでは危ない(攻撃者が検索している)キーワードで過去のコミットをすべて洗い出してくれます。gitleaksで引っかかるようなリポジトリであれば、その内容を見直す必要があるでしょう。思わぬ被害を食らう前にぜひチェックしましょう。

gitleaksはGo製のオープンソース・ソフトウェア(GPL v3)です。

zricethezav/gitleaks: Searches full repo history for secrets and keys