LoginSignup
0
2

More than 5 years have passed since last update.

gitフックによりAWSアクセスキー混入を防止する

Last updated at Posted at 2017-05-16

概要

~/.git_templateディレクトリを作っておくことにより、git initgit cloneしたとき必ず所定の.git/hooks/pre-commitフックが入るようにする。フックの中でAWS_ACCESS_KEYが入っていないかチェックする。

参考:
http://qiita.com/k0kubun/items/5cb8209e3d1854ac2e2e
http://dev.classmethod.jp/etc/git_aws_access_key/

セットアップ

~/.gitconfig
[init]
    templatedir = ~/.git_template

フックのテンプレートを作成する:

mkdir -p ~/.git_template/hooks/
cat > ~/.git_template/hooks/pre-commit <<EOF
#!/bin/sh

GREP_RESULT=`git diff --cached | grep -i KEY | grep AKI[A]` 
if [ -n "${GREP_RESULT}" ]; then
    echo 'AWS_ACCESS_KEYがインデックスに入っている可能性があります。git diff --cachedで確認してください。'
    echo "${GREP_RESULT}" 
    exit 1 
else
    exit 0
fi
EOF
chmod +x ~/.git_template/hooks/pre-commit
0
2
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
2