Advanced IAM
Mastering Advanced IAM Policy Evaluation Logic is what separates the average script devs from true cloud security architects. ποΈπ‘οΈ
When you scale up across hundreds of accounts and thousands of microservices, you can't be guessing how permissions evaluate. You need to know the exact decision tree AWS runs every single millisecond an API call hits the wire.
Key Takeawaysβ
Let's deep dive into the evaluation flow, identity-vs-resource unions, dynamic policy variables, and policy types for your master notes.
π¦ The Evaluation Flow: The Golden Rule of Denyβ
When an IAM principal attempts an API call, AWS starts with an Implicit Deny by default. The decision engine then evaluates all applicable policies following a strict priority sequence:

- Explicit Deny Wins Always π: If any applicable policy (Identity policy, Resource policy, SCP, or Permission Boundary) contains an
"Effect": "Deny", evaluation stops dead in its tracks. Explicit Deny trumps any number of explicit Allows, period. - Explicit Allow Required β
: If no explicit Deny exists, AWS searches for at least one explicit
"Effect": "Allow". - Implicit Deny Fallback β: If no policy explicitly grants an Allow, the request defaults to a Deny.
π Identity Policies vs. Resource Policies: The Union Ruleβ
When accessing single-account resources like an Amazon S3 Bucket, permissions evaluate as the UNION of the IAM Identity Policy and the Resource-based Policy.

The Single-Account Union Principle: Within the same AWS account, access is granted if EITHER the IAM identity policy OR the S3 bucket policy allows the action (as long as neither side explicitly denies it)!
π§ͺ The Four Evaluation Scenariosβ
-
Scenario 1: IAM Allow | No Bucket Policy
-
Result: ALLOWED β . The IAM policy grant is sufficient.
-
Scenario 2: IAM Allow | Bucket Policy Explicit Deny
-
Result: DENIED β. Explicit Deny on the resource overrides the IAM Allow.
-
Scenario 3: Empty IAM Policy | Bucket Policy Explicit Allow
-
Result: ALLOWED β . The S3 Bucket Policy grants access directly, even if the EC2 role/User IAM policy contains zero S3 permissions!
-
Scenario 4: IAM Explicit Deny | Bucket Policy Explicit Allow
-
Result: DENIED β. Explicit Deny on the identity overrides the resource Allow.
π Policy Categorization: Managed vs. Inlineβ
AWS provides three structural ways to attach policies to identities, chief:
| Policy Type | Managed By | Reusable across Identities? | Version Control & Rollbacks? | Use Case / Best Practice |
|---|---|---|---|---|
| AWS Managed π’ | AWS | Yes (Globally across accounts) | Yes (Managed by AWS) | Fast baseline setup for standard job functions (e.g., AdministratorAccess). |
| Customer Managed π οΈ | You | Yes | Yes (Up to 5 versions) | AWS Best Practice. Reusable, auditable, modular access control. |
| Inline π | You | No (1-to-1 strict bind) | No | Strict single-principal binding. Deleted when the principal is deleted. |
The Inline Policy Size Trap: Inline policies share a strict character/byte quota directly on the user or role object (e.g., 2 KB limit for users). If you paste massive JSON policies into an inline block, deployment will fail due to size limits! Always prefer Customer Managed policies.
π― Dynamic Policy Variables: Scaling Least-Privilegeβ
Instead of creating hundreds of individual policies for every developer in your team (/home/zoro, /home/luffy), you write ONE dynamic policy using runtime IAM Policy Variables:
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::my-company-user-vault/home/${aws:username}/*"
}
- Runtime Replacement: When user
Zoroattempts an S3 call, AWS dynamically resolves${aws:username}toZoroon the fly, locking them strictly to/home/Zoro/*while keeping your administrative overhead practically zero!
Exam Tipsβ
- The Single-Account Bucket Access Fix: If an exam question mentions an EC2 instance that lacks S3 permissions in its IAM role, but still needs access to an S3 bucket in the same accountβyou do not need to edit the IAM role! You can simply add an explicit Allow for the role ARN directly inside the S3 Bucket Policy!
- The Scalable User Directory Pattern: If a scenario asks for the most efficient, scalable way to grant 500 developers write access to their own personal sub-folder in a shared S3 bucket without creating 500 separate policiesβchoose the option that deploys a single policy using the
${aws:username}policy variable!