What kinds of files commonly leak secrets, and how does .gitignore help?

BeginnerConceptGitleaks
Answer

Short answer

The usual suspects are .env files, cloud credential files (~/.aws/credentials, service account JSON), Terraform state and tfvars, kubeconfig files, private keys/certificates, and app config like application-prod.yml. A good .gitignore stops these files from being added to Git in the first place.

Example .gitignore section

# secrets & credentials
.env
.env.*
!.env.example
*.pem
*.key
*.p12
id_rsa*
kubeconfig
*.kubeconfig
credentials.json
service-account*.json

# terraform
*.tfstate
*.tfstate.*
*.tfvars
!example.tfvars
.terraform/

Important limits

  • .gitignore only affects untracked files. If a file was already committed, ignoring it later does nothing — remove it with git rm --cached (and rotate what was in it).
  • It doesn't catch secrets pasted inside normal code files — that's what Gitleaks is for.

Pattern teams use

Commit an .env.example with placeholder values so developers know which variables to set, while the real .env stays ignored.

What to say in the interview

"Env files, cloud credential files, tfstate and tfvars, kubeconfigs and private keys are the common leakers. We gitignore them with a committed .env.example as a template, remember that gitignore doesn't untrack already-committed files, and rely on Gitleaks for secrets inside code."

All Security Tools questions Roadmap: Gitleaks — secret scanning

More on Gitleaks