Pre-Commit Secret Scanning Gate Prompt
Stop secrets before they reach git — configure pre-commit and CI secret scanners (gitleaks, detect-secrets, trufflehog) with a baseline, tuned rules, and developer-friendly remediation that doesn't get bypassed.
- Target user
- Developers and platform engineers preventing credential leaks
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are an application-security engineer who has rolled out secret scanning across many repos and knows the difference between a gate developers respect and one they `--no-verify` around. I will provide: - My languages/stack and where config/secrets tend to live - My git host and CI (GitHub Actions, GitLab CI, etc.) - Whether I want pre-commit hooks, CI scanning, or both - Any false positives that have annoyed me before Your job — DEFENSIVE leak prevention only: 1. **Pick the right layers — defense in depth.** Recommend BOTH a local pre-commit hook (fast, catches it before commit) and a CI/server-side scan (the real gate, since `--no-verify` skips local hooks). Explain why local-only is insufficient. 2. **Choose the scanner.** Compare gitleaks, detect-secrets, and trufflehog for my case (regex+entropy vs verified-secret validation), and recommend one primary. Note trufflehog's live-verification advantage for triage. 3. **Config files.** Provide a ready-to-use `.pre-commit-config.yaml` and the scanner config (`.gitleaks.toml` or `.secrets.baseline`) with sensible rules and an allow-list for known false positives (test fixtures, example keys) — using narrow path/regex exclusions, never a blanket disable. 4. **Baseline the existing repo.** Show how to generate a baseline so the gate starts green on legacy findings, while still catching NEW secrets — and stress that baselined findings should be triaged, not forgotten. 5. **The CI gate.** Provide the CI job that scans the diff (and on a schedule scans full history), fails the build on a new finding, and posts a clear message. Make it required for merge. 6. **Remediation guidance for developers.** A short, copy-pasteable "you committed a secret" runbook: rotate the credential FIRST (assume it's compromised), remove it from code, use history-rewrite only as cleanup — and never rely on a force-push alone to undo exposure. 7. **Prevent the bypass** — explain why server-side/CI scanning is the enforcement point and how to detect `--no-verify` usage. Output: (a) `.pre-commit-config.yaml`, (b) scanner config + allow-list, (c) baseline-generation command, (d) the required CI job, (e) the developer remediation runbook (rotate-first). Bias toward: rotate-first on any leak, CI as the real gate, narrow allow-lists over disabling rules.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Gitleaks Custom Rules & False-Positive Tuning Prompt
Tune a Gitleaks config — custom rules, allowlists, and entropy thresholds — to catch real secrets while cutting the false positives that train developers to ignore the gate.
-
Terraform State Security Review Prompt
Review how Terraform/OpenTofu state is stored, encrypted, locked, and accessed — state files routinely contain plaintext secrets and full infrastructure topology, making them a high-value target.
-
HashiCorp Vault Dynamic Secrets Design Prompt
Design short-lived, dynamic secrets in HashiCorp Vault — database, cloud, and PKI engines — with auth methods, lease/TTL strategy, and least-privilege policies that replace long-lived static credentials.
-
Secrets Management Architecture Design Prompt
Design a centralized secrets-management architecture (Vault or cloud secret manager) — storage, dynamic credentials, access policy, injection, rotation, and break-glass — for an existing stack.
More DevOps Security & Hardening prompts & error guides
Browse every DevOps Security & Hardening prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.