Skip to content

Commit a45218f

Browse files
authored
Merge pull request #192895 from johndowns/bicep-scenarios-rbac
Bicep - Update RBAC scenarios article
2 parents eac2b20 + 41a7e96 commit a45218f

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

articles/azure-resource-manager/bicep/scenarios-rbac.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@ description: Describes how to create role assignments and role definitions by us
44
author: johndowns
55
ms.author: jodowns
66
ms.topic: conceptual
7-
ms.date: 12/20/2021
7+
ms.date: 05/15/2022
88
---
99
# Create Azure RBAC resources by using Bicep
1010

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.
1212

1313
## Role assignments
1414

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+
1517
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.
1618

1719
### Scope
1820

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+
1923
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:
2024

2125
::: code language="bicep" source="~/azure-docs-bicep-samples/samples/scenarios-rbac/scope.bicep" highlight="17" :::
2226

23-
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:
2428

2529
::: code language="bicep" source="~/azure-docs-bicep-samples/samples/scenarios-rbac/scope-default.bicep" highlight="4" :::
2630

@@ -31,14 +35,15 @@ If you don't explicitly specify the scope, Bicep uses the file's `targetScope`.
3135
3236
### Name
3337

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).
3539

36-
> [!TIP]
37-
> Use the `guid()` function to help you to create a deterministic GUID for your role assignment names, like in this example:
38-
>
39-
> ```bicep
40-
> name: guid(subscription().id, principalId, roleDefinitionResourceId)
41-
> ```
40+
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:
43+
44+
```bicep
45+
name: guid(subscription().id, principalId, roleDefinitionResourceId)
46+
```
4247

4348
### Role definition ID
4449

@@ -61,8 +66,16 @@ The following example shows how to create a user-assigned managed identity and a
6166

6267
::: code language="bicep" source="~/azure-docs-bicep-samples/samples/scenarios-rbac/managed-identity.bicep" highlight="15-16" :::
6368

69+
### Resource deletion behavior
70+
71+
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+
6475
## Custom role definitions
6576

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+
6679
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.
6780

6881
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
8598
- [Create a new role def via a subscription level deployment](https://azure.microsoft.com/resources/templates/create-role-def/)
8699
- [Assign a role at subscription scope](https://azure.microsoft.com/resources/templates/subscription-role-assignment/)
87100
- [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

Comments
 (0)