IAM deny policies in GCP - Time & Space Complexity
We want to understand how the time to evaluate IAM deny policies changes as we add more policies or rules.
Specifically, how does checking permissions grow when there are many deny rules?
Analyze the time complexity of evaluating deny policies during an access request.
// Pseudocode for IAM deny policy evaluation
for each denyPolicy in denyPolicies:
for each denyRule in denyPolicy.rules:
if denyRule matches request:
deny access
allow access if no deny rules matched
This sequence checks all deny rules in all deny policies to decide if access should be denied.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Checking each deny rule against the access request.
- How many times: Once for every deny rule in all deny policies.
As the number of deny rules increases, the system must check more rules one by one.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 rule checks |
| 100 | 100 rule checks |
| 1000 | 1000 rule checks |
Pattern observation: The number of checks grows directly with the number of deny rules.
Time Complexity: O(n)
This means the time to evaluate deny policies grows linearly with the number of deny rules.
[X] Wrong: "Adding more deny policies won't affect evaluation time much because they run in parallel."
[OK] Correct: In reality, all deny rules must be checked one after another, so more rules mean more checks and longer evaluation time.
Understanding how deny policies scale helps you design secure and efficient access controls in cloud environments.
"What if deny rules were grouped and checked using a fast lookup instead of one by one? How would the time complexity change?"
Practice
Solution
Step 1: Understand IAM deny policy function and compare with other policy types
An IAM deny policy explicitly blocks permissions, overriding any allow policies. Unlike allow policies that grant access, deny policies prevent actions even if allowed elsewhere.Final Answer:
To explicitly block certain permissions even if other policies allow them -> Option CQuick Check:
IAM deny policy blocks permissions [OK]
- Confusing deny policies with allow policies
- Thinking deny policies grant permissions
- Assuming deny policies only monitor actions
Solution
Step 1: Identify correct deny rule syntax and check each option
Deny rules use "denyRules" with "deniedPermissions" as a list of strings. "denyRules": [{"deniedPermissions": ["storage.buckets.delete"]}] correctly uses a list for "deniedPermissions". "allowRules": [{"allowedPermissions": ["storage.buckets.delete"]}] uses allowRules, which is incorrect. "denyRules": [{"allowedPermissions": ["storage.buckets.delete"]}] mixes denyRules with allowedPermissions, which is invalid. "denyRules": [{"deniedPermissions": "storage.buckets.delete"}] uses a string instead of a list, which is invalid.Final Answer:
"denyRules": [{"deniedPermissions": ["storage.buckets.delete"]}] -> Option AQuick Check:
Deny rules need deniedPermissions as list [OK]
- Using allowRules instead of denyRules
- Providing deniedPermissions as a string instead of list
- Mixing allowedPermissions inside denyRules
{"denyRules": [{"deniedPermissions": ["compute.instances.start"]}]}What happens if a user has an allow policy for
compute.instances.start but this deny policy is applied?Solution
Step 1: Understand deny policy precedence and apply to the example
Deny policies always override allow policies for the specified permissions. Even if the user has an allow for starting instances, the deny rule blocks it.Final Answer:
The user cannot start instances because deny policies block the permission -> Option DQuick Check:
Deny overrides allow for blocked permissions [OK]
- Thinking allow policies override deny policies
- Assuming deny policies need conditions to work
- Believing deny policies only log actions
{"denyRules": [{"deniedPermissions": "storage.objects.delete"}]}What is the error?
Solution
Step 1: Check deniedPermissions data type and identify the error in the JSON
deniedPermissions must be a list of strings, not a single string. The policy uses a string instead of a list, so it is invalid and won't block the permission.Final Answer:
deniedPermissions should be a list, not a string -> Option BQuick Check:
deniedPermissions requires a list [OK]
- Using string instead of list for deniedPermissions
- Confusing denyRules with allowRules
- Thinking conditions are mandatory
storage.buckets.delete only for requests made after 2024-01-01T00:00:00Z. Which IAM deny policy condition should you use?Solution
Step 1: Identify the condition to restrict by time and match condition syntax
To deny only for requests after the date, use a condition checking request.time > '2024-01-01T00:00:00Z'. Use a condition withrequest.time > '2024-01-01T00:00:00Z'uses request.time with inequality to apply after the date, which is correct.Final Answer:
Use a condition withrequest.time > '2024-01-01T00:00:00Z'-> Option AQuick Check:
Condition on request.time restricts deny by time [OK]
- Using resource.name instead of request.time for time check
- Using IP condition unrelated to time
- Applying deny without condition blocks all users
Ready to prove it?
Pass the test and this pattern moves unknown
