Services

Resources

Company

/

AWS IAM

AWS IAM (Identity and Access Management)

AWS IAM (Identity and Access Management) controls access to everything in an AWS account. For every API call it does two jobs: it checks the request signature to learn who is calling, and it checks policies to decide whether that caller may run that action on that resource. Those are the two halves of authentication vs authorization. IAM is global, not regional, and has no extra charge.

How it works

There are three kinds of things to keep apart. An IAM user is a long-lived identity with a password or access keys that stay valid until someone rotates or deletes them. An IAM role has no long-term credentials. An EC2 instance, a Lambda function, a CI job or a person signed in through IAM Identity Center assumes it and gets temporary credentials from AWS STS (Security Token Service), valid for 1 hour by default.

A policy is a JSON document of statements, each with an Effect, Action, Resource and optional Condition. Policies attach to users, groups and roles, and a role also has a trust policy that says who may assume it.

Evaluation is deny by default. A request is allowed only if some policy allows it, and an explicit Deny anywhere beats every allow. This least-privilege policy lets a deploy role upload a static site to one bucket and nothing else:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "UploadSite",
      "Effect": "Allow",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::site-prod/*"
    },
    {
      "Sid": "ListSite",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::site-prod"
    }
  ]
}
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "UploadSite",
      "Effect": "Allow",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::site-prod/*"
    },
    {
      "Sid": "ListSite",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::site-prod"
    }
  ]
}
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "UploadSite",
      "Effect": "Allow",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::site-prod/*"
    },
    {
      "Sid": "ListSite",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::site-prod"
    }
  ]
}
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "UploadSite",
      "Effect": "Allow",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::site-prod/*"
    },
    {
      "Sid": "ListSite",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::site-prod"
    }
  ]
}
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "UploadSite",
      "Effect": "Allow",
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::site-prod/*"
    },
    {
      "Sid": "ListSite",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::site-prod"
    }
  ]
}

Any other call, such as s3:DeleteBucket or ec2:RunInstances, gets AccessDenied.

For example, a CI pipeline deploys with an IAM user whose access key has AdministratorAccess. The key leaks into a build log and is found 40 days later, so it was usable for 40 x 24 = 960 hours, against every service. Switch the pipeline to assume a role with the policy above, and a leaked credential works for at most 1 hour and can only write files to site-prod.

Why it matters in production

Most IAM trouble is permissions that grew and never shrank: wildcards like "Action": "*", access keys that are years old, and roles whose trust policy lets any principal in the account assume them. Prefer roles over users, scope Resource to real ARNs, and use IAM Access Analyzer or CloudTrail to find permissions nobody has used in 90 days.

See also

On the One2N blog

References

  1. What is IAM? AWS Identity and Access Management User Guide

  2. AWS IAM: Policy evaluation logic

Before and after for AWS IAM. On the left, an IAM user access key with AdministratorAccess reaches every service: S3, EC2, Lambda and IAM. On the right, a role assumed through STS allows only s3:PutObject on the site-prod bucket, and a call to EC2 gets AccessDenied. Below, bars show how long a leaked credential works: the user key for 40 days x 24 = 960 hours, in red, against 1 hour for the role credential.