The access key nobody retired: how to find and kill stale AWS keys
Barracuda disclosed this month that attackers got into about ten of its cloud accounts using a single access key. According to Barracuda, the key had been given to a third-party vendor for the length of a previous project and was never retired afterwards. The vendor's development environment was compromised in October, and Barracuda says that is where the attacker found it. The first call with the key came at 04:33 UTC on November 1. The last recorded activity was about 44 hours later, and a Barracuda engineer noticed on November 4, after the activity had stopped. (Details here are from Skycloak's write-up, which cites Barracuda and BleepingComputer. The coverage I read does not say which cloud provider was involved, but the lesson is identical on AWS.)
Nothing about the technique was new. The key was valid, so no exploit was needed. It outlived the reason it was created, and nobody was looking at it. That is the most common way an old project turns into a breach, and you can check your own AWS accounts for it in under an hour.
Step 1: List every active key that nobody uses
IAM can export every user and key in the account as a credential report. Generate it, then filter for active keys that were never used, or not used in the last 90 days:
aws iam generate-credential-report
aws iam get-credential-report --query Content --output text | base64 -d | python3 -c '
import csv, sys, datetime as d
now = d.datetime.now(d.timezone.utc)
parse = lambda v: d.datetime.fromisoformat(v.replace("Z", "+00:00"))
for r in csv.DictReader(sys.stdin):
for n in ("1", "2"):
if r["access_key_%s_active" % n] != "true":
continue
last = r["access_key_%s_last_used_date" % n]
age = (now - parse(r["access_key_%s_last_rotated" % n])).days
idle = None if last in ("N/A", "") else (now - parse(last)).days
if idle is None or idle > 90:
print(r["user"], "key" + n, "created", age, "days ago; last used:", "never" if idle is None else "%d days ago" % idle)
'
Two rows deserve extra attention. A key that was never used is a credential someone created and forgot, which is exactly what an attacker hopes to find. And the <root_account> row should have no active keys at all. If it does, deal with that first.
The report only shows IAM users. Vendors and CI systems are often given a dedicated IAM user, so look at the user names too: anything named after a project, a contractor or a tool that no longer exists is a candidate.
Step 2: Check what each key has actually done
For each key on the list, find out when and where it was last used, and by which service:
aws iam get-access-key-last-used --access-key-id AKIAEXAMPLEKEYID
If the answer is a service or region you do not recognise, look at its recent activity. CloudTrail event history keeps 90 days of management events and can be filtered by key:
aws cloudtrail lookup-events --lookup-attributes AttributeKey=AccessKeyId,AttributeValue=AKIAEXAMPLEKEYID --max-results 50
Event history is per region. For anything important, run the same lookup in every region you use, or query a trail in Athena. You are looking for source IP addresses that do not belong to you or the vendor, calls to services the key was never meant to touch, and bursts of List* and Describe* calls, which is what discovery looks like.
Step 3: Deactivate first, delete later
Do not delete a stale key straight away. Something may still depend on it, in a cron job, a CI variable or a laptop script nobody remembers. Deactivating is reversible, and deleting is not:
aws iam update-access-key --user-name SOME_USER --access-key-id AKIAEXAMPLEKEYID --status Inactive
Wait a week. If something breaks, someone will tell you, and you can set the key back to Active while you work out what it was doing. If nothing breaks, delete it. For keys that must stay, rotate them in order: create the new key, deploy it, confirm the old key shows no recent use, deactivate it, then delete it.
Step 4: Replace vendor keys with roles
A key given to a third party is a permanent door with your address on it. Whenever you can, give vendors a role they assume instead: access that is temporary, limited to what the integration needs, and visible in CloudTrail as an assumed-role session. Bear in mind what the Qubole breach showed, which is that a role alone is not enough. The trust policy should name a specific principal, include an External ID, and be removed when the integration ends. Our audit for past compromise covers how to check the roles you already have.
When a project with an outside party ends, put the access review on the same checklist as the final invoice. Barracuda's key survived because nothing in the offboarding process asked about it.
Step 5: Make new stale keys harder to create
- Prefer roles and short-lived credentials. People should sign in through IAM Identity Center or a federated identity provider, and workloads should use roles. A key that expires in an hour is not worth stealing from a repository.
- Restrict who can create keys. A service control policy or IAM policy that denies
iam:CreateAccessKeyexcept for a small set of administrators turns key creation into a deliberate act. - Turn on the checks AWS already offers. The managed AWS Config rule
access-keys-rotatedflags keys older than a threshold you choose, and IAM Access Analyzer has findings for unused access. - Scan repositories for secrets. Barracuda says the key was found in the vendor's environment, and secret scanning is the only thing that catches a key committed to a repository you do not control.
Step 6: Get told when a key is created or used somewhere new
An audit shows you today's keys. Two alerts show you the rest. The first fires whenever a new key is created, which is rare enough in most accounts to be worth reading each time. IAM is a global service, so create the rule in us-east-1:
{
"source": ["aws.iam"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": { "eventName": ["CreateAccessKey"] }
}
Send it to an SNS topic as you would any EventBridge rule. The second is harder to build yourself: an alert when an existing key is used from a network or region it has never used before. That is the signal that would have shown the Barracuda activity on the first call, not after 44 hours. Our own monitoring does something similar for API activity in a region an account has never used, which is also how a stolen key usually announces itself.
How much is a stolen key worth?
It helps to put a number on it when deciding how urgent this is. Our blast-radius calculator estimates what an attacker could run up with a stolen key on GPU instances or Bedrock, comparing a SpikeCatcher alert within 15 minutes with a billing-data alert that can arrive a day later. For most accounts the answer is larger than people expect, and the key you forgot about is the one that decides it. 14-day free trial, 5-minute setup, read-only IAM.
Related articles
How to audit AWS for signs of past compromise (after the Qubole breach)
A vendor's IAM credentials assumed customer roles for two weeks unnoticed. A step-by-step audit with commands: trusted roles, AssumeRole hunting, persistence.
The first thing attackers do after stealing AWS credentials: switch off your alarms
Intruders often disable GuardDuty, stop AWS Config or delete logs first. The CloudTrail events to alert on, plus a copy-paste EventBridge rule.
Bought the wrong Savings Plan? You have a short window to return it
AWS lets you return a mistaken Savings Plan for a limited time. The exact rules, the calendar-month trap, and which plans cannot be returned.
Protect your AWS account — 14-day free trial
Real-time threat and cost anomaly detection. Detects credential theft, cryptomining, and runaway costs in under 15 minutes. 5-minute setup via CloudFormation.
No credit card. Cancel anytime.