appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

IAM and least privilege

Lesson 2 of 511 minBeginner

Control who can do what, and why you should almost never use the root account.

IAM (Identity and Access Management) decides who can do what in your AWS account. It is the most important service to understand, because every other service depends on it.

The main pieces

  • Root user: the identity created with the account. It can do everything and cannot be restricted.
  • IAM user: a person or program with its own credentials.
  • Group: a set of users that share permissions.
  • Role: an identity with permissions that something temporarily assumes, such as an EC2 instance, a Lambda function or a person using single sign-on. A role has no long-term password or key.
  • Policy: a JSON document that lists the allowed or denied actions.
A policy that only allows reading one bucket
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["s3:GetObject", "s3:ListBucket"],
    "Resource": ["arn:aws:s3:::my-reports", "arn:aws:s3:::my-reports/*"]
  }]
}

Least privilege

Give each identity only the permissions it needs for its job and nothing else. Start with nothing and add. By default everything is denied, and an explicit Deny always beats an Allow.

CarefulProtect the root user with a strong password and MFA, create no access keys for it and use it only for the few tasks that require it. Do your daily work with an IAM identity or single sign-on.

NotePrefer roles and temporary credentials to long-lived access keys. Never commit keys to Git. If one leaks, deactivate it at once.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. What is the principle of least privilege?
2. What should you do with the root user?
3. Which has no long-term credentials of its own?

Key terms