Course outline · 0% complete

0/27 lessons0%

Course overview →

Policies: the permission language

lesson 2-2 · ~12 min · 5/27

What a policy looks like

"Give Ben read access" is too vague for a computer to enforce: which files, which actions, forever or until when? IAM needs permissions written in an exact, checkable form, and that form is what you will actually read at work — the first step in debugging almost every AccessDenied error is opening a policy document.

A policy is that document: JSON attached to an identity. It is a list of statements, and each statement has three core parts:

  • Effect: Allow or Deny
  • Action: what API calls, like s3:GetObject (read a file from S3)
  • Resource: what things, named by ARN (Amazon Resource Name), a globally unique ID like arn:aws:s3:::my-app-photos/*
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["s3:GetObject", "s3:PutObject"],
    "Resource": "arn:aws:s3:::my-app-photos/*"
  }]
}

Read it aloud: this identity may read and write objects, but only inside the my-app-photos bucket. That is least privilege from lesson 2-1 written down.

The three evaluation rules

When a request arrives, IAM gathers every policy attached to the identity and applies three rules, in order:

  1. Default deny. With no policies at all, the answer is no.
  2. An explicit Deny always wins. If any statement denies the action, it is denied even if ten others allow it.
  3. Otherwise, one Allow is enough.

That is the whole algorithm. Explicit denies exist as guardrails: a company can attach deny deleting databases in production to everyone, and no allow anywhere can override it.

Code exercise · bash

This function is IAM's evaluation algorithm in miniature. It takes two answers, "is there an explicit deny?" and "is there an explicit allow?", and decides. Run it and check the three rules against the output.

Code exercise · bash

Your turn. Ben requests s3:DeleteObject in three situations. Call decide once per situation, in this order: (1) Ben has no policies at all. (2) A policy allows s3:* for Ben, but a company guardrail explicitly denies DeleteObject. (3) A policy explicitly allows DeleteObject and nothing denies it. Predict the three lines before you run.

Quiz

An identity has policy A allowing s3:* on every bucket and policy B explicitly denying s3:DeleteObject on arn:aws:s3:::prod-data/*. What happens when it tries to delete prod-data/backup.zip?

Problem

Read an ARN like IAM does. A policy's Resource line says arn:aws:s3:::acme-billing-exports/*. Which bucket does this statement scope access to? (Just the bucket name.)