Unlocking Granular Control A Guide to Custom Roles in Azure

June 10, 2025

Unlocking Granular Control: A Guide to Custom Roles in Azure

If you’re like me, you’re always looking for better ways to manage access to your Azure resources. While Azure’s built-in roles are a great starting point, sometimes you need something a little more specific. That’s where custom roles come in, giving you the power to define precisely who can do what.

In this post, we’ll dive into creating custom roles in Azure. We’ll explore how to use Role-Based Access Control (RBAC) and data attributes to create a security model that’s both powerful and flexible. Think of it as creating a “just right” key for every user, instead of handing out master keys to everyone.

Why Go Custom?

Before we jump into the “how,” let’s talk about the “why.” You might need a custom role when:

Getting Started with RBAC

At the heart of Azure security is Role-Based Access Control (RBAC). RBAC allows you to grant users, groups, and service principals access to Azure resources. You can assign roles at different scopes, such as the management group, subscription, resource group, or individual resource.

Here’s a quick rundown of the key concepts:

Creating Your First Custom Role

Ready to get your hands dirty? Let’s create a custom role that allows users to restart virtual machines in a specific resource group.

First, you’ll need to create a JSON file that defines the role. Here’s an example:

{
  "Name": "Virtual Machine Operator (Custom)",
  "IsCustom": true,
  "Description": "Can restart virtual machines.",
  "Actions": [
    "Microsoft.Compute/virtualMachines/restart/action"
  ],
  "NotActions": [],
  "DataActions": [],
  "NotDataActions": [],
  "AssignableScopes": [
    "/subscriptions/your_subscription_id/resourceGroups/your_resource_group"
  ]
}

In this example:

Once you’ve created the JSON file, you can use the Azure CLI or PowerShell to create the role.

Taking it a Step Further with Data Attributes

Now, let’s talk about something really cool: data attributes. With data attributes, you can add conditions to your role assignments based on tags or other metadata. This allows you to create even more granular access control policies.

For example, you could create a custom role that only allows users to access storage blobs with a specific tag. This is incredibly useful for scenarios where you need to restrict access to sensitive data.

Here’s an example of how you might use data attributes in your role definition:

{
  "Name": "Blob Data Reader (Custom)",
  "IsCustom": true,
  "Description": "Can read blobs with the 'sensitive' tag.",
  "Actions": [],
  "NotActions": [],
  "DataActions": [
    "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read"
  ],
  "NotDataActions": [],
  "AssignableScopes": [
    "/subscriptions/your_subscription_id"
  ]
}

In this case, we’re using the DataActions property to specify that the role can only read blobs. We can then add a condition to the role assignment that checks for the “sensitive” tag.

Key Takeaways

I hope this post has given you a good starting point for creating custom roles in Azure. As you can see, there’s a lot of power and flexibility at your fingertips. So go ahead, start experimenting, and create a security model that’s just right for you!