Skip to content

Commit 01c6347

Browse files
Merge pull request #227929 from vivgk/vvkeditaadnew
vvkaadeditnew
2 parents 8f6d94b + 8c4fe7a commit 01c6347

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

articles/mysql/flexible-server/concepts-azure-ad-authentication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ The following permissions are required to allow the UMI to read from the Microso
8181

8282
For guidance about how to grant and use the permissions, refer to [Overview of Microsoft Graph permissions](/graph/permissions-overview)
8383

84-
After you grant the permissions to the UMI, they're enabled for all servers or instances created with the UMI assigned as a server identity.
84+
After you grant the permissions to the UMI, they're enabled for all servers created with the UMI assigned as a server identity.
8585

8686
## Token Validation
8787

articles/mysql/flexible-server/how-to-azure-ad.md

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ To create an Azure AD Admin user, follow the following steps.
5555
- [GroupMember.Read.All](/graph/permissions-reference#group-permissions): Allows access to Azure AD group information.
5656
- [Application.Read.ALL](/graph/permissions-reference#application-resource-permissions): Allows access to Azure AD service principal (application) information.
5757

58-
For guidance about how to grant and use the permissions, refer to [Overview of Microsoft Graph permissions](/graph/permissions-overview)
59-
60-
After you grant the permissions to the UMI, they're enabled for all servers or instances created with the UMI assigned as a server identity.
61-
6258
> [!IMPORTANT]
6359
> Only a [Global Administrator](../../active-directory/roles/permissions-reference.md#global-administrator) or [Privileged Role Administrator](../../active-directory/roles/permissions-reference.md#privileged-role-administrator) can grant these permissions.
6460
@@ -67,6 +63,73 @@ After you grant the permissions to the UMI, they're enabled for all servers or i
6763
> [!NOTE]
6864
> Only one Azure AD admin can be created per MySQL server, and selecting another overwrites the existing Azure AD admin configured for the server.
6965
66+
### Grant permissions to User assigned managed identity
67+
68+
The following sample PowerShell script grants the necessary permissions for a UMI. This sample assigns permissions to the UMI `umiservertest`.
69+
70+
To run the script, you must sign in as a user with a Global Administrator or Privileged Role Administrator role.
71+
72+
The script grants the `User.Read.All`, `GroupMember.Read.All`, and `Application.Read.ALL` permissions to a UMI to access [Microsoft Graph](/graph/auth/auth-concepts#microsoft-graph-permissions).
73+
74+
```powershell
75+
# Script to assign permissions to the UMI "umiservertest"
76+
77+
import-module AzureAD
78+
$tenantId = '<tenantId>' # Your Azure AD tenant ID
79+
80+
Connect-AzureAD -TenantID $tenantId
81+
# Log in as a user with a "Global Administrator" or "Privileged Role Administrator" role
82+
# Script to assign permissions to an existing UMI
83+
# The following Microsoft Graph permissions are required:
84+
# User.Read.All
85+
# GroupMember.Read.All
86+
# Application.Read.ALL
87+
88+
# Search for Microsoft Graph
89+
$AAD_SP = Get-AzureADServicePrincipal -SearchString "Microsoft Graph";
90+
$AAD_SP
91+
# Use Microsoft Graph; in this example, this is the first element $AAD_SP[0]
92+
93+
#Output
94+
95+
#ObjectId AppId DisplayName
96+
#-------- ----- -----------
97+
#47d73278-e43c-4cc2-a606-c500b66883ef 00000003-0000-0000-c000-000000000000 Microsoft Graph
98+
#44e2d3f6-97c3-4bc7-9ccd-e26746638b6d 0bf30f3b-4a52-48df-9a82-234910c4a086 Microsoft Graph #Change
99+
100+
$MSIName = "<managedIdentity>"; # Name of your user-assigned
101+
$MSI = Get-AzureADServicePrincipal -SearchString $MSIName
102+
if($MSI.Count -gt 1)
103+
{
104+
Write-Output "More than 1 principal found, please find your principal and copy the right object ID. Now use the syntax $MSI = Get-AzureADServicePrincipal -ObjectId <your_object_id>"
105+
106+
# Choose the right UMI
107+
108+
Exit
109+
}
110+
111+
# If you have more UMIs with similar names, you have to use the proper $MSI[ ]array number
112+
113+
# Assign the app roles
114+
115+
$AAD_AppRole = $AAD_SP.AppRoles | Where-Object {$_.Value -eq "User.Read.All"}
116+
New-AzureADServiceAppRoleAssignment -ObjectId $MSI.ObjectId -PrincipalId $MSI.ObjectId -ResourceId $AAD_SP.ObjectId[0] -Id $AAD_AppRole.Id
117+
$AAD_AppRole = $AAD_SP.AppRoles | Where-Object {$_.Value -eq "GroupMember.Read.All"}
118+
New-AzureADServiceAppRoleAssignment -ObjectId $MSI.ObjectId -PrincipalId $MSI.ObjectId -ResourceId $AAD_SP.ObjectId[0] -Id $AAD_AppRole.Id
119+
$AAD_AppRole = $AAD_SP.AppRoles | Where-Object {$_.Value -eq "Application.Read.All"}
120+
New-AzureADServiceAppRoleAssignment -ObjectId $MSI.ObjectId -PrincipalId $MSI.ObjectId -ResourceId $AAD_SP.ObjectId[0] -Id $AAD_AppRole.Id
121+
```
122+
123+
In the final steps of the script, if you have more UMIs with similar names, you have to use the proper `$MSI[ ]array` number. An example is `$AAD_SP.ObjectId[0]`.
124+
125+
### Check permissions for user-assigned managed identity
126+
127+
To check permissions for a UMI, go to the [Azure portal](https://portal.azure.com). In the **Azure Active Directory** resource, go to **Enterprise applications**. Select **All Applications** for **Application type**, and search for the UMI that was created.
128+
129+
Select the UMI, and go to the **Permissions** settings under **Security**.
130+
131+
After you grant the permissions to the UMI, they're enabled for all servers created with the UMI assigned as a server identity.
132+
70133
## Connect to Azure Database for MySQL flexible server using Azure AD
71134

72135
### 1 - Authenticate with Azure AD

0 commit comments

Comments
 (0)