الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

gitleaks

Find passwords, API keys and tokens in Git repositories, in files and in what you are about to commit.

المستوى
خدمة DevSecOps
المجموعة
الفحص الأمني والتقوية
يحتاج root
لا
الحزمة
gitleaks

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

Gitleaks uses regex rules (AWS keys, GitHub tokens, Azure connection strings, private keys, JWTs …) plus entropy to find secrets. It scans the whole Git history (a secret deleted in a later commit is still leaked), plain folders, or only staged changes in a pre-commit hook. In CI it fails the pipeline when it finds something.

When a secret is found: rotate it first, then clean the history.

طريقة الكتابة

gitleaks git [PATH] [OPTIONS]
gitleaks dir [PATH] [OPTIONS]
gitleaks protect --staged

الأجزاء الرئيسية

Commands

git [PATH]
Scan the Git history of a repo.
dir [PATH]
Scan files (no Git needed).
stdin
Scan text from a pipe.
protect --staged
Scan staged changes (pre-commit; older name, still used).

الخيارات 8

الأكثر استخدامًا

Flags

-c, --config FILE
Own rules (.gitleaks.toml).
--baseline-path FILE
Ignore findings from an old report.
-r, --report-path FILE
Write a report.
-f, --report-format json|csv|sarif|junit
Report format.
--redact
Hide the secret values in output.
--log-opts "--since=…"
Limit the commits (git).
-v
Show every finding.
--exit-code N
Exit code when leaks are found (default 1).

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Scan a repo's full history

    gitleaks git -v --redact .
  2. 2Scan a folder that is not a repo

    gitleaks dir --redact ./config
  3. 3Only recent commits

    gitleaks git --log-opts="--since=2026-10-01" .
  4. 4Stop secrets before commit

    cat .pre-commit-config.yaml
    repos:
      - repo: https://github.com/gitleaks/gitleaks
        rev: v8.21.2
        hooks:
          - id: gitleaks
    pre-commit install
  5. 5Use it in GitHub Actions

    cat .github/workflows/secrets.yml
          - uses: actions/checkout@v4
            with: { fetch-depth: 0 }
          - uses: gitleaks/gitleaks-action@v2
            env: { GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" }
  6. 6Report as SARIF

    gitleaks git -f sarif -r gitleaks.sarif --redact .
  7. 7Add your own rule and an allow list

    cat .gitleaks.toml
    [extend]
    useDefault = true
    [[rules]]
    id = "s0sta-installer-key"
    description = "Installer key"
    regex = '''INSTALL_KEY\s*=\s*['"][a-f0-9]{32}['"]'''
    [allowlist]
    paths = ['''docs/examples/''']
  8. 8Accept old findings with a baseline

    gitleaks git -r baseline.json -f json .
    gitleaks git --baseline-path baseline.json .
  9. 9Scan text from a pipe

    kubectl get configmap app -o yaml | gitleaks stdin --redact
  10. 10After a leak: rotate, then clean history

    git filter-repo --replace-text expressions.txt
    git push --force-with-lease --all

انتبه

  • Deleting the file is not enough: the secret is in the history and maybe in forks and caches. Rotate it.
  • Do not print found secrets in CI logs — use --redact.

الملفات

.gitleaks.toml
Rules and allow lists.
.gitleaksignore
Fingerprints of accepted findings.

نصائح للحفظ

  • GitHub push protection (secret scanning) is a second layer; use both.

رموز الخروج

0No leaks.
1Leaks found (or error).