Sub topic 7
Why the root user should have no access keys
This chapter assumes you have created an AWS account, enabled MFA on the root user, and can run the AWS CLI. You should also know the difference between the root user and IAM identities.
What root access keys are
An access key is a pair of values: an access key ID and a secret access key. The AWS CLI, SDKs, and scripts use the pair to sign API requests. The root user can create these keys, and a key signs requests with the full authority of the root user.
MFA does not protect an access key. The console asks for an MFA code when you sign in, but a script that holds a key signs requests directly. Anyone who obtains the pair can act as root with no second factor.
Why the risk is higher than for other keys
Access keys leak in ordinary ways:
- A key is committed to a public Git repository.
- A key is pasted into a ticket, chat, or screenshot.
- A key is left in a shell history, a backup, or a container image.
- A laptop that stores
~/.aws/credentialsis lost or compromised.
When an IAM user's key leaks, the damage is limited by that user's permissions, and you can narrow those permissions further. A root key cannot be limited. It can close the account, change the root email, and remove your other administrators. Automated scanners find leaked keys within minutes, and attackers often use them to launch large fleets of compute instances for cryptocurrency mining. You pay for that usage.
The rule
Do not create access keys for the root user. If your account already has them, replace them and delete them. The steps are:
- Sign in as an administrative IAM identity, not as root.
- Find every script or tool that uses the root key. Searching your repositories and CI settings for the key ID is a good start.
- Move each one to an IAM role or to temporary credentials with only the permissions it needs.
- Sign in as root, open Security credentials, and mark the root key inactive first.
- Wait a few days to see whether anything fails. Then delete the key.
Making the key inactive before deleting it gives you a way back. Reactivating an inactive key takes seconds, while a deleted key is gone for good.
Check for root keys with the CLI
The account summary reports whether root keys exist. A value of 1 means at least one key is present, and 0 means none.
aws iam get-account-summary \
--query 'SummaryMap.{RootMFA:AccountMFAEnabled,RootAccessKeys:AccountAccessKeysPresent}'Run this as your admin identity. Healthy output looks like this:
{
"RootMFA": 1,
"RootAccessKeys": 0
}Also confirm that your CLI is not using root credentials:
aws sts get-caller-identityIf the Arn ends in :root, you are calling the API as the root user. Stop, and switch to an IAM identity or a role.
Common errors
- Keeping a key "just in case." An unused key is still a way into your account. Delete it.
- Deleting before migrating. A script that fails at 2 a.m. is a sign you skipped the inactive step.
- Confusing the two checks.
AccountMFAEnabledof1is good.AccountAccessKeysPresentof1is bad. - Reading the output as proof of safety. The summary covers root only. It does not tell you whether your IAM users have old keys. The credential report covers those.
Exercise
Your aws iam get-account-summary query returns "RootMFA": 1 and "RootAccessKeys": 1. What do you do, and in what order?
Show answer
MFA is on, but a root access key exists, and MFA does not protect it. Sign in as an admin IAM identity and find what uses the key. Move those workloads to IAM roles or temporary credentials. Then mark the root key inactive, wait to see whether anything breaks, and delete it. Run the query again and confirm that RootAccessKeys is 0.
Exercise
Why can a leaked root access key do more damage than a leaked key for an IAM user?
Show answer
An IAM user's key is limited by that user's attached permissions. A root key has unrestricted access to the whole account, including billing, account closure, and the root email address, and you cannot restrict it with IAM policies.