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
Trigger phrases:
"implementing secrets scanning in ci cd"
"Integrate gitleaks and trufflehog into CI/CD pipelines to detect leaked secrets "
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
Prerequisites
- Python 3.9 or later
- gitleaks v8.x installed and available on PATH
- trufflehog v3.x installed and available on PATH
- A git repository or directory to scan
- Access to CI/CD platform (GitHub Actions, GitLab CI, Jenkins)
Steps
Install scanning tools: Install gitleaks via package manager or binary download. Install trufflehog via brew install trufflehog or download from GitHub releases.
Configure gitleaks: Create a .gitleaks.toml configuration file in the repository root to define custom rules, allowlists, and path exclusions. Use --config flag to point to custom configs.
Run gitleaks directory scan: Execute gitleaks dir --source . --report-format json --report-path gitleaks-report.json to scan the working directory and generate a JSON report.
Run trufflehog filesystem scan: Execute trufflehog filesystem /path/to/repo --json > trufflehog-report.json to scan files and output JSON findings to a report file.
Parse and filter findings: Use the agent script to parse both JSON reports, filter findings by severity (critical, high, medium, low), and determine whether the CI pipeline should pass or fail.
Integrate into CI pipeline: Add the scanning step to your GitHub Actions workflow, GitLab CI config, or Jenkins pipeline as a pre-deployment gate. Use --exit-code flag in gitleaks to control pipeline behavior.
Configure pre-commit hooks: Set up gitleaks as a pre-commit hook using gitleaks protect --staged to catch secrets before they are committed.
Review and triage findings: Examine the JSON output for false positives, add legitimate entries to .gitleaksignore, and rotate any confirmed leaked credentials immediately.
Expected Output
The agent script produces a JSON report containing:
- Total findings count from each scanner
- Findings grouped by severity level
- Individual finding details including file path, line number, rule ID, and redacted secret
- A CI gate verdict (pass/fail) based on the configured severity threshold
- Execution metadata including scan duration and tool versions
{
"scan_summary": {
"tool": "both",
"total_findings": 3,
"critical": 1,
"high": 1,
"medium": 1,
"low": 0,
"ci_gate": "FAIL",
"fail_reason": "Found 1 critical and 1 high severity findings"
},
"findings": [...]
}
When NOT to Use
- You need to test the implementation (use performing-* skills)
- Task is about configuring existing tools (use configuring-* skills)
- You need to analyze security events (use analyzing-* skills)
- Task is about building detection rules (use building-* skills)
- You don't have access to the target environment
- Task requires vendor-specific expertise (consult vendor docs)
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Sharing sensitive findings or credentials in unencrypted communications
- Failing to properly scope and contain the assessment before starting
Process
- Plan — Define infrastructure requirements, security constraints, rollback strategy
- Implement — Configure resources, apply security best practices, test in staging
- Deploy & Monitor — Roll out to production, verify health checks, set up alerting
Verification
- All steps executed successfully against a test environment before production use
- Output documented with screenshots or logs demonstrating expected behavior
- Results validated against known-good baselines or reference implementations
- Documentation complete enough for another analyst to reproduce findings
Anti-Rationalization Table
| Rationalization |
Reality |
| "We are too small to be targeted" |
Automated attacks target everyone. Size does not matter. |
| "Security slows us down" |
A breach slows you down 100x more. Build security in from the start. |
| "We will fix it after launch" |
Vulnerabilities in production are exploited within hours. Fix before deploy. |
1---2name: implementing-secrets-scanning-in-ci-cd3description: Use when integrate gitleaks and trufflehog into CI/CD pipelines to detect4 leaked secrets before deployment. Use when integrateing gitleaks and trufflehog5 into ci/cd pipelines to detect leaked.6domain: cybersecurity7subdomain: devsecops8tags:9- secrets-scanning10- gitleaks11- trufflehog12- ci-cd13version: '1.0'14author: oyi7715license: Apache-2.016nist_csf:17- PR.PS-0118- GV.SC-0719- ID.IM-0420- PR.PS-0421category: cybersecurity22metadata:23 source: https://skillmd.com/skills/oyi77/implementing-secrets-scanning-in-ci-cd24---25262728# Implementing Secrets Scanning in CI/CD2930## Overview3132This 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.3334Gitleaks 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.353637## When to Use38**Trigger phrases:**39- "implementing secrets scanning in ci cd"40- "Integrate gitleaks and trufflehog into CI/CD pipelines to detect leaked secrets "414243- When deploying or configuring implementing secrets scanning in ci cd capabilities in your environment44- When establishing security controls aligned to compliance requirements45- When building or improving security architecture for this domain46- When conducting security assessments that require this implementation4748## Prerequisites4950- Python 3.9 or later51- gitleaks v8.x installed and available on PATH52- trufflehog v3.x installed and available on PATH53- A git repository or directory to scan54- Access to CI/CD platform (GitHub Actions, GitLab CI, Jenkins)5556## Steps57581. **Install scanning tools**: Install gitleaks via package manager or binary download. Install trufflehog via `brew install trufflehog` or download from GitHub releases.59602. **Configure gitleaks**: Create a `.gitleaks.toml` configuration file in the repository root to define custom rules, allowlists, and path exclusions. Use `--config` flag to point to custom configs.61623. **Run gitleaks directory scan**: Execute `gitleaks dir --source . --report-format json --report-path gitleaks-report.json` to scan the working directory and generate a JSON report.63644. **Run trufflehog filesystem scan**: Execute `trufflehog filesystem /path/to/repo --json > trufflehog-report.json` to scan files and output JSON findings to a report file.65665. **Parse and filter findings**: Use the agent script to parse both JSON reports, filter findings by severity (critical, high, medium, low), and determine whether the CI pipeline should pass or fail.67686. **Integrate into CI pipeline**: Add the scanning step to your GitHub Actions workflow, GitLab CI config, or Jenkins pipeline as a pre-deployment gate. Use `--exit-code` flag in gitleaks to control pipeline behavior.69707. **Configure pre-commit hooks**: Set up gitleaks as a pre-commit hook using `gitleaks protect --staged` to catch secrets before they are committed.71728. **Review and triage findings**: Examine the JSON output for false positives, add legitimate entries to `.gitleaksignore`, and rotate any confirmed leaked credentials immediately.7374## Expected Output7576The agent script produces a JSON report containing:77- Total findings count from each scanner78- Findings grouped by severity level79- Individual finding details including file path, line number, rule ID, and redacted secret80- A CI gate verdict (pass/fail) based on the configured severity threshold81- Execution metadata including scan duration and tool versions8283```json84{85 "scan_summary": {86 "tool": "both",87 "total_findings": 3,88 "critical": 1,89 "high": 1,90 "medium": 1,91 "low": 0,92 "ci_gate": "FAIL",93 "fail_reason": "Found 1 critical and 1 high severity findings"94 },95 "findings": [...]96}97```98## When NOT to Use99100- You need to test the implementation (use performing-* skills)101- Task is about configuring existing tools (use configuring-* skills)102- You need to analyze security events (use analyzing-* skills)103- Task is about building detection rules (use building-* skills)104- You don't have access to the target environment105- Task requires vendor-specific expertise (consult vendor docs)106107108## Red Flags109110- Performing actions without explicit written authorization from the asset owner111- Testing against production systems without a defined scope and rules of engagement112- Sharing sensitive findings or credentials in unencrypted communications113- Failing to properly scope and contain the assessment before starting114115## Process1161171. **Plan** — Define infrastructure requirements, security constraints, rollback strategy1181. **Implement** — Configure resources, apply security best practices, test in staging1191. **Deploy & Monitor** — Roll out to production, verify health checks, set up alerting120121## Verification122123- All steps executed successfully against a test environment before production use124- Output documented with screenshots or logs demonstrating expected behavior125- Results validated against known-good baselines or reference implementations126- Documentation complete enough for another analyst to reproduce findings127128## Anti-Rationalization Table129130| Rationalization | Reality |131|---|---|132| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |133| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |134| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |