使用 gMSA 为 Defender for Identity 配置目录服务帐户

本文章介绍如何创建组一个托管服务帐户 (gMSA),用作 Defender for Identity DSA 项。

有关更多信息,请参阅 Microsoft Defender for Identity 目录服务帐户

提示

在多林、多域环境中,我们建议为每个林或域创建具有唯一名称的 gMSA。 此外,在每个域中创建一个通用组,其中包含所有传感器的计算机帐户,以便所有传感器都可以检索 gMSA 的密码,并执行跨域身份验证。

先决条件:授予检索 gMSA 帐户密码的权限

在创建 gMSA 帐户之前,请考虑如何分配检索帐户密码的权限。

使用 gMSA 项时,传感器需要从 Active Directory 中检索 gMSA 的密码。 这可以通过分配给每个传感器或使用一个组来完成。

  • 在单林、单域部署中,如果你不打算在任何 AD FS/AD CS 服务器上安装传感器,则可以使用内置的域控制器安全组。

  • 在具有多个域的林中,如果要使用单个 DSA 帐户,我们建议创建一个通用组,并将每个域控制器和 AD FS/AD CS 服务器添加到通用组中。

如果在计算机接收到 Kerberos 票证后将计算机帐户添加到通用组,则在接收到新的 Kerberos 票证之前,将无法检索 gMSA 的密码。 Kerberos 票证具有颁发票证时实体所属的组列表。

在这种应用场景下,请执行以下操作之一:

  • 等待颁发新的 Kerberos 票证。 Kerberos 票证有效期通常为 10 小时。

  • 重新启动服务器。 重新启动服务器时,将使用新的组成员身份请求新的 Kerberos 票证。

  • 清除现有的 Kerberos 票证。 这将强制域控制器请求新的 Kerberos 票证。

    要清除票证,请在域控制器上的管理员命令提示符下运行以下命令:klist purge -li 0x3e7

创建 gMSA 帐户

本节介绍如何创建一个可以检索帐户密码的特定组,创建 gMSA 帐户,然后测试该帐户是否可以使用。

使用环境的变量值更新以下代码。 然后,以管理员身份运行 PowerShell 命令:

# Variables:
# Specify the name of the gMSA you want to create:
$gMSA_AccountName = 'mdiSvc01'
# Specify the name of the group you want to create for the gMSA,
# or enter 'Domain Controllers' to use the built-in group when your environment is a single forest, and will contain only domain controller sensors.
$gMSA_HostsGroupName = 'mdiSvc01Group'
# Specify the computer accounts that will become members of the gMSA group and have permission to use the gMSA. 
# If you are using the 'Domain Controllers' group in the $gMSA_HostsGroupName variable, then this list is ignored
$gMSA_HostNames = 'DC1', 'DC2', 'DC3', 'DC4', 'DC5', 'DC6', 'ADFS1', 'ADFS2'

# Import the required PowerShell module:
Import-Module ActiveDirectory

# Set the group
if ($gMSA_HostsGroupName -eq 'Domain Controllers') {
    $gMSA_HostsGroup = Get-ADGroup -Identity 'Domain Controllers'
} else {
    $gMSA_HostsGroup = New-ADGroup -Name $gMSA_HostsGroupName -GroupScope DomainLocal -PassThru
    $gMSA_HostNames | ForEach-Object { Get-ADComputer -Identity $_ } |
        ForEach-Object { Add-ADGroupMember -Identity $gMSA_HostsGroupName -Members $_ }
}

# Create the gMSA:
New-ADServiceAccount -Name $gMSA_AccountName -DNSHostName "$gMSA_AccountName.$env:USERDNSDOMAIN" `
 -PrincipalsAllowedToRetrieveManagedPassword $gMSA_HostsGroup

授予所需的 DSA 权限

DSA 要求对 Active Directory 中的所有对象(包含已删除对象容器)具有只读权限。

已删除对象容器的只读权限允许 Defender for Identity 检测 Active Directory 中的用户删除。

使用以下代码示例可以帮助你授予已删除对象容器所需的读取权限,无论是否使用 gMSA 帐户。

提示

如果要授予权限的 DSA 是组托管服务帐户 (gMSA),则必须首先创建一个安全组,将 gMSA 添加为成员,然后将权限添加到该组。 有关更多信息,请参阅使用 gMSA 为 Defender for Identity 配置目录服务帐户

# Declare the identity that you want to add read access to the deleted objects container:
$Identity = 'mdiSvc01'

# If the identity is a gMSA, first to create a group and add the gMSA to it:
$groupName = 'mdiUsr01Group'
$groupDescription = 'Members of this group are allowed to read the objects in the Deleted Objects container in AD'
if(Get-ADServiceAccount -Identity $Identity -ErrorAction SilentlyContinue) {
    $groupParams = @{
        Name           = $groupName
        SamAccountName = $groupName
        DisplayName    = $groupName
        GroupCategory  = 'Security'
        GroupScope     = 'Universal'
        Description    = $groupDescription
    }
    $group = New-ADGroup @groupParams -PassThru
    Add-ADGroupMember -Identity $group -Members ('{0}$' -f $Identity)
    $Identity = $group.Name
}

# Get the deleted objects container's distinguished name:
$distinguishedName = ([adsi]'').distinguishedName.Value
$deletedObjectsDN = 'CN=Deleted Objects,{0}' -f $distinguishedName

# Take ownership on the deleted objects container:
$params = @("$deletedObjectsDN", '/takeOwnership')
C:\Windows\System32\dsacls.exe $params

# Grant the 'List Contents' and 'Read Property' permissions to the user or group:
$params = @("$deletedObjectsDN", '/G', ('{0}\{1}:LCRP' -f ([adsi]'').name.Value, $Identity))
C:\Windows\System32\dsacls.exe $params
  
# To remove the permissions, uncomment the next 2 lines and run them instead of the two prior ones:
# $params = @("$deletedObjectsDN", '/R', ('{0}\{1}' -f ([adsi]'').name.Value, $Identity))
# C:\Windows\System32\dsacls.exe $params

有关更多信息,请参阅更改已删除对象容器的权限

验证 gMSA 帐户是否具有所需的权限

Defender for Identity 传感器服务 Azure 高级威胁防护传感器作为 LocalService 运行,并执行 DSA 帐户的模拟。 如果配置了登录即服务策略,但尚未向将权限授予 gMSA 帐户,则模拟将失败。 在这种情况下,你将看到以下健康状况问题:目录服务用户凭据不正确。

如果你看到此警报,我们建议检查是否配置了登录即服务策略。 如果需要配置登录即服务策略,请在组策略设置或本地安全策略中进行配置。

  • 要检查本地策略,请运行 secpol.msc 并选择本地策略。 在用户权限分配下,转到登录即服务策略设置。 例如:

    作为服务属性登录的屏幕截图。

    如果启用了该策略,请将 gMSA 帐户添加到可以使用登录即服务的帐户列表中。

  • 要检查是否在组策略中配置了该设置:运行 rsop.msc 并查看是否选择了计算机配置 -> Windows 设置 -> 安全设置 -> 本地策略 -> 用户权限分配 -> 登录即服务策略。 例如:

    组策略管理编辑器中“作为服务策略登录”的屏幕截图。

    如果配置了该设置,请将 gMSA 帐户添加到组策略管理编辑器中可以使用登录即服务的帐户列表中。

注意

如果使用组策略管理编辑器配置登录即服务设置,请确保同时添加 NT Service\All Services 和你创建的 gMSA 帐户。

在 Microsoft Defender XDR 中配置目录服务帐户

若要将传感器与 Active Directory 域连接,需要在 Microsoft Defender XDR 中配置目录服务帐户。

  1. Microsoft Defender XDR 中,转到 设置 > 身份。 例如:

    Microsoft Defender XDR 中标识设置的屏幕截图。

  2. 选择目录服务帐户。 你将看到哪些帐户与哪些域相关联。 例如:

    “目录服务帐户”页面的屏幕截图。

  3. 要添加目录服务帐户凭证,请选择添加凭证,然后输入你之前创建的帐户的帐户名密码。 你还可以选择是组托管服务帐户 (gMSA),还是属于单标签域。 例如:

    添加凭据窗格的屏幕截图。

    字段 评论
    帐户名(必填) 输入只读 AD 用户名。 例如:DefenderForIdentityUser

    - 必须使用标准 AD 用户或 gMSA 帐户。
    请勿- 使用 UPN 格式作为用户名。
    - 当使用 gMSA 时,用户字符串应以 $ 符号结束。 例如:mdisvc$

    注意:我们建议避免使用分配给特定用户的帐户。
    密码(对于标准 AD 用户帐户为必填项) 对于仅 AD 用户帐户,请为只读用户生成强密码。 例如:PePR!BZ&}Y54UpC3aB
    组托管服务帐户(对于 gMSA 帐户为必填项) 对于仅 gMSA 帐户,请选择组托管服务帐户
    (必填) 输入只读用户的域。 例如 contoso.com。

    请务必输入用户所在域的完整 FQDN。 例如,如果用户的帐户位于域 corp.contoso.com,则需要输入 corp.contoso.com 而不是 contoso.com

    有关更多信息,请参阅 Microsoft 对单标签域的支持
  4. 选择“保存”。

  5. (可选)如果选择一个帐户,将打开一个详细内容窗格,其中包含该帐户的设置。 例如:

    帐户详细信息窗格的屏幕截图。

注意

你可以使用相同的过程更改标准 Active Directory 用户帐户的密码。 gMSA 帐户没有设置密码。

故障排除

有关更多信息,请参阅传感器检索 gMSA 凭证失败

下一步