Credential Compromise occurs when AWS credentials (access keys, secret keys, session tokens, console passwords) are exposed to unauthorized parties. This is the most common and dangerous AWS security incident, and the speed at which it unfolds surprises most teams: keys pushed to a public repository are routinely discovered and abused by automated scanners within minutes, not days.
The textbook incident starts with a developer committing a .env file or a hardcoded key pair to a public GitHub repository. Scanners operated by attackers watch the public commit stream continuously, so the key is tested and abused within minutes. The typical first actions are reconnaissance calls, then resource creation for cryptomining (EC2 spot fleets, SageMaker jobs) or, increasingly, Bedrock model invocations billed to the victim. AWS also scans public repositories: when it detects an exposed key it opens a support case and attaches the managed policy AWSCompromisedKeyQuarantineV3 to the affected user. That policy denies a long list of high-abuse actions (running EC2 instances, creating IAM users and keys, invoking Bedrock models, deleting S3 objects, and more), but it is a damage limiter, not a fix. The recurring mistake is treating the quarantine policy or the key deactivation as the end of the incident. Attackers know they have a short window, so the first thing a competent one does is create persistence: a new IAM user, a second access key on an existing user, or a role with a trust policy pointing at their own account. If you rotate the leaked key but skip the CloudTrail review, you have locked the front door while the attacker holds a copy of the back door key.
First, kill the key, then pull its history. Deactivate rather than delete so the key ID stays visible in your investigation:
aws iam update-access-key --user-name ci-user --access-key-id AKIAIOSFODNN7EXAMPLE --status Inactive
Then query CloudTrail for everything that key did:
aws cloudtrail lookup-events --lookup-attributes AttributeKey=AccessKeyId,AttributeValue=AKIAIOSFODNN7EXAMPLE --start-time 2026-07-01T00:00:00Z
The lookup-events command covers the last 90 days of management events in the Region you query, returns up to 50 events per page, and is rate limited to two requests per second. Pay particular attention to iam:CreateUser, iam:CreateAccessKey, iam:CreateRole, iam:UpdateAssumeRolePolicy, and sts:AssumeRole events: those are the persistence and pivot moves. For investigations older than 90 days you need a CloudTrail trail delivering to S3, queried with Athena.
Most compromises are preventable with unglamorous hygiene: prefer IAM roles and temporary credentials over long-lived access keys, enforce IMDSv2 on EC2 so SSRF cannot reach instance credentials, run secret scanning in CI and as a pre-commit hook, require MFA on console access, and alert on GuardDuty findings that indicate credential misuse, including instance credentials being used from outside AWS.
Can I revoke a leaked session token?
Not directly. STS session tokens remain valid until they expire. The mitigation is attaching a deny policy to the role with an aws:TokenIssueTime condition, which invalidates every session issued before the timestamp you set, then letting legitimate workloads re-assume the role.
Is rotating the exposed key enough to end the incident?
No. Rotation stops that one credential. You still have to review CloudTrail for persistence mechanisms (new users, keys, roles, modified trust policies) and remove them, otherwise the attacker walks back in with credentials you never knew existed.
How far back can I investigate API activity?
The CloudTrail LookupEvents API covers 90 days per Region. Anything older requires a trail that was already delivering events to S3 or CloudWatch Logs, which is one of the strongest arguments for configuring an organization trail before you ever need it.
A long-term credential pair (access key ID + secret access key) used to authenticate programmatic requests to AWS. Should be replaced with IAM roles wherever possible.
Short-lived AWS credentials (access key, secret key, session token) issued by STS that expire automatically, eliminating the risk of permanent credential exposure.
A security mechanism requiring two or more forms of verification (password + device/token) before granting access to an AWS account or resource.
The structured process of detecting, containing, eradicating, and recovering from a security incident, following frameworks like NIST SP 800-61.
A step-by-step documented procedure for handling specific security incidents - from detection through containment, eradication, recovery, and lessons learned.
Toc Consulting: AWS Security & Cloud Architecture
Our team helps engineering teams secure and architect AWS the right way: assessment in week one, a prioritized action plan in week two.