Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
IAM — Who May Do What  ›  Lesson

IAM Policies

Policies 16 minAn IAM policy is a JSON document of statements that allow or deny actions on resources, and AWS evaluates them so that an explicit deny beats any allow and anything not allowed is denied.

IAM Policies

Inkwell's developers need to upload book covers to the inkwell-covers bucket and read them back. Last month someone deleted two hundred covers by mistake, so this time deleting must be impossible. Groups say who; policies say what exactly they may do.

The rule

Deny wins; then allow; otherwise, no.

A policy is a JSON document of statements:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:PutObject"],
      "Resource": "arn:aws:s3:::inkwell-covers/*"
    },
    {
      "Effect": "Deny",
      "Action": "s3:DeleteObject",
      "Resource": "arn:aws:s3:::inkwell-covers/*"
    }
  ]
}
  • Effect: Allow or Deny.
  • Action: API operations, written service:Operation. Wildcards work: s3:* means every S3 action.
  • Resource: which things, named by ARN (Amazon Resource Name). arn:aws:s3:::inkwell-covers is the bucket; arn:aws:s3:::inkwell-covers/* is every object inside it.
  • Condition (optional): extra tests, such as requiring MFA or a source IP range.
  • Version is always "2012-10-17", the current policy language, not today's date.

When a request arrives, AWS gathers every policy that applies and decides in a fixed order:

  1. Any explicit Deny that matches → denied, no matter what else says.
  2. Otherwise, any Allow that matches → allowed.
  3. Otherwise → denied. This default is called the implicit deny.

Policies attached to users, groups and roles are identity-based. Policies attached to a resource, such as an S3 bucket policy, are resource-based and name a Principal, the who. You will write one of those in the S3 section.

Policies also come in two packagings. Managed policies stand alone and can be attached to many identities: AWS publishes ready-made ones such as ReadOnlyAccess, and you can write your own. Inline policies are embedded in a single identity and are deleted with it. Prefer your own managed policies that grant only the actions the job needs: the principle of least privilege.

The shortcut

Evaluate every request with the three-line check: Is there a matching Deny? Is there a matching Allow? If neither, it is no. Stop at the first yes.

Can Priya delete a cover?Step 1 of 3
  1. Any matching Deny?

    Yes: s3:DeleteObject on inkwell-covers/*. Stop. Denied.

The trap is the resource ARN. Listing a bucket acts on the bucket ARN (no /*), while reading objects acts on the object ARN (with /*). A policy with only one of them grants only half of what you meant.

Drills

Answer fast — trust the rule.

quick drill

A request matches no Allow and no Deny statement. What happens?

quick drill

One policy allows s3:* on the bucket; another explicitly denies s3:DeleteObject. Can the user delete an object?

quick drill

Which ARN names every object inside the inkwell-covers bucket?

quick drill

What does "Version": "2012-10-17" in a policy mean?

quick drill

Which kind of policy contains a Principal element?

Remember

  • Deny wins; then allow; otherwise, no.
  • Statements are Effect, Action, Resource, optional Condition; resource policies add Principal.
  • Trap: the bucket ARN and the object ARN (/*) are different resources.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainRead and write a policy

Write, in JSON or clear words, a policy that lets Inkwell's developers read and upload objects in the inkwell-covers bucket but never delete them. Then explain what happens if a developer tries s3:DeleteObject with no deny in place, and what changes if another attached policy allows s3:* while yours contains an explicit deny for s3:DeleteObject.