Lesson 1 of 6 AWS IAM

Choosing IAM Users, Groups and Roles

This lesson explains each kind of IAM identity, which credentials it uses and when it is the right choice, since every request on AWS is made by an IAM principal.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish the root user, IAM users, groups and roles.
  • Explain how trust policies and permissions policies define a role.
  • Protect the root user and remaining IAM users.
  • Replace long-term access keys with roles.

Identities

IAM provides several types of identity, which differ in the credentials they use. The root user is created with the account and has full access that no IAM policy can restrict. It should be used only for the few tasks that require it, such as changing the account's support plan, and protected with MFA and no access keys.

An IAM user has long-term credentials: a console password, access keys, or both. Because long-term keys can leak and do not expire, IAM users are rarely the right answer today; employees sign in through IAM Identity Center instead. An IAM group is a collection of users that share permissions. A group has no credentials of its own, cannot contain other groups, and cannot be named as a principal in a policy.

An IAM role has no permanent credentials. A trusted principal, such as an AWS service, a user in another account or a federated user, assumes the role and receives temporary credentials that expire automatically. Roles are how EC2 instances, Lambda functions and ECS tasks call AWS services, through instance profiles, execution roles and task roles. A service-linked role is a role that a service creates and manages for itself, such as the role Auto Scaling uses to launch instances; its permissions can be viewed but not changed. The following table summarises the identity types.

IdentityCredentialsUse for
Root userFull, unrestrictable accessOnly the tasks that require it; protect with MFA, no access keys
IAM userLong-term password and/or access keysRarely needed today; workforce users belong in IAM Identity Center
IAM groupNone; attaches permissions to its usersManaging many users; groups cannot be nested and cannot be a principal
IAM roleTemporary, when a trusted principal assumes itAWS services (instance profiles, Lambda execution roles, ECS task roles), other accounts, federated users
Service-linked roleManaged by a serviceServices such as Auto Scaling or ELB; you can view but not change its permissions

A role for the workload is always better than shared keys, whether the caller is an instance, a container or a function.

Sort into groups

Which identity?

Exam skills 1.1.1 · 1.1.2

Decide which IAM identity each statement describes.

Log in to try this activity Interactive activities are free with an account.

How roles work

An IAM role is an identity without long-term credentials. It is defined by two kinds of policy. Its trust policy states who may assume it, such as an AWS service, another account or a federated user. Its permissions policies state what it may do once assumed.

Assuming a role returns temporary credentials from AWS Security Token Service (AWS STS) that expire automatically, so there is nothing long-lived that can leak. Workloads receive roles in different ways: an EC2 instance receives a role through an instance profile, while Lambda functions, ECS tasks and other services assume their roles themselves. To give a role to a service, for example when creating a Lambda function, a user needs the iam:PassRole permission for that role, which prevents users from escalating their privileges by handing a more powerful role to a service.

The following diagram shows how a workload obtains and uses a role's credentials.

How a workload uses an IAM role. The workload, such as an EC2 instance with an instance profile or a Lambda function, asks AWS STS to assume the role. STS checks the role's trust policy and returns temporary credentials that expire automatically. Calls made with them are allowed or denied by the role's permissions policies.
The trust policy is checked when the role is assumed; the permissions policies are checked on every call made with the credentials.
True or false

How roles work

Exam skills 1.1.2 · 1.1.3

Check how IAM roles are defined and handed to services.

Log in to try this activity Interactive activities are free with an account.

Protecting the root user and remaining IAM users

The root user and any remaining IAM users hold long-term credentials, so they need particular protection. The root user can do anything in the account and cannot be restricted by IAM policies. It should have MFA enabled, have no access keys, and be used only for the few tasks that require it. In AWS Organizations, centralised root access management can remove member accounts' root credentials altogether.

Remaining IAM users should have a password policy and MFA, and their access keys should be rotated or, better, removed in favour of roles. The credential report lists every user's password and access key ages, which shows stale credentials, and last accessed information shows which services each identity actually uses, which identifies permissions that can be removed.

Worked example

Removing long-term keys from an application

An application on EC2 reads from S3 using an IAM user's access keys stored in a configuration file. An audit flags the keys as a risk: they never expire and would work from anywhere if leaked.

StepAction
1Create a role trusted by ec2.amazonaws.com with a policy allowing s3:GetObject on the one bucket
2Attach the role to the instances through an instance profile
3Remove the keys from the configuration file; the SDK now uses the role's temporary credentials automatically
4Deactivate, then delete, the IAM user's keys

The application code does not change, because the SDK's credential chain finds the instance role. Credentials now rotate automatically every few hours and exist only on the instance. The same principle applies to every compute service: Lambda execution roles, ECS task roles, EKS Pod Identity.

Check yourself

What should be done with the root user's access keys?

Show answer

Delete them, or never create them, enable MFA on the root user and use it only for the few tasks that require it.

Exam Tips

Remember for the exam

  • Applications on EC2, Lambda and ECS should use roles; never store access keys on instances or in code.
  • Manage permissions for many users through groups.
  • A group cannot be a principal in a policy and cannot contain other groups.
  • To find unused access keys and old passwords, use the IAM credential report.
  • Protect the root user with MFA and give it no access keys.