Skip to content

Instantly share code, notes, and snippets.

@abelgvidal
Created November 21, 2022 10:08
Show Gist options
  • Save abelgvidal/c5f38ecd62a6bf7ba781619ff6728e22 to your computer and use it in GitHub Desktop.
Save abelgvidal/c5f38ecd62a6bf7ba781619ff6728e22 to your computer and use it in GitHub Desktop.
### this script checks for secrets (sensitive information) in a github repo
### usage ----
### checksecrets.sh git@github.com:prometheus-community/elasticsearch_exporter.git
#!/bin/bash
# Create a temporary directory and store its name in a variable.
TEMPD=$(mktemp -d)
REPO=$1
if [[ "$1" == '' ]] ; then
echo "missing param REPO"
exit 1
fi
# Exit if the temp directory wasn't created successfully.
if [ ! -e "$TEMPD" ]; then
>&2 echo "Failed to create temp directory"
exit 1
fi
cd $TEMPD
echo "Looking for secrets in $1..."
echo "Cloning $1 in ${TEMPD}..."
git clone $REPO
docker run -v $(pwd):/path zricethezav/gitleaks:v8.13.0 detect --source="/path" --verbose --no-git
# Make sure the temp directory gets removed on script exit.
trap "exit 1" HUP INT PIPE QUIT TERM
trap 'rm -rf "$TEMPD"' EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment