Responding to Compromised Credentials
This lesson provides a playbook for leaked access keys and stolen role credentials, the most common starting point of AWS incidents. The response depends on the credential type, because long-term keys can be disabled directly while temporary credentials stay valid until they expire.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the response to a compromised long-term IAM access key.
- Revoke the sessions of compromised temporary role credentials.
- Describe the response to instance credentials used from outside AWS.
- Describe containment for federated and other kinds of credentials.
Long-term IAM user access keys
A compromised long-term access key requires an immediate and structured response. The response consists of the following steps.
-
Deactivate the key
Deactivate it (
update-access-key --status Inactive) rather than deleting it, so it remains identifiable in the investigation and can be re-enabled if you got the wrong one. -
Trace its use
Search CloudTrail for the access key ID to see every action taken, from which IP addresses and in which Regions.
-
Look for persistence
New IAM users, keys, roles or trust policy changes, Lambda functions, EC2 instances in unused Regions, changed resource policies.
-
Revoke derived credentials
The attacker may have used the key to obtain temporary credentials (
GetSessionToken,AssumeRole), which outlive the key; revoke those too. -
Replace the credential
Use a role-based alternative where possible.
When AWS finds an account's key exposed publicly, for example on GitHub, it attaches the AWSCompromisedKeyQuarantine managed policy to the user, which denies high-risk actions, and notifies the account through AWS Health. The policy is a stopgap, not a fix.
The following diagram compares the options for containing stolen instance-role credentials when the instance must be kept running.

A leaked access key
Temporary role credentials
You cannot invalidate one role session. Instead, revoke active sessions on the role (in the IAM console, or by adding the equivalent inline policy yourself). It denies every action when aws:TokenIssueTime is earlier than the revocation time, so all existing sessions stop working and new sessions are unaffected.
{"Effect": "Deny", "Action": "*", "Resource": "*",
"Condition": {"DateLessThan": {"aws:TokenIssueTime": "2026-10-09T14:05:00Z"}}}Credentials stolen from an EC2 instance
GuardDuty reports InstanceCredentialExfiltration findings when an instance role's credentials are used from outside AWS or from another account. Respond by revoking the role's active sessions, isolating the instance for forensics, and finding how the credentials were taken (SSRF to IMDSv1 is a common cause). Prevent recurrence with IMDSv2 and with conditions on aws:EC2InstanceSourceVPC and aws:EC2InstanceSourcePrivateIPv4, which make instance credentials work only from the instance's own VPC and address.
Stolen instance credentials
Federated and other credentials
Credentials other than IAM access keys each need their own containment. For an IAM Identity Center user, disable the user at the identity source so they cannot sign in again, and revoke their active sessions. Sessions already issued for permission set roles stay valid until they expire, so revoke sessions on those roles as well. For the root user, reset the password, replace the MFA device and delete any root access keys; with centralised root access, remove the member account's root credentials altogether.
For a secret in Secrets Manager, rotate it immediately, then search CloudTrail for GetSecretValue calls to find who read it. For Cognito user tokens, global sign-out revokes the user's refresh tokens. Access tokens already issued remain valid until they expire, which is why short token lifetimes matter. The following table summarises the containment steps.
| Credential | Containment |
|---|---|
| IAM Identity Center user | Disable the user at the identity source and revoke their active sessions; also revoke sessions on the permission set roles they used |
| Root user | Reset the password, rotate MFA, delete any root access keys; with centralised root access, remove root credentials altogether |
| Secrets in Secrets Manager | Rotate immediately; check GetSecretValue calls in CloudTrail for who read it |
| Cognito user tokens | Global sign-out to revoke refresh tokens; access tokens expire within their validity period |
Containing other credentials
Help during an incident
Several AWS services and practices support the response to an incident. The following list describes them.
- AWS Security Incident Response triages GuardDuty and Security Hub findings, manages cases and gives access to the AWS Customer Incident Response Team.
- Detective shows the activity of a key or role session across time and IP addresses.
- Prepare runbooks in advance, as Systems Manager Automation documents or Step Functions workflows, and rehearse them.
GuardDuty reports that credentials of the role attached to a web server's instance profile are being used from an IP address outside AWS. The security team must stop the attacker immediately without terminating the instance, which is needed for forensics.
Deleting the role would break the application and destroy evidence; detaching the instance profile does not invalidate credentials already stolen. The fastest containment is to revoke the role's active sessions with an aws:TokenIssueTime deny, then isolate the instance with a restrictive security group and snapshot its volumes.
Why deactivate a compromised access key rather than delete it?
Show answer
It stays identifiable in the investigation and can be re-enabled if the wrong key was chosen.
Exam Tips
Remember for the exam
- Deactivate, do not delete, compromised access keys during an investigation.
- Revoke role sessions with a deny on aws:TokenIssueTime; individual sessions cannot be invalidated.
- Look for persistence: new users, keys, roles, functions and resources in unused Regions.
- AWSCompromisedKeyQuarantine is attached automatically when AWS finds exposed keys.
- Bind instance credentials to their VPC with aws:EC2InstanceSourceVPC and aws:EC2InstanceSourcePrivateIPv4.