| name | implementing-secrets-scanning-in-ci-cd |
| description | Integrate gitleaks and trufflehog into CI/CD pipelines to detect leaked secrets before deployment |
| domain | cybersecurity |
| subdomain | devsecops |
| tags | ["secrets-scanning","gitleaks","trufflehog","ci-cd"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
| nist_csf | ["PR.PS-01","GV.SC-07","ID.IM-04","PR.PS-04"] |
Implementing Secrets Scanning in CI/CD
Overview
This skill covers implementing automated secrets scanning in CI/CD pipelines using gitleaks and trufflehog. It enables security teams to detect API keys, tokens, passwords, and other credentials that have been accidentally committed to source code repositories, providing a CI gate that blocks deployments containing high-severity findings.
Gitleaks scans git repositories and directories for hardcoded secrets using regex patterns and entropy analysis. TruffleHog performs filesystem and git history scans with optional secret verification against live services. Together they provide comprehensive coverage for secrets detection.
When to Use
- When deploying or configuring implementing secrets scanning in ci cd capabilities in your environment
- When establishing security controls aligned to compliance requirements
- When building or improving security architecture for this domain
- When conducting security assessments that require this implementation
Common Misconfigurations & Verification
The most common failure is a scanner that runs but never fails the pipeline:
- No
--exit-code, or exit code swallowed. gitleaks detect/dir without --exit-code 1 (or wrapped in || true, or a job with continue-on-error: true) reports findings while the stage stays green. The CI gate verdict must translate to a non-zero process exit.
- Shallow clone / HEAD-only scan. A default
fetch-depth: 1 checkout or scanning only the latest commit means secrets buried in history go undetected. Use fetch-depth: 0 and scan full history (no narrowing --log-opts).
- TruffleHog without verification or scoped too narrow.
trufflehog filesystem over a partial path, or ignoring --only-verified semantics, changes what counts as a finding — be explicit about scope and severity mapping.
- Threshold set too high. A gate that only fails on
critical lets high secrets through; confirm the parse-and-filter step's threshold matches policy.
- Over-broad
.gitleaksignore / allowlist silently suppresses real leaks.
- Pre-commit hook in report-only mode instead of
gitleaks protect --staged, so secrets still reach the repo.
Concrete verification: Add a known fake credential (e.g. plus a fake secret key, or a token) to a tracked file and run the pipeline. Confirm gitleaks/trufflehog report it, the CI gate verdict is , and the — then remove the test secret.