All case studies

Security forensics

Tracing a leaked key the standard tools said was barely used

An audit of scheduled jobs found a long-lived access key baked into container images. Before rotating it, we needed to know everything that used it. The standard tools showed it had barely been used.

Stack
AWS CloudTrail, CloudWatch Logs Insights, IAM, AWS Batch, Python
My role
Investigation, tooling and the rotation plan
Outcome
A full report per key in about 33 seconds. Every caller identified before rotation.

Where it started

While auditing scheduled jobs, I found the access key of a long-lived IAM user inside two container images that AWS Batch ran every night. Anyone who could pull those images had the key. Rotating a key takes seconds. The real work is rotating it without breaking something that quietly depends on it. So the first question was who was using this key, from where, and for what.

The obvious tools undercount

aws cloudtrail lookup-events returned one old event across 90 days. The same key, queried against the organization’s CloudTrail log group in CloudWatch Logs, showed 1,434 events in two days. Three things explained the gap:

Logs Insights has its own traps

Two limits make large investigations silently wrong:

So I wrote a Python tool that keeps splitting the time window until every slice is under the row limit and skips nothing. It then merges the slices into one result.

What the report shows

For a key and a time window, the report lists:

A companion lookup matches each IP to our own NAT gateways, load balancers and compute. If an IP isn’t ours, it names the cloud provider or ISP.

Making it fast

I timed it on a second, much busier key: a two-hour window with 16,916 events. The first version took 5 minutes 15 seconds. Most of that time wasn’t spent querying. It went on repeated connectivity checks, identity calls made one account at a time, an IAM call that was always going to be denied, and grouping user agents after the fact. With those removed, the same report took about 33 seconds.

What it found

On that busier key, the report showed normal traffic from containers and Firehose. Next to it were eight IPs on mobile networks in two countries, all with Android user agents, calling S3 PutObject directly. One of those calls succeeded. That pattern means the key has shipped inside a mobile app. The key went straight to rotation, and the triage logic now treats that pattern as its own “rotate immediately” rule.

What changed afterwards

What I’d do differently

What I took from it

  • Check where the data actually lives before trusting an empty result.
  • A query can report success and still have skipped most of the data.
  • Time the slow parts before optimizing. Here, the overhead around the query cost more than the query itself.