Sub topic 1
Why long-term access keys are a liability
This chapter explains what is wrong with IAM user access keys. It also sets up the rest of the tutorial, which replaces them with temporary credentials from IAM Identity Center.
Prerequisites
You should be comfortable with the following:
- Basic command-line use.
- AWS CLI version 2, installed and on your path.
- AWS accounts and IAM roles, including what it means for a role to be assumed.
Later chapters also assume an IAM Identity Center instance with a user and at least one assigned permission set. You do not need one for this chapter.
What a long-term access key is
An IAM user can have an access key, which is a pair of values: an access key ID and a secret access key. The CLI signs every request with this pair. The pair does not expire. It stays valid until someone deactivates or deletes it.
The usual setup is to run aws configure and paste the pair in. The CLI stores it in plain text:
[default]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYThe file is ~/.aws/credentials. The values above are the placeholder keys from the AWS documentation.
Why this is a liability
Each of the following problems follows from the key never expiring.
- A leak stays useful. A key committed to a Git repository, pasted into a chat, or captured in a log works for whoever finds it. It keeps working until you notice and revoke it. Automated scanners find exposed keys on public repositories within minutes.
- Copies spread. The key lives on laptops, in scripts, in CI variables, and in old backups. You cannot easily list every place it was copied.
- Rotation is manual and often skipped. Rotating means creating a second key, updating every consumer, and then deleting the first. Teams postpone this, so keys end up years old.
- Attribution is weak. If several people or jobs share one key, CloudTrail shows the same identity for all of them. You cannot tell who did what.
- Offboarding is easy to miss. When someone leaves, any key they copied survives unless you find and delete it.
You can check how old your keys are. This command lists the keys for the current IAM user:
aws iam list-access-keys
aws iam get-access-key-last-used --access-key-id AKIAIOSFODNN7EXAMPLEThe first command shows each key's creation date and status. The second shows when and where it was last used. Keys that are old or unused are the ones most likely to have gone unnoticed.
The temporary credential alternative
Temporary credentials come from AWS STS, the Security Token Service. They consist of an access key ID, a secret, and a session token. They expire after a fixed time, usually between one and twelve hours. A leaked temporary credential stops working on its own, so the damage window is limited.
IAM Identity Center is how this tutorial gets such credentials. You sign in through a browser. The CLI then obtains short-lived role credentials and refreshes them while your session lasts. No secret is stored permanently in a file you wrote.
When keys are still around
Some systems still use long-term keys, such as old tools or third-party services that cannot assume roles. Treat each one as a risk to track. Give it minimal permissions, rotate it on a schedule, and replace it when you can. The final chapters cover alternatives for automation and CI.
Exercise
A teammate says, "Our access key is in a private repository, so it is safe." Give two reasons a long-term key is still a liability in that situation.
Show answer
Any person or tool with read access to the repository gets a key that never expires, and cloned copies and backups keep it alive after the repository is cleaned up. Also, the key is shared across people or jobs, so CloudTrail cannot say who used it, and it stays valid until someone remembers to rotate or delete it. A temporary credential would expire on its own.