Security & FinOps · Freelance
Automated IAM Compromise Detection and Credential Revocation
A SAM stack watches CloudTrail logs for access-denied bursts and automatically strips credentials from the offending IAM user.
// Overview
The template creates a trail delivering to S3 and CloudWatch Logs. A Lambda subscribed to AccessDenied and UnauthorizedOperation error codes decodes the log batch, extracts the principal, notifies an email-subscribed SNS topic, deletes the access key and removes the console login profile. A Contributor Insights rule groups activity by principal and event.
// The problem
Compromised credentials generate bursts of unauthorised calls; immediate automatic containment plus notification was needed.
// Flow
- CloudTrailtrail logging to S3 and CloudWatch Logs
- Log filterpattern on AccessDenied and UnauthorizedOperation
- Lambda triggersubscription event on the function
- Decodebase64 and gzip decode, parse the identity
- NotifySNS email naming the suspected principal
- Revoke keys gatedelete the access key used in the event
- Revoke consoledelete the login profile
- Observabilitylog retention and Contributor Insights rule
// Design decisions & guardrails
- Fully event-driven and serverless.
- Containment first, humans notified immediately after.
- A production version should scope the function role and the trigger threshold; both are called out as follow-ups.
// Outcome
Seconds from anomalous activity to revoked credentials and an alert.