-
Notifications
You must be signed in to change notification settings - Fork 290
/
manage-roles-portal.yml
273 lines (208 loc) · 13.9 KB
/
manage-roles-portal.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
### YamlMime:HowTo
---
metadata:
title: Assign Microsoft Entra roles to users
description: Learn how to grant access to users in Microsoft Entra ID by assigning Microsoft Entra roles.
author: rolyon
ms.author: rolyon
manager: amycolannino
ms.reviewer: vincesm
ms.date: 03/04/2024
ms.service: entra-id
ms.subservice: role-based-access-control
ms.topic: how-to
ms.custom:
- it-pro
- has-azure-ad-ps-ref
- azure-ad-ref-level-one-done
- ge-structured-content-pilot
title: |
Assign Microsoft Entra roles to users
introduction: |
To grant access to users in Microsoft Entra ID, you assign Microsoft Entra roles. A role is a collection of permissions. This article describes how to assign Microsoft Entra roles using the Microsoft Entra admin center and PowerShell.
prerequisites:
summary: |
- Privileged Role Administrator. To know who your Privileged Role Administrator is, see [List Microsoft Entra role assignments](view-assignments.md)
- Microsoft Entra ID P2 license when using Privileged Identity Management (PIM)
- [Microsoft Graph PowerShell](/powershell/microsoftgraph/overview) module when using PowerShell
- Admin consent when using Graph explorer for Microsoft Graph API
For more information, see [Prerequisites to use PowerShell or Graph Explorer](prerequisites.md).
procedureSection:
- title: |
Microsoft Entra admin center
summary: |
Follow these steps to assign Microsoft Entra roles using the Microsoft Entra admin center. Your experience will be different depending on whether you have [Microsoft Entra Privileged Identity Management (PIM)](~/id-governance/privileged-identity-management/pim-configure.md) enabled.
### Assign a role
[!INCLUDE [portal updates](~/includes/portal-update.md)]
1. Sign in to the [Microsoft Entra admin center](https://entra.microsoft.com) as at least a [Privileged Role Administrator](~/identity/role-based-access-control/permissions-reference.md#privileged-role-administrator).
1. Browse to **Identity** > **Roles & admins** > **Roles & admins**.
![Screenshot of Roles and administrators page in Microsoft Entra ID.](./media/common/roles-and-administrators.png)
1. Find the role you need. You can use the search box or **Add filters** to filter the roles.
1. Select the role name to open the role. Don't add a check mark next to the role.
![Screenshot that shows selecting a role.](./media/common/role-select-mouse.png)
1. Select **Add assignments** and then select the users you want to assign to this role.
If you see something different from the following picture, you might have PIM enabled. See the next section.
![Screenshot of Add assignments pane for selected role.](./media/manage-roles-portal/add-assignments.png)
[!INCLUDE [rbac-assign-roles-guest-user-note](../../includes/rbac-assign-roles-guest-user-note.md)]
1. Select **Add** to assign the role.
### Assign a role using PIM
If you have [Microsoft Entra Privileged Identity Management (PIM)](~/id-governance/privileged-identity-management/pim-configure.md) enabled, you have additional role assignment capabilities. For example, you can make a user eligible for a role or set the duration. When PIM is enabled, there are two ways that you can assign roles using the Microsoft Entra admin center. You can use the Roles and administrators page or the PIM experience. Either way uses the same PIM service.
Follow these steps to assign roles using the **Roles and administrators** page. If you want to assign roles using Privileged Identity Management, see [Assign Microsoft Entra roles in Privileged Identity Management](~/id-governance/privileged-identity-management/pim-how-to-add-role-to-user.md).
steps:
- |
Sign in to the [Microsoft Entra admin center](https://entra.microsoft.com) as at least a [Privileged Role Administrator](~/identity/role-based-access-control/permissions-reference.md#privileged-role-administrator).
- |
Browse to **Identity** > **Roles & admins** > **Roles & admins**.
![Screenshot of Roles and administrators page in Microsoft Entra ID when PIM enabled.](./media/common/roles-and-administrators.png)
- |
Find the role you need. You can use the search box or **Add filters** to filter the roles.
- |
Select the role name to open the role and see its eligible, active, and expired role assignments. Don't add a check mark next to the role.
![Screenshot that shows selecting a role.](./media/common/role-select-mouse.png)
- |
Select **Add assignments**.
- |
Select **No member selected** and then select the users you want to assign to this role.
![Screenshot of Add assignments page and Select a member pane with PIM enabled.](./media/manage-roles-portal/add-assignments-pim.png)
- |
Select **Next**.
- |
On the **Setting** tab, select whether you wan to make this role assignment **Eligible** or **Active**.
An eligible role assignment means that the user must perform one or more actions to use the role. An active role assignment means that the user doesn't have to perform any action to use the role. For more information about what these settings mean, see [PIM terminology](~/id-governance/privileged-identity-management/pim-configure.md#terminology).
![Screenshot of Add assignments page and Setting tab with PIM enabled.](./media/manage-roles-portal/add-assignments-pim-setting.png)
- |
Use the remaining options to set the duration for the assignment.
- |
Select **Assign** to assign the role.
- title: |
PowerShell
summary: |
Follow these steps to assign Microsoft Entra roles using PowerShell.
### Setup
1. Open a PowerShell window and use [Import-Module](/powershell/module/microsoft.powershell.core/import-module) to import the Microsoft Graph PowerShell module. For more information, see [Prerequisites to use PowerShell or Graph Explorer](prerequisites.md).
```powershell
Import-Module -Name Microsoft.Graph.Identity.Governance -Force
```
1. In a PowerShell window, use [Connect-MgGraph](/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0&preserve-view=true) to sign in to your tenant.
```powershell
Connect-MgGraph -Scopes "RoleManagement.ReadWrite.Directory"
```
1. Use [Get-MgUser](/powershell/module/microsoft.graph.users/get-mguser?view=graph-powershell-1.0&preserve-view=true) to get the user you want to assign a role to.
```powershell
$user = Get-MgUser -Filter "userPrincipalName eq 'johndoe@contoso.com'"
```
### Assign a role
1. Use [Get-MgRoleManagementDirectoryRoleDefinition](/powershell/module/microsoft.graph.identity.governance/get-mgrolemanagementdirectoryroledefinition?view=graph-powershell-1.0&preserve-view=true) to get the role you want to assign.
```powershell
$roledefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'Billing Administrator'"
```
1. Use [New-MgRoleManagementDirectoryRoleAssignment](/powershell/module/microsoft.graph.identity.governance/new-mgrolemanagementdirectoryroleassignment?view=graph-powershell-1.0&preserve-view=true) to assign the role.
```powershell
$roleassignment = New-MgRoleManagementDirectoryRoleAssignment -DirectoryScopeId '/' -RoleDefinitionId $roledefinition.Id -PrincipalId $user.Id
```
### Assign a role as eligible using PIM
If PIM is enabled, you have additional capabilities, such as making a user eligible for a role assignment or defining the start and end time for a role assignment. These capabilities use a different set of PowerShell commands. For more information about using PowerShell and PIM, see [PowerShell for Microsoft Entra roles in Privileged Identity Management](/powershell/microsoftgraph/tutorial-pim).
steps:
- |
Use [Get-MgRoleManagementDirectoryRoleDefinition](/powershell/module/microsoft.graph.identity.governance/get-mgrolemanagementdirectoryroledefinition?view=graph-powershell-1.0&preserve-view=true) to get the role you want to assign.
```powershell
$roledefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'Billing Administrator'"
```
- |
Use the following command to create a hash table to store all the necessary attributes required to assign the role to the user. The Principal ID will be the user ID to which you want to assign the role. In this example, the assignment will be valid only for **10 hours**.
```powershell
$params = @{
"PrincipalId" = "aaaaaaaa-bbbb-cccc-1111-222222222222"
"RoleDefinitionId" = "b0f54661-2d74-4c50-afa3-1ec803f12efe"
"Justification" = "Add eligible assignment"
"DirectoryScopeId" = "/"
"Action" = "AdminAssign"
"ScheduleInfo" = @{
"StartDateTime" = Get-Date
"Expiration" = @{
"Type" = "AfterDuration"
"Duration" = "PT10H"
}
}
}
```
- |
Use [New-MgRoleManagementDirectoryRoleEligibilityScheduleRequest](/powershell/module/microsoft.graph.identity.governance/new-mgrolemanagementdirectoryroleeligibilityschedulerequest?view=graph-powershell-1.0&preserve-view=true) to assign the role as eligible. Once the role has been assigned, it will reflect in the Microsoft Entra admin center under **Identity governance** > **Privileged Identity Management** > **Microsoft Entra roles** > **Assignments** > **Eligible Assignments** section.
```powershell
New-MgRoleManagementDirectoryRoleEligibilityScheduleRequest -BodyParameter $params | Format-List Id, Status, Action, AppScopeId, DirectoryScopeId, RoleDefinitionId, IsValidationOnly, Justification, PrincipalId, CompletedDateTime, CreatedDateTime
```
## Microsoft Graph API
Follow these instructions to assign a role using the Microsoft Graph API.
### Assign a role
In this example, a security principal with objectID `aaaaaaaa-bbbb-cccc-1111-222222222222` is assigned the Billing Administrator role (role definition ID `b0f54661-2d74-4c50-afa3-1ec803f12efe`) at tenant scope. To see the list of immutable role template IDs of all built-in roles, see [Microsoft Entra built-in roles](permissions-reference.md).
```http
POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments
Content-type: application/json
{
"@odata.type": "#microsoft.graph.unifiedRoleAssignment",
"roleDefinitionId": "b0f54661-2d74-4c50-afa3-1ec803f12efe",
"principalId": "aaaaaaaa-bbbb-cccc-1111-222222222222",
"directoryScopeId": "/"
}
```
### Assign a role using PIM
#### Assign a time-bound eligible role assignment
In this example, a security principal with objectID `aaaaaaaa-bbbb-cccc-1111-222222222222` is assigned a time-bound eligible role assignment to Billing Administrator (role definition ID `b0f54661-2d74-4c50-afa3-1ec803f12efe`) for 180 days.
```http
POST https://graph.microsoft.com/v1.0/rolemanagement/directory/roleEligibilityScheduleRequests
Content-type: application/json
{
"action": "adminAssign",
"justification": "for managing admin tasks",
"directoryScopeId": "/",
"principalId": "aaaaaaaa-bbbb-cccc-1111-222222222222",
"roleDefinitionId": "b0f54661-2d74-4c50-afa3-1ec803f12efe",
"scheduleInfo": {
"startDateTime": "2021-07-15T19:15:08.941Z",
"expiration": {
"type": "afterDuration",
"duration": "PT180D"
}
}
}
```
#### Assign a permanent eligible role assignment
In the following example, a security principal is assigned a permanent eligible role assignment to Billing Administrator.
```http
POST https://graph.microsoft.com/v1.0/rolemanagement/directory/roleEligibilityScheduleRequests
Content-type: application/json
{
"action": "adminAssign",
"justification": "for managing admin tasks",
"directoryScopeId": "/",
"principalId": "aaaaaaaa-bbbb-cccc-1111-222222222222",
"roleDefinitionId": "b0f54661-2d74-4c50-afa3-1ec803f12efe",
"scheduleInfo": {
"startDateTime": "2021-07-15T19:15:08.941Z",
"expiration": {
"type": "noExpiration"
}
}
}
```
#### Activate a role assignment
To activate the role assignment, use the [Create roleAssignmentScheduleRequests](/graph/api/rbacapplication-post-roleeligibilityschedulerequests) API.
```http
POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignmentScheduleRequests
Content-type: application/json
{
"action": "selfActivate",
"justification": "activating role assignment for admin privileges",
"roleDefinitionId": "b0f54661-2d74-4c50-afa3-1ec803f12efe",
"directoryScopeId": "/",
"principalId": "aaaaaaaa-bbbb-cccc-1111-222222222222"
}
```
For more information about managing Microsoft Entra roles through the PIM API in Microsoft Graph, see [Overview of role management through the privileged identity management (PIM) API](/graph/api/resources/privilegedidentitymanagementv3-overview).
relatedContent:
- text: List Microsoft Entra role assignments
url: view-assignments.md
- text: Assign custom roles with resource scope using PowerShell
url: custom-assign-powershell.md
- text: Microsoft Entra built-in roles
url: permissions-reference.md