LoginSignup
0
0

git-secretsを使ってみた

Posted at

Gitの設定で、git-secretsなるアクセスキーのコミットを防いでくれる便利な機能があることを知った。
設定を入れてみて実際にアクセスキーもどきを入力したファイルをコミットしようとしたらどうなるのかを確認してみたものをメモ書き。

インストールと設定

% brew install git-secrets
% git secrets --install
% git secrets --register-aws
% git secrets --list

ファイル作成

% vi test.txt
% cat test.txt
AKIAIOSFODNN7EXAMPLD
$ git add .
$ git commit -m "test"

結果
しっかりブロックされました。

% git commit -m "secrets test"
test.txt:1:AKIAIOSFODNN7EXAMPLD

[ERROR] Matched one or more prohibited patterns

Possible mitigations:
- Mark false positives as allowed using: git config --add secrets.allowed ...
- Mark false positives as allowed by adding regular expressions to .gitallowed at repository's root directory
- List your configured patterns: git config --get-all secrets.patterns
- List your configured allowed patterns: git config --get-all secrets.allowed
- List your configured allowed patterns in .gitallowed at repository's root directory
- Use --no-verify if this is a one-time false positive

片付け

% git rm --cached test.txt
% rm test.txt
% git status

参考
https://zenn.dev/kkk777/articles/8f55db1e9678f2
https://dev.classmethod.jp/articles/prevent-commit-using-git-secrets-and-husky/

実際の事件まとめ
https://dev.classmethod.jp/articles/accesskey-leak/

環境
Mac mba13 M1
OS Sonoma 14.5

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0