Sub topic 1
Why long-term access keys are a liability
This chapter explains what goes wrong with long-term IAM user access keys. It also shows what temporary credentials change. The rest of the tutorial then builds the replacement with IAM Identity Center.
Prerequisites
This chapter assumes you have:
- Basic command-line use (running commands, setting environment variables).
- AWS CLI version 2 installed.
- Familiarity with AWS accounts and IAM roles.
You do not need an IAM Identity Center instance yet. Later chapters need one, with a user and at least one assigned permission set.
What a long-term access key is
An IAM user can have an access key. It is a pair of values: an access key ID that starts with AKIA, and a secret access key. The CLI uses the pair to sign every API request. The pair does not expire. It works until someone deactivates or deletes it.
The classic setup is aws configure, which writes the pair to ~/.aws/credentials:
[default]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYThe values above are the placeholder keys from the AWS documentation. Never paste a real key into a document, chat, or repository.
A long-term key has one property that causes most of the trouble: possession is enough. AWS cannot tell whether the person using the key is you, a teammate, or an attacker. Whoever holds the two strings has your permissions.
Where long-term keys leak
Keys leak through ordinary work, not only through attacks.
- Source control. A key committed to a Git repository stays in the history even after you delete the file. Public repositories are scanned continuously, and attackers use leaked keys within minutes.
- Plain-text files.
~/.aws/credentialsis unencrypted. Backups, synced home folders, shared build machines, and malware that reads dotfiles all expose it. - Logs and shell history. A key passed with
export AWS_SECRET_ACCESS_KEY=...or on a command line can end up in shell history, CI logs, or crash reports. - Copies. Teams copy keys into chat messages, wikis, and
.envfiles. Each copy is another place the key can leak, and you cannot list them all. - Screen sharing and tickets. A key pasted into a support ticket or shown during a demo is exposed to everyone who sees it.
Why the damage lasts
Leaking a key is bad. The properties of the key make it worse.
- No expiry. A leaked key stays valid until someone notices and revokes it. Keys leaked years ago still work if nobody rotated them.
- Rotation is manual. AWS recommends rotating keys, but rotation needs a person or a script to create a new key, update every place that uses it, and delete the old one. In practice, keys go unrotated for years.
- Weak attribution. CloudTrail records that the key
AKIA...made a call. It cannot show whether the real owner or a thief made it. - Broad permissions persist. Teams often attach wide policies to a user "to make things work" and never narrow them. The key carries that breadth with it.
- Slow detection. Nothing tells you a key is being misused unless you have set up monitoring for it.
A useful check is to list your keys and look at their age. This command reports each key's status and creation date for the calling user:
aws iam list-access-keys --user-name aliceIf the output shows a key with "Status": "Active" and a CreateDate from several years ago, you are looking at the problem. That key has had years of chances to leak.
You can also generate a credential report for the whole account. It lists the age and last use of every user's keys:
aws iam generate-credential-report
aws iam get-credential-report --query Content --output text | base64 --decodeRun generate-credential-report first. The report can take a moment to build, so repeat get-credential-report if it says the report is not ready.
What temporary credentials change
Temporary credentials come from the AWS Security Token Service (STS). They have three parts: an access key ID (starting with ASIA), a secret access key, and a session token. Every request must include all three. They also carry an expiration time, after which AWS rejects them.
The differences from long-term keys are structural:
| Property | Long-term IAM user key | Temporary credentials |
|---|---|---|
| Key ID prefix | `AKIA` | `ASIA` |
| Expiry | None | Minutes to hours |
| Extra secret | None | Session token |
| Rotation | Manual | Automatic, by issuing new ones |
| Stored on disk | Permanently, in plain text | Cached briefly, then discarded |
| Tied to | An IAM user | An assumed role session |
| Value after a leak | Valid until revoked | Valid only until expiry |
The last row matters most. If a temporary credential leaks, the attacker has a short window. If the credential is already expired, it is worthless. You limit the blast radius by design, not by detecting the leak in time.
The shape of the fix
The fix does not mean "make keys rotate faster". It changes where trust comes from. Instead of a stored secret that proves who you are, you sign in as a person and AWS issues short-lived credentials for a role. IAM Identity Center is the service that does this for people who use many accounts.
The diagram below contrasts the two models.
In the right-hand flow, nothing permanent sits on disk. When credentials expire, you sign in again and get new ones. Later chapters cover each step.
Edge cases and honest limits
Temporary credentials reduce risk. They do not remove it.
- A stolen live credential still works. Until it expires, an attacker with the full set (key ID, secret, and token) has your permissions. Short lifetimes shrink the window but do not close it.
- Cached credentials are still files. The CLI caches them on disk, so a compromised machine can still expose them during their lifetime.
- Some tools cannot use them. Older SDKs, third-party tools, and some CI systems expect static keys. A later chapter shows how to export temporary credentials for these tools, and another explains when to use a different approach for automation.
- IAM users are not always avoidable. A few services and integrations still need a long-term key, for example some systems outside AWS that cannot assume a role. If you must keep one, restrict its permissions, rotate it, and monitor it.
- Deleting a key is safe only after checking use. Before removing an old key, check when it was last used:
aws iam get-access-key-last-used --access-key-id AKIAIOSFODNN7EXAMPLEThe response shows the last use date, the service, and the Region. If a key was used yesterday, something still depends on it, and deleting it will break that system.
Common mistakes
- Treating
.gitignoreas protection. It stops future commits of a file, but it does not remove a key already committed. - Rotating without finding all copies. You create a new key, but an old script still has the old one and fails, so someone re-enables the old key "temporarily".
- Deactivating versus deleting. Setting a key to inactive is reversible and a good first step. Deleting is permanent. Deactivate first, wait to see what breaks, then delete.
- Assuming a short-lived credential needs no care. Do not log it, commit it, or paste it into chat, even if it expires soon.
Summary of the argument
Long-term access keys never expire, sit in plain text, spread through copies, and give weak attribution. Temporary credentials expire on their own, tie each session to a signed-in person and a role, and limit the harm of a leak to a short window. The rest of this tutorial shows how IAM Identity Center and the AWS CLI provide that model.
Exercise
A teammate says, "Our key was in a public repo for an hour, but we deleted the file, so we are fine." Give two reasons this is wrong, and name the first action you would take.
Show answer
First, the key remains in the Git history, so anyone can still read it. Second, long-term keys do not expire, and scanners find exposed keys within minutes, so the key may already have been used. The first action is to deactivate the key (for example with aws iam update-access-key --access-key-id <ID> --status Inactive --user-name <user>), then review CloudTrail for calls made with it, then delete it once you confirm nothing depends on it.
Exercise
You find a credential that starts with ASIA in a leaked log file. How does its risk differ from a leaked AKIA key, and what two extra values must an attacker have for it to work?
Show answer
An ASIA credential is temporary, so it works only until its expiration time. After that AWS rejects it. An attacker also needs the secret access key and the session token along with the key ID. The AKIA key has no expiry and stays valid until someone revokes it.