Assign a built-in role to a user at resource and Resource Group scope using ARM template

Published Mar 18 2022 09:55 AM 1,863 Views
Senior Member

This article is focused on creating an ARM template which will create a storage account resource in the resource group and will assign role at both RG (Resource Group) scope and created storage account resource level

This article is divided into following 5 sections.

  1. Fetch User Object ID
  2. Fetch Built-in Role ID
  3. Create ARM template to provision storage account
  4. Role assignment in ARM template
  5. Deploying ARM template to Azure Portal

 

Let’s start step by step as mentioned above, we will fetch the user object ID which will be used in deploying ARM template

  1. So firstly, lets fetch the user’s object id

Use the PowerShell script to fetch user’s object id by its email id.

PS Script: Get-AzADUser | Where-Object { $_.UserPrincipalName -eq "testuser@testdomain.xyz.com" }

This will show the user details like, DisplayName, Id, Mail, UserPrincipalName, Grab the Id and save it for further use

You can also fetch the user object Id from Azure Portal, Navigate to Azure Active Director > Users > Select the user you want to fetch the Id of > Copy the Object Id

 

  1. Similarly, we will fetch the built-in role Id using PowerShell script, for this article I will fetch the “Reader” role id but you can fetch your required role id,

PS Script: Get-AzRoleDefinition -Name Reader

This script will output few of the Role details, grab the Id from the output and save it for further use

 

  1. Now it’s time to create the ARM Template which will create the Storage account and assign user with Reader role to the created storage account also, we will assign user with Reader role to the Resource group using scope.

 

Follow the template mentioned below for creating storage account and role assignment.

Refer Microsoft documentation to know more on ARM Template syntax and details and to know more details on role assignment

 

{

    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",

    "contentVersion": "1.0.0.0",

    "parameters": {

        "AAD_Object_ID": {

            "metadata": {

                "description": "Object ID of the User, Group or Service Principal"

            },

            "type": "string"

        },

        "Role_Definition_ID": {

            "metadata": {

                "description": "Identifier (GUID) of the role definition to map to service principal"

            },

            "type": "string"

        }

    },

    "variables": {

        "Full Role_Definition_ID": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', parameters('Role_Definition_ID'))]",

        "StorageAccountName": "shrstrgacc",

        "StorageAccountAssignmentName": "[concat(variables('StorageAccountName'), '/Microsoft.Authorization/', guid(concat(resourceGroup().id), variables('Full Role_Definition_ID')))]"                                

    },

    "resources": [

        {

            "type": "Microsoft.Storage/storageAccounts",

            "apiVersion": "2018-07-01",

            "name": "[variables('StorageAccountName')]",

            "comments": "Storage account used to store VM disks",

            "location": "[resourceGroup().location]",

            "sku": {

                "name": "Standard_LRS"

            },

            "kind": "Storage",

            "properties": {

                "roleDefinitionId": "[variables('Full Role_Definition_ID')]",

                "principalId": "[parameters('AAD_Object_ID')]"

            }

        },

        {

            "type": "Microsoft.Authorization/roleAssignments",

            "apiVersion": "2017-09-01",

            "name": "[guid(concat(resourceGroup().id), resourceId('Microsoft.Storage/storageAccounts', 'shrstrgacc'), variables('Full Role_Definition_ID'))]",

            "dependsOn": [

                "[resourceId('Microsoft.Storage/storageAccounts', 'shrstrgacc')]"

            ],

            "properties": {

                "roleDefinitionId": "[variables('Full Role_Definition_ID')]",

                "principalId": "[parameters('AAD_Object_ID')]",

                "scope": "[resourceGroup().id]"

            }

        },

        {

            "type": "Microsoft.Storage/storageAccounts/providers/roleAssignments",

            "apiVersion": "2017-05-01",

            "name": "[variables('StorageAccountAssignmentName')]",

            "dependsOn": [

                "[resourceId('Microsoft.Storage/storageAccounts', 'shrstrgacc')]"

            ],

            "properties": {

                "roleDefinitionId": "[variables('Full Role_Definition_ID')]",

                "principalId": "[parameters('AAD_Object_ID')]"

            }

        }

    ],

    "outputs": {}

}

 

As you can see from the above ARM template, we have given 2 input parameters which are, “AAD_Object_ID” & “Role_Definition_ID”, so to give a brief about what this input parameter will hold, AAD_Object_ID will be the User object Id fetched from Step 1 and Role_Definitation_ID will be the built in Reader Role ID fetched from Step 2

 

To further drill down to the ARM Template resources, we will be using;

Type: Microsoft.Storage/storageAccounts to provision storage account with the mentioned properties in the ARM Template

Type: Microsoft.Authorization/roleAssignments to assign role at Resource group scope

Type: Microsoft.Storage/storageAccounts/providers/roleAssignments to assign role to the storage account resource

Also, save the above mentioned template code in a file with  .json extension for example armtest.json and copy the file path as we will need it while deploying it to Azure in the final step

 

  1. Now it’s the time to deploy ARM Template to Azure Portal use the following script

#Connect to Azure Account

Connect Az-Account

 

# Use PowerShell command New-AzResourceGroupDeployment, this command deploys azure resources to the Resource group

Refer, Microsoft documentation on deploying using New-AzResourceGroupDeployment

 

New-AzResourceGroupDeployment -ResourceGroupName <your-   resource-group-name>`

-TemplateFile <ARMTemplateFilePath > `

-AAD_Object_ID <user object Id> `

-Role_Definition_ID <Built in Reader role Id>

 

Note - Pass the copied path of the saved ARM Template file to the TemplateFile parameter in the script

 

Now it’s time to verify the outcome in the Azure Portal,

Wohoo, Storage is created in the Resource group mentioned in the New- AzResourceGroupDeployment

 

ShrushtiShah_2-1647592558283.png

Fig 1.1: Storage Account created using ARM Template

 

Now, Lets check if the Reader role to the testuser is assigned to the Resource Group

Navigate to Azure Portal > Resource Group > Select the Resource group you added in the ARM deployment script > Access Control > Role Assignments

Wohoo, we can see the Reader role to the test user is assigned access to the Resource Group scope

 

ShrushtiShah_3-1647592558288.png

Fig 1.2: Role Assignment to the Resource Group using ARM Template

 

It’s time to verify the role access at the storage account resource level,

Navigate to Azure Portal > Resource Group > Select the Resource group you added in the ARM deployment script > Select the created storage account > Access control > Role Assignments

Wohoo, at storage account level we can see the reader role is assigned to the test user and the same is inherited from the Resource Group.

 

ShrushtiShah_4-1647592558293.png

Fig 1.3: Role assigned to created storage account using ARM Template

 

I hope this article seems useful for all the Azure enthusiasts on how they can assign RBAC to the users/groups/SPNs/Managed Identities using ARM Template.

Keep Learning!

Keep Sharing!

 

 

%3CLINGO-SUB%20id%3D%22lingo-sub-3260803%22%20slang%3D%22en-US%22%3EAssign%20a%20built-in%20role%20to%20a%20user%20at%20resource%20and%20Resource%20Group%20scope%20using%20ARM%20template%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3260803%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20article%20is%20focused%20on%20creating%20an%20ARM%20template%20which%20will%20create%20a%20storage%20account%20resource%20in%20the%20resource%20group%20and%20will%20assign%20role%20at%20both%20RG%20(Resource%20Group)%20scope%20and%20created%20storage%20account%20resource%20level%3C%2FP%3E%0A%3CP%3EThis%20article%20is%20divided%20into%20following%205%20sections.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EFetch%20User%20Object%20ID%3C%2FLI%3E%0A%3CLI%3EFetch%20Built-in%20Role%20ID%3C%2FLI%3E%0A%3CLI%3ECreate%20ARM%20template%20to%20provision%20storage%20account%3C%2FLI%3E%0A%3CLI%3ERole%20assignment%20in%20ARM%20template%3C%2FLI%3E%0A%3CLI%3EDeploying%20ARM%20template%20to%20Azure%20Portal%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20start%20step%20by%20step%20as%20mentioned%20above%2C%20we%20will%20fetch%20the%20user%20object%20ID%20which%20will%20be%20used%20in%20deploying%20ARM%20template%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ESo%20firstly%2C%20lets%20fetch%20the%20user%E2%80%99s%20object%20id%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EUse%20the%20PowerShell%20script%20to%20fetch%20user%E2%80%99s%20object%20id%20by%20its%20email%20id.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EPS%20Script%3C%2FSTRONG%3E%3A%20%3CSTRONG%3EGet-AzADUser%20%7C%20Where-Object%20%7B%20%24_.UserPrincipalName%20-eq%20%22testuser%40testdomain.xyz.com%22%20%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThis%20will%20show%20the%20user%20details%20like%2C%20DisplayName%2C%20Id%2C%20Mail%2C%20UserPrincipalName%2C%20Grab%20the%20Id%20and%20save%20it%20for%20further%20use%3C%2FP%3E%0A%3CP%3EYou%20can%20also%20fetch%20the%20user%20object%20Id%20from%20Azure%20Portal%2C%20Navigate%20to%20Azure%20Active%20Director%20%26gt%3B%20Users%20%26gt%3B%20Select%20the%20user%20you%20want%20to%20fetch%20the%20Id%20of%20%26gt%3B%20Copy%20the%20Object%20Id%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%222%22%3E%0A%3CLI%3ESimilarly%2C%20we%20will%20fetch%20the%20built-in%20role%20Id%20using%20PowerShell%20script%2C%20for%20this%20article%20I%20will%20fetch%20the%20%E2%80%9CReader%E2%80%9D%20role%20id%20but%20you%20can%20fetch%20your%20required%20role%20id%2C%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3EPS%20Script%3A%20Get-AzRoleDefinition%20-Name%20Reader%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThis%20script%20will%20output%20few%20of%20the%20Role%20details%2C%20grab%20the%20Id%20from%20the%20output%20and%20save%20it%20for%20further%20use%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%223%22%3E%0A%3CLI%3ENow%20it%E2%80%99s%20time%20to%20create%20the%20ARM%20Template%20which%20will%20create%20the%20Storage%20account%20and%20assign%20user%20with%20Reader%20role%20to%20the%20created%20storage%20account%20also%2C%20we%20will%20assign%20user%20with%20Reader%20role%20to%20the%20Resource%20group%20using%20scope.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFollow%20the%20template%20mentioned%20below%20for%20creating%20storage%20account%20and%20role%20assignment.%3C%2FP%3E%0A%3CP%3ERefer%20Microsoft%20documentation%20to%20know%20more%20on%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-resource-manager%2Ftemplates%2Fsyntax%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EARM%20Template%3C%2FA%3E%20syntax%20and%20details%20and%20to%20know%20more%20details%20on%20role%20assignment%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%22%24schema%22%3A%20%22%3CA%20href%3D%22https%3A%2F%2Fschema.management.azure.com%2Fschemas%2F2015-01-01%2FdeploymentTemplate.json%23%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fschema.management.azure.com%2Fschemas%2F2015-01-01%2FdeploymentTemplate.json%23%3C%2FA%3E%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%22contentVersion%22%3A%20%221.0.0.0%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%22parameters%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22AAD_Object_ID%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22metadata%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22description%22%3A%20%22Object%20ID%20of%20the%20User%2C%20Group%20or%20Service%20Principal%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22type%22%3A%20%22string%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22Role_Definition_ID%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22metadata%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22description%22%3A%20%22Identifier%20(GUID)%20of%20the%20role%20definition%20to%20map%20to%20service%20principal%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22type%22%3A%20%22string%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%7D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%22variables%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22Full%20Role_Definition_ID%22%3A%20%22%5Bconcat('%2Fsubscriptions%2F'%2C%20subscription().subscriptionId%2C%20'%2Fproviders%2FMicrosoft.Authorization%2FroleDefinitions%2F'%2C%20parameters('Role_Definition_ID'))%5D%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22StorageAccountName%22%3A%20%22shrstrgacc%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22StorageAccountAssignmentName%22%3A%20%22%5Bconcat(variables('StorageAccountName')%2C%20'%2FMicrosoft.Authorization%2F'%2C%20guid(concat(resourceGroup().id)%2C%20variables('Full%20Role_Definition_ID')))%5D%22%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%7D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%22resources%22%3A%20%5B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22type%22%3A%20%22Microsoft.Storage%2FstorageAccounts%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22apiVersion%22%3A%20%222018-07-01%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22name%22%3A%20%22%5Bvariables('StorageAccountName')%5D%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22comments%22%3A%20%22Storage%20account%20used%20to%20store%20VM%20disks%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22location%22%3A%20%22%5BresourceGroup().location%5D%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22sku%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22name%22%3A%20%22Standard_LRS%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22kind%22%3A%20%22Storage%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22properties%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22roleDefinitionId%22%3A%20%22%5Bvariables('Full%20Role_Definition_ID')%5D%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22principalId%22%3A%20%22%5Bparameters('AAD_Object_ID')%5D%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22type%22%3A%20%22Microsoft.Authorization%2FroleAssignments%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22apiVersion%22%3A%20%222017-09-01%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22name%22%3A%20%22%5Bguid(concat(resourceGroup().id)%2C%20resourceId('Microsoft.Storage%2FstorageAccounts'%2C%20'shrstrgacc')%2C%20variables('Full%20Role_Definition_ID'))%5D%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22dependsOn%22%3A%20%5B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22%5BresourceId('Microsoft.Storage%2FstorageAccounts'%2C%20'shrstrgacc')%5D%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22properties%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22roleDefinitionId%22%3A%20%22%5Bvariables('Full%20Role_Definition_ID')%5D%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22principalId%22%3A%20%22%5Bparameters('AAD_Object_ID')%5D%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22scope%22%3A%20%22%5BresourceGroup().id%5D%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22type%22%3A%20%22Microsoft.Storage%2FstorageAccounts%2Fproviders%2FroleAssignments%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22apiVersion%22%3A%20%222017-05-01%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22name%22%3A%20%22%5Bvariables('StorageAccountAssignmentName')%5D%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22dependsOn%22%3A%20%5B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22%5BresourceId('Microsoft.Storage%2FstorageAccounts'%2C%20'shrstrgacc')%5D%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22properties%22%3A%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22roleDefinitionId%22%3A%20%22%5Bvariables('Full%20Role_Definition_ID')%5D%22%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%22principalId%22%3A%20%22%5Bparameters('AAD_Object_ID')%5D%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%5D%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%22outputs%22%3A%20%7B%7D%3C%2FP%3E%0A%3CP%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20you%20can%20see%20from%20the%20above%20ARM%20template%2C%20we%20have%20given%202%20input%20parameters%20which%20are%2C%20%E2%80%9CAAD_Object_ID%E2%80%9D%20%26amp%3B%20%E2%80%9CRole_Definition_ID%E2%80%9D%2C%20so%20to%20give%20a%20brief%20about%20what%20this%20input%20parameter%20will%20hold%2C%20AAD_Object_ID%20will%20be%20the%20User%20object%20Id%20fetched%20from%20Step%201%20and%20Role_Definitation_ID%20will%20be%20the%20built%20in%20Reader%20Role%20ID%20fetched%20from%20Step%202%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20further%20drill%20down%20to%20the%20ARM%20Template%20resources%2C%20we%20will%20be%20using%3B%3C%2FP%3E%0A%3CP%3EType%3A%20Microsoft.Storage%2FstorageAccounts%20to%20provision%20storage%20account%20with%20the%20mentioned%20properties%20in%20the%20ARM%20Template%3C%2FP%3E%0A%3CP%3EType%3A%20Microsoft.Authorization%2FroleAssignments%20to%20assign%20role%20at%20Resource%20group%20scope%3C%2FP%3E%0A%3CP%3EType%3A%20Microsoft.Storage%2FstorageAccounts%2Fproviders%2FroleAssignments%20to%20assign%20role%20to%20the%20storage%20account%20resource%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EAlso%2C%20save%20the%20above%20mentioned%20template%20code%20in%20a%20file%20with%20%26nbsp%3B.json%20extension%20for%20example%20armtest.json%20and%20copy%20the%20file%20path%20as%20we%20will%20need%20it%20while%20deploying%20it%20to%20Azure%20in%20the%20final%20step%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%20start%3D%224%22%3E%0A%3CLI%3ENow%20it%E2%80%99s%20the%20time%20to%20deploy%20ARM%20Template%20to%20Azure%20Portal%20use%20the%20following%20script%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%23Connect%20to%20Azure%20Account%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EConnect%20Az-Account%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23%20Use%20PowerShell%20command%20New-AzResourceGroupDeployment%2C%20this%20command%20deploys%20azure%20resources%20to%20the%20Resource%20group%3C%2FP%3E%0A%3CP%3ERefer%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.resources%2Fnew-azresourcegroupdeployment%3Fview%3Dazps-7.3.2%23examples%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMicrosoft%20documentation%20on%20deploying%20using%20New-AzResourceGroupDeployment%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENew-AzResourceGroupDeployment%20-ResourceGroupName%20%3CYOUR-%3E%60%3C%2FYOUR-%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E-TemplateFile%20%3CARMTEMPLATEFILEPATH%3E%20%60%3C%2FARMTEMPLATEFILEPATH%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E-AAD_Object_ID%20%3CUSER%20object%3D%22%22%20id%3D%22%22%3E%20%60%3C%2FUSER%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E-Role_Definition_ID%20%3CBUILT%20in%3D%22%22%20reader%3D%22%22%20role%3D%22%22%20id%3D%22%22%3E%3C%2FBUILT%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%20-%20Pass%20the%20copied%20path%20of%20the%20saved%20ARM%20Template%20file%20to%20the%20TemplateFile%20parameter%20in%20the%20script%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20it%E2%80%99s%20time%20to%20verify%20the%20outcome%20in%20the%20Azure%20Portal%2C%3C%2FP%3E%0A%3CP%3EWohoo%2C%20Storage%20is%20created%20in%20the%20Resource%20group%20mentioned%20in%20the%20New-%20AzResourceGroupDeployment%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ShrushtiShah_2-1647592558283.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F356783i68B6C2DB10DD5B62%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22ShrushtiShah_2-1647592558283.png%22%20alt%3D%22ShrushtiShah_2-1647592558283.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFig%201.1%3A%20Storage%20Account%20created%20using%20ARM%20Template%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%2C%20Lets%20check%20if%20the%20Reader%20role%20to%20the%20testuser%20is%20assigned%20to%20the%20Resource%20Group%3C%2FP%3E%0A%3CP%3ENavigate%20to%20Azure%20Portal%20%26gt%3B%20Resource%20Group%20%26gt%3B%20Select%20the%20Resource%20group%20you%20added%20in%20the%20ARM%20deployment%20script%20%26gt%3B%20Access%20Control%20%26gt%3B%20Role%20Assignments%3C%2FP%3E%0A%3CP%3EWohoo%2C%20we%20can%20see%20the%20Reader%20role%20to%20the%20test%20user%20is%20assigned%20access%20to%20the%20Resource%20Group%20scope%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ShrushtiShah_3-1647592558288.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F356784i1A09CE05F9421C67%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22ShrushtiShah_3-1647592558288.png%22%20alt%3D%22ShrushtiShah_3-1647592558288.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFig%201.2%3A%20Role%20Assignment%20to%20the%20Resource%20Group%20using%20ARM%20Template%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%E2%80%99s%20time%20to%20verify%20the%20role%20access%20at%20the%20storage%20account%20resource%20level%2C%3C%2FP%3E%0A%3CP%3ENavigate%20to%20Azure%20Portal%20%26gt%3B%20Resource%20Group%20%26gt%3B%20Select%20the%20Resource%20group%20you%20added%20in%20the%20ARM%20deployment%20script%20%26gt%3B%20Select%20the%20created%20storage%20account%20%26gt%3B%20Access%20control%20%26gt%3B%20Role%20Assignments%3C%2FP%3E%0A%3CP%3EWohoo%2C%20at%20storage%20account%20level%20we%20can%20see%20the%20reader%20role%20is%20assigned%20to%20the%20test%20user%20and%20the%20same%20is%20inherited%20from%20the%20Resource%20Group.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ShrushtiShah_4-1647592558293.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F356785i486B938E4C4DD9C4%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22ShrushtiShah_4-1647592558293.png%22%20alt%3D%22ShrushtiShah_4-1647592558293.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFig%201.3%3A%20Role%20assigned%20to%20created%20storage%20account%20using%20ARM%20Template%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20hope%20this%20article%20seems%20useful%20for%20all%20the%20Azure%20enthusiasts%20on%20how%20they%20can%20assign%20RBAC%20to%20the%20users%2Fgroups%2FSPNs%2FManaged%20Identities%20using%20ARM%20Template.%3C%2FP%3E%0A%3CP%3EKeep%20Learning!%3C%2FP%3E%0A%3CP%3EKeep%20Sharing!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-3260803%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20article%20is%20focused%20on%20creating%20an%20ARM%20template%20which%20will%20create%20a%20storage%20account%20resource%20in%20the%20resource%20group%20and%20will%20assign%20role%20at%20both%20RG%20(Resource%20Group)%20scope%20and%20created%20storage%20account%20resource%20level%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22ShrushtiShah_6-1647593433180.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F356787iC87C11615BA8C92A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22ShrushtiShah_6-1647593433180.png%22%20alt%3D%22ShrushtiShah_6-1647593433180.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3260803%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EARM%20Templates%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ERole-based%20access%20control%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EStorage%20Account%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Mar 18 2022 09:55 AM
Updated by: