Skip to content

Commit b735edb

Browse files
PratimDasguptarwestMSFT
authored andcommitted
Learn Editor: Update managed-identity.md
1 parent ac88c7b commit b735edb

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

docs/sql-server/azure-arc/managed-identity.md

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Learn how to use a managed identity with SQL Server 2025.
44
author: PratimDasgupta
55
ms.author: prdasgu
66
ms.reviewer: mikeray, randolphwest, mathoma, vanto
7-
ms.date: 06/09/2025
7+
ms.date: 07/06/2025
88
ms.service: sql
99
ms.topic: how-to
1010
ms.custom:
@@ -35,15 +35,15 @@ When using managed identity with SQL Server enabled by Azure Arc, consider the f
3535
- Only system-assigned managed identities are supported.
3636
- SQL Server uses this Azure Arc server level managed identity as the **primary managed identity**.
3737
- SQL Server can use this primary managed identity in either `inbound` and/or `outbound` connections.
38-
- `Inbound connections` are logins and users connecting to SQL Server. Inbound connections can also be achieved by using [App Registration available from SQL Server 2022](entra-authentication-setup-tutorial.md).
38+
- `Inbound connections` are logins and users connecting to SQL Server. Inbound connections can also be achieved by using [App registration](entra-authentication-setup-tutorial.md), starting in [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)].
3939
- `Outbound connections` are SQL Server connections to Azure resources, like backup to URL, or connecting to Azure Key Vault.
4040
- App Registration **can't** enable a SQL Server to make outbound connections. Outbound connections need a primary managed identity assigned to the SQL Server.
4141

4242
## Prerequisites
4343

4444
Before you can use a managed identity with SQL Server enabled by Azure Arc, ensure that you meet the following prerequisites:
4545

46-
- [Connect the SQL Server instance to Azure Arc](connect.md).
46+
- [Connect your SQL Server to Azure Arc](connect.md).
4747
- The latest version of the [Azure Extension for SQL Server](release-notes.md).
4848

4949
## Enable the primary managed identity
@@ -52,19 +52,18 @@ If you've installed the Azure Extension for SQL Server to your server, you can e
5252

5353
### [Azure portal](#tab/portal)
5454

55-
To enable the primary managed identity in the Azure portal, follow these steps:
55+
To enable the primary managed identity in the Azure portal, follow these steps:
5656

5757
1. Go to your [SQL Server enabled by Azure Arc](https://portal.azure.com/#view/Microsoft_Azure_ArcCenterUX/ArcCenterMenuBlade/~/sqlServerInstances) resource in the Azure portal.
5858
1. Under **Settings**, select **Microsoft Entra ID and Purview** to open the **Microsoft Entra ID and Purview** page.
5959

6060
> [!NOTE]
61-
> If you don't see the **Enable Microsoft Entra ID authentication** option, ensure that your SQL Server instance is connected to Azure Arc and that you have the latest SQL extension installed.
61+
> If you don't see the **Enable Microsoft Entra ID authentication** option, ensure that your SQL Server instance is connected to Azure Arc and that you have the latest SQL extension installed.
6262
6363
1. On the **Microsoft Entra ID and Purview** page, check the box next to **Use a primary managed identity** and then use **Save** to apply your configuration:
6464

6565
:::image type="content" source="media/managed-identity/entra-portal.png" alt-text="Screenshot of the Microsoft Entra option in the Azure portal." lightbox="media/managed-identity/entra-portal.png":::
6666

67-
6867
### [Manually](#tab/manual)
6968

7069
It's possible to manually enable the primary managed identity for your SQL Server instance by updating the registry, but should be done with extreme caution.
@@ -75,7 +74,7 @@ Grant **Read & execute** operating system permissions on the folder `C:\ProgramD
7574

7675
:::image type="content" source="media/managed-identity/tokens-folder-permissions.png" alt-text="Screenshot of Tokens folder Security properties tab.":::
7776

78-
You might need to grant admin permissions for the SQL Server service account on the `AzureConnectedMachineAgent` folder prior to the `Tokens` folder:
77+
You might need to grant admin permissions for the SQL Server service account on the `AzureConnectedMachineAgent` folder before the `Tokens` folder:
7978

8079
:::image type="content" source="media/managed-identity/azure-connected-machine-agent-folder-permissions.png" alt-text="Screenshot of AzureConnectedMachineAgent folder Security properties tab.":::
8180

@@ -153,7 +152,7 @@ This step backs up the registry before you make any changes. You can import this
153152

154153
#### Add entries
155154

156-
In this step, you'll add entries to the registry with Registry Editor.
155+
In this step, you add entries to the registry with Registry Editor.
157156

158157
1. Navigate this subkey: **\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQLServer\FederatedAuthentication**.
159158

@@ -171,7 +170,7 @@ In this step, you'll add entries to the registry with Registry Editor.
171170

172171
If you need to restore to previous registry settings, follow these steps.
173172

174-
1. Open the Registry Editor as described above.
173+
1. Open the Registry Editor as described previously.
175174
1. Select **File** from the menu.
176175
1. Select **Import**.
177176
1. Navigate to the location of your saved backup file.
@@ -187,35 +186,33 @@ The system-assigned managed identity, which uses the Arc-enabled machine name, m
187186

188187
You can use PowerShell to grant required permissions to the managed identity. Alternatively, you can [create a role-assignable group](/entra/identity/role-based-access-control/groups-create-eligible). After the group is created, assign the **Directory readers** role to the group, and add all system-assigned managed identities for your Arc-enabled machines to the group.
189188

190-
The following PowerShell script grants the required permissions to the managed identity:
189+
The following PowerShell script grants the required permissions to the managed identity. Make sure this script is run on PowerShell 7.5 or a later version, and has the `Microsoft.Graph` module 2.28 or later installed.
191190

192191
```powershell
193-
# Update these variables to match your Azure & Arc machine setup
192+
# Set your Azure tenant and managed identity name
194193
$tenantID = '<Enter-Your-Azure-Tenant-Id>'
195194
$managedIdentityName = '<Enter-Your-Arc-HostMachine-Name>'
196195
197-
# Install and connect to AzureAD
196+
# Connect to Microsoft Graph
198197
try {
199-
Install-Module -Name AzureAD -Force -Scope CurrentUser -ErrorAction Stop
200-
Import-Module AzureAD
201-
Connect-AzureAD -TenantId $tenantID
202-
Write-Output "Connected to AzureAD successfully."
203-
} catch {
204-
Write-Error "Failed to install or connect to AzureAD: $_"
198+
Connect-MgGraph -TenantId $tenantID -ErrorAction Stop
199+
Write-Output "Connected to Microsoft Graph successfully."
200+
}
201+
catch {
202+
Write-Error "Failed to connect to Microsoft Graph: $_"
205203
return
206204
}
207205
208-
# Get Microsoft Graph API service principal
206+
# Get Microsoft Graph service principal
209207
$graphAppId = '00000003-0000-0000-c000-000000000000'
210-
$graphSP = Get-AzureADServicePrincipal -Filter "appId eq '$graphAppId'"
208+
$graphSP = Get-MgServicePrincipal -Filter "appId eq '$graphAppId'"
211209
if (-not $graphSP) {
212210
Write-Error "Microsoft Graph service principal not found."
213211
return
214212
}
215213
216-
# Get the managed identity
217-
$managedIdentity = Get-AzureADServicePrincipal -SearchString $managedIdentityName | Where-Object { $_.DisplayName -eq $managedIdentityName }
218-
214+
# Get the managed identity service principal
215+
$managedIdentity = Get-MgServicePrincipal -Filter "displayName eq '$managedIdentityName'"
219216
if (-not $managedIdentity) {
220217
Write-Error "Managed identity '$managedIdentityName' not found."
221218
return
@@ -228,21 +225,27 @@ $requiredRoles = @(
228225
"Application.Read.All"
229226
)
230227
231-
# Assign roles
228+
# Assign roles using scoped syntax
232229
foreach ($roleValue in $requiredRoles) {
233-
$appRole = $graphSP.AppRoles | Where-Object { $_.Value -eq $roleValue -and $_.AllowedMemberTypes -contains "Application" }
230+
$appRole = $graphSP.AppRoles | Where-Object {
231+
$_.Value -eq $roleValue -and $_.AllowedMemberTypes -contains "Application"
232+
}
233+
234234
if ($appRole) {
235235
try {
236-
New-AzureADServiceAppRoleAssignment `
237-
-ObjectId $managedIdentity.ObjectId `
238-
-PrincipalId $managedIdentity.ObjectId `
239-
-ResourceId $graphSP.ObjectId `
240-
-Id $appRole.Id
236+
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $managedIdentity.Id `
237+
-PrincipalId $managedIdentity.Id `
238+
-ResourceId $graphSP.Id `
239+
-AppRoleId $appRole.Id `
240+
-ErrorAction Stop
241+
241242
Write-Output "Successfully assigned role '$roleValue' to '$managedIdentityName'."
242-
} catch {
243+
}
244+
catch {
243245
Write-Warning "Failed to assign role '$roleValue': $_"
244246
}
245-
} else {
247+
}
248+
else {
246249
Write-Warning "Role '$roleValue' not found in Microsoft Graph AppRoles."
247250
}
248251
}
@@ -261,6 +264,7 @@ Consider the following limitations when using a managed identity with SQL Server
261264
- The identity you choose to authenticate to SQL Server has to have either the **Directory Readers** role in Microsoft Entra ID or the following three Microsoft Graph application permissions (app roles): `User.Read.All`, `GroupMember.Read.All`, and `Application.Read.All`.
262265
- Once Microsoft Entra authentication is enabled, disabling isn't advisable. Disabling Microsoft Entra authentication forcefully by deleting registry entries can result in unpredictable behavior with SQL Server 2025.
263266
- Authenticating to SQL Server on Arc machines through Microsoft Entra authentication using the [FIDO2 method](/azure/active-directory/authentication/howto-authentication-passwordless-faqs) isn't currently supported.
267+
- [OPENROWSET BULK](../../t-sql/functions/openrowset-bulk-transact-sql.md) operations can also read the tokens folder `C:\ProgramData\AzureConnectedMachineAgent\Tokens\`. The `BULK` option requires either `ADMINISTER BULK OPERATIONS` or `ADMINISTER DATABASE BULK OPERATIONS` permissions. These permissions should be treated as equivalent to **[sysadmin](../../relational-databases/security/authentication-access/server-level-roles.md)**.
264268

265269
## Related content
266270

0 commit comments

Comments
 (0)