What happens when you leak AWS credentials and how AWS minimizes the damage
xebia.com
xebia.com
1. https://github.com/pypi-data/pypi-aws-secrets
2. https://github.com/pypi-data/pypi-aws-secrets/blob/main/keys...
These specific expressions may contain non-public information about the structure of the tokens.
But imagine we live in a world where companies are OK with exposing this information publicly and investing time in keeping the expressions up to date.
Now what? How do you report it to services whilst stopping abuse? Like, if the code isn’t public then all this is an endpoint to let anyone to disable another users (or companies) key without any explanation or recourse.
Pushing to GitHub is actually quite an elegant solution to these issues I think, even if I do think it is a bit too centralized.
I wouldn’t like to wake up to an email that says “your key has been disabled because someone anonymously reported is as leaked, sorry if this has broken your entire system”.
What do you do with this, outside of obviously quarantining and/or disabling the key? How was it leaked? What’s the context?
1. Are not malicious
2. Have access to a key
3. Are unable or unwilling to commit it to GitHub
It would be great if this stuff was public and available without a central authority. But after working on it for a while it seems like a fairly good compromise.
There are three issues with the use of GitHub here:
1. Not everybody knows that AWS will invalidate tokens committed into a public GitHub repository.
2. There is a window (67 seconds according to OP) in which the compromised token is public but working. For the “small intersection of people”, you could bring it down to 0.
3. GitHub protects GitHub keys, and apparently AWS keys, but does it protect Azure keys? Or GCP keys?
A few cycles ago [4] sudhirj pointed out that you could just use an actual URL as your secret key and have that be the URL you visit to revoke it, and I think that is genius.
[1] https://news.ycombinator.com/item?id=34009442
[2] https://news.ycombinator.com/item?id=31335081
Standards describe existing behaviour of value that benefits from a single interface. For that, the behaviour has to be first demonstrated. That's how the envelope is pushed. You make an implementation, then you show how that solves something worthwhile, and then if there are multiple implementations that could benefit from a single interface, you do that.
Ideally you’d have an endpoint that returns a set of patterns to check for and a way to submit a set of tokens for checking, along with some kind of context. It would probably be something like what GitHub requires[1].
Unfortunately that has somewhat limited value when GitHub can do most of the legwork for you, and as the de-facto place to publish code the majority of “accidental secrets exposed in code” are leaked there.
1. https://docs.github.com/en/code-security/secret-scanning/sec...
To answer "how do the bad guys find them so quickly" the answer is "judicious queries to the GitHub API."
My research group describes how this works, and what we could see with it, in this paper: https://bradreaves.net/mmr19.pdf
We're currently working on follow up work to make secret management better (with NSF funding[1]), and we're always looking for research collaborators[2].
[1] https://nsf.gov/awardsearch/showAward?AWD_ID=2055554&Histori...
I work at a very small shop (at a non-profit institution).
In the past, when we've accidentally leaked a credential, AWS has required us to rotate all of our AWS Access Keys in the account, not just the exposed one.
Which I know ideally rotation would be easy/automated and this wouldn't matter, but at the time it was disruptive for us. And a bit frustrating when we had intentionally created separate AWS credentials with least privs needed for the service, etc. But thinking on it, I guess any given credential might give permissions to create other credentials or other devious things, rotating all of them might be necessary to be safe.
It's been a couple years since we had a leaked credential now (hooray). I wonder if the policy has changed, or if I misunderstood, or if in fact you still need to rotate all credentials in the account, maybe OP just only had one credential in the account they were intentionally doing insecure things so the compromised key was in fact all keys. (I don't specifically remember the `AWSCompromisedKeyQuarantineV2` policy, but probably am just not remembering it, I had other things to worry about at the times!)
[1] https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-f... [2] https://github.com/aws/aws-cli/releases/tag/1.16.232
12:33:12 – Pushed the credentials to GitHub
12:34:19 – The AWSCompromisedKeyQuarantineV2 policy is attached to the IAM user test-user by AWS
Ah, so my exploit must detect and execute within about a minute. Seems doable.“Ok, secret is pushed, we have 77 seconds until Amazon shuts us off. Let’s go!!!!”
12:34:32 – Various List and Describe calls are made using the leaked credentials"What do I do if I notice unauthorized activity in my AWS account?" - https://repost.aws/knowledge-center/potential-account-compro...
It would need to identify strings that look like a key/password, and I guess also it would need an override, perhaps a comment like "// Demo password".
https://github.blog/2022-04-04-push-protection-github-advanc...
There exists some open source tooling in the same space.
https://gist.github.com/czardoz/b8bb58ad10f4063209bd
Then adapted with a better regex for secret keys I got from here: https://github.com/awslabs/git-secrets/blob/80230afa8c8bdeac...
(I think maybe I was getting false positives before)
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_p...
https://docs.aws.amazon.com/organizations/latest/userguide/o...
Can definitely do it at the permission policy level as shown in the links others provided.
*Do NOT just revoke keys if it is in a production system where other people are working or are depending on. Talk to your team and figure out what the remediation process is internally and follow that! If you are working by yourself and no one is relying on services this key is associated with, then yeah, just revoke and replace ASAP.
Here are a couple blogs that cover what you are looking for as well https://blog.gitguardian.com/leaking-secrets-on-github-what-... https://blog.gitguardian.com/thinking-like-a-hacker-aws-keys...
All of the AWS SDKs will get your credentials from
- hardcoded credentials in your code -> don’t do this
- environment variables - you get this when running locally from your control tower interface that most companies access via SSO via AD/Okta etc
- your global configuration file.
When running on AWS, your credentials are retrieved via the attached IAM Role for Lambda, ECS, EC2, etc.
I have done one third party integration where I used Azure DevOps to integrate with AWS using the AWS tools for Azure DevOps. Even then you store your credentials in an Azure vault separate from your source code.
Maybe they have a bot watching some "latest thing on github" API, that scans everything coming in for credentials.
(not sure why really)
It's probably just polling and luck to be honest.
https://docs.github.com/en/code-security/secret-scanning/abo...
Is this actually documented by aws anywhere? I assume other cloud providers must be doing something similar.