From git push to crypto miner in 5 minutes: what really happens when an AWS key leaks on GitHub
A minute-by-minute look at what GitHub, AWS and attackers do after an access key goes public, why AWS's automatic quarantine is not a kill switch, and a checklist so it never happens to you.
Every week, someone pushes a
.env file with an AWS access key to a public repository. It feels like a small mistake you can fix with the next commit. It isn't. Coming from cybersecurity and new to cloud, I wanted to know what actually happens after that push, so I went through the research. Here is the short version.The first minute: GitHub and AWS react
Palo Alto Networks' Unit 42 ran a controlled test: they created an IAM user, generated an access key and pushed it to a public GitHub repository. GitHub's push protection flagged the key first, so they had to bypass the warning on purpose. Then this happened:
Time after the push | What happened |
|---|---|
0 s | The key and secret land in a public repository |
10 s | AWS attaches the AWSCompromisedKeyQuarantineV3 policy to the IAM user |
11 s | GitHub emails the repository owner |
12 s | A "Risk IAM quarantine" alert appears in AWS Health |
21 s | AWS emails the account owner |
54 s | AWS opens a Support case with the key and user details |
A detail for defenders: in CloudTrail, that
AttachUserPolicy event shows the leaked IAM user as the actor, not an AWS service. If you build an alert, match on the policy name.The first five minutes: attackers react too
AWS is fast, but so are the bots. In the EleKtra-Leak campaign, Unit 42 saw an attacker find and use exposed AWS keys within five minutes of their exposure on GitHub. Between August 30 and October 6, 2023, they recorded 474 unique miners, most likely EC2 instances (
c5a.24xlarge ), mining Monero on their victims' bills. The researchers also believe the attacker could find exposed keys that AWS doesn't detect automatically, so for those keys the quarantine never kicks in.Why so fast? Every public push is visible almost immediately, and long-term access keys are easy to spot: their IDs start with
AKIA . Scanning GitHub for that pattern is cheap and fully automated.Quarantine is not a kill switch
This was the part that surprised me most. AWS does not disable the leaked key. The quarantine policy is a list of explicit
Deny statements for the actions attackers abuse the most, so it limits fraud without breaking your existing resources. The first version denied 28 actions in 5 services. V3 covers many more, for example:- Launching compute:
ec2:RunInstances,lambda:CreateFunction,ecs:CreateService
- Persistence:
iam:CreateUser,iam:CreateAccessKey,iam:CreateRole
- Data theft and ransomware:
s3:GetObject,s3:DeleteObject,s3:PutBucketPolicy
- AI abuse:
bedrock:InvokeModel
Anything that is not on the list still works if the key had permission. For example,
secretsmanager:GetSecretValue and dynamodb:Scan are not on it. The real limit is the set of permissions you gave that IAM user, not the quarantine.The policy description is blunt: "Do NOT remove this policy." Follow the instructions in the Support case instead.
If it happens to you: 5 steps
- Leave the quarantine policy in place and open the Support case AWS created.
- Deactivate, then delete the key from another identity, such as an admin user. The quarantined user can't do it, because
iam:UpdateAccessKeyandiam:DeleteAccessKeyare on the deny list.
aws iam update-access-key --user-name <user> --access-key-id <AKIA...> --status Inactiveaws iam delete-access-key --user-name <user> --access-key-id <AKIA...>- See what the key did: CloudTrail > Event history, filtered by AWS access key. It keeps 90 days of management events.
- Hunt for leftovers in every Region: EC2 instances, Lambda functions, new IAM users, roles and keys. Then check Billing for charges you don't recognize.
- Clean the repository, but don't count on it. Deleting the commit doesn't help, because the key was already copied. Rotating it is what protects you.
So it never happens: a checklist
- Don't create long-term keys for yourself. Use IAM Identity Center with
aws configure sso(AWS CLI v2) to get temporary credentials.
- Never create access keys for the root user, and turn on MFA for it.
- Keep secrets out of Git: add
.env,*.pemand.aws/to your.gitignore.
- Scan before you commit with git-secrets : run
git secrets --installandgit secrets --register-awsin your repository.
- Respect GitHub push protection. It's on by default for pushes to public repositories. If it blocks a real key, remove the key instead of clicking bypass.
- Set an AWS Budgets alert, so a crypto miner shows up as an email and not as a bill.
- Give least privilege to any IAM user that has keys. The quarantine only blocks a list; your own permissions decide how much damage a leak can do.
Takeaway
Treat the second you push a key as the second it's stolen. AWS and GitHub will warn you within a minute, but an attacker can be mining on your account within five, and the quarantine doesn't switch the key off. The best leaked key is the one that never existed: use temporary credentials.
Sources
- AWS Managed Policy Reference: AWSCompromisedKeyQuarantineV3
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article