Sub topic 7
Why the root user should have no access keys
This chapter assumes you have already created an AWS account, signed in as the root user, and turned on multi-factor authentication (MFA) for it. You should be comfortable running commands in a terminal and reading JSON. You do not need to know IAM policy syntax yet.
What a root access key is
An access key is a pair of long-term credentials: an access key ID (it starts with AKIA) and a secret access key. The AWS CLI, SDKs, and other tools use the pair to sign API requests without a password or MFA prompt.
The root user can create its own access keys, up to two at a time. Those keys carry the full authority of the root user. This is a problem because of three properties:
- No permission limits. An IAM policy cannot restrict the root user. Whoever holds the key can do anything the account owner can do through the API. That includes closing the account and reading billing data.
- No MFA at use time. MFA protects the console sign-in. A request signed with an access key skips that prompt. Your root MFA device does nothing if an attacker has a copy of the key.
- Long life. The key stays valid until you delete or deactivate it. It can sit in a shell history, a
.envfile, a backup, or a public repository for years.
The result is that one leaked string can give an attacker complete control of the account. AWS guidance is to have no root access keys at all.
How root keys leak
Root keys usually leak through ordinary mistakes, not sophisticated attacks:
- Committing
~/.aws/credentialsor a.envfile to a Git repository, including a private one that later becomes public. - Pasting a command with the key into a chat, ticket, or forum post.
- Baking the key into a container image or an AMI.
- Leaving the key on a laptop that is later lost, or on a shared build server.
- Installing a malicious package that scans the machine for credential files.
Automated scanners watch public code hosts for the AKIA pattern. Misuse often begins within minutes of a push. Typical abuse is launching many large instances for cryptocurrency mining in every Region, which creates a very large bill quickly.
Check whether root keys exist
You can check for root keys from the CLI. Run this with credentials for an IAM identity that is allowed to call iam:GetAccountSummary:
aws iam get-account-summary \
--query 'SummaryMap.{RootMFA:AccountMFAEnabled,RootAccessKeys:AccountAccessKeysPresent}'The output is JSON with two numbers:
{
"RootMFA": 1,
"RootAccessKeys": 0
}RootMFA should be 1. RootAccessKeys should be 0. A value of 1 for RootAccessKeys means at least one root access key exists, and you should remove it.
You can also confirm which identity your CLI is using:
aws sts get-caller-identityLook at the Arn field. If it ends in :root, your CLI is using root credentials. For example, arn:aws:iam::111122223333:root is a root identity, while arn:aws:iam::111122223333:user/alice or an assumed-role/... ARN is not. If you see :root, stop and fix it before doing anything else.
In the console, open the account menu in the top right, choose Security credentials, and look at the Access keys section. For a new account, it should list no keys.
Remove an existing root key
Do this from the console while signed in as the root user. The AWS CLI is not the right tool, because deleting the root key with the key itself is awkward and the root console session is the safer place to work.
- Sign in as the root user and open Security credentials.
- In Access keys, find the key. Note its last-used information first.
- Choose Actions, then Deactivate. A deactivated key is rejected by AWS but can be turned back on.
- Wait and watch for failures in anything that might still use the key.
- When nothing breaks, choose Delete.
Deactivating first is the safe order. If a script you forgot about was using the key, it fails loudly and you can find it. Deleting is permanent: a deleted key cannot be recovered, and you cannot re-create the same key ID.
What to use instead
Almost every task that people reach for a root key to do has a better path.
| Need | Instead of a root access key |
|---|---|
| Run CLI commands as the account owner | Sign in with an administrative identity, such as an IAM Identity Center user or a limited IAM user |
| Run code on EC2, Lambda, or ECS | Attach an IAM role to the resource. The service supplies temporary credentials |
| Run CI/CD pipelines | Use an OIDC trust to a role, so the pipeline gets temporary credentials |
| Run local development | Use `aws configure sso` or `aws login` to get short-lived credentials |
| Billing and cost access | Grant IAM identities billing permissions (covered in a later chapter) |
| Account recovery or root-only settings | Sign in to the console as root with the password and MFA (see the next chapter) |
The common thread is temporary credentials. They are issued by the AWS Security Token Service (STS), expire after minutes or hours, and are tied to an IAM role or user that has a limited set of permissions. A leaked temporary credential is far less dangerous than a leaked root key. It stops working on its own, and it can only do what its role allows.
Prevent root keys from coming back
Removing the key once is not enough if someone can create a new one later. Add controls that make root key creation fail or become visible.
Use a service control policy if you use Organizations
If your account is a member of an AWS Organization, a service control policy (SCP) can deny all root user API actions in member accounts. A common pattern is to deny every action when the principal is the root user:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyRootUser",
"Effect": "Deny",
"Action": "*",
"Resource": "*",
"Condition": {
"StringLike": {
"aws:PrincipalArn": "arn:aws:iam::*:root"
}
}
}
]
}SCPs apply only to member accounts, not to the management account. They also do not stop root console sign-in for the few tasks that need it. Organizations is covered at the end of this tutorial.
Use a credential report for auditing
The IAM credential report lists every user, including the root user, with the state of its keys and MFA. Generate it and decode it:
aws iam generate-credential-report
aws iam get-credential-report --query Content --output text | base64 --decodeFind the row whose first column is <root_account>. Check these columns:
mfa_activeshould betrue.access_key_1_activeandaccess_key_2_activeshould both befalse.
If generate-credential-report returns State: STARTED, wait a few seconds and run the second command again. A report can be regenerated at most about once every four hours, and an older report may be returned until then.
Alert on root activity
Even with no keys, you want to know when anyone signs in as root. An Amazon EventBridge rule on CloudTrail events can match userIdentity.type equal to Root and send a notification through Amazon SNS. A root sign-in that you did not make is a strong signal of compromise. AWS Security Hub and AWS Config also have managed checks for root access keys and root MFA that you can enable.
Edge cases and common errors
- A tool demands a root key. Some old tutorials and third-party tools ask for root keys. Treat that as a warning about the tool. Create a dedicated IAM role or user with only the permissions it needs.
- You already deleted the only admin identity. If you have no other identity, sign in to the console as root with the password and MFA, and create an administrative identity. You do not need a key to do this.
AccountAccessKeysPresentis1but you see no keys. Check that you are looking at the right account. Runaws sts get-caller-identityto confirm the account ID.- Access Denied on
get-account-summary. The call needsiam:GetAccountSummary. An identity with a narrow policy may lack it. This is expected. Use an administrative identity instead of a root key. - Inactive does not mean safe to ignore. A deactivated key is not usable, but it still appears in the list. Delete it once you are sure nothing depends on it.
- Two keys. The limit is two keys per user. Check both slots in the console or in the credential report.
Summary of the habit
Treat the root user like a break-glass credential. It has a strong password, MFA, and no access keys. You sign in with it only for the small set of tasks that need it. Everything else runs as a separate identity with temporary credentials and limited permissions. After this chapter, your account should report RootAccessKeys as 0, and get-caller-identity should never show :root.
Exercise
You run aws iam get-account-summary with a query for AccountMFAEnabled and AccountAccessKeysPresent, and the output is {"RootMFA": 1, "RootAccessKeys": 1}. Name the problem, the safest order of steps to fix it, and one reason an IAM policy cannot protect you here.
Show answer
The problem is that a root access key exists even though MFA is on. Sign in to the console as root, open Security credentials, note the key's last-used information, deactivate the key, wait to see whether anything fails, and then delete it. If the key was ever exposed, also review CloudTrail and contact AWS Support. An IAM policy cannot protect you because IAM policies do not restrict the root user, and requests signed with the key do not trigger an MFA prompt.
Exercise
A teammate wants to give a deployment script "the account keys" so it can create S3 buckets from a CI pipeline. What do you offer instead, and what makes it safer?
Show answer
Create an IAM role with only the S3 permissions the script needs, and let the pipeline assume it through an OIDC trust (or attach the role to the compute resource that runs the script). The pipeline receives temporary STS credentials that expire on their own and can do only what the role permits, so a leak has a short life and a small impact.