How does Trivy secret scanning work?

IntermediateConceptTrivy
Answer

Short answer

Trivy's secret scanner looks for credentials — AWS keys, GitHub tokens, private keys, Slack webhooks and more — in files on disk and inside container image layers. It's enabled by default for trivy fs and trivy image, so the same scan that finds CVEs also catches secrets that slipped into an image.

Examples

trivy fs --scanners secret .
trivy image --scanners secret shop-api:1.4.0
trivy image --scanners vuln,secret --severity HIGH,CRITICAL shop-api:1.4.0
app/config/.env (secrets)
HIGH: AWS (aws-access-key-id)
  AWS_ACCESS_KEY_ID=AKIA****************

Why scan images for secrets

A secret removed in a later Dockerfile step still exists in an earlier layer. Image scanning catches what source scanning can't, like files generated or copied during the build.

Custom rules and allowlists

trivy-secret.yaml with rules, allow-rules and disable-rules via --secret-config.

What to say in the interview

"Trivy's secret scanner finds credentials in filesystems and in every image layer, so a secret deleted in a later layer is still caught. We run it together with vulnerability scanning on built images, and Gitleaks on the repo."

All Security Tools questions Roadmap: Trivy — image, file system & IaC scanning

More on Trivy