你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

如何使用基于传入信任的流设置 Microsoft Entra ID 的 Windows 身份验证

本文介绍如何实现基于传入信任的身份验证流,以允许运行 Windows 10、Windows Server 2012 或更高版本的 Windows 且已建立 Active Directory (AD) 联接的客户端使用 Windows 身份验证向 Azure SQL 托管实例进行身份验证。

本文还包括在 Microsoft Entra ID(以前称为 Azure Active Directory)和受信任的域对象中轮换服务帐户的 Kerberos 密钥的步骤,以及移除受信任的域对象和所有 Kerberos 设置的步骤(如果需要)。

启用基于信任的传入身份验证流是使用 Microsoft Entra ID 和 Kerberos 为 Azure SQL 托管实例设置 Windows 身份验证的一个步骤。 新式交互式流适用于运行 Windows 10 20H1、Windows Server 2022 或 Windows 更高版本的启发式客户端。

注意

Microsoft Entra ID 以前称为 Azure Active Directory (Azure AD)。

权限

若要完成本文中所述的步骤,需要:

  • 本地 Active Directory 管理员用户名和密码。
  • Microsoft Entra 全局管理员帐户用户名和密码。

先决条件

若要实现基于传入信任的身份验证流,请先确保满足以下先决条件:

先决条件 说明
客户端必须运行 Windows 10、Windows Server 2012 或更高版本的 Windows。
客户端必须建立 AD 联接。 域的功能级别必须是 Windows Server 2012 或更高版本。 可以通过运行 dsregcmd 命令:dsregcmd.exe /status来确定客户端是否建立 AD 联接
Azure AD 混合身份验证管理模块。 此 PowerShell 模块提供本地设置管理功能。
Azure 租户。
同一 Microsoft Entra 租户下计划用于身份验证的 Azure 订阅。
已安装 Microsoft Entra Connect 混合环境,即 Microsoft Entra ID 和 AD 中都存在标识。

创建和配置 Microsoft Entra Kerberos 受信任的域对象

若要创建和配置 Microsoft Entra Kerberos 受信任的域对象,请安装 Azure AD 混合身份验证管理 PowerShell 模块。

然后,使用 Azure AD 混合身份验证管理 PowerShell 模块在本地 AD 域中设置受信任的域对象,并使用 Microsoft Entra ID 注册信任信息。 这会在本地 AD 中创建入站信任关系,从而使 Microsoft Entra ID 能够信任本地 AD。

设置受信任的域对象

若要设置受信任的域对象,请先安装 Azure AD 混合身份验证管理 PowerShell 模块。

安装 Azure AD 混合身份验证管理 PowerShell 模块

  1. 使用“以管理员身份运行”选项启动 Windows PowerShell 会话。

  2. 使用以下脚本安装 Azure AD 混合身份验证管理 PowerShell 模块。 脚本:

    • 启用 TLS 1.2 进行通信。
    • 安装 NuGet 包提供程序。
    • 注册 PSGallery 存储库。
    • 安装 PowerShellGet 模块。
    • 安装 Azure AD 混合身份验证管理 PowerShell 模块。
      • Azure AD 混合身份验证管理 PowerShell 使用 AzureADPreview 模块,该模块提供高级 Microsoft Entra 管理功能。
      • 若要防止与 Azure AD PowerShell 模块发生不必要的安装冲突,此命令包括 –AllowClobber 选项标志。
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Install-PackageProvider -Name NuGet -Force

if (@(Get-PSRepository | ? {$_.Name -eq "PSGallery"}).Count -eq 0){
    Register-PSRepository -DefaultSet-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
}

Install-Module -Name PowerShellGet -Force

Install-Module -Name AzureADHybridAuthenticationManagement -AllowClobber

设置受信任的域对象

  1. 使用“以管理员身份运行”选项启动 Windows PowerShell 会话。

  2. 设置通用参数。 在运行以下脚本之前,对其进行自定义。

    • $domain 参数设置为本地 Active Directory 域名。
    • Get-Credential 提示时,输入本地 Active Directory 管理员用户名和密码。
    • $cloudUserName 参数设置为用于 Microsoft Entra 云访问的全局管理员特权帐户的用户名。

    注意

    如果要将当前 Windows 登录帐户用于本地 Active Directory 访问,可以跳过将凭据分配给 $domainCred 参数的步骤。 如果采用此方法,则不要在此步骤之后的 PowerShell 命令中包含 -DomainCredential 参数。

    $domain = "your on-premesis domain name, for example contoso.com"
    
    $domainCred = Get-Credential
    
    $cloudUserName = "Azure AD user principal name, for example admin@contoso.onmicrosoft.com"
    
  3. 检查当前 Kerberos 域设置。

    运行以下命令,检查域的当前 Kerberos 设置:

    Get-AzureAdKerberosServer -Domain $domain `
        -DomainCredential $domainCred `
        -UserPrincipalName $cloudUserName
    

    如果这是第一次调用任何 Microsoft Entra Kerberos 命令,系统会提示你访问 Microsoft Entra 云。

    • 输入你的 Microsoft Entra 全局管理员帐户密码。
    • 如果你的组织使用其他新式身份验证方法(如 Microsoft Entra 多重身份验证或智能卡),请按照要求的说明进行登录。

    如果首次配置 Microsoft Entra Kerberos 设置,Get-AzureAdKerberosServer cmdlet 会显示空白信息,如以下示例输出所示:

    ID                  :
    UserAccount         :
    ComputerAccount     :
    DisplayName         :
    DomainDnsName       :
    KeyVersion          :
    KeyUpdatedOn        :
    KeyUpdatedFrom      :
    CloudDisplayName    :
    CloudDomainDnsName  :
    CloudId             :
    CloudKeyVersion     :
    CloudKeyUpdatedOn   :
    CloudTrustDisplay   :
    

    如果域已支持 FIDO 身份验证,则 Get-AzureAdKerberosServer cmdlet 会显示 Microsoft Entra 服务帐户信息,如以下示例输出所示。 CloudTrustDisplay 字段会返回空值。

    ID                  : 25614
    UserAccount         : CN=krbtgt-AzureAD, CN=Users, DC=aadsqlmi, DC=net
    ComputerAccount     : CN=AzureADKerberos, OU=Domain Controllers, DC=aadsqlmi, DC=net
    DisplayName         : krbtgt_25614
    DomainDnsName       : aadsqlmi.net
    KeyVersion          : 53325
    KeyUpdatedOn        : 2/24/2022 9:03:15 AM
    KeyUpdatedFrom      : ds-aad-auth-dem.aadsqlmi.net
    CloudDisplayName    : krbtgt_25614
    CloudDomainDnsName  : aadsqlmi.net
    CloudId             : 25614
    CloudKeyVersion     : 53325
    CloudKeyUpdatedOn   : 2/24/2022 9:03:15 AM
    CloudTrustDisplay   :
    
  4. 添加受信任的域对象。

    运行 Set-AzureAdKerberosServer PowerShell cmdlet 以添加受信任的域对象。 请务必包含 -SetupCloudTrust 参数。 如果没有 Microsoft Entra 服务帐户,此命令会创建一个新的 Microsoft Entra 服务帐户。 仅当存在 Microsoft Entra 服务帐户时,此命令才会创建请求的受信任的域对象。

    Set-AzureADKerberosServer -Domain $domain -UserPrincipalName $cloudUserName -DomainCredential $domainCred -SetupCloudTrust
    

    注意

    在多域林中,若要避免在子域上运行命令时出现 LsaCreateTrustedDomainEx 0x549 错误,请执行以下操作:

    1. 在根域上运行命令(包括 -SetupCloudTrust 参数)。
    2. 在不使用 -SetupCloudTrust 参数的情况下,在子域上运行相同命令。

    创建受信任的域对象后,可以使用 Get-AzureAdKerberosServer PowerShell cmdlet 检查更新的 Kerberos 设置,如上一步所示。 如果已使用 -SetupCloudTrust 参数成功运行 Set-AzureAdKerberosServer cmdlet,则 CloudTrustDisplay 字段现应返回 Microsoft.AzureAD.Kdc.Service.TrustDisplay,如以下示例输出所示:

    ID                  : 25614
    UserAccount         : CN=krbtgt-AzureAD, CN=Users, DC=aadsqlmi, DC=net
    ComputerAccount     : CN=AzureADKerberos, OU=Domain Controllers, DC=aadsqlmi, DC=net
    DisplayName         : krbtgt_25614
    DomainDnsName       : aadsqlmi.net
    KeyVersion          : 53325
    KeyUpdatedOn        : 2/24/2022 9:03:15 AM
    KeyUpdatedFrom      : ds-aad-auth-dem.aadsqlmi.net
    CloudDisplayName    : krbtgt_25614
    CloudDomainDnsName  : aadsqlmi.net
    CloudId             : 25614
    CloudKeyVersion     : 53325
    CloudKeyUpdatedOn   : 2/24/2022 9:03:15 AM
    CloudTrustDisplay   : Microsoft.AzureAD.Kdc.Service.TrustDisplay
    

    注意

    Azure 主权云需要设置 TopLevelNames 属性,默认设置为 windows.net。 SQL 托管实例的 Azure 主权云部署使用其他顶级域名,例如将 usgovcloudapi.net 用于 Azure 美国政府云。 使用以下 PowerShell 命令将受信任的域对象设置为该顶级域名:Set-AzureADKerberosServer -Domain $domain -DomainCredential $domainCred -CloudCredential $cloudCred -SetupCloudTrust -TopLevelNames "usgovcloudapi.net,windows.net"。 可以使用以下 PowerShell 命令来验证设置:Get-AzureAdKerberosServer -Domain $domain -DomainCredential $domainCred -UserPrincipalName $cloudUserName | Select-Object -ExpandProperty CloudTrustDisplay

配置组策略对象 (GPO)

  1. 识别你的 Microsoft Entra 租户 ID

  2. 使用基于传入信任的流将以下组策略设置部署到客户端计算机:

    1. 编辑“管理模板\系统\Kerberos\指定 Kerberos 客户端的 KDC 代理服务器”策略设置。

    2. 选择“启用”。

    3. 在“选项”下,选择“显示...”。此时将打开“显示内容”对话框。

      Screenshot of dialog box to enable 'Specify KDC proxy servers for Kerberos clients'. The 'Show Contents' dialog allows input of a value name and the related value.

    4. 使用如下所示映射定义 KDC 代理服务器设置。 将 your_Azure_AD_tenant_id 占位符替换为你的 Microsoft Entra 租户 ID。 请注意值映射中 https 之后和结尾 / 之前的空格。

      值名称
      KERBEROS.MICROSOFTONLINE.COM <https login.microsoftonline.com:443:your_Azure_AD_tenant_id/kerberos />

      Screenshot of the 'Define KDC proxy server settings' dialog box. A table allows input of multiple rows. Each row consists of a value name and a value.

    5. 选择“确定”以关闭“显示内容”对话框。

    6. 在“指定 Kerberos 客户端的 KDC 代理服务器”对话框中选择“应用”。

轮换 Kerberos 密钥

可以出于管理目的定期轮换创建的 Microsoft Entra 服务帐户和受信任的域对象的 Kerberos 密钥。

Set-AzureAdKerberosServer -Domain $domain `
   -DomainCredential $domainCred `
   -UserPrincipalName $cloudUserName -SetupCloudTrust `
   -RotateServerKey

轮换密钥后,需要几个小时才能在 Kerberos KDC 服务器之间传播更改的密钥。 由于密钥分发时间,24 小时内可轮换一次密钥。 如果出于任何原因需要在 24 小时内再次轮换密钥(例如,在刚刚创建受信任的域对象之后),可以添加 -Force 参数:

Set-AzureAdKerberosServer -Domain $domain `
   -DomainCredential $domainCred `
   -UserPrincipalName $cloudUserName -SetupCloudTrust `
   -RotateServerKey -Force

删除受信任的域对象

可以使用以下命令删除已添加的受信任的域对象:

Remove-AzureADKerberosTrustedDomainObject -Domain $domain `
   -DomainCredential $domainCred `
   -UserPrincipalName $cloudUserName

此命令将仅删除受信任的域对象。 如果域支持 FIDO 身份验证,则可以移除受信任的域对象,同时保留 FIDO 身份验证服务所需的 Microsoft Entra 服务帐户。

删除所有 Kerberos 设置

可以使用以下命令移除 Microsoft Entra 服务帐户和受信任的域对象:

Remove-AzureAdKerberosServer -Domain $domain `
   -DomainCredential $domainCred `
   -UserPrincipalName $cloudUserName

后续步骤

详细了解如何在 Azure SQL 托管实例上实现 Microsoft Entra 主体的 Windows 身份验证: