Skip to content

Commit 77b45e1

Browse files
authored
Add script to assign Managed Identity to Maestro app (#5427)
1 parent 144971b commit 77b45e1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<#
2+
.SYNOPSIS
3+
Assigns a given Managed Identity (MI) a role in the Maestro application.
4+
#>
5+
6+
[CmdletBinding()]
7+
param(
8+
[Parameter(Mandatory = $true)]
9+
[string]$SubscriptionId,
10+
11+
[Parameter(Mandatory = $true)]
12+
[string]$ResourceGroupName,
13+
14+
[Parameter(Mandatory = $true)]
15+
[string]$ManagedIdentityName,
16+
17+
[Parameter(Mandatory = $false)]
18+
[string]$AppServicePrincipal = "caf36d9b-2940-4270-9a1d-c494eda6ea18", # PROD Maestro application object ID
19+
20+
[Parameter(Mandatory = $false)]
21+
[ValidateSet("user", "admin")]
22+
[string]$Role = "user"
23+
)
24+
25+
# Set app role ID based on role parameter (get it from the JSON manifest of the Maestro application in Azure AD)
26+
$appRoleId = switch ($Role) {
27+
"user" { "108187e7-df11-4592-b306-2a2a0b15d8f0" } # User role ID
28+
"admin" { "8b5767ed-0675-4e95-9858-f9851b884345" } # Admin role ID
29+
}
30+
31+
Write-Host "Using role: $Role (ID: $appRoleId)"
32+
33+
az login
34+
35+
$resourceIdWithManagedIdentity = "/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$ManagedIdentityName"
36+
$principalId = (az identity show --resource-group $ResourceGroupName --name $ManagedIdentityName --subscription $SubscriptionId --query 'principalId' -o tsv)
37+
Write-Host "Managed identity principal ID: $($principalId)"
38+
39+
$body = "{'principalId': '$principalId', 'resourceId': '$($appServicePrincipal)', 'appRoleId': '$($appRoleId)'}"
40+
Write-Host "Body: $body"
41+
42+
az rest -m POST -u https://graph.microsoft.com/v1.0/servicePrincipals/$principalId/appRoleAssignments -b $body

0 commit comments

Comments
 (0)