Secrets and dependency scanning
Lessons on gitleaks, TruffleHog, Semgrep, and Grype: what a rule id, a redacted field, a severity word, or an advisory id does not prove.
- 26 lessons
- 5 h of reading
- 5 topics
A scanner is only useful when its output reaches someone who can fix it. These lessons cover running each tool, reading one finding precisely, deciding what blocks a merge, and recording accepted risk where reviewers can see it.
Scan repositories, images, and build output your team owns. When a secret turns up, revoke it before anything else.
gitleaks
6 lessons
- 01gitleaks: scan repository history and block secrets at commit timeScan a repository’s full git history with gitleaks, read a redacted finding, record accepted false positives by fingerprint, and add a pre-commit check so new keys never land.11 min
- 02gitleaks: a finding is a match in history, not a live secretA gitleaks finding means a rule matched text in a commit. Write the rule, file, commit, and fingerprint. Entropy and the author string do not show that the value still works.11 min
- 03gitleaks: the commit date is not the scan timeThe date on a gitleaks finding is the commit’s date. The scan time is when you ran the tool. Write both. Neither one means the value was used.11 min
- 04gitleaks: a directory scan has no commitA scan of a folder that is not walked as git history has no commit on the finding. Write that. Do not invent a commit, and do not describe the match as something history still contains.11 min
- 05gitleaks: the line number is in that commitThe line number on a gitleaks finding is the line in the file as that commit stored it. The same path in today’s checkout can sit on a different line. Write the commit with the number, and do not read today’s file as the match.11 min
- 06gitleaks: the rule id is not the fingerprintRuleID names which rule matched. The fingerprint identifies one finding. Two findings can share a rule and still be different fingerprints. Write both, and do not merge them because the rule id matches.11 min
TruffleHog
5 lessons
- 01TruffleHog: find verified secrets across your organization’s repositoriesScan your GitHub organization and build artifacts with TruffleHog, use credential verification to rank live secrets first, and decide when verification calls are not allowed.11 min
- 02TruffleHog: verified false is not a dead secretRead DetectorName, Verified, and whether the scan was allowed to check with the provider. Verified false means “not accepted” only when a check actually ran.12 min
- 03TruffleHog: the source type is where it was foundSource type says whether the result came from git, a filesystem, an image, or another source. Write it. Do not describe a filesystem path as a commit or an image layer as a repository file.11 min
- 04TruffleHog: the detector name is not the accountDetectorName is which detector printed the row. It is not a workspace, a channel, or an account that was accessed. Write the detector beside the source the row already names, and do not invent a login from the detector string.11 min
- 05TruffleHog: the redacted field is not the raw valueA redacted field is the masked text the report stored. It is not the original secret, and it is not something you paste into a service to test. Write the mask as a mask, and cite the location instead.11 min
Semgrep
7 lessons
- 01Semgrep in CI: scan only new code and triage the first findingsRun Semgrep with a curated ruleset in a pull-request job, use a baseline commit so only new findings fail the build, and triage the first results with the team that owns the code.11 min
- 02Writing a Semgrep rule for your codebase, with testsWrite a Semgrep rule for a mistake specific to your own code, add ruleid and ok test annotations, and run semgrep --test so the rule stays correct as it evolves.12 min
- 03Semgrep: a finding is the lines that matchedA Semgrep finding means a rule’s pattern matched at a path and line. Write the rule id and the lines. The message and the severity are the rule author’s words, not a confirmed defect.11 min
- 04Semgrep: the finding path is under the scan rootA Semgrep path is relative to the directory that was scanned. Write that root with the path. A same-named file elsewhere in the repo was not the file the finding means.11 min
- 05Semgrep: the check id is the full rule nameThe check id on a finding is the full rule name. A short suffix can match more than one rule. Write the full id with the path and line. Do not file a different rule that shares the ending.11 min
- 06Semgrep: the end line is part of the matchA Semgrep finding has a start line and an end line. The match is that span. Citing only the first line can drop the rest of the pattern. Write both numbers with the path and the rule id.11 min
- 07Semgrep: severity is not the finding countSeverity on a Semgrep finding is the label on that rule. A count is how many findings you have. Write the label and the count as different facts. Four warnings are four findings, not severity 4.11 min
Trivy
4 lessons
- 01Trivy: gate container images and Terraform in one pipeline stepUse Trivy to scan a built image for fixable high-severity vulnerabilities, scan Terraform for misconfigurations, and fail CI only on findings the team has agreed to block.11 min
- 02Trivy: a row matches a package version to an advisoryA Trivy row means this image or filesystem contained a package version that an advisory lists. Write the package, installed version, fixed version, and advisory id. Severity is not proof the lab was attacked.12 min
- 03Trivy: a tag is not the image digestA Trivy row belongs to the image that was scanned. A tag can move. Write the digest or image id the report printed, and do not apply the row to a cluster that only shares the tag.11 min
- 04Trivy: a config row is a check, not a CVEA misconfiguration result names a check id and a file. A vulnerability result names a package and an advisory. Write which kind of row you have. Do not give a config check an installed version it does not have.12 min
Grype
4 lessons
- 01Grype on stored SBOMs: catch new CVEs in images you already shippedGenerate an SBOM with Syft at release time, then rescan it daily with Grype so vulnerabilities published after the release reach the owning team without rebuilding the image.10 min
- 02Grype: the database date is part of the resultA Grype row is a match against the vulnerability database that was loaded. Write that database’s built time with the package. Two scans with different database dates are not a change in the image.12 min
- 03Grype: the fixed version is not what is installedA Grype row can name the version that was in the scan and a version the advisory lists as a fix. The fix version is not installed unless a later scan says so. Write the two versions as two facts.12 min
- 04Grype: the vulnerability id is the advisoryThe vulnerability id on a Grype row is the advisory. The package name is the artifact that matched. Write both. Do not treat the advisory id as a package, or one advisory as every package in the SBOM.12 min