If you’re like me when granting permissions, you want to do it according to least privilege. This is not always possible, but in Azure you have complete control over access given to custom RBAC roles.
Custom RBAC role management is now also available in the portal, which I think is great. Hopefully this generates more use of the feature!
In this post I want to show you a couple of RBAC templates, more precisely a custom RBAC role for Notification Hub Reader and Notification Hub Administrator. I searched for a role like this, but couldn’t find it, so why not attempt to create one myself.
If you’re new to the Azure Custom RBAC Roles, I recommend reading here first to get some fundamental information. PowerShell is the tool of choice for me, so I will be using this in my examples. You can find all the resource provider operations here for reference.
There isn’t really much to creating these roles. Just download the definitions from my github, update with your own subscriptions guid(s) and run the PowerShell cmdlets provided below. After you have done this, the role can be assigned at the scopes you defined.
After the custom role has been created, you can update the role with Set-AzRoleDefinition. You need to add the definition id, but make sure all the required settings are there, or they will be removed from the role.
New-AzRoleDefinition -InputFile "<pathtofile>\NotificationHubReader.json" Set-AzRoleDefinition -InputFile "<pathtofile>\NotificationHubReader.json"
I will now explain some of the definitions of this file. I will not go into the actual structure of Custom RBAC definition files, as this is already noted in the Microsoft docs.
“/subscriptions/<your subscription guid1>”,
“/subscriptions/<your subscription guid2>”,
“/subscriptions/<your subscription guid1>/<your resource group>”
Replace the values with your subscriptions/resource groups. You do not need to add resource group if it is not relevant for you. I just add all the subscriptions where this custom role should be assignable.
Notification Hub Reader Role
This one grants list permission on the resource group itself. Without it it seems like you can not even see the resource group Notification Hub is connected to.
This one grants all the possible “read”-actions on all Notification Hubs and Notification Hubs Namespaces in the resource group. Note that there are other actions which can be considered “read”, but are instead “action”.
I haven’t added the */action, because there could be actions I do not want readers to perform. In short, these grant some specific operations not covered by Microsoft.NotificationHubs/*/read.
This one merits a specific mention, as it grants all sub-operations on NotificationHubs/authorizationRules. I tried doing only read and listkeys, but the Access Policies section in the portal was greyed out. Ended up just adding all the authRules operations here, but added a “NotAction” to remove delete operation. The user granted this role can regenerate, write and update keys. Maybe it is possible to list keys from PowerShell or Az CLI, but I did not test.
If you want to limit the operations possible for the reader role, you can just play around with it to test what fits or not. E.g. the permission to read and regenerate keys can be removed, and the user will not be able to see them. This fit my use case, and it does not grant too much permissions on the relevant resources at the moment.
Notification Hub Admin
This role is somewhat easier, as there are fewer but more generic actions allowed.
This operations grants permission for creating a new deployment in the resource group. Necessary if the admin needs to create new Notification Hubs or Namespaces.
This operation grants access to list the resource group, same as reader role above.
This one grants all possible operations on the NotificationHubs resource provider. You can limit this as much as necessary with the “NotActions” setting. For now this role is good enough