Lab 1: Secret Scanning & Pre-Commit
Install and run gitleaks
Catches API keys, passwords, and credentials before they reach your repository.
Gitleaks
$ curl -sSfL https://github.com/gitleaks/gitleaks/releases/download/v8.18.0/gitleaks_8.18.0_linux_x64.tar.gz | tar xz $ sudo mv gitleaks /usr/local/bin/ # Create a test repo with a planted secret $ mkdir test-repo && cd test-repo && git init $ echo 'AKIAIOSFODNN7EXAMPLE' > config.txt $ git add . && git commit -m 'test' # Scan $ gitleaks detect -v # Should find the AWS key pattern
Set up pre-commit hooks
Every commit is scanned automatically. Secrets never reach the repo.
Pre-commit
$ cat > .pre-commit-config.yaml << 'EOF' repos: - repo: https://github.com/gitleaks/gitleaks rev: v8.18.0 hooks: - id: gitleaks EOF $ pre-commit install # Try to commit a secret — should be blocked: $ echo 'aws_secret=wJalrXUtnFEMI/K7MDENG' > test.txt $ git add . && git commit -m 'test' # Blocked by gitleaks