Skip to content

Commit 9fb5285

Browse files
committed
chore: use user and group admin on au scope for replicator sp
Assigning custom role to the replicator on AU scope is not possible due to a bug in Azure See hashicorp/terraform-provider-azuread#1546. Therefore we need to assign User and Groups administrator built in roles. This only allows replicator to have admin permissions on the groups and users assigned to the AU. For replicator to assign users to groups successfully, we therefore need User.Read.All on tenant level.
1 parent a5748a2 commit 9fb5285

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [v0.13.2]
11+
12+
### Changed
13+
14+
- Assign User.Read.All permission to replicator when using administrative units.
15+
- Assign replicator to User Administrator and Groups Administrator roles in administrative units scope.
16+
1017
## [v0.13.1]
1118

1219
### Changed

modules/meshcloud-replicator-service-principal/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ No modules.
1616
| Name | Type |
1717
|------|------|
1818
| [azuread_administrative_unit.meshcloud_replicator_au](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/administrative_unit) | resource |
19+
| [azuread_administrative_unit_role_member.groups_admin_assignment](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/administrative_unit_role_member) | resource |
20+
| [azuread_administrative_unit_role_member.user_admin_assignment](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/administrative_unit_role_member) | resource |
1921
| [azuread_app_role_assignment.meshcloud_replicator-administrativeunit](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/app_role_assignment) | resource |
2022
| [azuread_app_role_assignment.meshcloud_replicator-directory](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/app_role_assignment) | resource |
2123
| [azuread_app_role_assignment.meshcloud_replicator-group](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/app_role_assignment) | resource |
2224
| [azuread_app_role_assignment.meshcloud_replicator-user](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/app_role_assignment) | resource |
25+
| [azuread_app_role_assignment.meshcloud_replicator-users_read_all](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/app_role_assignment) | resource |
2326
| [azuread_application.meshcloud_replicator](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application) | resource |
2427
| [azuread_application_federated_identity_credential.meshcloud_replicator](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application_federated_identity_credential) | resource |
2528
| [azuread_application_password.application_pw](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application_password) | resource |
26-
| [azuread_custom_directory_role.meshcloud_replicator_au_role](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/custom_directory_role) | resource |
27-
| [azuread_directory_role_assignment.meshcloud_replicator_au_assignment](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/directory_role_assignment) | resource |
29+
| [azuread_directory_role.groups_administrator](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/directory_role) | resource |
30+
| [azuread_directory_role.user_administrator](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/directory_role) | resource |
2831
| [azuread_service_principal.meshcloud_replicator](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/service_principal) | resource |
2932
| [azurerm_management_group_policy_assignment.privilege-escalation-prevention](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/management_group_policy_assignment) | resource |
3033
| [azurerm_policy_definition.privilege_escalation_prevention](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/policy_definition) | resource |

modules/meshcloud-replicator-service-principal/module.tf

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ resource "azuread_app_role_assignment" "meshcloud_replicator-administrativeunit"
232232
depends_on = [azuread_application.meshcloud_replicator]
233233
}
234234

235+
resource "azuread_app_role_assignment" "meshcloud_replicator-users_read_all" {
236+
count = var.administrative_unit_name == null ? 0 : 1
237+
app_role_id = data.azuread_service_principal.msgraph.app_role_ids["User.Read.All"]
238+
principal_object_id = azuread_service_principal.meshcloud_replicator.object_id
239+
resource_object_id = data.azuread_service_principal.msgraph.object_id
240+
depends_on = [azuread_application.meshcloud_replicator]
241+
}
242+
235243
//---------------------------------------------------------------------------
236244
// Policy Definition for preventing the Application from assigning other privileges to itself
237245
// Assign it to the specified scope
@@ -311,35 +319,38 @@ resource "azuread_administrative_unit" "meshcloud_replicator_au" {
311319
}
312320

313321
//--------------------------------------------------------------------------
314-
// Custom AU-scoped Role
322+
// AU Role Assignment for meshcloud_replicator
315323
//--------------------------------------------------------------------------
316324

317-
resource "azuread_custom_directory_role" "meshcloud_replicator_au_role" {
325+
326+
/*
327+
328+
There is an issue when assigning the replicator a custom role in the AU scope, where the role is not found.
329+
330+
See https://github.com/hashicorp/terraform-provider-azuread/issues/1546.
331+
332+
For now we assign User Administrator and Groups Administrator roles as that is already restricted to the AU scope.
333+
*/
334+
resource "azuread_directory_role" "user_administrator" {
318335
count = var.administrative_unit_name == null ? 0 : 1
319-
display_name = "meshStack Replicator AU Role"
320-
description = "Custom role for meshStack replicator with limited User and Group permissions"
321-
enabled = true
322-
version = "1.0"
336+
display_name = "User Administrator"
337+
}
323338

324-
# users permissions
325-
permissions {
326-
allowed_resource_actions = [
327-
"microsoft.directory/users/standard/read",
328-
"microsoft.directory/groups/standard/read",
329-
"microsoft.directory/groups/create",
330-
"microsoft.directory/groups/members/update",
331-
"microsoft.directory/groups/members/read",
332-
"microsoft.directory/groups/memberOf/read",
333-
]
334-
}
339+
resource "azuread_directory_role" "groups_administrator" {
340+
count = var.administrative_unit_name == null ? 0 : 1
341+
display_name = "Groups Administrator"
335342
}
336343

337-
//--------------------------------------------------------------------------
338-
// AU Role Assignment for meshcloud_replicator
339-
//--------------------------------------------------------------------------
344+
resource "azuread_administrative_unit_role_member" "user_admin_assignment" {
345+
count = var.administrative_unit_name == null ? 0 : 1
346+
role_object_id = azuread_directory_role.user_administrator[0].object_id
347+
administrative_unit_object_id = azuread_administrative_unit.meshcloud_replicator_au[0].object_id
348+
member_object_id = azuread_service_principal.meshcloud_replicator.object_id
349+
}
340350

341-
resource "azuread_directory_role_assignment" "meshcloud_replicator_au_assignment" {
342-
count = var.administrative_unit_name == null ? 0 : 1
343-
role_id = azuread_custom_directory_role.meshcloud_replicator_au_role[0].object_id
344-
principal_object_id = azuread_service_principal.meshcloud_replicator.object_id
351+
resource "azuread_administrative_unit_role_member" "groups_admin_assignment" {
352+
count = var.administrative_unit_name == null ? 0 : 1
353+
role_object_id = azuread_directory_role.groups_administrator[0].object_id
354+
administrative_unit_object_id = azuread_administrative_unit.meshcloud_replicator_au[0].object_id
355+
member_object_id = azuread_service_principal.meshcloud_replicator.object_id
345356
}

0 commit comments

Comments
 (0)