Skip to content

Commit ac47234

Browse files
authored
Merge pull request #116163 from rolyon/rolyon-rbac-arm-quickstart
[Azure RBAC] Quickstart: Add an Azure role assignment using template
2 parents 7c81a40 + a3cb33b commit ac47234

File tree

5 files changed

+152
-91
lines changed

5 files changed

+152
-91
lines changed

.openpublishing.redirection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33927,6 +33927,11 @@
3392733927
"redirect_url": "/azure/role-based-access-control/role-assignments-portal",
3392833928
"redirect_document_id": false
3392933929
},
33930+
{
33931+
"source_path": "articles/role-based-access-control/tutorial-role-assignments-user-template.md",
33932+
"redirect_url": "/azure/role-based-access-control/quickstart-role-assignments-template",
33933+
"redirect_document_id": true
33934+
},
3393033935
{
3393133936
"source_path": "articles/active-directory/privileged-identity-management/active-directory-securing-privileged-access.md",
3393233937
"redirect_url": "/azure/active-directory/users-groups-roles/directory-admin-roles-secure",

articles/role-based-access-control/TOC.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
items:
1212
- name: View access for a user
1313
href: check-access.md
14+
- name: ARM template
15+
displayName: Resource Manager
16+
href: quickstart-role-assignments-template.md
1417
- name: Tutorials
1518
items:
1619
- name: Grant a user access - Portal
1720
href: quickstart-assign-role-user-portal.md
1821
- name: Grant a user access - PowerShell
1922
href: tutorial-role-assignments-user-powershell.md
20-
- name: Grant a user access - Resource Manager Template
21-
displayName: ARM, resource manager template
22-
href: tutorial-role-assignments-user-template.md
2323
- name: Grant a group access - PowerShell
2424
href: tutorial-role-assignments-group-powershell.md
2525
- name: Create a custom role - PowerShell
@@ -67,7 +67,8 @@
6767
href: role-assignments-cli.md
6868
- name: REST API
6969
href: role-assignments-rest.md
70-
- name: Template
70+
- name: ARM template
71+
displayName: Resource Manager
7172
href: role-assignments-template.md
7273
- name: List deny assignments
7374
items:
@@ -113,8 +114,8 @@
113114
href: /cli/azure/role?view=azure-cli-latest
114115
- name: REST API
115116
href: /rest/api/authorization/
116-
- name: Resource Manager templates
117-
displayName: ARM
117+
- name: ARM templates
118+
displayName: Resource Manager
118119
items:
119120
- name: Role Assignments
120121
href: /azure/templates/microsoft.authorization/roleassignments
78.5 KB
Loading
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
title: "Quickstart: Add an Azure role assignment using an Azure Resource Manager template - Azure RBAC"
3+
description: Learn how to grant access to Azure resources for a user at resource group scope using Azure Resource Manager templates and Azure role-based access control (Azure RBAC).
4+
services: role-based-access-control,azure-resource-manager
5+
author: rolyon
6+
manager: mtillman
7+
ms.service: role-based-access-control
8+
ms.topic: quickstart
9+
ms.custom: subject-armqs
10+
ms.workload: identity
11+
ms.date: 05/21/2020
12+
ms.author: rolyon
13+
14+
#Customer intent: As a new user, I want to see how to grant access to resources by using Azure Resource Manager template so that I can start automating role assignment processes.
15+
16+
---
17+
18+
# Quickstart: Add an Azure role assignment using an Azure Resource Manager template
19+
20+
[Azure role-based access control (Azure RBAC)](overview.md) is the way that you manage access to Azure resources. In this quickstart, you create a resource group and grant a user access to create and manage virtual machines in the resource group. This quickstart uses a Resource Manager template to grant the access.
21+
22+
[!INCLUDE [About Azure Resource Manager](../../includes/resource-manager-quickstart-introduction.md)]
23+
24+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
25+
26+
## Prerequisites
27+
28+
To add role assignments, you must have:
29+
30+
* `Microsoft.Authorization/roleAssignments/write` and `Microsoft.Authorization/roleAssignments/delete` permissions, such as [User Access Administrator](built-in-roles.md#user-access-administrator) or [Owner](built-in-roles.md#owner)
31+
32+
## Create a role assignment
33+
34+
To add a role assignment, you must specify three elements: security principal, role definition, and scope. For this quickstart, the security principal is you or another user in your directory, the role definition is [Virtual Machine Contributor](built-in-roles.md#virtual-machine-contributor), and the scope is a resource group that you specify.
35+
36+
### Review the template
37+
38+
The template used in this quickstart is from [Azure Quickstart templates](https://azure.microsoft.com/resources/templates/101-rbac-builtinrole-resourcegroup/). The template has three parameters and a resources section. In the resources section, notice that it has the three elements of a role assignment: security principal, role definition, and scope.
39+
40+
:::code language="json" source="~/quickstart-templates/101-rbac-builtinrole-resourcegroup/azuredeploy.json" highlight="30-32":::
41+
42+
### Deploy the template
43+
44+
1. Sign in to the [Azure portal](https://portal.azure.com).
45+
46+
1. Determine your email address that is associated with your Azure subscription. Or determine the email address of another user in your directory.
47+
48+
1. Open Azure Cloud Shell for PowerShell.
49+
50+
1. Copy and paste the following script into Cloud Shell.
51+
52+
```azurepowershell
53+
$resourceGroupName = Read-Host -Prompt "Enter a resource group name (i.e. ExampleGrouprg)"
54+
$emailAddress = Read-Host -Prompt "Enter an email address for a user in your directory"
55+
$location = Read-Host -Prompt "Enter a location (i.e. centralus)"
56+
57+
$roleAssignmentName = New-Guid
58+
$principalId = (Get-AzAdUser -Mail $emailAddress).id
59+
$roleDefinitionId = (Get-AzRoleDefinition -name "Virtual Machine Contributor").id
60+
$templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-rbac-builtinrole-resourcegroup/azuredeploy.json"
61+
62+
New-AzResourceGroup -Name $resourceGroupName -Location $location
63+
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -roleAssignmentName $roleAssignmentName -roleDefinitionID $roleDefinitionId -principalId $principalId
64+
```
65+
66+
1. Enter a resource group name such as ExampleGrouprg.
67+
68+
1. Enter an email address for yourself or another user in your directory.
69+
70+
1. Enter a location for the resource group such as centralus.
71+
72+
1. If necessary, press Enter to run the New-AzResourceGroupDeployment command.
73+
74+
The [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup) command creates a new resource group and the [New-AzResourceGroupDeployment](/powershell/module/az.resources/new-azresourcegroupdeployment) command deploys the template to add the role assignment.
75+
76+
You should see output similar to the following:
77+
78+
```azurepowershell
79+
PS> New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -roleAssignmentName $roleAssignmentName -roleDefinitionID $roleDefinitionId -principalId $principalId
80+
81+
DeploymentName : azuredeploy
82+
ResourceGroupName : ExampleGrouprg
83+
ProvisioningState : Succeeded
84+
Timestamp : 5/22/2020 9:01:30 PM
85+
Mode : Incremental
86+
TemplateLink :
87+
Uri : https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-rbac-builtinrole-resourcegroup/azuredeploy.json
88+
ContentVersion : 1.0.0.0
89+
90+
Parameters :
91+
Name Type Value
92+
==================== ========================= ==========
93+
roleAssignmentName String {roleAssignmentName}
94+
roleDefinitionID String 9980e02c-c2be-4d73-94e8-173b1dc7cf3c
95+
principalId String {principalId}
96+
97+
Outputs :
98+
DeploymentDebugLogLevel :
99+
```
100+
101+
## Review deployed resources
102+
103+
1. In the Azure portal, open the resource group you created.
104+
105+
1. In the left menu, click **Access control (IAM)**.
106+
107+
1. Click the **Role assignments** tab.
108+
109+
1. Verify that the **Virtual Machine Contributor** role is assigned to the user you specified.
110+
111+
![New role assignment](./media/quickstart-role-assignments-template/role-assignment-portal.png)
112+
113+
## Clean up resources
114+
115+
To remove the role assignment and resource group you created, follow these steps.
116+
117+
1. Copy and paste the following script into Cloud Shell.
118+
119+
```azurepowershell
120+
$emailAddress = Read-Host -Prompt "Enter the email address of the user with the role assignment to remove"
121+
$resourceGroupName = Read-Host -Prompt "Enter the resource group name to remove (i.e. ExampleGrouprg)"
122+
123+
$principalId = (Get-AzAdUser -Mail $emailAddress).id
124+
125+
Remove-AzRoleAssignment -ObjectId $principalId -RoleDefinitionName "Virtual Machine Contributor" -ResourceGroupName $resourceGroupName
126+
Remove-AzResourceGroup -Name $resourceGroupName
127+
```
128+
129+
1. Enter the email address of the user with the role assignment to remove.
130+
131+
1. Enter the resource group name to remove such as ExampleGrouprg.
132+
133+
1. If necessary, press Enter to run the Remove-AzResourceGroup command.
134+
135+
1. Enter **Y** to confirm that you want to remove the resource group.
136+
137+
## Next steps
138+
139+
> [!div class="nextstepaction"]
140+
> [Tutorial: Grant a user access to Azure resources using Azure PowerShell](tutorial-role-assignments-user-powershell.md)

articles/role-based-access-control/tutorial-role-assignments-user-template.md

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)