Geavanceerd
Zoeken inInstallatiegidsen
Zo zoek je
  • Plak een foutmelding tussen aanhalingstekens, bijv. "permission denied", om de oplossingstabel te vinden.
  • Kies een gebied en een deel van de gids (installeren, eerste instellingen, dagelijks gebruik, beveiliging, oplossingen) om direct naar de juiste stap te gaan.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Gids 65Gitleaks · Security

Install and set up Gitleaks (find secrets in Git)

Gitleaks finds secrets — passwords, API keys, tokens, private keys — in Git history, in files and in new commits before they are pushed. Leaked secrets in Git are one of the most common causes of breaches. This guide installs Gitleaks, scans a repository's full history, sets up a pre-commit hook so secrets never get committed, adds a CI job, writes a config with your own rules and allow lists, and shows what to do when a secret was already leaked.

  • 10 Lessen
  • 8 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

65.1

Know it before you install

Gitleaks checks text against rules (regular expressions + entropy + keywords) for 150+ secret types (AWS keys, GitHub tokens, Slack webhooks, private keys …). Each finding has a fingerprint (commit:file:rule:line) you can use to mark a reviewed false positive.

ItemValue
Programgitleaks (one binary)
Commandsgitleaks git (Git history), gitleaks dir (files), gitleaks stdin
Config.gitleaks.toml in the repo (extends the default rules)
Ignore list.gitleaksignore (fingerprints of reviewed false positives)
Reports--report-format json/sarif/csv --report-path FILE

65.2

Install on RHEL and Ubuntu

Choose the version from github.com/gitleaks/gitleaks/releases:

GVER=8.28.0
curl -fsSLO https://github.com/gitleaks/gitleaks/releases/download/v$GVER/gitleaks_${GVER}_linux_x64.tar.gz
tar -xzf gitleaks_${GVER}_linux_x64.tar.gz gitleaks
install -m 0755 gitleaks /usr/local/bin/gitleaks
gitleaks version

Or the container: docker run --rm -v "$PWD":/repo zricethezav/gitleaks:v8.28.0 git /repo.

65.3

First configuration: scan a repository

Scan the whole history (secrets deleted in later commits are still in Git):

cd my-project
gitleaks git -v --redact
Finding:     aws_secret_access_key = "REDACTED"
Secret:      REDACTED
RuleID:      aws-access-token
File:        deploy/old-config.env
Commit:      3f9c2a1…
Fingerprint: 3f9c2a1…:deploy/old-config.env:aws-access-token:4
4:21PM WRN leaks found: 1
gitleaks dir . --redact
gitleaks git --report-format sarif --report-path gitleaks.sarif

--redact hides the secret value in the output (important in CI logs).

Your own rules and allow lists, on top of the default rules:

.gitleaks.toml
[extend]
useDefault = true
 
[[rules]]
id = "shop-internal-token"
description = "Internal shop API token"
regex = '''shop_tok_[A-Za-z0-9]{32}'''
keywords = ["shop_tok_"]
 
[allowlist]
description = "Test fixtures and docs examples"
paths = [
  '''tests/fixtures/''',
  '''docs/examples/''',
]
regexes = [
  '''AKIAIOSFODNN7EXAMPLE''',
]

A reviewed false positive goes into .gitleaksignore by fingerprint (one per line).

65.4

Stop secrets before the commit

With the pre-commit framework (works for the whole team):

.pre-commit-config.yaml
repos:
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.28.0
    hooks:
      - id: gitleaks
pipx install pre-commit
pre-commit install
git commit -m "Add config"
Detect hardcoded secrets.................................................Failed

Or a plain Git hook: gitleaks git --pre-commit --staged --redact in .git/hooks/pre-commit.

65.5

A CI job

Run it on every push and pull request (here GitLab CI; GitHub Actions and Jenkins work the same with the binary or container):

.gitlab-ci.yml
secrets-scan:
  stage: test
  image:
    name: zricethezav/gitleaks:v8.28.0
    entrypoint: [""]
  variables:
    GIT_DEPTH: 0
  script:
    - gitleaks git --redact --report-format sarif --report-path gitleaks.sarif .
  artifacts:
    when: always
    paths: [gitleaks.sarif]

GIT_DEPTH: 0 gives the full history. (The official GitHub Action needs a license key for organization accounts; running the binary or container needs none.)

65.6

Daily use and when a secret leaked

gitleaks git --log-opts="--since=2026-11-01" --redact
gitleaks git --log-opts="main..feature-x" --redact
gitleaks dir ./config --redact
cat app.log | gitleaks stdin --redact
gitleaks git --baseline-path gitleaks-baseline.json --redact

--baseline-path reports only new findings compared to an older report — useful when you start on an old repository.

Let op

When a real secret is found, the order is: 1) revoke and rotate it at the provider at once, 2) check its logs for misuse, 3) then clean the history (git filter-repo) if needed, and 4) add a rule or hook so it does not happen again. Deleting the file in a new commit does not remove the secret.

Real uses at work:

  • Pre-commit hooks for all developers; a CI gate on every merge request.
  • One-time scans of old repositories before making them public.
  • Scanning config folders, logs and backups for credentials.

65.7

Make it safe

Security checklist:

  • Scan full history once, then every commit (hook + CI).
  • --redact in CI so reports do not leak the secrets again; keep reports private.
  • Allow lists are narrow (paths for test fixtures), reviewed in pull requests.
  • Rotate first, clean later; use a secret manager (Vault, SOPS, cloud secrets) so secrets are not in code.
  • Pin the Gitleaks version; add custom rules for your internal token formats.

65.8

Update and remove

Download the new release and replace the binary; update rev in .pre-commit-config.yaml (pre-commit autoupdate). Remove: rm /usr/local/bin/gitleaks, pre-commit uninstall.

Commando's in deze les

65.9

Fix common problems

ProblemCauseFix
Unknown command detect / protect warningsOld commands from v8 before 8.19.Use gitleaks git (history) and gitleaks dir (files).
CI finds nothing in old commitsShallow clone.Fetch full history (GIT_DEPTH: 0, fetch-depth: 0).
Many false positives in tests or docsExample keys look real.Allowlist those paths/regexes; add fingerprints to .gitleaksignore.
Very slow on a huge repositoryScanning all history every time.Limit with --log-opts (only new commits) and a baseline.
The hook does not runpre-commit install was not run in this clone.Run it; for the team, also enforce in CI.

65.10

Next steps

1You deleted a leaked password in a new commit. Is the leak fixed?

No. It is still in the Git history — rotate the password first.

2Why use --redact in CI?

So the secret value does not appear again in the CI log or report.

Alle commando's in dit hoofdstuk