AWS IAM: who can do what

Read identity policies and permissions boundaries the way AWS evaluates them, then write least-privilege policies that a checker tests against real requests.

Draft. Not yet reviewed by a second person. The checker covers the parts of IAM these exercises use, and says so when a policy goes beyond them.

Every request to AWS starts denied. It is allowed only if an identity policy has a statement that allows it, nothing anywhere denies it, and, if the principal has a permissions boundary, the boundary allows it too. An explicit Deny always wins, wherever it is.

A statement applies to a request when its action matches, its resource matches and its condition, if any, holds. Action names ignore case and accept * and ?; resources are ARNs and their case matters. NotAction and NotResource match everything except what they list, which makes an Allow with them far broader than it looks.

A condition compares a value from the request, such as aws:SourceIp or a resource tag, with the policy. When the request does not carry that key, a positive operator such as StringEquals does not match, while a negated one such as NotIpAddress does. That last rule is how a network guard rail can deny calls that carry no source IP at all.

The checker here follows AWS's documented evaluation order for identity policies and boundaries in one account. It covers one condition operator with one key per statement; it refuses anything outside that, rather than guessing. Resource policies, organisation policies and session policies are out of scope.

From AWS's documentation

Read a policy and decide

A read-only reports role

An analytics job has one identity policy and no boundary.

Identity policy 1

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadReports",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject"
      ],
      "Resource": "arn:aws:s3:::reports/*"
    },
    {
      "Sid": "ListReports",
      "Effect": "Allow",
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::reports"
    }
  ]
}
For each request, what does AWS decide?
s3:GetObject on arn:aws:s3:::reports/2026/q3.csv

s3:PutObject on arn:aws:s3:::reports/2026/q4.csv

s3:ListBucket on arn:aws:s3:::reports

s3:GetObject on arn:aws:s3:::billing/2026/q3.csv

A broad grant with a guard rail

An operator has two identity policies: one grants all of S3, the other protects the backups.

Identity policy 1

{
  "Version": "2012-10-17",
  "Statement": {
    "Effect": "Allow",
    "Action": "s3:*",
    "Resource": "*"
  }
}

Identity policy 2

{
  "Version": "2012-10-17",
  "Statement": {
    "Sid": "KeepBackups",
    "Effect": "Deny",
    "Action": [
      "s3:DeleteObject",
      "s3:PutLifecycleConfiguration"
    ],
    "Resource": [
      "arn:aws:s3:::prod-backups",
      "arn:aws:s3:::prod-backups/*"
    ]
  }
}
For each request, what does AWS decide?
s3:DeleteObject on arn:aws:s3:::prod-backups/2026-11-19.dump

s3:DeleteObject on arn:aws:s3:::scratch/tmp.txt

s3:GetObject on arn:aws:s3:::prod-backups/2026-11-19.dump

s3:PutLifecycleConfiguration on arn:aws:s3:::prod-backups

Everything except IAM

A developer role was given "everything except IAM" with NotAction, plus a narrow IAM grant.

Identity policy 1

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllButIam",
      "Effect": "Allow",
      "NotAction": "iam:*",
      "Resource": "*"
    },
    {
      "Sid": "OwnKeys",
      "Effect": "Allow",
      "Action": [
        "iam:ListAccessKeys",
        "iam:CreateAccessKey"
      ],
      "Resource": "arn:aws:iam::111122223333:user/dev-*"
    }
  ]
}
For each request, what does AWS decide?
ec2:RunInstances on *

iam:CreateUser on arn:aws:iam::111122223333:user/someone

iam:ListAccessKeys on arn:aws:iam::111122223333:user/dev-asha

kms:ScheduleKeyDeletion on arn:aws:kms:eu-west-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab

A permissions boundary

A team lead may create roles for services, but each role gets this boundary. One such role has a generous identity policy.

Identity policy 1

{
  "Version": "2012-10-17",
  "Statement": {
    "Effect": "Allow",
    "Action": [
      "s3:*",
      "dynamodb:*",
      "sqs:SendMessage"
    ],
    "Resource": "*"
  }
}

Permissions boundary

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "dynamodb:GetItem",
        "dynamodb:Query"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "sqs:*",
      "Resource": "arn:aws:sqs:eu-west-1:111122223333:orders-*"
    }
  ]
}
For each request, what does AWS decide?
s3:PutObject on arn:aws:s3:::orders-archive/2026/1.json

dynamodb:DeleteTable on arn:aws:dynamodb:eu-west-1:111122223333:table/orders

sqs:SendMessage on arn:aws:sqs:eu-west-1:111122223333:orders-events

sqs:PurgeQueue on arn:aws:sqs:eu-west-1:111122223333:orders-events

sqs:SendMessage on arn:aws:sqs:eu-west-1:111122223333:billing

Start and stop by team tag

An on-call engineer may start and stop instances that belong to their team.

Identity policy 1

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "OwnInstances",
      "Effect": "Allow",
      "Action": [
        "ec2:StartInstances",
        "ec2:StopInstances"
      ],
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/team": "payments"
        }
      }
    },
    {
      "Sid": "NeedMfa",
      "Effect": "Deny",
      "Action": "ec2:StopInstances",
      "Resource": "*",
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": "false"
        }
      }
    }
  ]
}
For each request, what does AWS decide?
ec2:StartInstances on arn:aws:ec2:eu-west-1:111122223333:instance/i-0a1 · aws:ResourceTag/team = payments, aws:MultiFactorAuthPresent = true

ec2:StartInstances on arn:aws:ec2:eu-west-1:111122223333:instance/i-0b2 · aws:ResourceTag/team = Payments, aws:MultiFactorAuthPresent = true

ec2:StopInstances on arn:aws:ec2:eu-west-1:111122223333:instance/i-0a1 · aws:ResourceTag/team = payments, aws:MultiFactorAuthPresent = false

ec2:StartInstances on arn:aws:ec2:eu-west-1:111122223333:instance/i-0c3 · aws:MultiFactorAuthPresent = true

Only from the office network

A finance role may read invoices, and a guard rail denies requests from outside the office range.

Identity policy 1

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadInvoices",
      "Effect": "Allow",
      "Action": [
        "dynamodb:GetItem",
        "dynamodb:Query"
      ],
      "Resource": "arn:aws:dynamodb:eu-west-1:111122223333:table/invoices"
    },
    {
      "Sid": "OfficeOnly",
      "Effect": "Deny",
      "Action": "*",
      "Resource": "*",
      "Condition": {
        "NotIpAddress": {
          "aws:SourceIp": "198.51.100.0/24"
        }
      }
    }
  ]
}
For each request, what does AWS decide?
dynamodb:Query on arn:aws:dynamodb:eu-west-1:111122223333:table/invoices · aws:SourceIp = 198.51.100.40

dynamodb:Query on arn:aws:dynamodb:eu-west-1:111122223333:table/invoices · aws:SourceIp = 203.0.113.5

dynamodb:UpdateItem on arn:aws:dynamodb:eu-west-1:111122223333:table/invoices · aws:SourceIp = 198.51.100.40

dynamodb:Query on arn:aws:dynamodb:eu-west-1:111122223333:table/invoices

Write a least-privilege policy

Let the backup job write, never delete

The nightly backup job uploads files under backups/nightly/ in the backups bucket and needs to list the bucket to check what is already there. It must not read, delete or overwrite anything outside that prefix, and must not touch other buckets.

Hint 1 of 2

Two statements: one for objects under the prefix, one for the bucket itself. Objects and buckets have different ARNs.

Hint 2 of 2

Name each action. A wildcard such as s3:* or s3:Put* also grants things you did not mean.

One solution opens once your policy passes, or after three checks.

Start and stop only your team's instances

The search team's on-call engineers may start and stop any EC2 instance tagged team = search, and nothing else on EC2: not other teams' instances, and never terminate.

Hint 1 of 2

One Allow for the two actions, limited by a condition on the aws:ResourceTag/team key.

Hint 2 of 2

Without the condition, every instance in the account is covered; with ec2:*, so is terminating.

One solution opens once your policy passes, or after three checks.

Read orders, only from the office

A support role may read single orders and query the orders table, but only from the office range 198.51.100.0/24. It may not write, and may not read other tables.

Hint 1 of 2

Name the two read actions and the table's ARN. dynamodb:* or dynamodb:Get* grants more than asked.

Hint 2 of 2

Add an IpAddress condition on aws:SourceIp to the Allow, so requests from elsewhere are simply not allowed.

One solution opens once your policy passes, or after three checks.

Esc
↑ ↓ to move↵ to open