Gitleaks found a real AWS key in the repo. What do you do?

BeginnerScenarioGitleaks
Answer

Short answer

Treat it as an incident: revoke/rotate the key immediately, check whether it was used (CloudTrail), replace it with a proper secret mechanism, and only then clean the history if needed. Removing the commit alone does not make you safe.

Step by step

  1. Rotate now — deactivate and delete the access key in IAM; create a new one only if still needed (better: switch to an IAM role / OIDC so no static key exists).
  2. Assess impact — search CloudTrail for activity by that access key ID; check for new IAM users, EC2 instances, unusual regions, S3 access; check billing.
  3. Fix the code — read the value from environment variables or a secret manager; add the file pattern to .gitignore.
  4. Clean history (optional but recommended) — git filter-repo --replace-text or BFG, then force-push and ask everyone to re-clone. Remember forks and clones may still have it — rotation is what actually protects you.
  5. Prevent — pre-commit hook, required CI scan, GitHub push protection, short-lived credentials.
  6. Document — short post-incident note.

Rotation order of priority

Production cloud keys, payment keys, database passwords → highest. Everything found is assumed compromised.

What to say in the interview

"Rotate first — deactivate the key — then check CloudTrail for misuse, move the app to a role or secret manager, optionally rewrite history with git filter-repo, and tighten prevention. Cleaning history alone isn't a fix because clones and forks still contain it."

All Security Tools questions Roadmap: Gitleaks — secret scanning

More on Gitleaks