Skip to content

Instantly share code, notes, and snippets.

@stevendanna
Last active March 21, 2016 15:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stevendanna/4db970716cabb8f5def4 to your computer and use it in GitHub Desktop.
Save stevendanna/4db970716cabb8f5def4 to your computer and use it in GitHub Desktop.
Pre-commit hook to help prevent key leakage
#!/bin/bash
#
# Warn about possible cloud access keys before committing
#
exec </dev/tty
unset possible_keys
possible_keys=$(git diff --cached | egrep '^[+\-].*(AKIA|AWS_ACCESS|AWS_SECRET|OS_PASSWORD|OS_USERNAME)')
if [[ -n "$possible_keys" ]];then
echo -e "WARNING: Diff contains possible access keys:\n"
echo "${possible_keys}"
echo ""
read -p "Continue to commit? (y/n)" answer
case $answer in
y*)
echo "OK. Committing."
exit 0
;;
n*)
echo "OK. Not Committing."
exit 1
;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment