Skip to content
Draft: this topic has not been reviewed yet. Check facts against the linked AWS documentation before relying on them.

IAM basics — users, groups, roles and policies

Cloud Practitioner · Domain 2 · Security and ComplianceTask 2.3: Identify AWS access management capabilitiesLevel 124 minDraft
Difficulty
Confidence

AWS Identity and Access Management (IAM) decides two things for every request made to your AWS account:

  1. Authentication: who is making this request? Is it really them?
  2. Authorization: what are they allowed to do?

IAM is a global service (not tied to a Region) and costs nothing extra. Getting IAM right is the customer’s part of the shared responsibility model.

The root user: the master key

When you create an AWS account, you sign up with an email address and password. That identity is the root user. It has complete access to everything in the account, and its access cannot be limited by IAM policies.

Protecting the root user:

  • Turn on multi-factor authentication (MFA). AWS enforces MFA for root users by default, but you still need to register a device.
  • Do not use it for everyday work. Create other identities for daily tasks.
  • Do not create access keys for the root user; delete any that exist.
  • Use a strong password, and keep the email account behind it secure.

Tasks that need the root user include:

  • Changing the account’s root email address, root password or root access keys (for standalone accounts).
  • Closing the AWS account (for standalone accounts).
  • Restoring permissions if the only IAM administrator accidentally removes their own.
  • Activating IAM access to the Billing console.
  • Removing a misconfigured S3 bucket policy or SQS queue policy that denies everyone.

In AWS Organizations, many of these can be managed centrally from the management account instead.

The building blocks

Group: DevelopersUser AnaUser BenUser ChenPolicy: what the group may doattached once, applies to every memberEC2 instanceIAM roleassumesS3 buckettemporary credentials,no stored keys
People get permissions through groups and policies. AWS services, like an EC2 instance, assume a role and receive temporary credentials.
Block What it is Example
User An identity for one person or application, with long-term credentials (a password and/or access keys) maria who signs in to the console
Group A collection of users. Permissions attached to a group apply to all members Developers, Finance
Role An identity with permissions that is assumed temporarily. It has no password; whoever assumes it gets temporary credentials An EC2 instance reading from S3; a user from another account
Policy A JSON document listing what is allowed or denied “Read objects in bucket example-reports”

Policies in detail

A policy says which actions are allowed or denied on which resources:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::example-reports/*"
}
]
}

This allows reading (getting) objects from one bucket, and nothing else.

Three rules decide the result:

  1. Everything is denied by default. A user with no policies can do nothing.
  2. An Allow grants access, if nothing denies it.
  3. An explicit Deny always wins over any Allow.

Types of policy you will hear about:

  • AWS managed policies: ready-made by AWS, such as ReadOnlyAccess. Easy to start with, but often broader than you need.
  • Customer managed policies: written by you, reusable across users, groups and roles. Best for fitting exactly what a job needs.
  • Inline policies: embedded directly in one user, group or role.

The principle of least privilege

Grant only the permissions needed to do a task, and no more. If a developer only needs to read logs, do not give them administrator access.

Least privilege limits the damage if credentials are stolen or a mistake is made. Start small and add permissions as needed, rather than starting with everything.

Ways to sign in and prove who you are

Method How it works Use it for
Password Console sign-in for an IAM user People, with a strong password policy (length, complexity, rotation)
MFA A code or security key in addition to the password Every privileged person, and always for root
Access keys An access key ID and secret for CLI, SDK and API calls Programs, only when roles are not possible; rotate them and never share or embed them in code
IAM roles Temporary credentials when a role is assumed AWS services, applications and cross-account access
AWS IAM Identity Center One sign-in portal for many AWS accounts and applications, using your company directory People in an organization (recommended)
Federation Trusting an outside identity provider, such as a corporate directory Letting employees use their existing company login

Cross-account roles let a user in account A assume a role in account B, instead of creating separate users in every account.

Where to keep secrets

Never put passwords or keys in code or configuration files.

  • AWS Secrets Manager stores secrets such as database passwords and API keys, and can rotate them automatically.
  • AWS Systems Manager Parameter Store stores configuration values and secrets, such as settings and connection strings.

Applications fetch the secret when they need it, using an IAM role for permission.

Putting it together: a small team

A startup has five developers, one accountant and an app running on EC2.

  1. The founder turns on MFA for the root user and stops using it.
  2. Developers sign in through IAM Identity Center, in a group with permissions for development resources.
  3. The accountant gets a billing-only permission set: least privilege.
  4. The EC2 app uses an IAM role to read from S3, so no access keys are stored on the server.
  5. The database password lives in Secrets Manager, rotated automatically.

Common mix-ups

  • User vs role. A user has long-term credentials for one identity; a role is assumed and gives temporary credentials.
  • Group vs role. A group is a set of users sharing permissions; you cannot “sign in as a group”. A role is assumed by someone or something.
  • IAM is global. You do not create IAM users per Region.
  • Root can’t be restricted by IAM policies. That is why it must be protected and rarely used.

Check yourself

An application on EC2 needs to read from an S3 bucket. What is the most secure way to give it access?

Attach an IAM role to the instance. It gets temporary credentials automatically, with no access keys stored on the server.

Ten developers need the same permissions. How should you grant them?

Put them in an IAM group and attach the policy to the group.

What wins if one policy allows an action and another explicitly denies it?

The explicit Deny always wins.

Where should an application store its database password?

In AWS Secrets Manager (which can rotate it automatically) or Systems Manager Parameter Store, never in code.

Which task requires signing in as the root user?

For example, closing a standalone AWS account or changing the root user’s email address or password.

Key takeaways

  • IAM handles authentication and authorization; it is global and free.
  • Protect the root user with MFA and use it only for root-only tasks.
  • Users, groups, roles and policies; deny by default, explicit deny wins.
  • Prefer roles and IAM Identity Center over long-term keys; keep secrets in Secrets Manager.

Cloud Study Lab is an independent study site. It is not affiliated with or endorsed by Amazon Web Services. AWS and the names of AWS certifications are trademarks of Amazon.com, Inc. or its affiliates.