Labs 5.1 and 5.2: IAM policy puzzles, permission boundaries and an offline policy linter
Predict allow or deny for ten IAM evaluation puzzles, confirm each with an offline evaluator and the IAM policy simulator, lint a deliberately bad policy, and design a permission boundary that lets a developer create roles without escalating privileges.
Assumes: .NET 10 LTS · xUnit v3 4.0.3 · hl-policy (lab tool, a simplified teaching model of IAM evaluation) · AWS CLI v2 · IAM policy simulator · Region us-east-1. Verified against official sources on 2026-11-18.
Learning objectives
By the end of these labs you can:
- Predict, for a request, whether IAM returns Allow, explicit deny or implicit deny, using the evaluation order: explicit deny first, then organisation guardrails, resource policy, identity policy, permissions boundary and session policy.
- Explain why a Service Control Policy (SCP), a Resource Control Policy (RCP) and a permissions boundary grant nothing; each only caps what other policies grant.
- Tell a same-account request from a cross-account one, and say which sides must allow it.
- Run
hl-policy lint,explainandevaluateon policies offline, and read the trace line by line. - Spot the lint patterns that matter in a bank: full wildcards,
iam:PassRoleon*,kms:Decrypton every key, missing MFA conditions on destructive actions, and theBool-versus-BoolIfExiststrap. - Design a permissions boundary and a delegated "create roles" policy so a developer can create roles for their application without being able to make themselves an administrator.
- State where the offline evaluator is a simplification, and why the IAM policy simulator in a sandbox account is the authority.
This page covers Lab 5.1 (policy evaluation puzzles) and Lab 5.2 (permissions boundary). The theory is in Policy evaluation logic and Boundaries, SCPs, RCPs and resource policies.
Prerequisites
- IAM in depth, Policy evaluation logic and Boundaries, SCPs, RCPs and resource policies.
- Docker Desktop. The .NET 10 SDK is optional.
- Optional, for the "confirm with AWS" step: AWS CLI v2 and
aws sso login --profile learn-sandbox. The simulator calls cost nothing. Use only the sandbox account.
Why this matters in banking
A change request says "give the reporting team read access to the statements bucket". Someone adds an identity policy in the reporting account and the job still fails, because the bucket policy in the workload account never granted the role. Someone else "fixes" it with a wildcard principal, and now a statements bucket is readable far more widely than intended. Auditors then ask why the bank's guardrail did not stop it. Every one of these mistakes is a failure to predict the result of a policy combination. People who can predict it make smaller, safer changes and debug access problems in minutes rather than days.
The idea in plain language
When a request arrives, IAM gathers every policy that applies and decides using a fixed procedure. It is not a vote. It works like a building's access system with several layers of locks:
- Any explicit deny wins. If any policy says Deny and its condition matches, the answer is deny. Nothing can override it.
- Guardrails must permit. Organisation policies (RCPs for resources, SCPs for principals) must not block the request. They are filters: an SCP that says "allow everything" grants nothing.
- Someone must grant. Within one account, an identity-based policy or a resource-based policy can grant. Across accounts, both sides must allow.
- Caps apply. If the principal has a permissions boundary or a session policy, the request must be allowed by those as well. Effective permissions are the intersection.
- If nobody granted, the default is implicit deny.
Analogy: a branch vault. The bank's head office (SCP and RCP) says which vaults any branch may ever enter. The vault's own register (resource policy) says who is on its list. Your keycard (identity policy) says which doors you may open. A temporary visitor pass (session policy) and your department's cap (permissions boundary) shrink what the card can do. A written ban from anyone (explicit deny) beats every list.
What the AWS services do here
- IAM evaluates the policies. The IAM policy simulator (
aws iam simulate-custom-policyand the console) evaluates policies you supply without making real calls. - AWS Organizations carries SCPs (what principals in your accounts may do) and RCPs (what can be done to resources in your accounts, including by outsiders).
- IAM Access Analyzer and policy generation (not used here) help right-size policies from CloudTrail activity.
- The lab's hl-policy tool is not an AWS service. It is a small offline model so you can experiment quickly, repeatedly and safely.
Microsoft / Azure comparison
| You know (Microsoft/Azure) | AWS in this lab | What's different |
|---|---|---|
| Azure RBAC role assignments (allow only) | IAM identity-based policies | IAM policies can also deny, and an explicit deny beats any allow |
| Azure Policy and management group deny assignments | SCPs and RCPs | SCPs and RCPs never grant. They cap what accounts can do or what can be done to their resources |
| Entra ID Conditional Access (MFA, location) | Condition blocks such as aws:MultiFactorAuthPresent | The condition lives in the policy, and the key may be absent from the request context, which changes the result |
| Azure PIM and permission scopes | Session policies and permissions boundaries | Both only shrink permissions. Neither grants anything |
| Resource locks and ACLs on a storage account | Resource-based policies (bucket, key, queue) | A resource policy can grant access to a principal that has no identity policy at all, within the same account |
Architecture
The tool follows the same shape and prints a numbered trace (steps 1 to 7), so you can see which step produced the answer. That is a simplification. Real IAM has more cases (for example how a same-account resource policy that names a role differs from one that names a user, and service-linked roles), which is why the last word always belongs to the policy simulator and a sandbox account.
Step-by-step implementation
The lab folder is labs/m05-secure-banking-api. Everything for these labs is in policies/ and the tool is src/Harbourline.Security.PolicyLinter (assembly name hl-policy).
Part 1: run the tests (free)
Run the whole solution's tests in Docker
MSYS_NO_PATHCONV=1 docker run --rm --memory 3g \
-v "$PWD/labs/m05-secure-banking-api:/src" \
-v cea-nuget-m05:/root/.nuget/packages \
-w /src mcr.microsoft.com/dotnet/sdk:10.0 \
sh -c "dotnet test --solution SecureBankingApi.slnx; find . -type d \( -name bin -o -name obj \) -prune -exec rm -rf {} +"Expected result (verified 2026-11-18 in Docker): total: 72, failed: 0, succeeded: 71, skipped: 1. This solution also holds the code for the other Module 5 labs. The policy tests are in PolicyTests.cs:
| Test | What it proves |
|---|---|
Every_puzzle_evaluates_to_its_expected_answer (per file) | Each puzzle's expected field matches the evaluator's answer |
There_are_ten_puzzles | Nobody deleted a puzzle without noticing |
Bad_admin_policy_fails_lint_with_the_expected_rules | The lint rules fire on bad-wildcard-admin.json |
Good_policies_have_no_lint_errors (3 files) | The good identity, resource and boundary policies lint clean |
Evaluate_command_reports_a_matching_answer | The command-line path works end to end |
Explicit_deny_beats_an_allow_in_the_same_policy, No_policy_means_implicit_deny | The two basic rules |
If you change a policy file or the tool, run these again. The tests protect the puzzles from drifting.
Part 2: the ten puzzles (Lab 5.1, free)
For each puzzle write your prediction first. Only then run it. A wrong guess teaches more than a right one.
Read a scenario, predict, then run
The scenarios are in policies/scenarios/puzzle-01-...json to puzzle-10-...json. Each names the request, the policy files that apply (identity, SCPs, RCPs, resource policy, boundary and session policy) and an expected answer. Open the file but look away from expected, and write down: Allow, ExplicitDeny or ImplicitDeny, and the one policy statement that decides it.
dotnet run --project src/Harbourline.Security.PolicyLinter -- evaluate policies/scenarios/puzzle-04-boundary-caps-identity.jsonThe command prints a trace and Decision: and exits with 0 if it matches expected (1 if it differs, 2 on a usage or parse error). To run all ten in Docker with the already built tool, use the same docker run as above with sh -c "for p in policies/scenarios/*.json; do dotnet run --project src/Harbourline.Security.PolicyLinter -- evaluate \$p; done".
The ten requests in short
| # | Situation | Layers in play |
|---|---|---|
| 1 | The Accounts API role reads an item from its own DynamoDB table | Identity policy, SCP full access |
| 2 | A developer with s3:* deletes an object in the audit-log bucket | Identity allow plus identity deny |
| 3 | A developer invokes a Lambda function in us-west-2 | Identity allow, SCP with a Region guardrail |
| 4 | A developer's identity policy allows secretsmanager:* | Identity policy and a permissions boundary |
| 5 | A developer with a read-only session tries s3:PutObject | Identity, boundary and session policy |
| 6 | The reporting account's role reads a statement from the workload account's bucket | Cross-account, bucket policy does not mention the role |
| 7 | The same role reads a report from the exports bucket | Cross-account, bucket policy names the role |
| 8 | A role in a partner's organisation calls kms:Decrypt on a Harbourline key | RCP and key policy |
| 9 | A role with no identity policy for KMS, but the key policy names it | Same-account resource policy grant |
| 10 | A security admin schedules a key deletion from a script with no MFA information | A BoolIfExists deny |
Confirm the tricky ones with the IAM policy simulator (optional)
For a puzzle you got wrong, or that surprised you, ask AWS. The simulator takes policy documents, an action, a resource and context keys:
# Policy 4: does the developer identity policy allow GetSecretValue? (No boundary here, so expect "allowed".)
aws iam simulate-custom-policy \
--policy-input-list file://policies/developer-identity.json \
--action-names secretsmanager:GetSecretValue \
--resource-arns "arn:aws:secretsmanager:us-east-1:111122223333:secret:hl-m05/accounts-api/blind-index-key-AbCdEf" \
--profile learn-sandbox
# Now add the boundary: the effective answer is the intersection, so it should be implicitDeny.
aws iam simulate-custom-policy \
--policy-input-list file://policies/developer-identity.json \
--permissions-boundary-policy-input-list file://policies/permission-boundary-developer.json \
--action-names secretsmanager:GetSecretValue \
--resource-arns "arn:aws:secretsmanager:us-east-1:111122223333:secret:hl-m05/accounts-api/blind-index-key-AbCdEf" \
--profile learn-sandboxRead EvalDecision in the JSON output (allowed, explicitDeny or implicitDeny). The --policy-input-list and --permissions-boundary-policy-input-list options exist on simulate-custom-policy; confirm option names with aws iam simulate-custom-policy help on your CLI version (⚠ VERIFY). The simulator does not model SCPs and RCPs the way a live organisation does for custom simulations, so for puzzles 3 and 8 trust the lesson and the evaluator's reasoning rather than the simulator (⚠ VERIFY current simulator coverage).
Part 3: the linter and the explainer (free)
Lint the bad policy
dotnet run --project src/Harbourline.Security.PolicyLinter -- lint policies/bad-wildcard-admin.jsonReal output from this build (verified 2026-11-18): the report ends FAIL (7 error(s)), with 12 findings in all. The errors are HL001 (full administrator, Action: "*"), HL003 (permissions-management actions on *), HL005 (iam:PassRole on *, twice) and HL007 (kms:Decrypt on every key, twice). The warnings are HL002 (kms:*), HL003 (write actions on *), HL008 (no Version) and HL009 (sensitive actions without an MFA condition, twice).
Read each finding and its Fix: line. Notice that one statement, Action: "*", trips several rules at once, because * includes iam:PassRole, kms:Decrypt and everything else.
List the rules and lint the good policies
dotnet run --project src/Harbourline.Security.PolicyLinter -- rules
dotnet run --project src/Harbourline.Security.PolicyLinter -- lint policies/good-accounts-api-read.json
dotnet run --project src/Harbourline.Security.PolicyLinter -- lint policies/bucket-policy-tls-only.json --kind resource
dotnet run --project src/Harbourline.Security.PolicyLinter -- lint policies/scp-deny-outside-regions.json --kind scprules prints HL001 to HL011. The good identity policy and the TLS-only bucket policy report 0 finding(s) and PASS. The SCP reports one Info finding (HL001) for FullAWSAccess, with the note that this is normal for a guardrail, because the restriction is carried by the Deny statement. The --kind option takes identity, resource, trust, boundary, scp, rcp or session, and changes how some rules apply (a wildcard allow is expected in an SCP).
Explain a policy in words
dotnet run --project src/Harbourline.Security.PolicyLinter -- explain policies/permission-boundary-developer.jsonThe output (verified) is two lines: CapAtApplicationServices allows five actions (s3:*, dynamodb:*, lambda:*, logs:*, sqs:*) on all resources, and NoBoundaryRemoval denies two actions (iam:DeleteRolePermissionsBoundary, iam:DeleteUserPermissionsBoundary) and adds "An explicit deny overrides any allow in any policy." Use explain on the good Accounts API policy too: its KMS statement is described as allowed "only when at least one value of kms:EncryptionContextKeys equals customer_id".
Part 4: permissions boundaries (Lab 5.2, free)
The problem: a platform team wants developers to create their own application roles, without waiting for a ticket, but never to create a role more powerful than they are. The tool for that is a permissions boundary plus a delegated policy that only allows CreateRole when the boundary is attached.
Read the boundary
policies/permission-boundary-developer.json caps anything it is attached to at five application services, and denies removing a boundary. The developer's identity policy (developer-identity.json) is far broader: it allows six services including Secrets Manager. The boundary is why puzzle 4 returns implicit deny: the effective permission for Secrets Manager is the intersection of "allowed by identity" and "allowed by boundary", which is nothing.
Write the delegated role-creation policy
Create policies/role-creator.json in your copy of the lab (your own file, not part of the original folder). It allows creating and modifying application roles only when the new role carries the boundary:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CreateRolesOnlyWithTheBoundary",
"Effect": "Allow",
"Action": ["iam:CreateRole", "iam:PutRolePolicy", "iam:AttachRolePolicy"],
"Resource": "arn:aws:iam::111122223333:role/hl-m05-app-*",
"Condition": {
"StringEquals": { "iam:PermissionsBoundary": "arn:aws:iam::111122223333:policy/hl-m05-developer-boundary" }
}
},
{
"Sid": "DenyBoundaryRemoval",
"Effect": "Deny",
"Action": ["iam:DeleteRolePermissionsBoundary", "iam:DeleteUserPermissionsBoundary"],
"Resource": "*"
}
]
}The role-name prefix hl-m05-app- limits which roles the developer can touch, so they cannot edit the platform team's roles. Whether iam:PermissionsBoundary is honoured as a request condition for PutRolePolicy and AttachRolePolicy exactly as shown should be confirmed in the policy simulator and the IAM documentation (⚠ VERIFY). The standard documented pattern uses it for CreateRole and the permissions-boundary actions.
Test it with four scenarios
Create four scenario files next to your policy (copy the structure of a puzzle file; policy paths are relative to the scenario file). The request is iam:CreateRole on arn:aws:iam::111122223333:role/hl-m05-app-orders by hl-m05-developer. Change only the context and the action:
| Scenario | Context | Predicted | Why |
|---|---|---|---|
| A | iam:PermissionsBoundary is the boundary policy ARN | Allow | The condition matches the only allow |
| B | No iam:PermissionsBoundary key at all | ImplicitDeny | StringEquals on an absent key is false, so the allow does not apply |
| C | iam:PermissionsBoundary is some other policy ARN | ImplicitDeny | The condition does not match |
| D | Action iam:DeleteRolePermissionsBoundary | ExplicitDeny | The deny statement matches |
Verified in this build: these four scenarios, run with hl-policy evaluate, gave Allow, ImplicitDeny, ImplicitDeny and ExplicitDeny, and the linter reported one warning (HL009: sensitive IAM actions without an MFA condition) and PASS (no errors) for role-creator.json. Adding an MFA condition is Exercise 🟡.
Why the boundary is not enough on its own
A boundary caps what a role can do. It does not stop that role from creating another role without a boundary, unless the identity policy that allows iam:CreateRole insists on one. That is exactly what the Condition above does, and why the deny on removing boundaries exists. Escalation needs both pieces: the cap, and the rule that every role the developer creates carries the cap.
AWS Console instructions
- IAM policy simulator: open the IAM Policy Simulator (search "IAM Policy Simulator" in the console), choose a role or paste a custom policy, pick the service and action, fill in resource ARN and context keys, and run. Console wording changes over time (⚠ VERIFY).
- See a boundary: Console → IAM → Roles → your role → Permissions tab → Permissions boundary.
- See organisation policies (management account only): Console → AWS Organizations → Policies → Service control policies and Resource control policies.
AWS CLI
# Look up the boundary attached to a role (a role created with one shows PermissionsBoundary).
aws iam get-role --role-name hl-m05-app-orders --query "Role.PermissionsBoundary" --profile learn-sandbox
# Create a role WITH the boundary (what the delegated policy permits). Replace the account id.
aws iam create-role --role-name hl-m05-app-orders \
--assume-role-policy-document file://trust-lambda.json \
--permissions-boundary arn:aws:iam::<account-id>:policy/hl-m05-developer-boundary \
--tags Key=Project,Value=cea-lab Key=Lab,Value=m05-policies Key=Environment,Value=learn Key=Owner,Value=you \
--profile learn-sandboxYou do not need to create AWS resources for the labs above. The two commands above are optional, to see the real behaviour in a sandbox account. If you run them, delete the role and the policy afterwards (see Cost and cleanup).
Infrastructure as Code
Boundaries and delegated policies are small enough to write directly. The Terraform below creates the boundary policy from the lab file, and a role that carries it.
resource "aws_iam_policy" "developer_boundary" {
name = "hl-m05-developer-boundary"
policy = file("${path.module}/../../policies/permission-boundary-developer.json")
}
resource "aws_iam_role" "app" {
name = "hl-m05-app-orders"
permissions_boundary = aws_iam_policy.developer_boundary.arn
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = { Service = "lambda.amazonaws.com" }
Action = "sts:AssumeRole"
}]
})
}These snippets are illustrative and were not applied or synthesised in this build (⚠ VERIFY against your Terraform AWS provider and CDK versions; for CDK in C# also remember Amazon.CDK.Tags.Of(this) inside a Stack, and that cdk-nag 3.x uses Validations.Of(...).Acknowledge(...) with exact finding IDs, not the removed suppression API).
Complete code
The evaluator is in src/Harbourline.Security.PolicyLinter/PolicyEvaluator.cs, condition handling in ConditionEvaluator.cs, lint rules in PolicyLinter.cs, the scenario loader in Scenario.cs and the command line in Program.cs. The scenario file format is the one worth knowing, because you will write your own:
{
"description": "Puzzle 4: the developer's identity policy allows secretsmanager:*, but the permissions boundary does not list Secrets Manager.",
"request": {
"principalArn": "arn:aws:sts::111122223333:assumed-role/hl-m05-developer/alex",
"principalRoleArn": "arn:aws:iam::111122223333:role/hl-m05-developer",
"action": "secretsmanager:GetSecretValue",
"resource": "arn:aws:secretsmanager:us-east-1:111122223333:secret:hl-m05/accounts-api/blind-index-key-AbCdEf",
"context": { "aws:RequestedRegion": "us-east-1" }
},
"identityPolicies": ["../developer-identity.json"],
"scps": ["../scp-full-access.json"],
"permissionBoundary": "../permission-boundary-developer.json",
"expected": "ImplicitDeny"
}And the trickiest policy in the set, the MFA guard from puzzle 10:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "SecurityAdminTasks",
"Effect": "Allow",
"Action": ["kms:ScheduleKeyDeletion", "kms:DisableKey", "kms:DescribeKey"],
"Resource": "arn:aws:kms:us-east-1:111122223333:key/*"
},
{
"Sid": "DenyDestructiveKeyActionsWithoutMfa",
"Effect": "Deny",
"Action": ["kms:ScheduleKeyDeletion", "kms:DisableKey"],
"Resource": "*",
"Condition": { "BoolIfExists": { "aws:MultiFactorAuthPresent": "false" } }
}
]
}Code explained line by line
"principalArn"is the session ARN (an assumed-role session);"principalRoleArn"is the role itself. Resource policies that name a role match the role ARN, not the session ARN."resourceAccount"(optional) tells the evaluator the resource lives in another account. Without it the request is treated as same-account. In puzzles 6 and 7 the principal is in444455556666and the resource in111122223333, so both the bucket policy and the identity policy must allow."context"supplies condition keys. An absent key is not the same as a key with valuefalse. That difference decides puzzle 10 and the lab's lint rule HL010."scps"is a list, one entry per level of the organisation hierarchy. Every level must allow, which is why puzzle 3 has two entries: an allow-all and the Region guardrail. The evaluator's trace says "SCP level 2" when the second one denies."rcps"works the same for resource guardrails. Puzzle 8's RCP denies when the principal'saws:PrincipalOrgIDis not the bank's organisation."expected"is optional. When present, the command exits 0 on a match and 1 on a difference, which is what makes the puzzles testable in CI.- In
admin-with-mfa-guard.json,BoolIfExistsmeans: "the condition is true when the key is absent or when it is present and equalsfalse". A script using long-term keys sends no MFA information, so the Deny fires. A plainBoolwould not match an absent key, and the guard would silently let the script through. The lint rule HL010 warns about exactly that.
Security considerations
⚠ Learning shortcut — not for production
hl-policy evaluate is a teaching model. It does not model every IAM feature (service-linked roles, VPC endpoint policies, all condition operators and edge cases, resource-based policies on every service, policy variables in all positions). Never approve a production policy change because the offline tool said Allow or Deny. Use the IAM policy simulator, IAM Access Analyzer policy validation and custom policy checks, and a sandbox account that mirrors production guardrails.
- Least privilege is a process. Start narrow, then widen with evidence from CloudTrail and Access Analyzer. The lint rules are a net for the worst patterns, not a proof of least privilege.
- Never rely on a boundary alone. The
Conditiononiam:CreateRoleand the deny on boundary removal are what make it effective. - Guard destructive actions.
kms:ScheduleKeyDeletionshould need MFA (via an Identity Center permission set or a condition) and should usually be limited to a security role. - Region guardrails use
NotActioncarefully: global services (iam:*,sts:*,organizations:*,route53:*,cloudfront:*,support:*,budgets:*) have no Region and must be excluded or the SCP would break them. - Fictional data only. Account IDs
111122223333,444455556666and777788889999are made up. Do not paste real policies from your employer into any tool or page. - This lab does not make anything compliant. It trains a skill.
Banking use case
A payments platform team lets product teams create their own Lambda execution roles. The delegated policy only allows iam:CreateRole for names starting with the team's prefix and only when the standard boundary is attached; the boundary caps those roles at DynamoDB, SQS, Lambda and CloudWatch Logs; an SCP denies any action outside two approved Regions; and an RCP prevents principals from outside the bank's organisation from reading any bucket or key, even if a team misconfigures a resource policy. When a team asks "why can't my role read this secret?", an engineer predicts the answer from the policies in two minutes and confirms it in the simulator.
Common mistakes
- Thinking an SCP grants permissions. It does not. A full-access SCP changes nothing on its own (puzzle 1's Step 3 says "grants nothing by itself").
- Forgetting the other side of a cross-account grant (puzzle 6).
- Using
BoolwhereBoolIfExistsis needed for "deny unless MFA" (puzzle 10). - Assuming a resource policy needs an identity policy too. Within one account, a resource policy that names a role can grant on its own (puzzle 9). Across accounts, it cannot.
- Putting a boundary on a role and forgetting that the identity policy still has to grant. The boundary only caps.
- Writing
Resource: "*"oniam:PassRole. This is the classic privilege-escalation path (HL005). - Trusting your prediction without a trace. Read the numbered steps. If your reasoning skipped a step, find which.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Output differs from your prediction | Usually a missing-key condition rule (IfExists, negated operators), or a cross-account side you forgot | Read the trace step by step; confirm with the IAM policy simulator |
error: ... and exit code 2 | The JSON is invalid, a relative policy path is wrong, or --kind is unknown | Policy paths are relative to the scenario file; kinds are identity, resource, trust, boundary, scp, rcp, session |
DIFFERS from expected answer | Your edited policy changed the result, or your expected is wrong | Decide which is right, then fix the policy or the expectation and run the tests |
Simulator says implicitDeny for something you expect to be allowed | A required context key is not supplied (for example aws:SecureTransport) | Add the key in the simulator's context section |
dotnet run is slow in Docker | The first build downloads packages | Build once with dotnet build -c Release and reuse the container, or use the local SDK |
PolicyTests fail after you edited a puzzle | The test enforces ten puzzles with matching expected | Restore the file, or update expected and the lesson that quotes it |
Cost and cleanup
Cost: free. The offline tool uses no AWS. The simulator has no charge. If you created the optional role and boundary policy in the sandbox account:
aws iam delete-role --role-name hl-m05-app-orders --profile learn-sandbox
aws iam delete-policy --policy-arn arn:aws:iam::<account-id>:policy/hl-m05-developer-boundary --profile learn-sandbox
# Remove local build output
find labs/m05-secure-banking-api -type d \( -name bin -o -name obj -o -name TestResults \) -prune -exec rm -rf {} +You may need to detach or delete the role's policies before delete-role succeeds.
Exercises
- 🟢 Guided: predict all ten puzzles on paper, run them, and record each mismatch with the step that decided it. Then run the linter on
bad-wildcard-admin.jsonand fix the policy untillintpasses with no errors. - 🟡 Challenge: extend
role-creator.jsonso thatiam:CreateRolealso requires MFA (Boolonaws:MultiFactorAuthPresentistrue) and so thatiam:PassRoleis allowed only for the application roles and only tolambda.amazonaws.com(iam:PassedToService). Write scenarios for MFA present, MFA absent and the wrong service, and predict each before running. - 🔴 Live problem: a ticket reads: "The reporting job in account 4444… gets
AccessDeniedreading a CSV from the exports bucket since Tuesday. It worked last month. Nobody changed the role." The bucket is in account 1111…. Using only the policy files the team gives you and the evaluator, list every policy layer that could have changed (bucket policy, role policy, SCP, RCP, key policy if the object uses SSE-KMS), say how you would tell which one did, and write the first three CloudTrail or simulator checks you would run.
Assignment
Add two new puzzles to the lab (puzzles 11 and 12) that each teach a different rule. One must involve a session policy that makes a request allowed only because the session policy and boundary overlap; the other must use an RCP or SCP with a condition. Provide the scenario JSON, the policy files, a one-paragraph explanation of the intended lesson, and make the test suite count them (update the count test). Add a short README section "How to add a puzzle". Keep it in your portfolio repository.
Solutions
| # | Answer | Deciding step |
|---|---|---|
| 1 | Allow | good-accounts-api-read.json statement ReadAccountsTable allows dynamodb:GetItem. The SCP is an allow-all guardrail: it permits but grants nothing |
| 2 | ExplicitDeny | NeverTouchProductionLogs denies s3:DeleteObject on hl-m05-audit-logs-*. The broad s3:* allow cannot override it |
| 3 | ExplicitDeny | The Region SCP (level 2) denies everything outside us-east-1 and eu-west-2 except global services |
| 4 | ImplicitDeny | Identity allows it, but the boundary lists no Secrets Manager action. Effective permissions are the intersection |
| 5 | ImplicitDeny | Identity and boundary allow s3:PutObject, but the read-only session policy does not |
| 6 | ImplicitDeny | Cross-account needs both sides. The bucket policy (TLS-only plus a same-account reader) never names the reporting role |
| 7 | Allow | The bucket policy names the reporting role for s3:GetObject under reports/*, and the role's identity policy allows it |
| 8 | ExplicitDeny | The RCP denies principals whose aws:PrincipalOrgID is not the bank's organisation, even though the key policy would allow |
| 9 | Allow | The key policy names the role directly for kms:Decrypt; in the same account a resource policy can grant by itself |
| 10 | ExplicitDeny | BoolIfExists matches the absent MFA key, so the deny fires |
Add "Bool": { "aws:MultiFactorAuthPresent": "true" } alongside the StringEquals in the allow's Condition (all operators in a condition block must be true). Add a second allow for iam:PassRole with Resource set to arn:aws:iam::111122223333:role/hl-m05-app-* and "StringEquals": { "iam:PassedToService": "lambda.amazonaws.com" }. Scenarios: MFA true with the right boundary gives Allow; MFA absent gives ImplicitDeny (the Bool is false on an absent key); iam:PassedToService set to ec2.amazonaws.com gives ImplicitDeny. Remember that console users in Identity Center sessions carry MFA information while scripts using long-term keys carry none.
Layers to check, in order of "most likely to change without anyone touching the role": (1) an SCP or RCP change in AWS Organizations (a new Region guardrail, a new org-only RCP, or the reporting account moved to another OU); (2) the bucket policy (a change that removed the role from the principal list or added a deny); (3) the KMS key policy if the objects use SSE-KMS (cross-account key use needs the key policy to allow the role too); (4) the role's identity policy or boundary; (5) a session policy if the job assumes the role with one. First checks: aws cloudtrail lookup-events for PutBucketPolicy, PutKeyPolicy and AttachPolicy events (and Organizations policy events) since the last good run; the full AccessDenied event in CloudTrail, whose error message often names the kind of policy that denied; and an IAM Access Analyzer or simulator run with the real principal, action and resource. Record each check and its result in the ticket.
Knowledge check
Answer: Nothing. An SCP never grants. Without an identity or resource policy that grants, the result is implicit deny.
Answer: Yes, as long as nothing denies it and the caps (boundary, session policy) do not block it. A same-account resource policy that names the principal can grant by itself. Across accounts the identity side would also need to allow.
Answer: s3:GetObject. The boundary and the identity policy must both allow, so the result is the intersection.
Answer: A script using long-term access keys sends no MFA information, so the key is absent from the context. Bool on an absent key evaluates to false, so the deny does not fire. BoolIfExists treats an absent key as a match.
Answer: The developer could create a new role without a boundary. The identity policy that allows iam:CreateRole must require the boundary through iam:PermissionsBoundary, and boundary removal must be denied.
Interview questions
- "Walk me through how IAM decides a request." Gather the policies; any explicit deny wins; organisation guardrails (RCP, SCP) must allow; a resource or identity policy must grant (both, across accounts); a boundary and session policy cap the result; otherwise implicit deny.
- "What is the difference between an SCP and a permissions boundary?" An SCP applies to every principal in an account or OU, set by the organisation. A boundary applies to one user or role, set in IAM. Neither grants anything.
- "How do you let developers create roles safely?" A delegated policy that requires a permissions boundary on every role they create, a name-prefix limit, a deny on boundary removal, and a boundary that caps them at the services they need.
- "How would you check a change before production?" Policy validation and custom policy checks in IAM Access Analyzer, the simulator, a sandbox account that mirrors guardrails, and CloudTrail review after.
Certification practice
A developer's role has an identity policy that allows secretsmanager:GetSecretValue on all secrets and a permissions boundary that allows only s3:* and dynamodb:*. An SCP allows all actions. What happens when the developer calls GetSecretValue?
A. Allowed, because the identity policy allows it. B. Allowed, because the SCP allows everything. C. Denied, because the boundary does not allow the action. D. Denied, because an SCP cannot allow actions.
Answer: C. The effective permissions are the intersection of the identity policy and the boundary, and the boundary does not list Secrets Manager. A ignores the boundary. B treats the SCP as a grant. D is incorrect reasoning: the SCP allows the action as a guardrail but cannot grant it.
An application in account A must read objects from an S3 bucket in account B. The role in account A has an identity policy allowing s3:GetObject on the bucket. Requests are denied. What is the MOST likely missing piece?
A. A bucket policy in account B granting the role in account A access. B. A larger instance size. C. An internet gateway in account B. D. A permissions boundary in account A.
Answer: A. Cross-account access needs both the caller's identity policy and the resource owner's policy to allow. B and C are irrelevant. D would only restrict, not grant.
A policy denies kms:ScheduleKeyDeletion when Bool: aws:MultiFactorAuthPresent is false. An operator runs the call from a script with long-term access keys and it succeeds. What change fixes the policy?
A. Change Bool to BoolIfExists.
B. Change Deny to Allow.
C. Remove the condition.
D. Add kms:* to the allow.
Answer: A. The key is absent for credentials without MFA, and Bool does not match an absent key. BoolIfExists does. B inverts the intent. C would deny everyone (including MFA users). D grants more and does not address the missing key.
Completion checklist
- I ran the tests and saw
total: 72, succeeded: 71, skipped: 1 - I predicted all ten puzzles before running them and recorded my misses
- I linted the bad policy and understood each finding
- I wrote and tested the delegated role-creation policy with four scenarios
- I know where the offline evaluator is a simplification
- I deleted
bin/andobj/and removed any optional sandbox role and policy
Key takeaways
- Explicit deny always wins; guardrails (SCP, RCP) only cap; boundaries and session policies only cap; someone must grant.
- Cross-account needs two allows. Same-account can be one.
- An absent condition key is not a
falsekey. Use...IfExistsdeliberately. - A boundary helps only when the policy that lets people create roles insists on it.
- Offline tools build intuition; the simulator and a sandbox account are the authority.
Further reading
Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.
Federation and segregation of duties
Connect Microsoft Entra ID or Active Directory to IAM Identity Center, federate CI/CD pipelines with OIDC, use attributes for access control, and design roles that separate building, approving, deploying and auditing.
AWS KMS: keys, key policies and envelope encryption
Create and govern customer managed KMS keys for a bank: key policies, grants, encryption context, envelope encryption from .NET, rotation, multi-Region keys, quotas, pricing and safe deletion.