Someone accidentally committed an AWS access key to a public GitHub repository. What do you do?
IntermediateScenarioReal-world scenarios
Answer
In one line: Treat it as a security incident: deactivate and rotate the key immediately, check for any misuse, clean up the damage, then remove it from Git history and add controls so it can't happen again.
Step 1 — Contain (minutes matter)
- Deactivate/delete the access key in IAM right away. Bots scan public GitHub for keys within minutes, so assume it's already been seen.
- Create a new key (or better, switch to a role/OIDC with no long-lived key) and update the systems that legitimately used it.
- If it was a high-privilege key, consider also revoking active sessions and checking other credentials that user had.
Step 2 — Investigate misuse
- CloudTrail — look for API calls made with that key, especially from unknown IPs: new IAM users or keys, EC2 instances launched (crypto mining is common), S3 data access, changed security groups.
- Billing / Cost Explorer — sudden cost spikes.
- GuardDuty findings.
- Check all regions — attackers often launch resources in regions you don't use.
Step 3 — Clean up
- Terminate any resources the attacker created; remove any backdoor users, keys or roles.
- If data may have been accessed, follow your incident and data-breach process (legal/compliance may need to be informed).
- AWS may also contact you — follow their guidance.
Step 4 — Remove it from Git
- Deleting the file in a new commit is not enough — it's still in history.
- Rewrite history with
git filter-repo(or BFG), force-push, and ask collaborators to re-clone. Forks and caches may still have it — which is why rotation is the real fix.
Step 5 — Prevent
- Pre-commit hooks with Gitleaks/TruffleHog.
- GitHub secret scanning and push protection to block pushes containing secrets.
- No long-lived keys — use IAM roles, SSO and OIDC for pipelines.
- Least-privilege permissions so any leak causes less damage.
- Blameless post-mortem and team training.
Tip for interviews: the most important point is the order — revoke first, then investigate, then clean history. Many candidates start with "remove it from Git", which is the least urgent step.
More on Real-world scenarios
The website is slow. How do you troubleshoot it?IntermediateA deployment to production just failed halfway. What do you do?IntermediateDevelopers complain that the CI pipeline takes 40 minutes. How would you speed it up?IntermediateYour production disk is 95% full and the alert just fired. What do you do?IntermediateHow would you set up CI/CD for a brand-new microservice from scratch?IntermediateYour cloud bill doubled this month. How do you find out why and reduce it?Intermediate