(Twitter thread which summarises multiple experiments)
#ProductSecurity #gitlab #security
Pre-commit : scan for secrets before commit. Prevents committing secrets by devs
Problem: requires access to dev laptops (privacy issue?). Hard to manage regexes in their laptop. Harder in a company hiring lots of devs
Problem: If a person commits secret to code, server rejects push. The person requires (advanced) git skills to remove secret from git history
Problem: The secret is already committed to the code. Anyone having access to Gitlab repo can see.
If secret found, create a Gitlab confidential issue. Make sure the secret is revoked and secure best practices applied to the repo and deployment.
Found multiple secret scanning tools. Picked two of them - trufflehog and gitleaks.
Trufflehog :
- code in python
- fast for few commits, slow for many commits
- customizable regex
- easy CLI commands
- good documentation
- code in golang
- comparatively slow for smaller commits, but very fast in large repos
- customizable regex
- supports whitelisting of issues
- lacking documentation
- lots of options in CLI commands
- allows scan of single commit, but downloads the entire repo
Gitleaks won the first fight.
Task at hand:
Scan all the commits in real time to find secrets and create Gitlab confidential issues
docs.gitlab.com/ee/system_hook…
Gitlab can be configured to notify us every time a git push is made (all the push events).
Results with Gitleaks:
- has capability to scan only few commits. But downloads the entire repo. (We have a few repos which are 1GB+)
- very very memory intense. Takes up many cores and is still greedy
- downloads the entire repo
- slower than gitleaks
- less memory intense
Few commits made to huge 1GB repos, gitleaks downloads the same repo again and again from scratch. So gitleaks takes more disk and memory.
Its a tie for Gitleaks and Trufflehog.
Configured gitleaks and trufflehog to scan the diff.
Trufflehog defeated Gitleaks with ease. Trufflehog takes lesser time than gitleaks to scan almost the same secrets.
1. runs trufflehog
2. creates Gitlab confidential issues if secret found
So this is how the final product looks:
Gitlab system hooks --> cloud fn running trufflehog --> cloud fn to create Gitlab issue --> security team follow up to revoke
If you have followed the thread till here, please follow @fahrishb and @sanjogpanda. This thread is just a summary of our 1 month experiments.