📖 Scenario: You are managing access control in an Azure subscription. You want to create a custom role that allows users to read virtual machines and start them, but not delete or modify other resources.
🎯 Goal: Create a custom role definition JSON that grants read and start permissions on virtual machines only.
📋 What You'll Learn
Create a JSON object named customRole with the required properties for a custom role definition.
Include Name, Description, Actions, NotActions, AssignableScopes properties.
Grant read and start permissions on virtual machines using the correct Azure resource provider actions.
Assign the role to the scope of the subscription /subscriptions/12345678-1234-1234-1234-123456789abc.
💡 Why This Matters
🌍 Real World
Custom roles allow precise control over who can do what in your Azure environment, improving security and compliance.
💼 Career
Cloud administrators and security engineers often create and manage custom roles to enforce least privilege access.
Progress0 / 4 steps
1
Create the basic custom role structure
Create a JSON object called customRole with the properties Name set to "VM Reader and Starter" and Description set to "Can read and start virtual machines".
Azure
Hint
Start by defining the Name and Description properties inside the JSON object.
2
Add the Actions and NotActions properties
Add the Actions property as a list containing "Microsoft.Compute/virtualMachines/read" and "Microsoft.Compute/virtualMachines/start/action". Add an empty list for NotActions.
Azure
Hint
Use the exact action strings for reading and starting virtual machines inside the Actions list.
3
Add the AssignableScopes property
Add the AssignableScopes property as a list containing the subscription scope string "/subscriptions/12345678-1234-1234-1234-123456789abc".
Azure
Hint
Use the exact subscription ID string inside the AssignableScopes list.
4
Add the final properties for a valid custom role
Add the Type property set to "CustomRole" and the Id property set to null to complete the custom role definition JSON.
Azure
Hint
These properties are required for Azure to recognize the JSON as a custom role definition.
Practice
(1/5)
1. What is the main purpose of creating a custom role definition in Azure?
easy
A. To tailor permissions exactly to specific needs
B. To delete all existing roles in Azure
C. To automatically assign roles to all users
D. To create virtual machines quickly
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 A
Quick Check:
Custom roles = tailored permissions [OK]
Hint: Custom roles = tailor permissions to your needs [OK]
Common Mistakes:
Thinking custom roles delete existing roles
Assuming custom roles auto-assign to all users
Confusing custom roles with VM creation
2. Which JSON property is required to specify the permissions allowed in a custom role definition?
easy
A. "NotActions"
B. "Actions"
C. "allowedActions"
D. "permissions"
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 B
Quick Check:
Allowed permissions = "Actions" [OK]
Hint: Allowed permissions are under "Actions" in JSON [OK]
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 D
Quick Check:
Action includes "read" = read access [OK]
Hint: Look for "read" in actions for read-only permission [OK]
Common Mistakes:
Assuming full control from read action
Confusing read with write permissions
Ignoring empty NotActions meaning no exclusions
4. You created a custom role but users report they cannot perform allowed actions. Which is the most likely error in the role definition?
medium
A. Role description is missing
B. "Actions" property is missing or empty
C. "NotActions" includes the same actions as "Actions"
D. Role name is too long
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 C
Quick Check:
Conflicting "NotActions" denies permissions [OK]
Hint: "NotActions" overrides "Actions" if overlapping [OK]
Common Mistakes:
Ignoring "NotActions" effect
Thinking role name or description affects permissions
Assuming missing "Actions" is common
5. You want to create a custom role that allows users to start and stop virtual machines but denies deleting them. Which JSON snippet correctly defines this?
hard
A. { "Actions": ["Microsoft.Compute/virtualMachines/*"], "NotActions": ["Microsoft.Compute/virtualMachines/delete"] }
B. { "Actions": ["Microsoft.Compute/virtualMachines/start"], "NotActions": ["Microsoft.Compute/virtualMachines/delete"] }
C. { "Actions": ["Microsoft.Compute/virtualMachines/start", "Microsoft.Compute/virtualMachines/delete"], "NotActions": [] }
D. { "Actions": ["Microsoft.Compute/virtualMachines/delete"], "NotActions": ["Microsoft.Compute/virtualMachines/start"] }
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.