適用於: SQL Server 2025 (17.x)
本文提供逐步指南,教您如何設定和配置由 Azure Arc 啟用的 Microsoft Entra ID 的受控身份,用於 SQL Server。
關於 SQL Server 管理身份的概述,請參見 Azure Arc 啟用的 SQL Server 管理身份。
先決條件
在使用 Azure Arc 啟用的 SQL Server 管理身份之前,請確保你符合以下先決條件:
- 支援 SQL Server 2025 及以後版本,運行於 Windows。
- 將您的 SQL Server 連線到 Azure Arc。
- 最新版的 適用於 SQL Server 的 Azure 擴充功能。
啟用主要管理式識別
如果您已將適用於 SQL Server 的 Azure 擴充功能安裝到伺服器,您可以直接從 Azure 入口網站為您的 SQL Server 實例啟用主要受控識別。 您也可以藉由更新登錄來手動啟用主要受控識別,但應謹慎執行。
若要在 Azure 入口網站中啟用主要受控識別,請遵循下列步驟:
移至 Azure 入口網站,以查看由 Azure Arc 啟用的 SQL Server 資源。
在 [ 設定] 底下,選取 [Microsoft Entra ID 和 Purview ],以開啟 [Microsoft Entra ID 和 Purview ] 頁面。
備註
如果您沒有看到 [ 啟用Microsoft專案標識符驗證 ] 選項,請確定您的 SQL Server 實例已連線到 Azure Arc,且已安裝最新的 SQL 擴充功能。
在 [Microsoft Entra ID 和 Purview ] 頁面上,核取 [ 使用主要受控識別 ] 旁的方塊,然後使用 [儲存 ] 來套用您的設定:
將應用程式權限授予身份
這很重要
只有 特殊許可權角色管理員 或更高角色可以授與這些許可權。
系統指派的受控識別,其使用已啟用 Arc 的電腦名稱,必須具有下列Microsoft Graph 應用程式許可權(應用程式角色):
User.Read.All:允許存取 Microsoft Entra 使用者資訊。
GroupMember.Read.All:允許存取 Microsoft Entra 群組資訊。
Application.Read.ALL:允許存取 Microsoft Entra 服務主體 (應用程式) 資訊。
您可以使用 PowerShell 將必要的許可權授與受控識別。 或者,您可以 建立可指派角色的群組。 建立群組之後,請將目錄讀取者角色或 User.Read.All、 和 GroupMember.Read.AllApplication.Read.All 許可權指派給群組,並將已啟用 Azure Arc 的機器的所有系統指派受控識別新增至群組。 我們不建議在生產環境中使用 Directory Readers 角色。
下列 PowerShell 腳本會將必要的許可權授與受控識別。 請確定此腳本是在 PowerShell 7.5 或更新版本上執行,並 Microsoft.Graph 已安裝模組 2.28 或更新版本。
# Set your Azure tenant and managed identity name
$tenantID = '<Enter-Your-Azure-Tenant-Id>'
$managedIdentityName = '<Enter-Your-Arc-HostMachine-Name>'
# Connect to Microsoft Graph
try {
Connect-MgGraph -TenantId $tenantID -ErrorAction Stop
Write-Output "Connected to Microsoft Graph successfully."
}
catch {
Write-Error "Failed to connect to Microsoft Graph: $_"
return
}
# Get Microsoft Graph service principal
$graphAppId = '00000003-0000-0000-c000-000000000000'
$graphSP = Get-MgServicePrincipal -Filter "appId eq '$graphAppId'"
if (-not $graphSP) {
Write-Error "Microsoft Graph service principal not found."
return
}
# Get the managed identity service principal
$managedIdentity = Get-MgServicePrincipal -Filter "displayName eq '$managedIdentityName'"
if (-not $managedIdentity) {
Write-Error "Managed identity '$managedIdentityName' not found."
return
}
# Define roles to assign
$requiredRoles = @(
"User.Read.All",
"GroupMember.Read.All",
"Application.Read.All"
)
# Assign roles using scoped syntax
foreach ($roleValue in $requiredRoles) {
$appRole = $graphSP.AppRoles | Where-Object {
$_.Value -eq $roleValue -and $_.AllowedMemberTypes -contains "Application"
}
if ($appRole) {
try {
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $managedIdentity.Id `
-PrincipalId $managedIdentity.Id `
-ResourceId $graphSP.Id `
-AppRoleId $appRole.Id `
-ErrorAction Stop
Write-Output "Successfully assigned role '$roleValue' to '$managedIdentityName'."
}
catch {
Write-Warning "Failed to assign role '$roleValue': $_"
}
}
else {
Write-Warning "Role '$roleValue' not found in Microsoft Graph AppRoles."
}
}
建立帳號和使用者
請遵循 Microsoft Entra 教學 課程中的步驟,建立受控識別的登入和使用者。