An access key gets pushed to a public repository, pasted into a support ticket or left on a stolen laptop. The usual reactions make things worse. Someone rewrites the Git history and tells nobody, so the key still works. Or someone deletes the key and stops there, while the attacker's sessions keep running and the user they created stays behind.
Treat a credential that left your control as used. Removing it from the repository does not change that. Work through the three steps below in order.
What you do depends on the kind of credential.
| Credential | How to cut it off |
|---|---|
IAM user access key (starts with AKIA) | Deactivate it with the command below. Do not delete it yet. You need the key ID for the next step |
Role session (starts with ASIA) | In the IAM console, open the role and choose Revoke active sessions. This does not work for roles that IAM Identity Center created, so use the next row for those |
| Person who signs in with SSO | Follow Revoke user access: block their user ID with a deny SCP, remove them from every Entra ID group that grants AWS access, then disable them. Disabling alone lets a live portal session keep assuming roles |
| Workload that uses Entra ID federation | Remove its app role assignment in Entra ID. Entra ID caches managed identity tokens for about 24 hours, so also add a deny for that identity's sub to the AWS role's trust policy. Then revoke the role's sessions. Other workloads on the role fail until their cached credentials expire, up to the role's maximum session duration, or until you restart them |
| IAM Roles Anywhere certificate | Revoke it in your CA, check that Roles Anywhere has the new revocation list, then revoke the role's sessions |
| SCIM token | Delete it in IAM Identity Center, create a new one and update Entra ID provisioning |
| Management account root user | Change the password, remove any MFA device you do not recognise and delete any root access keys. See Do you lock down the AWS root user? |
aws iam update-access-key \--user-name svc-mail \--access-key-id AKIAIOSFODNN7EXAMPLE \--status Inactive
Warning: Deactivating a key does not end the role sessions that someone already started with it. AWS says temporary credentials are valid until they expire. Revoke the sessions on every role the key could assume, and attach a deny policy on aws:TokenIssueTime to the IAM user as well. Revoking only blocks sessions issued before that moment, so close the way in first.
Figure: Deactivating the key is only half of cutting it off
When AWS finds one of your keys in public, it attaches the AWSCompromisedKeyQuarantineV3 policy to the user and opens a support case. Leave the policy in place and follow the steps in the case.
Search your organization trail or Microsoft Sentinel for the key ID. Both cover every account and Region.
If you have neither, use CloudTrail event history:
aws cloudtrail lookup-events \--region us-east-1 \--lookup-attributes AttributeKey=AccessKeyId,AttributeValue=AKIAIOSFODNN7EXAMPLE
Event history has limits that matter here:
AssumeRole event holds a new temporary key ID that starts with ASIA. Search for that ID tooLook first for anything that lets the attacker back in after you roll the key: CreateUser, CreateAccessKey, CreateLoginProfile, CreateRole, AttachUserPolicy and UpdateAssumeRolePolicy. Then look for spend, such as RunInstances or Bedrock calls in Regions you do not use. Delete what the attacker created.
Issue the new key through your deployment pipeline. If you followed Do you use service control policies as guardrails in AWS?, only the deployment role can create one. Then delete the old key.
Better, do not issue a new key at all. Move the workload to a role with Entra ID federation, IAM Roles Anywhere or OIDC in your pipeline, so there is no key to expose next time.