Roles
๐ Azure Roles and Role-Based Access Control (RBAC)¶
In Azure, roles are used to manage access control by defining what actions users, groups, or applications can perform on specific resources. Azure implements Role-Based Access Control (RBAC) to achieve this.
๐ง Key Concepts¶
-
Role Definition :
A set of permissions that determine what actions can be performed.
Examples:-
Owner: Full access, including access management -
Contributor: Create/manage resources, but cannot grant access -
Reader: View-only access
-

-
Role Assignment
A binding between a role definition, a security principal (user, group, service principal), and a scope. -
Scope
Defines where access applies:-
Management Group
-
Subscription
-
Resource Group
-
Individual Resource
-
๐งพ Types of Azure Roles¶
-
Built-in Roles (Predefined by Microsoft)
-
Owner: Full control, including permissions assignment -
Contributor: Manage resources, no permission management -
Reader: Read-only access
-
-
Custom Roles
-
Created by users to meet specific access needs
-
Defined using JSON templates with granular permissions
-
-
User-Defined Roles
- Another term often used for custom roles created by users to match organizational needs
โ๏ธ Role Management Actions in Entra ID (Azure AD)¶
โ Create Role¶
-
Admin logs into Entra ID Portal
-
Navigates to Roles section
-
Clicks New Role
-
Enters Role Name & Description
-
Assigns Permissions & Settings
-
Assigns role to Users or Groups
-
Clicks Create
๐น Role is successfully created
๐ Overwrite Role¶
-
Admin logs into Entra ID Portal
-
Navigates to Roles section
-
Selects the Role
-
Clicks Edit
-
Updates Role Name, Permissions, or Settings
-
Clicks Save
๐น Role is successfully overwritten
โ Delete Role¶
-
Admin logs into Entra ID Portal
-
Navigates to Roles section
-
Selects the Role
-
Clicks Delete
-
Confirms deletion
๐น Role is successfully deleted
๐ค User Role Assignments¶
โ Add Role to User¶
-
Admin logs into Entra ID Portal
-
Navigates to Users section
-
Selects the User
-
Clicks Assigned Roles
-
Clicks Add Assignment
-
Selects Role
-
Clicks Assign
๐น Role is successfully assigned to user
โ Remove Role from User¶
-
Admin logs into Entra ID Portal
-
Navigates to Users section
-
Selects the User
-
Clicks Assigned Roles
-
Selects the Role
-
Clicks Remove Assignment
๐น Role is successfully removed from user
๐ฅ Group Role Assignments¶
โ Add Role to Group¶
-
Admin logs into Entra ID Portal
-
Navigates to Groups section
-
Selects the Group
-
Clicks Assigned Roles
-
Clicks Add Assignment
-
Selects Role
-
Clicks Assign
๐น Role is successfully assigned to group
โ Remove Role from Group¶
-
Admin logs into Entra ID Portal
-
Navigates to Groups section
-
Selects the Group
-
Clicks Assigned Roles
-
Selects the Role
-
Clicks Remove Assignment
๐น Role is successfully removed from group
โ๏ธ Azure RBAC via Terraform¶
โ Prerequisites¶
Make sure the following Terraform provider is defined:
1๏ธโฃ Create a Custom Role¶
resource "azurerm_role_definition" "custom_reader" {
name = "CustomReader"
scope = data.azurerm_subscription.primary.id
description = "Custom Reader with limited actions"
permissions {
actions = [
"Microsoft.Resources/subscriptions/resourceGroups/read",
"Microsoft.Compute/virtualMachines/read"
]
not_actions = []
}
assignable_scopes = [
data.azurerm_subscription.primary.id
]
}
data "azurerm_subscription" "primary" {}
2๏ธโฃ Assign Built-in Role to a User¶
resource "azurerm_role_assignment" "user_contributor" {
principal_id = azurerm_user_assigned_identity.example.principal_id
role_definition_name = "Contributor" # or use role_definition_id for custom roles
scope = azurerm_resource_group.example.id
}
resource "azurerm_user_assigned_identity" "example" {
name = "my-identity"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "East US"
}
3๏ธโฃ Assign Custom Role to Azure AD Group¶
resource "azurerm_role_assignment" "group_custom_role" {
principal_id = data.azuread_group.devops_team.id
role_definition_id = azurerm_role_definition.custom_reader.role_definition_resource_id
scope = azurerm_resource_group.example.id
}
data "azuread_group" "devops_team" {
display_name = "DevOpsTeam"
}
4๏ธโฃ Remove Role Assignment (by deleting the resource)¶
To remove a role assignment, simply delete the corresponding azurerm_role_assignment resource from your Terraform code and apply the change.
โน๏ธ Notes¶
-
principal_id: The Object ID of the user, group, or service principal
-
scope: Can be a subscription, resource group, or individual resource
-
role_definition_name: For built-in roles (e.g.,
Reader,Contributor) -
role_definition_id: For custom roles created via
azurerm_role_definition
ROLES FOR IDENTITY¶
Giving or assigning roles and permission for identities (users or resources) for interact with other identities..
- SERVICE PRINCIPALS: assign roles to the users to interact with the resources. 3a-Service-principals.md
- MANAGED IDENTITIES: assign roles to resources to interact with other resources. 3b-managed-identities.md
- difference between service principals and managed identities. 3c-service-principals-vs-managed-identities.md