Join our Newsletter — 33% off our NHI Course
Home› Guides› AWS Access Keys Security Guide: IAM User Keys,…
Guide Secrets Management

AWS Access Keys Security Guide: IAM User Keys, Detection, Rotation and Replacement

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 13 min read
On this page

An IAM user access key is a long-lived bearer credential that works from anywhere on the internet until someone deactivates it, so it needs the same care as a password. The key pair (an access key ID beginning AKIA and a secret access key) is easy to detect with scanners, easy to test, and often attached to far more permission than the script that uses it needs. This guide covers how AWS access keys work and how to tell them apart from temporary credentials, who can create them, where they leak, how to detect misuse with CloudTrail, GuardDuty and AWS Health, a safe rotation and replacement process, and the controls that keep new keys from appearing. It is for cloud security engineers, platform teams and incident responders. IAM policy design is covered in the AWS IAM Policies and Roles Guide; the step-by-step incident response is in the Cloud Access Key Leak Playbook.

This is an independent guide from NHI Mgmt Group, based on AWS's public documentation as of November 2026. It is not sponsored or reviewed by AWS. Product features change, so confirm settings against AWS's current documentation.

Key takeaways

  • AKIA means long-lived, ASIA means temporary. The prefix tells responders what they are dealing with: AKIA keys belong to IAM users or the root user and persist until deactivated; ASIA keys come from STS and need a session token.
  • AWS's own best practice is not to create them. Humans should use IAM Identity Center federation and workloads should use roles, including IAM Roles Anywhere outside AWS.
  • Two keys per user enables rotation, and attackers. The second key slot exists for zero-downtime rotation, and creating a second key is also a classic persistence move.
  • AWS watches for public exposure. An AWS_RISK_CREDENTIALS_EXPOSED Health event and the AWSCompromisedKeyQuarantineV3 policy on the user are signals to act on within minutes.
  • Deactivate first, delete later. Setting a key to Inactive stops use, is reversible and keeps the key ID for investigation.

How identity and access work for AWS access keys

An access key is a pair: the access key ID (for example AKIAIOSFODNN7EXAMPLE), which identifies the key, and the secret access key, which signs requests with Signature Version 4. AWS shows the secret only at creation; if it is lost, the key must be replaced. Each IAM user can hold at most two access keys. A request signed with the key carries the permissions of the IAM user, filtered by any permissions boundary, service control policy and resource policy.

CredentialPrefixLifetimeCan be deactivatedTypical source
IAM user access keyAKIAUntil deactivated or deletedYes, Active or InactiveCreated by the user or an administrator
Root user access keyAKIAUntil deletedYesShould not exist (Security Hub IAM.4, Critical)
STS temporary credentialsASIAMinutes to hours, with a session tokenNo; revoke sessions by issue timeAssumeRole, Identity Center, instance profiles, Lambda, ECS
STS service bearer tokenABIAShort-livedNoService-specific bearer tokens

Scanners rely on these prefixes. The gitleaks aws-access-token rule matches A3T, AKIA, ASIA, ABIA and ACCA followed by 16 base32 characters, with an entropy threshold, and has separate rules for Bedrock API keys. Because AKIA keys are so recognisable, attackers find them quickly in public code, container images and paste sites; see the Git Secret Scanning Guide.

Alternatives AWS recommends

Use caseReplace the access key with
Engineers using the CLI or SDKIAM Identity Center federation (aws sso login), short-lived role sessions
Code on EC2, Lambda, ECS or EKSInstance profiles, execution roles, task roles, EKS Pod Identity or IRSA
CI/CD pipelinesOIDC federation with AssumeRoleWithWebIdentity; see the GitHub and GitHub Actions Security Guide
On-premises servers and other cloudsIAM Roles Anywhere with X.509 certificates; see the AWS IAM Roles Anywhere Security Guide
Third-party SaaS reading your accountCross-account role with an external ID
Tools that only accept a key (AWS lists examples such as some WordPress plugins and third-party clients)A dedicated IAM user with tightly scoped permissions, source conditions and scheduled rotation

Admin roles and privileged access

Whoever holds iam:CreateAccessKey on a user can mint a new permanent credential for it, so the action is a privilege escalation path whenever the target user is more powerful than the caller. Treat it, along with iam:UpdateAccessKey and iam:CreateUser, as administrative.

  • No root access keys: AWS states not to use root credentials to create access keys, and Security Hub control IAM.4 flags any root access key as Critical. Delete existing ones and protect the root user with phishing-resistant MFA.
  • Block key creation at the organisation level: a service control policy that denies iam:CreateAccessKey (with an exception for a break-glass or approved automation role) stops new keys appearing in member accounts. See the AWS Organizations and SCPs Guide.
  • Self-service only for own keys: where IAM users must exist, scope self-management policies with ${aws:username} so users cannot create keys for others.
  • No administrators with keys: an AdministratorAccess user with an access key is the worst case in every leak; move administrators to Identity Center permission sets.
  • Least privilege for remaining keys: use IAM Access Analyzer policy generation from CloudTrail activity to cut a key's policy down to the actions it really calls.

Integrations, API tokens and service accounts

Most surviving access keys belong to non-human identities: legacy scripts, backup agents, on-premises applications, monitoring tools, SaaS integrations and developer laptops. Each one should have an owner, a purpose and a planned replacement.

Where keys leak

  • Source code and history: keys committed to Git remain in history after the file is deleted (ATT&CK T1552.001 Credentials In Files, T1593.003 Code Repositories).
  • The shared credentials file: AWS notes that ~/.aws/credentials stores keys in plaintext, making developer laptops and infostealer logs a rich source.
  • Environment files and images: .env files on web servers and secrets baked into container layers.
  • CI variables and logs: keys printed in build output or stored as unprotected pipeline variables.
  • Instance metadata: role credentials taken from IMDS (T1552.005) are ASIA keys, but the response pattern is similar; GuardDuty's InstanceCredentialExfiltration findings cover them.

Making unavoidable keys safer

  • Source conditions: add aws:SourceIp or aws:SourceVpce conditions so a stolen key fails outside the expected network.
  • Store keys in a secrets manager: fetch them at runtime or use credential_process, never in code or config committed to a repository. See the Cloud Secrets Managers Guide.
  • One key, one consumer: separate IAM users per integration so a key can be rotated or revoked without breaking others, and tag users with owner and system.
  • Push protection: block AKIA patterns at commit and push time; see the Push Protection Guide.

Logging and detection

Every API call made with a key is recorded in CloudTrail with userIdentity.accessKeyId. Attackers usually start by testing the key with sts:GetCallerIdentity, which no IAM policy can deny, then enumerate.

SignalSourceMeaning
AWS_RISK_CREDENTIALS_EXPOSEDAWS Health event (service RISK), routable via EventBridge source aws.healthAWS found the key in a public location; the event includes the exposed URL
AWSCompromisedKeyQuarantineV3 attached to a userIAM, CloudTrail AttachUserPolicy by AWSAWS has restricted the exposed key's user; do not remove the policy, follow the support case
CredentialAccess:IAMUser/CompromisedCredentialsGuardDutyAmazon threat intelligence flags the key as compromised and it is being used
Persistence:IAMUser/AnomalousBehaviorGuardDutyAnomalous CreateAccessKey or similar persistence API (T1098.001)
Recon:IAMUser/TorIPCaller, UnauthorizedAccess:IAMUser/MaliciousIPCallerGuardDutyKey used from Tor or known malicious infrastructure
PenTest:IAMUser/KaliLinuxGuardDutyCalls from an attack distribution; unexpected outside authorised tests
Stealth:IAMUser/CloudTrailLoggingDisabledGuardDutyTrail deleted or changed, often after key compromise
CreateAccessKey, CreateUser, CreateLoginProfileCloudTrailNew credentials or identities (T1136, T1098.001)
RunInstances in unused regions, Bedrock InvokeModel spikesCloudTrail, billing alarmsResource hijacking (T1496.001 Compute Hijacking, T1496.004 Cloud Service Hijacking)
  • Track key age and use: the IAM credential report shows each key's active state, last rotation and last use; aws iam get-access-key-last-used gives the last service and region. The report refreshes at most every four hours.
  • Alert on Health events automatically: AWS publishes a sample (notify-and-remediate-exposed-access-key) that routes the Health event to notifications and can disable the key; decide in advance whether automatic deactivation is acceptable for production keys.
  • Watch S3 for destructive patterns: watch for long-term keys used with GetObject and PutObject to re-encrypt objects with customer-provided keys (SSE-C) that AWS never stores.

First hour after a suspected leak

  1. Identify the credential: read the key ID from the alert or finding. AKIA means an IAM user or root key; ASIA means a temporary session that cannot be deactivated.
  2. Confirm with the owner: GuardDuty guidance is to ask the owner whether they made the call, at that time, from that IP. If nobody can confirm it, treat the key as compromised.
  3. Contain: set an AKIA key to Inactive; for ASIA sessions, revoke by token issue time on the role.
  4. Scope: search CloudTrail by access key ID across all regions for CreateUser, CreateAccessKey, CreateLoginProfile, AttachUserPolicy, RunInstances and changes to CloudTrail or GuardDuty.
  5. Remove persistence: delete attacker-created users, keys, roles and functions before issuing a replacement key, ideally replacing the key with a role.

The full sequence, including communications and evidence handling, is in the Cloud Access Key Leak Playbook and the Leaked Credential Response Playbook.

Hardening baseline

ControlSetting or checkEvidence
No root keysDelete root access keysSecurity Hub IAM.4 (iam-root-access-key-check)
RotationRotate IAM user keys within 90 daysSecurity Hub IAM.3 (access-keys-rotated)
Unused credentialsRemove credentials unused for 45 daysSecurity Hub IAM.22 and IAM.8 (iam-user-unused-credentials-check)
New key preventionSCP denying iam:CreateAccessKey except approved rolesOrganizations policy and CloudTrail denials
Federation for peopleIAM Identity Center for console and CLICount of IAM users with console passwords or keys
DetectionGuardDuty enabled in all accounts and regions; Health events routed to the SOCDelegated administrator coverage
LoggingOrganisation CloudTrail trail with log file validation, delivered to a separate log archive accountTrail status and bucket policy
ScanningSecret scanning and push protection on all repositories, images and CI logsScanner coverage report

Rotation that does not break production

  1. Create the second key: aws iam create-access-key while the first is still active, and store the secret in the secrets manager.
  2. Update every consumer: deploy the new key to all applications that use the user.
  3. Check the old key: wait several days, then run aws iam get-access-key-last-used on the first key.
  4. Deactivate, do not delete: aws iam update-access-key to set the first key to Inactive.
  5. Confirm and roll back if needed: if anything fails, set the old key back to Active, fix the consumer and repeat.
  6. Delete: remove the old key with aws iam delete-access-key once nothing has broken for an agreed period. See the Secrets Rotation Runbook Template.

Replacing keys programme-wide

  1. Inventory: pull credential reports from every account and list keys by age, last use and attached permissions.
  2. Kill the dead: deactivate keys unused for 90 days, wait, then delete.
  3. Move humans: migrate engineers to Identity Center and remove their personal keys.
  4. Move workloads: convert CI to OIDC, AWS workloads to roles and on-premises servers to Roles Anywhere.
  5. Lock the door: apply the SCP once the remaining keys are documented exceptions with owners.

Small and large organisations: a single-account start-up can delete most keys in a week by moving to Identity Center and OIDC, and should skip building custom rotation tooling. A large organisation with hundreds of accounts needs the credential report pipeline, an exceptions register with expiry dates, automated Health event handling and the SCP rolled out by organisational unit with an audit-only period watching CloudTrail for CreateAccessKey calls.

Common misconfigurations

  • Keys on administrator users: a single leak hands over the account.
  • Deleting the file instead of the key: a key removed from a repository is still valid and still in Git history until it is deactivated.
  • Removing the quarantine policy: teams detach AWSCompromisedKeyQuarantineV3 to restore a broken integration and leave the exposed key active.
  • Rotation without consumer tracking: keys are not rotated because nobody knows what uses them, so they reach years of age.
  • Treating ASIA keys like AKIA keys: temporary credentials cannot be deactivated; responders must revoke sessions with an aws:TokenIssueTime deny condition or the role's "Revoke active sessions" action and fix the source of the theft.
  • GuardDuty only in the main region: attackers launch resources in regions nobody monitors.

Framework mapping

Control areaNIST SP 800-53 Rev. 5NIST CSF 2.0CIS Controls v8.1ISO/IEC 27001:2022 Annex A
Key inventory and ownershipIA-4, AC-2ID.AM-02, PR.AA-015A.5.16
Rotation, removal of unused keysIA-5, IA-5(1), AC-2(3)PR.AA-015, 6A.5.17, A.5.18
No embedded keys, scanningIA-5(7)PR.DS-013, 16A.8.4, A.8.28
Least privilege and SCP guardrailsAC-6, AC-6(5)PR.AA-056A.8.2
CloudTrail, GuardDuty and Health monitoringAU-2, AU-6, SI-4DE.CM-03, DE.CM-098, 13A.8.15, A.8.16

Detection and measurement

  • Active IAM user keys: total across the organisation, trending down each quarter.
  • Key age: percentage of active keys older than 90 days (Security Hub IAM.3 pass rate).
  • Dormant keys: active keys unused for 45 or more days (IAM.22).
  • Privileged keys: keys on users with administrative or IAM write permissions (target: zero).
  • Exposure response time: minutes from an AWS_RISK_CREDENTIALS_EXPOSED event or scanner alert to key deactivation.

Practitioner checklist

  • Delete all root user access keys and confirm Security Hub IAM.4 passes in every account.
  • Generate credential reports organisation-wide and record an owner for every active key.
  • Deactivate keys unused for 45 days, then delete them after a safe waiting period.
  • Move engineers to IAM Identity Center and CI pipelines to OIDC federation.
  • Replace on-premises and multi-cloud keys with IAM Roles Anywhere where possible.
  • Scope remaining keys with Access Analyzer generated policies and source IP or VPC endpoint conditions.
  • Apply an SCP denying iam:CreateAccessKey with documented exceptions.
  • Enable GuardDuty everywhere and route AWS_RISK_CREDENTIALS_EXPOSED Health events to the SOC.
  • Turn on secret scanning and push protection for AKIA, ASIA and Bedrock key patterns.
  • Rehearse the deactivate, investigate, rotate sequence with the leak playbook.

Standards and references

Related NHI Mgmt Group resources: AWS IAM Policies and Roles Guide · Cloud Access Key Leak Playbook · AWS IAM Roles Anywhere Security Guide · Top 10 AWS IAM Mistakes · OWASP NHI Top 10 NHI7 Long-Lived Secrets Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.