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
- 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).
- Assess impact — search CloudTrail for activity by that access key ID; check for new IAM users, EC2 instances, unusual regions, S3 access; check billing.
- Fix the code — read the value from environment variables or a secret manager; add the file pattern to
.gitignore. - Clean history (optional but recommended) —
git filter-repo --replace-textor BFG, then force-push and ask everyone to re-clone. Remember forks and clones may still have it — rotation is what actually protects you. - Prevent — pre-commit hook, required CI scan, GitHub push protection, short-lived credentials.
- 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."
More on Gitleaks
What is Gitleaks and how do you use it?BeginnerWhat is a secret leak and why is it dangerous?BeginnerWhat is Gitleaks?BeginnerHow do you scan a repository's full history with Gitleaks and create a report?BeginnerHow do you stop secrets before they're committed using a pre-commit hook?BeginnerHow do you run Gitleaks in a CI pipeline and fail the build on findings?Beginner