Initial Pipeline Setup
Start with a basic pipeline that prepares environments, runs code quality checks, SAST, and unit tests:Add the Secret Detection Component
Pull in the official component from the GitLab Components catalog and conditionally disable it via a variable:This component leverages Gitleaks to scan commits and code for secrets.
For full details, visit the Secret Detection documentation.
For full details, visit the Secret Detection documentation.
Ignoring Specific Lines
If you need to keep placeholder secrets or test tokens in your code, annotate those lines so Gitleaks will skip them:Use
# gitleaks:allow sparingly—never suppress detection of real or production secrets.Enabling Full-History Scans
By default, Secret Detection inspects only the diff of each commit. To scan the entire repository history, set:
Customizing Detection Rules
Gitleaks ships with over 100 built-in rules. You can override or extend these by providing a custom TOML file:
Configuring the Secret Detection Job
Integrate thesecret_detection job into your .gitlab-ci.yml:

Running a Test Secret Scan
Commit a dummy secret (e.g., anid_rsa SSH private key) to a feature branch and watch the Secret Detection job:
Viewing Artifacts
After the job finishes, download the JSON report from the artifacts list:
Interpreting the JSON Report
Thegl-secret-detection-report.json includes each finding’s details:
Next Steps
- Remove exposed secrets from the current commit.
- Rewrite history to purge sensitive data.
- Rotate any compromised keys or tokens.