Sub topic 2
IAM users and the root user
This chapter covers the two kinds of long-lived identities in an AWS account: the root user and IAM users. It assumes you can use the AWS Management Console, read JSON, and run basic AWS CLI commands. You should also know the difference between authentication (proving who you are) and authorization (deciding what you may do), which the previous chapter introduced.
Two kinds of identity at the account level
Every AWS account starts with one identity: the root user. You create it when you sign up, using an email address and password. Everything else in the account is built from it.
An IAM user is an identity you create inside the account. It represents one person or one application and has its own name and credentials. IAM users are free to create. A new account allows up to 5,000 of them by default.
| Property | Root user | IAM user |
|---|---|---|
| Created by | AWS sign-up | An administrator, or you |
| Sign-in | Email address and password | Account ID or alias, user name, and password |
| Permissions | Full, and cannot be limited by IAM policies | None until you grant them |
| Count per account | One | Many |
| Intended use | A short list of account-level tasks | Named people, or workloads that cannot use roles |
The root user
The root user has complete access to every resource and billing detail in the account. Two facts matter in practice.
- You cannot restrict the root user with identity-based policies. It is not subject to them.
- Some tasks can only be done as root. Examples include changing the account name, email address, or root password, closing the account, and changing or canceling your AWS Support plan. Some of these tasks have also been made available to other identities over time, so check the current list in the AWS documentation.
Because root is so powerful, treat it as a break-glass identity.
- Set a strong, unique password and enable multi-factor authentication (MFA) on it. MFA adds a second proof of identity, such as a code from a device.
- Do not create access keys for the root user. If keys already exist and nothing needs them, delete them.
- Create an administrative identity for daily work and stop signing in as root.
- Keep the root email address on a mailbox that a team controls, not one person's inbox, so recovery does not depend on one individual.
IAM users
An IAM user has a friendly name such as dev-user, a unique ID, and an Amazon Resource Name (ARN). An ARN is the unique identifier AWS uses for a resource. For a user it looks like this:
arn:aws:iam::111122223333:user/dev-userThe parts are the partition (aws), the service (iam), the account ID (111122223333), and the resource (user/dev-user). The region field is empty because IAM is a global service.
A user can optionally have a path, such as /engineering/, which gives the ARN user/engineering/dev-user. Paths let you organize users and write policies that match a whole group of ARNs. The path is part of the ARN but not part of the sign-in name.
A new user has no permissions
A user you have just created can authenticate, but it is not authorized to do anything. AWS denies by default (an implicit deny, covered in the evaluation chapter). Permissions arrive only when you attach policies to the user or add it to a group that has them.
Creating a user with the CLI
The following command creates a user. The --permissions-boundary option sets a ceiling on what the user can ever be granted. You will study boundaries later, so for now, notice that the option exists at creation time.
aws iam create-user \
--user-name dev-user \
--permissions-boundary arn:aws:iam::111122223333:policy/DevBoundaryWithout a boundary, the command is simply aws iam create-user --user-name dev-user. A successful call returns a User object with UserName, UserId, Arn, and CreateDate.
To check the result and see which identity you are acting as, use these commands:
aws iam get-user --user-name dev-user
aws sts get-caller-identityget-caller-identity is the quickest way to confirm whether your CLI is using a user, a role, or root. Its Arn field shows the answer.
Choosing between a user and a role
IAM users carry long-lived credentials. A password or access key stays valid until someone changes or deletes it, so a leaked key keeps working until you notice. Roles, covered in a later chapter, issue temporary credentials instead.
AWS recommends that people reach the account through a role-based sign-in, such as federation with an identity provider or AWS IAM Identity Center, and that workloads use roles. An IAM user is still reasonable in a few situations:
- A small or personal account where you have not set up federation.
- A third-party tool or on-premises system that cannot assume a role or use federation.
- Emergency access accounts you keep as a fallback if your identity provider is unavailable.
If you use an IAM user for a person, give it its own identity. Do not share one user among several people, because CloudTrail logs would show the same name for different humans and you could not tell who did what.
How a user signs in
IAM users can authenticate in two ways, and each user can have either or both.
- Console access: a password, used at the account-specific sign-in URL or through the account ID or alias.
- Programmatic access: an access key (an access key ID and a secret access key) used by the CLI, SDKs, and API calls.
An account alias is a friendly name for the sign-in URL, such as my-company, in place of the 12-digit account ID. It must be unique across AWS. Set one with:
aws iam create-account-alias --account-alias my-companyThe sign-in URL then becomes https://my-company.signin.aws.amazon.com/console. The next chapter covers passwords, MFA, and access keys in detail.
Lifecycle and common mistakes
Users need maintenance. Without it, unused identities become the weakest point in an account.
- Orphaned users. People leave and their users remain. Review the IAM credential report, a CSV listing every user and the age and last use of each credential, and remove users that are no longer needed.
- Attaching policies directly to many users. This becomes hard to audit. Use groups, which a later chapter explains.
- Shared users. These destroy accountability, as described above.
- Using root for convenience. Root actions appear in logs, but nothing limits what root can do. One mistaken command can affect the whole account.
- Confusing user names with IDs. If you delete a user and recreate one with the same name, it is a different identity with a new unique ID. Policies that reference the old user by ARN may appear to apply, but the new user does not inherit the old user's history or credentials.
Deleting a user requires removing its dependencies first: access keys, the console password, MFA devices, signing certificates, SSH keys, group memberships, and attached or inline policies. The console does this for you. The CLI requires each step explicitly.
Summary of working rules
- Use root only for tasks that require it, and protect it with MFA and no access keys.
- Create IAM users only when roles or federation do not fit.
- Give every user a unique identity, and grant permissions through policies, preferably via groups.
- Audit users regularly with the credential report.
Exercise
You find an access key for the root user in your account, and no application uses it. A colleague suggests attaching a restrictive policy to root to limit the risk. What should you do instead, and why?
Show answer
Delete the root access key. IAM identity-based policies cannot limit the root user, so a restrictive policy would not reduce the risk. Also enable MFA on root and do daily work with an administrative identity that is not root.
Exercise
You run aws iam create-user --user-name alex and then try aws s3 ls using alex's new access key. What happens, and why?
Show answer
The call is denied with an access denied error. A new user has no policies, so every request ends in an implicit deny until you attach a policy to the user or add it to a group that has one.