Lesson 12 of 13 · 20m
A key just leaked: the first hour
Deactivation vs quarantine vs deletion, killing live sessions with aws:TokenIssueTime, and reading the trail it left.
AWS scrapes public GitHub for its own credential format — AKIA plus sixteen characters for long-term access keys — and when it finds one it attaches a quarantine policy to the principal and emails you. If that email is how you find out, the key was public before you knew it existed. If you find out from your bill, it was in use for hours. This is the first hour after you learn a key leaked, sequenced the way an incident responder runs it.
Step one: identify what leaked
aws sts get-caller-identity with the key is safe — it just names the principal. Match it against CloudTrail's userIdentity.accessKeyId to see when it last ran and what it called. An IAM user key and an assumed-role session (ASIA prefix) are different problems: the user key is revoked at the user; the role session dies at the role.
Step two: contain without breaking prod
Three options, graded by blast radius:
- Deactivate:
aws iam update-access-key --status Inactive. New API calls with that key fail instantly; it is reversible if something critical turns out to depend on it. Critically, sessions already assumed keep working until they expire — deactivation stops new auth, not existing sessions. - Quarantine: attach
AWSCompromisedKeyQuarantineV2, the AWS-managed policy AWS itself applies. It denies the dangerous actions — new keys, policy changes, org tampering — while preserving the identity so forensics still work. Quarantine is the designed-for-this answer; it is what the GitHub-scraping pipeline does to your key automatically. - Delete:
aws iam delete-access-key. Irreversible, and kills anything still using the key — which is sometimes exactly the point, once you know what depended on it.
Step three: kill the live sessions
This is the part everyone misses. An assumed-role session minted with the leaked key lives up to twelve hours. You cannot revoke a session — but you can deny it: attach an identity policy with Effect: Deny on everything, conditioned on aws:TokenIssueTime being DateLessThan the compromise timestamp:
{
"Effect": "Deny",
"Action": "*",
"Resource": "*",
"Condition": {
"DateLessThan": { "aws:TokenIssueTime": "2026-11-16T14:00:00Z" }
}
}Sessions issued before that timestamp die; anything after (your fresh, clean creds) works. Apply it to the role too if role sessions are in play.
Step four: find out what it did
Athena or CloudTrail Lake, keyed on userIdentity.accessKeyId or the role-session ARN:
SELECT eventTime, eventName, awsRegion, sourceIPAddress, userAgent
FROM cloudtrail_logs
WHERE userIdentity.accessKeyId = 'AKIA...'
ORDER BY eventTime;Read the sequence, not the count. GetCallerIdentity → ListBuckets → DescribeInstances is recon. CreateUser, CreateAccessKey, AttachUserPolicy, CreateLoginProfile is persistence. RunInstances, RunJobFlow, CreateFunction is monetization — check regions you never operate in, and check the bill; Cost Anomaly Detection catches the miner your eyes missed. StopLogging, DeleteTrail, PutEventSelectors is anti-forensics — and the reason the trail lives in a different account.
Step five: eradicate persistence
Every principal, key, role, and login profile created inside the compromise window is suspect. So are the quiet backdoors: a Lambda triggered by a scheduled events:PutRule, a new OIDC provider in IAM, an EC2 instance in an unwatched region running as a persistence host. Delete the path in, then delete what it built.
Step six: recover and write it down
Once deactivation holds with no breakage, delete the key permanently. Rotate everything the key could have read — secrets it fetched from Secrets Manager, database credentials it could pull from parameter stores, anything in buckets it listed. Write the timeline while it is fresh: discovery vector, first malicious call, actions taken, blast radius. Your postmortem and your insurer's evidence are the same document.
Then fix why the key existed. A leaked long-lived key means someone needed an identity and reached for the wrong primitive — the fix is the OIDC/role path or Secrets Manager, and a gitleaks step in CI so the next key dies pre-push instead of post-bill.
Exercise
In a sandbox account, stage a drill: create a user key, use it to run a few API calls including an AssumeRole, then simulate the leak. Walk the sequence: deactivate, attach quarantine, apply the TokenIssueTime deny, watch the session calls die, run the Athena query, delete the key. Time yourself — the real version of this exercise has a pager going off.
Field notes
- Never paste the leaked key into tickets, chat, or the postmortem. If it is still active, it works wherever you pasted it. Refer to keys by their ID.
ASIAsession credentials from a role are contained at the role — theTokenIssueTimedeny on the role is the tool; deleting the calling user does not shorten a role session.GitHub→ leak → AWS quarantine email usually beats your own detection to the punch. Treat that email as a page, not a newsletter.- The question after "what did it do" is "why did it exist." Long-lived keys are a process smell; every one you delete is an incident that cannot happen.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
AWS Emulator Puts AWS on Your Laptop. Keep Your IAM Tests Off It.
AWS released AWS Emulator on November 11, a free local server that answers AWS API calls on 127.0.0.1 with per-run keys and fresh certificates.
Big Tech Plans to Work with the Public Sector for Cybersecurity
Both Microsoft, Inc. and Alphabet, Inc. will put a combined $30 billion dollars into cybersecurity over the next five years and work with the public sector on several initiatives to help improve cybersecurity.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.
What is SSRF? Server-Side Request Forgery and the Attack That Breached Capital One
SSRF tricks your server into making requests to internal systems — cloud metadata services, internal APIs, AWS credentials endpoints. It turned a WAF misconfiguration into 100 million stolen Capital One records