You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/scenarios-rbac.md
+24-11Lines changed: 24 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,27 @@ description: Describes how to create role assignments and role definitions by us
4
4
author: johndowns
5
5
ms.author: jodowns
6
6
ms.topic: conceptual
7
-
ms.date: 12/20/2021
7
+
ms.date: 05/15/2022
8
8
---
9
9
# Create Azure RBAC resources by using Bicep
10
10
11
-
Azure has a powerful role-based access control (RBAC) system. By using Bicep, you can programmatically define your RBAC role assignments and role definitions.
11
+
Azure has a powerful role-based access control (RBAC) system. For more information on Azure RBAC, see [What is Azure Role-based access control (Azure RBAC)?](../../role-based-access-control/overview.md)By using Bicep, you can programmatically define your RBAC role assignments and role definitions.
12
12
13
13
## Role assignments
14
14
15
+
Role assignments enable you to grant a principal (such as a user, a group, or a service principal) access to a specific Azure resource.
16
+
15
17
To define a role assignment, create a resource with type [`Microsoft.Authorization/roleAssignments`](/azure/templates/microsoft.authorization/roleassignments?tabs=bicep). A role definition has multiple properties, including a scope, a name, a role definition ID, a principal ID, and a principal type.
16
18
17
19
### Scope
18
20
21
+
Role assignments apply at a specific *scope*, which defines the resource or set of resources that you're granting access to. For more information, see [Understand scope for Azure RBAC](../../role-based-access-control/scope-overview.md).
22
+
19
23
Role assignments are [extension resources](scope-extension-resources.md), which means they apply to another resource. The following example shows how to create a storage account and a role assignment scoped to that storage account:
If you don't explicitly specify the scope, Bicep uses the file's `targetScope`. In the following example, no `scope` property is specified, so the role assignment applies to the subscription:
27
+
If you don't explicitly specify the scope, Bicep uses the file's `targetScope`. In the following example, no `scope` property is specified, so the role assignment is scoped to the subscription:
@@ -31,14 +35,15 @@ If you don't explicitly specify the scope, Bicep uses the file's `targetScope`.
31
35
32
36
### Name
33
37
34
-
A role assignment's resource name must be a globally unique identifier (GUID). It's a good practice to create a GUID that uses the scope, principal ID, and role ID together. Role assignment resource names must be unique within the Azure Active Directory tenant, even if the scope is narrower.
38
+
A role assignment's resource name must be a globally unique identifier (GUID).
35
39
36
-
> [!TIP]
37
-
> Use the `guid()` function to help you to create a deterministic GUID for your role assignment names, like in this example:
Role assignment resource names must be unique within the Azure Active Directory tenant, even if the scope is narrower.
41
+
42
+
For your Bicep deployment to be repeatable, it's important for the name to be deterministic - in other words, to use the same name every time you deploy. It's a good practice to create a GUID that uses the scope, principal ID, and role ID together. It's a good idea to use the `guid()` function to help you to create a deterministic GUID for your role assignment names, like in this example:
When you delete a user, group, service principal, or managed identity from Azure AD, it's a good practice to delete any role assignments. They aren't deleted automatically.
72
+
73
+
Any role assignments that refer to a deleted principal ID become invalid. If you try to reuse a role assignment's name for another role assignment, the deployment will fail.
74
+
64
75
## Custom role definitions
65
76
77
+
Custom role definitions enable you to define a set of permissions that can then be assigned to a principal by using a role assignment. For more information on role definitions, see [Understand Azure role definitions](../../role-based-access-control/role-definitions.md).
78
+
66
79
To create a custom role definition, define a resource of type `Microsoft.Authorization/roleDefinitions`. See the [Create a new role def via a subscription level deployment](https://azure.microsoft.com/resources/templates/create-role-def/) quickstart for an example.
67
80
68
81
Role definition resource names must be unique within the Azure Active Directory tenant, even if the assignable scopes are narrower.
@@ -85,4 +98,4 @@ Role definition resource names must be unique within the Azure Active Directory
85
98
-[Create a new role def via a subscription level deployment](https://azure.microsoft.com/resources/templates/create-role-def/)
86
99
-[Assign a role at subscription scope](https://azure.microsoft.com/resources/templates/subscription-role-assignment/)
87
100
-[Assign a role at tenant scope](https://azure.microsoft.com/resources/templates/tenant-role-assignment/)
88
-
- [Create a resourceGroup, apply a lock and RBAC](https://azure.microsoft.com/resources/templates/create-rg-lock-role-assignment/)
101
+
-[Create a resourceGroup, apply a lock and RBAC](https://azure.microsoft.com/resources/templates/create-rg-lock-role-assignment/)
0 commit comments