Volume 3 · Chapter 2 — Identity, Security and Compliance

IAM Policies and Permission Evaluation

Goutham Mayaluri 9 min read AWSCloudIAMSecurityCompliance

2.1 Introduction

Policies are how permissions are actually expressed in AWS - JSON documents that state what actions are allowed or denied, on which resources, under which conditions. Understanding how policies are written and, crucially, how AWS evaluates them when multiple policies apply is essential, because real environments have several policies acting on any given request, and the evaluation logic determines the outcome. This is a frequent interview topic precisely because the “explicit deny wins” rule and the interaction of identity and resource policies trip people up.

2.2 The Anatomy of a Policy

An IAM policy is a JSON document made of statements, each specifying an Effect (Allow or Deny), an Action (the API operations, likes3:GetObject), a Resource (which resources the statement applies to, by ARN), and optionally a Condition (extra constraints, like a source IP range, whether MFA was used, or a required encryption setting). A statement reads as “allow (or deny) these actions on these resources when these conditions hold.” Well-written policies name specific actions and specific resource ARNs rather than wildcards, and use conditions to tighten access further - for example, allowing an action only if the request is encrypted or comes from an approved network.


{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["s3:GetObject", "s3:PutObject"],
    "Resource": "arn:aws:s3:::bank-statements/*",
    "Condition": {
      "Bool": { "aws:SecureTransport": "true" },
      "StringEquals": { "s3:x-amz-server-side-encryption": "aws:kms" }
    }
  }]
}

2.3 Identity-Based vs Resource-Based Policies

Policies attach in two places. Identity-based policies attach to an identity (user, group, or role) and say what that identity can do - “this role may read this bucket.” Resource-based policies attach directly to a resource (like an S3 bucket, an SQS queue, or a KMS key) and say who may access that resource - “this bucket may be accessed by that account or role.” Both express permissions, but from opposite ends. Resource-based policies are especially important for cross-account access, because a resource policy can grant access to a principal in another account directly, and for controlling access to shared resources. In many designs the two work together: the identity policy grants the identity the action, and the resource policy confirms the resource permits that principal.

2.4 How Permissions Are Evaluated

When a request is made, AWS evaluates all applicable policies together to decide allow or deny, and the logic follows firm rules. By default, everything is implicitly denied - if nothing explicitly allows an action, it’s denied. An explicit Allow in any applicable policy grants the action. But an explicit Deny in any policy overrides everything - an explicit deny always wins, no matter how many allows exist. So the decision is: start denied; if there’s an explicit deny anywhere, deny; otherwise if there’s an explicit allow, allow; otherwise (no allow) deny by default. This “explicit deny always wins” rule is the single most important thing to remember, because it’s how guardrails work: an organization-wide deny (via a service control policy or permission boundary) can cap what any identity can do, regardless of the allows in its own policies.

flowchart TD
  Req[Request made] --> D{Explicit Deny in any policy?}
  D -->|Yes| Deny[DENY - explicit deny always wins]
  D -->|No| A{Explicit Allow present?}
  A -->|Yes| Allow[ALLOW]
  A -->|No| Default[DENY - implicit default deny]

2.5 Guardrails: Boundaries and Service Control Policies

The evaluation rules enable powerful org-wide guardrails. A permission boundary is a policy that sets the maximum permissions an identity can have - even if its own policies grant more, the boundary caps the effective set. Service control policies (SCPs), applied at the AWS Organizations level, set guardrails across entire accounts - for example denying the ability to disable encryption, create public S3 buckets, or operate outside approved Regions - and because a deny in an SCP overrides any allow, these limits hold no matter what an account’s own administrators grant. This is how a bank enforces non-negotiable rules centrally: individual teams manage their own permissions within accounts, but SCPs impose hard limits that no one below can exceed.

2.6 Banking Production Scenario

A bank writes tight identity policies (specific actions on specific resource ARNs, with conditions requiring encryption in transit and at rest) and resource policies on shared resources like KMS keys and buckets to control exactly which principals may use them, including cross-account access to a central logging bucket. Over the top, organization-wide SCPs deny disabling encryption, deny creating public buckets, and restrict resource creation to Canadian Regions for data residency - and because an explicit deny always wins, these limits hold even if a team’s own policy would allow the action. Permission boundaries cap what developer-created roles can grant. The result is precise per-resource control combined with hard, centrally-enforced guardrails that no account-level administrator can override.

2.7 Troubleshooting: Unexpected Allow or Deny

Policy evaluation surprises usually come from not tracing all the applicable policies. When an action is unexpectedly denied despite an allow, the cause is almost always an explicit deny somewhere - often in a service control policy or permission boundary higher up - overriding the allow; the fix is to find the deny, which policy simulators and the IAM evaluation trace will surface. When an action is unexpectedly allowed, some policy grants it more broadly than intended - a wildcard action or resource, or a broad managed policy - and the fix is to tighten it. For cross-account access failures, both sides must permit it: the identity policy in the caller’s account and the resource policy on the target. The diagnostic discipline is to enumerate every policy that applies - identity, resource, boundary, SCP - and apply the rule: explicit deny wins, then explicit allow, else default deny.

Interview Question

How does AWS evaluate permissions when multiple policies apply, and why does "explicit deny always wins" matter?

When a request is made, AWS evaluates all the policies that apply to it together and reaches a single allow-or-deny decision using a firm set of rules. The starting point is implicit default deny: if nothing explicitly allows an action, it is denied - permissions are never granted by omission. An explicit Allow in any applicable policy grants the action. But an explicit Deny in any applicable policy overrides everything - it always wins, regardless of how many allows exist. So the evaluation is: begin denied; if there’s an explicit deny anywhere, the result is deny; otherwise, if there’s an explicit allow, the result is allow; otherwise, with no allow at all, it’s deny by the default. The policies considered include identity-based policies on the user or role, resource-based policies on the target resource, and boundaries like permission boundaries and organization service control policies. Why does “explicit deny always wins” matter so much? Because it’s the mechanism that makes guardrails enforceable. It means a higher-level deny can cap what any identity is able to do no matter what that identity’s own policies grant. A service control policy applied across an AWS Organization can deny disabling encryption, deny creating public S3 buckets, or deny operating outside approved Regions, and because that deny overrides any allow beneath it, no team, administrator, or role in those accounts can do the forbidden thing even if someone writes a policy trying to allow it. Permission boundaries use the same rule to cap the maximum permissions a role can have. This is how a large organization delegates day-to-day permission management to individual teams while still enforcing non-negotiable, centrally-defined limits that cannot be exceeded from below - the deny is a hard ceiling. It also explains a common troubleshooting scenario: an action that seems like it should be allowed (the identity’s own policy allows it) is denied because an explicit deny in an SCP or boundary higher up overrides that allow. So the rule to internalize is the ordering - explicit deny beats explicit allow beats implicit default deny - and its significance is that it turns org-wide denies into unbreakable guardrails, which is fundamental to governing security at scale in a regulated environment.

Interview Question

What's the difference between identity-based and resource-based policies, and when do resource policies matter most?

Identity-based and resource-based policies both express permissions in AWS, but they attach in different places and answer the question from opposite directions. An identity-based policy attaches to an identity - a user, group, or role - and describes what that identity is allowed to do: “this role may read and write this bucket.” A resource-based policy attaches directly to a resource - such as an S3 bucket, an SQS queue, an SNS topic, or a KMS key - and describes who is allowed to access that resource: “this bucket may be accessed by this principal or this account.” So identity policies are organized around the actor and resource policies around the resource. Both are evaluated together when a request is made, and in many designs they complement each other: the identity policy grants the identity the action, and the resource policy confirms the resource permits that principal. Resource-based policies matter most in two situations. The first and most important is cross-account access. A resource-based policy can directly grant a principal in another AWS account access to the resource, which is the clean way to share a resource across account boundaries - for example, allowing a central logging account’s role to write to, or a partner account to read from, a specific bucket or key. Without a resource policy, cross-account access is much harder to express. The second is controlling access to shared resources generally - a KMS key used by several services, or a queue consumed by multiple producers - where attaching the access rules to the resource itself centralizes and clarifies who may use it. There’s also a subtle point for services like KMS: the key policy (a resource policy) is authoritative for the key, so access to a key is ultimately governed there. So the distinction is identity-based (attached to the actor, “what can this identity do”) versus resource-based (attached to the resource, “who can access this resource”), and resource-based policies are especially important for cross-account sharing and for governing access to shared resources like keys, buckets, and queues - which in a multi-account enterprise like a bank is a routine and critical need.

Chapter Revision Notes

  • A policy is JSON: Effect (Allow/Deny), Action, Resource, optional Condition; prefer specific actions/ARNs and tightening conditions.
  • Identity-based policies attach to users/roles (“what can this identity do”); resource-based policies attach to resources (“who can access this”).
  • Evaluation: implicit default deny → explicit allow grants → explicit deny overrides everything. Explicit deny always wins.
  • That rule makes guardrails enforceable: SCPs and permission boundaries impose hard limits no lower policy can exceed.
  • Resource-based policies matter most for cross-account access and shared resources (keys, buckets, queues).