Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add gitguardian precommit checks #2109

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ coverage
.dccache
.idea
.pgdata
.cache_ggshield
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ Because redirects are served directly from the backend, shortlinks can be access
but that is really being proxied to `localhost:8080/shortlink`. One-time passwords for all log-in attempts on localhost
are obtained using [maildev](https://github.com/maildev/maildev) and accessed via `http://localhost:1080/`.

### Setting up secrets detection (optional)

For more safety, you may enable secrets detection on pre-commit using GitGuardian.

To set it up, install `ggshield` locally following the [official installation guide](https://github.com/GitGuardian/ggshield#installation).
Create a personal GitGuardian account, generate an access token key with scanning permissions, then set `GITGUARDIAN_API_KEY` to this key inside a `.env` file in the root folder.

### Setting up the infrastructure

Much of this step will involve setting up key infrastructure components since we do not have docker-compose
Expand Down
22 changes: 22 additions & 0 deletions secrets-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,27 @@ if [ "$KEY_ID" != "" -a "$KEY_ID" != "," -a "$KEY" != "" ]; then
exit 1
fi

gitguardian_secrets_check() {
if !(command -v ggshield &> /dev/null); then
echo "Skipping GitGuardian check for secrets as ggshield is not installed."
return 0
fi

[ -e .env ] && export $(cat .env | xargs)
if [ -z "${GITGUARDIAN_API_KEY}" ]; then
echo "Skipping GitGuardian check for secrets as GitGuardian API key is not configured."
return 0
fi

ggshield secret scan pre-commit
}

# Check changed files for secrets using GitGuardian
gitguardian_secrets_check
exit_status=$?
if [ $exit_status -ne 0 ]; then
exit $exit_status
fi

# Normal exit
exit 0