You can create a custom role in Azure by using the Azure portal, Azure CLI, or Azure PowerShell.
Using the Azure Portal
- Navigate to the Azure portal: Log in to the Azure portal and search for "Role assignments".
- Click on "Role assignments": You'll be taken to the role assignments page.
- Click on "Add role assignment": This will open a new window where you can create a new role assignment.
- Select the scope: Choose the scope for the role assignment. This could be a resource group, subscription, or management group.
- Select the role: Choose the built-in role or select "Custom role" to create a new custom role.
- Define the permissions: Specify the permissions that you want to assign to the custom role. You can choose from a list of available actions, or you can define custom permissions.
- Name the custom role: Give your custom role a descriptive name.
- Click "Create": This will create the custom role and assign it to the selected scope.
Using Azure CLI
- Open Azure Cloud Shell: Launch Azure Cloud Shell in your browser.
- Use the
az role definition create
command: This command creates a new custom role. - Provide the required information: You'll need to provide the following information:
--name
: The name of the custom role.--role-type
: The type of role, which is always "CustomRole" for custom roles.--description
: A description of the custom role.--permissions
: The permissions that you want to assign to the custom role. You can specify actions, data actions, or not actions.
Example:
az role definition create --name "MyCustomRole" --role-type CustomRole --description "My custom role description" --permissions "Microsoft.Storage/storageAccounts/read"
Using Azure PowerShell
- Connect to Azure: Connect to your Azure subscription using Azure PowerShell.
- Use the
New-AzRoleDefinition
cmdlet: This cmdlet creates a new custom role. - Provide the required information: You'll need to provide the following information:
Name
: The name of the custom role.RoleType
: The type of role, which is always "CustomRole" for custom roles.Description
: A description of the custom role.Permissions
: The permissions that you want to assign to the custom role. You can specify actions, data actions, or not actions.
Example:
New-AzRoleDefinition -Name "MyCustomRole" -RoleType CustomRole -Description "My custom role description" -Permissions "Microsoft.Storage/storageAccounts/read"
Practical Insights
- Use custom roles to control access to Azure resources: You can use custom roles to restrict access to specific resources or actions.
- Create roles for specific tasks: You can create custom roles for different tasks, such as managing virtual machines, deploying applications, or monitoring resources.
- Simplify role management: Custom roles can help you simplify role management by grouping permissions together.