Custom role definitions in Azure - Time & Space Complexity
When creating custom role definitions in Azure, it's important to understand how the time to create or update roles changes as you add more permissions.
We want to know how the number of permissions affects the time it takes to manage these roles.
Analyze the time complexity of defining a custom role with multiple permissions.
// Define a custom role with a list of permissions
az role definition create --role-definition '{
"Name": "CustomRole",
"Description": "Role with specific permissions",
"Actions": ["Microsoft.Compute/virtualMachines/start/action", "Microsoft.Storage/storageAccounts/read", "..."],
"AssignableScopes": ["/subscriptions/xxxx-xxxx-xxxx"]
}'
This sequence creates a custom role by specifying a list of allowed actions (permissions).
Look at what happens repeatedly when creating or updating a role with many permissions.
- Primary operation: Processing each permission in the Actions list to validate and store it.
- How many times: Once per permission in the list.
As you add more permissions, the system checks and stores each one individually.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | About 10 permission checks and stores |
| 100 | About 100 permission checks and stores |
| 1000 | About 1000 permission checks and stores |
Pattern observation: The time grows roughly in direct proportion to the number of permissions.
Time Complexity: O(n)
This means the time to create or update a custom role grows linearly with the number of permissions you include.
[X] Wrong: "Adding more permissions won't affect the time much because it's just one role creation call."
[OK] Correct: Each permission must be processed individually, so more permissions mean more work behind the scenes.
Understanding how the number of permissions affects role creation time helps you design efficient access controls and shows you can think about system behavior as it scales.
What if we batch multiple role definitions in one request? How would the time complexity change?
Practice
Solution
Step 1: Understand role customization
Custom roles allow you to specify exactly which permissions are granted or denied, unlike built-in roles which are fixed.Step 2: Identify the purpose of custom roles
They help tailor permissions to fit specific needs, improving security and control.Final Answer:
To tailor permissions exactly to specific needs -> Option AQuick Check:
Custom roles = tailored permissions [OK]
- Thinking custom roles delete existing roles
- Assuming custom roles auto-assign to all users
- Confusing custom roles with VM creation
Solution
Step 1: Review custom role JSON structure
The property "Actions" lists the allowed operations in the role definition.Step 2: Differentiate from other properties
"NotActions" lists denied permissions, "permissions" is a container but not the direct property, and "allowedActions" is not a valid property.Final Answer:
"Actions" -> Option BQuick Check:
Allowed permissions = "Actions" [OK]
- Using "allowedActions" which is invalid
- Confusing "NotActions" with allowed permissions
- Mistaking "permissions" as direct actions list
{
"Name": "Storage Reader",
"Actions": ["Microsoft.Storage/storageAccounts/read"],
"NotActions": []
}
What permission does this role grant?Solution
Step 1: Analyze the "Actions" property
The action "Microsoft.Storage/storageAccounts/read" grants read-only access to storage accounts.Step 2: Check "NotActions" property
It is empty, so no permissions are excluded.Final Answer:
Read access to storage accounts -> Option DQuick Check:
Action includes "read" = read access [OK]
- Assuming full control from read action
- Confusing read with write permissions
- Ignoring empty NotActions meaning no exclusions
Solution
Step 1: Understand "NotActions" effect
"NotActions" excludes permissions even if listed in "Actions".Step 2: Identify conflict in permissions
If "NotActions" includes the same actions as "Actions", those permissions are denied, causing users to lack access.Final Answer:
"NotActions" includes the same actions as "Actions" -> Option CQuick Check:
Conflicting "NotActions" denies permissions [OK]
- Ignoring "NotActions" effect
- Thinking role name or description affects permissions
- Assuming missing "Actions" is common
Solution
Step 1: Identify required permissions
Users need to start and stop VMs, so all VM actions except delete are allowed.Step 2: Check each option
{ "Actions": ["Microsoft.Compute/virtualMachines/*"], "NotActions": ["Microsoft.Compute/virtualMachines/delete"] } allows all VM actions with "*" but denies delete explicitly, matching requirements perfectly.Step 3: Eliminate incorrect options
{ "Actions": ["Microsoft.Compute/virtualMachines/start"], "NotActions": ["Microsoft.Compute/virtualMachines/delete"] } misses stop (deallocate) action; { "Actions": ["Microsoft.Compute/virtualMachines/start", "Microsoft.Compute/virtualMachines/delete"], "NotActions": [] } allows delete; { "Actions": ["Microsoft.Compute/virtualMachines/delete"], "NotActions": ["Microsoft.Compute/virtualMachines/start"] } denies start but allows delete.Final Answer:
{ "Actions": ["Microsoft.Compute/virtualMachines/*"], "NotActions": ["Microsoft.Compute/virtualMachines/delete"] } -> Option AQuick Check:
Allow all except delete = Actions with * and NotActions delete [OK]
- Missing stop (deallocate) action
- Allowing delete action by mistake
- Denying start action instead of delete
Ready to prove it?
Pass the test and this pattern moves unknown
