Sub topic 3
Passwords, MFA, and access keys
This chapter assumes you know what an IAM user is, can read JSON, and have the AWS CLI configured with an administrator profile. It covers the credentials an IAM user can hold, how to protect them, and how to rotate and audit them. Roles and temporary credentials come in later chapters.
The credentials a user can hold
An IAM user proves its identity with credentials. Each type serves a different way of signing in:
| Credential | Used for | Limit per user |
|---|---|---|
| Console password | Signing in to the AWS Management Console | 1 |
| MFA device | A second factor for console sign-in, and for API calls that require it | Up to 8 |
| Access key | Signing programmatic requests from the CLI, SDKs, or direct API calls | 2 |
Users can also hold SSH public keys for AWS CodeCommit and service-specific credentials, which this chapter does not cover. A user does not need every credential type. A person who only uses the console needs no access key. A script that calls the API needs no password. Create only what the identity needs, because each unused credential is something an attacker could steal.
Console passwords and the password policy
A console password is created with a login profile. Setting --password-reset-required forces the user to choose a new password at first sign-in.
aws iam create-login-profile \
--user-name dev-user \
--password 'Temp-Passw0rd-ChangeMe!' \
--password-reset-requiredThe password rules are set once for the whole account, not per user. The account password policy applies to every IAM user's console password. It does not apply to the root user.
aws iam update-account-password-policy \
--minimum-password-length 14 \
--require-symbols \
--require-numbers \
--require-uppercase-characters \
--require-lowercase-characters \
--max-password-age 90 \
--password-reuse-prevention 24 \
--allow-users-to-change-passwordA few details are easy to miss:
- The minimum length can be set between 6 and 128 characters. Longer is better than complex.
--max-password-agemakes passwords expire. Add--hard-expiryif an expired password should lock the user out until an administrator resets it. Without it, the user can set a new password at sign-in.- Changing the policy does not rewrite existing passwords. Existing users meet the new rules only when they next change their password.
- A user can change their own password only if the policy allows it and the user has the
iam:ChangePasswordpermission.
Multi-factor authentication
Multi-factor authentication (MFA) requires a second proof of identity in addition to the password. A stolen or guessed password alone is then not enough to sign in.
IAM supports these MFA types:
- Passkeys and security keys use FIDO2. They are phishing-resistant because the device checks which site is asking for the sign-in.
- Virtual authenticator apps generate a time-based one-time password (TOTP), a six-digit code that changes every 30 seconds.
- Hardware TOTP tokens work like authenticator apps but run on a dedicated device.
You can register more than one device, up to 8 per user. A second device is useful as a backup if the first is lost.
MFA does not secure access keys by itself. An access key signs requests without any code. To tie programmatic access to MFA, the user first calls AWS STS get-session-token with the MFA serial number and a current code. STS then returns temporary credentials that carry the MFA context.
aws sts get-session-token \
--serial-number arn:aws:iam::111122223333:mfa/dev-user \
--token-code 123456The response holds an AccessKeyId, SecretAccessKey, and SessionToken. You export them as shown in the STS chapter. Requests signed with them satisfy the aws:MultiFactorAuthPresent condition key.
Enforcing MFA with a policy
Registering MFA is a user choice unless a policy forces it. The usual approach is an explicit deny on sensitive actions when MFA is absent. The Deny policy with BoolIfExists from the conditions chapter does this. BoolIfExists matters here because requests signed with plain long-term access keys carry no aws:MultiFactorAuthPresent value at all. A plain Bool test would not match those requests, so the deny would never apply to them. BoolIfExists also matches when the key is missing.
Access keys
An access key is a pair of values. The access key ID identifies the key and is not secret. The secret access key signs requests and must be kept private. IAM shows the secret only once, at creation. If you lose it, you cannot recover it. You can only create a new key.
aws iam create-access-key --user-name dev-userThe response contains AccessKeyId, SecretAccessKey, Status, and CreateDate. Long-term key IDs start with AKIA. Temporary credentials from STS start with ASIA, so the prefix tells you which kind you are looking at in logs.
Each user can have at most two access keys. The limit exists to make rotation possible without downtime.
Why access keys are a risk
A long-term key never expires on its own and works from anywhere on the internet. It tends to leak through source control, container images, shared screenshots, and laptop config files. Whoever holds the key holds every permission of that user. Prefer roles whenever the workload runs on AWS or can federate, and keep access keys for the cases where nothing else works. The next chapters cover roles in detail.
Key states and rotation
An access key is either Active or Inactive. Setting a key to Inactive is reversible, which makes it a safe way to test whether anything still depends on it before you delete it.
Rotation follows five steps:
- Create a second key for the user.
- Update every application and machine to use the new key.
- Check
get-access-key-last-usedon the old key until it shows no recent use. - Set the old key to Inactive and watch for failures.
- Delete the old key once nothing breaks.
aws iam list-access-keys --user-name dev-user
aws iam get-access-key-last-used \
--access-key-id AKIAIOSFODNN7EXAMPLE
aws iam update-access-key \
--user-name dev-user \
--access-key-id AKIAIOSFODNN7EXAMPLE \
--status Inactive
aws iam delete-access-key \
--user-name dev-user \
--access-key-id AKIAIOSFODNN7EXAMPLEAuditing credentials
The credential report is a CSV file listing every user in the account, with the state of each password, MFA device, and access key. It shows the last use and last rotation of each. Generate it, then download it:
aws iam generate-credential-report
aws iam get-credential-report \
--query Content --output text | base64 --decode > credential-report.csvGeneration can take a moment, and AWS reuses a report less than four hours old. Look for users with a password but mfa_active set to false, access keys unused for months, and keys older than your rotation policy allows.
Common mistakes
- Giving a human user both a password and an access key when only the console is needed.
- Relying on the password policy's expiry alone and never enabling MFA.
- Leaving a second access key Active "just in case" after rotation.
- Using
Boolinstead ofBoolIfExistsin an MFA deny, which silently exempts access-key callers. - Storing keys in code. Use the CLI's credentials file or, better, a role.
Exercise
A user has two access keys. You want to rotate one without breaking the application that uses it. What is the safest order of steps, and why can't you simply create a third key?
Show answer
Create the replacement key first, which is only possible because a user can hold a maximum of two, so you must have deleted or not yet used the second slot. Update the application to use the new key, confirm with get-access-key-last-used that the old key is no longer in use, set the old key to Inactive and watch for failures, then delete it. A third key cannot be created because IAM allows at most two access keys per user. If both slots are full, you must delete one key before creating a new one.
Exercise
Why does an MFA-enforcing Deny policy use BoolIfExists with aws:MultiFactorAuthPresent set to "false" instead of Bool?
Show answer
Requests signed with long-term access keys carry no aws:MultiFactorAuthPresent value. With Bool, a missing key means the condition does not match, so the Deny would not apply to those requests. BoolIfExists treats a missing key as a match, so the Deny covers requests made without MFA, including those signed with plain access keys.