How it works
An IAM user's long-term access key is a pair: an access key ID and a secret access key. The caller signs each API request with the secret, and AWS needs nothing else. There is no session, no device binding and no MFA step, so whoever copies the pair can use it from any network. It is the cloud form of a hardcoded credential and of a long-lived secret.
The keys end up in predictable places:
- The shared credentials file. The AWS CLI and SDKs read
~/.aws/credentialson Linux and macOS and%USERPROFILE%\.aws\credentialson Windows. Each profile holdsaws_access_key_idandaws_secret_access_keyin clear text, plusaws_session_tokenfor temporary credentials. Any process running as the user, and anyone with a copy of the home directory or a backup of it, can read the file. - The config file and its chains.
~/.aws/configcan define a profile with arole_arnand asource_profile. The source profile's long-term key is the root of that chain, so one file can open several roles and accounts. - Environment variables.
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEYandAWS_SESSION_TOKENin shell profiles,.envfiles, container definitions and process environments. - Source code and its history. A key committed once stays in the repository history after the file is fixed. See leaked secrets in GitHub repositories.
- CI static secrets. A pipeline that deploys to AWS with a stored key gets the value in clear text at run time. A workflow reference only names the secret; the job's environment holds the value, and every step of the job can read it.
Once the attacker has the key, two STS operations turn it into temporary credentials without any role: GetSessionToken returns a session that is still the same IAM user, and GetFederationToken returns a federated user session. Both carry their own expiration and keep working after the key is deactivated, which makes key status and session validity separate questions. That step is covered in STS session token persistence.
Prerequisites
- An IAM user with an active long-term access key. Roles and IAM Identity Center users have no long-term key to steal.
- Read access to a location that holds the key: the user's profile on a workstation or server, a file share or backup, a repository, a container image or build artifact, or a CI job that receives it.
- For the CI variant: the ability to influence what a job with access to the secret executes, such as push access to a branch that the workflow runs on.
- Nothing in AWS. The first request the attacker sends is already authenticated.
Attack steps
For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.
1. Collect keys from a host
# Profiles and where the CLI would take credentials from
aws configure list-profiles
aws configure list --profile default
# The files themselves
cat ~/.aws/credentials
cat ~/.aws/config
# Keys exported into the environment or left in dotfiles
env | grep '^AWS_'
grep -rIl 'aws_secret_access_key\|AWS_SECRET_ACCESS_KEY' ~ 2>/dev/null
# Windows
Get-Content "$env:USERPROFILE\.aws\credentials"
Get-Content "$env:USERPROFILE\.aws\config"
Get-ChildItem Env:AWS_*
A credentials file looks like this:
[default]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
[deploy]
role_arn = arn:aws:iam::111122223333:role/deploy
source_profile = default
The AWS CLI can also resolve a profile and print whatever credentials it ends up with, including ones it obtains through a role or a credential process:
aws configure export-credentials --profile deploy --format env
2. Search repositories, directories and images
# TruffleHog verifies candidate keys against AWS and reports only live ones
trufflehog filesystem /path/to/checkout /home/alice
trufflehog git https://github.com/example-org/example-repo --results=verified
trufflehog github --org=example-org --results=verified
# Gitleaks: a directory, or a git repository including its history
gitleaks dir -v /path/to/checkout
gitleaks git -v
3. Take a key from a CI job
A workflow that deploys with stored keys exposes them to every step of the job:
jobs:
deploy:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-west-1
steps:
- uses: actions/checkout@v4
- run: ./scripts/deploy.sh
An attacker who can change deploy.sh, the workflow file on a branch the workflow runs for, or a dependency the script installs, runs code in that job and reads the two variables from the environment. The secret store masks exact secret values in the job log, but the job can send the values to a host the attacker controls or write them in an encoded form.
4. Identify and validate the key
# The account that owns a key ID (works without the secret)
aws sts get-access-key-info --access-key-id AKIAIOSFODNN7EXAMPLE
# Use the stolen pair
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
aws sts get-caller-identity
A successful GetCallerIdentity proves the key is active and names the user. It says nothing about permissions; that is the job of IAM enumeration.
5. Extend the access
# A session as the same IAM user, valid for up to 36 hours and independent of the key's later status
aws sts get-session-token --duration-seconds 129600
# Follow the role chains the config file described
aws sts assume-role --role-arn arn:aws:iam::111122223333:role/deploy --role-session-name build
Impact
The attacker is the IAM user for every API the user's policies allow, from any location, for as long as the key stays active. IAM users with access keys are typically automation and deployment identities, and those tend to be broadly permitted: creating and changing infrastructure, reading buckets and secrets, passing roles to services.
A key in a config file with source_profile chains reaches further, into each role the profile can assume, often in other accounts. With IAM write permissions the attacker makes the access permanent, for example by creating another access key. Common monetization of leaked keys is fast and automated: compute for mining, email sending, and paid AI model invocation.
Rotation is the only real end. The key does not expire on its own, and sessions minted from it outlive its deactivation until their own expiry.
OPSEC and artifacts
- Reading a file leaves nothing in AWS. Copying
~/.aws/credentials, an environment variable or a CI secret is a local event. CloudTrail starts recording at the first signed request. Evidence of the theft itself can only come from the host or the CI system: file access auditing, EDR telemetry, workflow run logs and repository audit logs. - Validate quietly.
sts get-access-key-inforeveals the account without using the stolen secret.GetCallerIdentitycannot be denied and is called by every SDK, so it is a low-noise first call, but it is still a CloudTrail event with the attacker'ssourceIPAddressanduserAgent. - Match the owner's pattern. Requests from the same cloud provider range, Region and user agent family that the key normally uses stand out less. A deployment key that has only ever called CloudFormation from CI runners and now lists IAM users from a residential address stands out a lot.
- Convert to a session early. Calling
GetSessionTokenorGetFederationTokengives credentials that survive the key's deactivation. The price is a distinctive STS event by an IAM user that rarely has a reason to call it: see GetFederationToken. - What CloudTrail keeps for every use:
userIdentity.typeIAMUser,userIdentity.accessKeyId,userIdentity.userName,sourceIPAddress,userAgent,awsRegion, the operation and anyerrorCode. The key ID identifies the credential, not the person holding it. - Public exposure is noticed by others first. A key pushed to a public repository is found by automated scanners. When AWS learns that a key is exposed, it attaches a quarantine policy to the user.
- IAM keeps one more trace: the key's last-used time, service and Region (
GetAccessKeyLastUsed), which a later legitimate use overwrites.
Detection
- A key used from somewhere new. Baseline each long-term key by source network, user agent and the set of services it calls. A change in all three at once is the strongest signal available from CloudTrail.
- Discovery right after a new source appears.
GetCallerIdentityfollowed by IAM list calls or by many denied calls: the IAM enumeration rules and the permission brute force rules. - Session minting by an IAM user.
GetSessionTokenandGetFederationTokenfrom a user that never called them, and a console sign-in built from API credentials with GetSigninToken: the federation token and console session rules. - AWS's own exposure signal. The quarantine policy attached to a user means the key is public: the access key quarantine rules.
- GuardDuty. IAM findings such as
UnauthorizedAccess:IAMUser/MaliciousIPCallerandUnauthorizedAccess:IAMUser/TorIPCallerreport API calls from known bad addresses. - New keys. An attacker who can, adds a key of their own: CreateAccessKey.
-- Where has each long-term access key been used from? (Athena, CloudTrail table)
SELECT useridentity.accesskeyid AS access_key,
useridentity.username AS iam_user,
sourceipaddress,
useragent,
count(DISTINCT eventsource) AS services,
min(eventtime) AS first_seen,
max(eventtime) AS last_seen,
count(*) AS requests
FROM cloudtrail_logs
WHERE useridentity.type = 'IAMUser'
AND useridentity.accesskeyid LIKE 'AKIA%'
AND eventtime >= '2026-11-22T00:00:00Z'
GROUP BY 1, 2, 3, 4
ORDER BY access_key, first_seen
A key that appears with a second address and a different user agent partway through the window is the row to open. Interpret sourceIPAddress and userAgent with proxies, NAT gateways and AWS services calling on the user's behalf in mind. CloudTrail cannot see the file read or the CI job that leaked the key, so pair it with host and pipeline evidence.
Mitigation
- Stop issuing long-term keys to people. Give users temporary credentials through IAM Identity Center; the IAM Identity Center guide covers the setup. A credentials file that only holds short sessions is a much smaller prize. The glossary page on IAM users versus roles explains the difference.
- Stop storing keys in CI. Use OIDC workload identity federation so the pipeline exchanges a signed job token for a role session, with trust conditions on repository, branch or environment. The conditions need care of their own: see GitHub Actions OIDC trust abuse.
- Inventory the keys that remain. Use the credential report to find every active key, its age and last use. Give each an owner, remove unused ones, and apply secret rotation to the rest.
- Limit where a key works. Add conditions such as
aws:SourceIporaws:SourceVpcto the user's policies, and require MFA for sensitive actions withaws:MultiFactorAuthPresent, so a copied key is useless from the attacker's network. - Scope the permissions. A deployment key should be able to deploy one thing. Remove IAM write, broad read and
sts:AssumeRoleon unrelated roles. - Scan before others do. Run secret scanning on repositories, images and artifacts, block pushes that contain keys, and keep
~/.awsout of backups and shared home directories. - Respond completely. Deactivate the key, then search for
GetSessionToken,GetFederationTokenandAssumeRoleevents from it and cut those sessions off by policy, review what the user did during the window, and check for keys, users and roles the attacker created.
Detection rules for this attack
Log events to collect
FAQ
Does MFA protect a stolen AWS access key?
Not by default. An access key signs API requests directly, with no MFA step, even when the IAM user has an MFA device for the console. MFA only matters for API calls if a policy requires it with a condition such as aws:MultiFactorAuthPresent, in which case the caller must first get a session with an MFA code. Few policies do that, so a leaked key usually works as it is.
How can you tell a long-term key from temporary credentials?
By the prefix and the parts. A long-term IAM user key ID conventionally starts with AKIA and comes with a secret access key only. Temporary credentials from STS start with ASIA and need a session token as a third value. In CloudTrail a long-term key appears with userIdentity.type IAMUser and its accessKeyId. Treat the prefix as a hint: it identifies the credential type, not the holder.
Does deactivating a leaked key end the attacker's access?
It stops new requests signed with that key. It does not end sessions the attacker already created from it: AWS states that temporary security credentials stay valid until they expire and cannot be revoked. Search CloudTrail for GetSessionToken and GetFederationToken by that user, and deny those sessions by changing the user's permissions, for example with a deny on tokens issued before the response time.
Why are access keys in CI secrets a risk if the secret store is encrypted?
Because the job gets the value in clear text at run time. Anyone who can change what the job runs, by editing the workflow on a branch, changing a build script or compromising a dependency or a runner, can read the key and send it out. The key is also long-lived, so one leak gives lasting access. Workload identity federation removes the stored key.
References
- Unsecured Credentials: Credentials In Files, T1552.001 (MITRE ATT&CK)
- Valid Accounts: Cloud Accounts, T1078.004 (MITRE ATT&CK)
- Location of the shared config and credentials files (AWS SDKs and Tools Reference Guide)
- IAM identifiers: unique ID prefixes (IAM User Guide)
- GetSessionToken (AWS STS API Reference)
- Permissions for temporary security credentials (IAM User Guide)
- CloudTrail userIdentity element (AWS CloudTrail User Guide)
- Configuring OpenID Connect in Amazon Web Services (GitHub Docs)
- TruffleHog (Truffle Security)
Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.