Lesson 6 of 6 Incident Response and Forensics

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.

  1. 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.

  2. Trace its use

    Search CloudTrail for the access key ID to see every action taken, from which IP addresses and in which Regions.

  3. Look for persistence

    New IAM users, keys, roles or trust policy changes, Lambda functions, EC2 instances in unused Regions, changed resource policies.

  4. Revoke derived credentials

    The attacker may have used the key to obtain temporary credentials (GetSessionToken, AssumeRole), which outlive the key; revoke those too.

  5. 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.

Choosing the containment for stolen instance-role credentials when the instance must be kept. Deleting the role breaks the application and destroys evidence; detaching the instance profile leaves stolen credentials valid. Revoking active sessions with an aws:TokenIssueTime deny is fastest, followed by isolation and snapshots.
The instance must be kept for forensics.
Put in order

A leaked access key

Exam skills 2.2.4 · 2.2.2

Arrange the response to a leaked long-term access key.

Log in to try this activity Interactive activities are free with an account.

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.

Scenario questions

Stolen instance credentials

Exam skills 2.2.4 · 3.2.2

Respond to and prevent theft of instance role credentials.

Log in to try this activity Interactive activities are free with an account.

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.

CredentialContainment
IAM Identity Center userDisable the user at the identity source and revoke their active sessions; also revoke sessions on the permission set roles they used
Root userReset the password, rotate MFA, delete any root access keys; with centralised root access, remove root credentials altogether
Secrets in Secrets ManagerRotate immediately; check GetSecretValue calls in CloudTrail for who read it
Cognito user tokensGlobal sign-out to revoke refresh tokens; access tokens expire within their validity period
Match the pairs

Containing other credentials

Exam skills 2.2.4 · 4.1.3

Match each compromised credential with its containment.

Log in to try this activity Interactive activities are free with an account.

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.
Worked example

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.

Check yourself

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.