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

本文介绍如何创建组托管服务帐户 (gMSA) 用作标识目录服务帐户条目的Microsoft Defender。

先决条件

  • 请确保你有权在 Active Directory 中创建 gMSA 和安全组。

  • 分配允许传感器检索 gMSA 密码的权限。

  • 选择如何配置密码检索:

    • 将 gMSA 帐户直接分配给每个传感器。

    • 使用包含需要使用 gMSA 帐户的所有传感器的组。

  • 根据部署选择适当的组:

    • 单林、单域部署:如果未在 AD FS) 或 Active Directory 证书服务 Active Directory 联合身份验证服务 ( (AD CS) 服务器上安装传感器,请使用内置域控制器安全组。

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

  • 在多林或多域环境中,请确保创建 gMSA 的域信任传感器的计算机帐户。

  • 在每个域中创建一个包含所有传感器计算机帐户的通用组,以便所有传感器都可以检索 gMSA 的密码,并执行跨域身份验证。

创建 gMSA 帐户

  1. 如果以前从未使用过 gMSA 帐户,则可能需要为 Active Directory 中的 Microsoft 组密钥分发服务 (KdsSvc) 生成新的根密钥。 每个林仅需要一次此步骤。 若要生成新的根密钥以供立即使用,请运行以下命令:

    Add-KdsRootKey -EffectiveImmediately
    
  2. 以管理员身份运行 PowerShell 命令。 此脚本将:

    • 创建 gMSA 帐户。
    • 为 gMSA 帐户创建组。
    • 将指定的计算机帐户添加到该组。
  3. 运行脚本之前:

    • 更新变量值以匹配你的环境。
    • 确保为每个 gMSA 指定每个林或域的唯一名称。
# 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

更改组成员身份后刷新 Kerberos 票证

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

若要刷新 Kerberos 票证,可以:

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

  • 重新启动服务器 以请求具有新组成员身份的新 Kerberos 票证。

  • 清除现有的 Kerberos 票证 以强制域控制器请求新的 Kerberos 票证。 运行以下命令,从域控制器上的管理员命令提示符清除票证: klist purge -li 0x3e7

授予所需的目录服务帐户权限

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 高级威胁防护传感器作为模拟 DSA 帐户的 LocalService 运行。 如果配置了 “以服务身份登录” 策略,但未向 gMSA 帐户授予权限,则模拟会失败。 在这种情况下,会看到以下运行状况问题: 目录服务用户凭据不正确。

如果看到此警报,检查查看是否在组策略设置或本地安全策略中配置了“以服务身份登录”策略。

检查本地安全策略

  1. 运行 secpol.msc

  2. 选择“本地策略>”“用户权限分配

  3. 打开 “以服务身份登录”策略 设置。

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

  4. 启用策略后,将 gMSA 帐户添加到可以作为服务登录的帐户列表。

检查组策略设置

  1. 运行 rsop.msc

  2. 转到 计算机配置 -> Windows 设置 -> 安全设置 -> 本地策略 -> 用户权限分配 -> 以服务身份登录。

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

  3. 配置设置后,将 gMSA 帐户添加到可以在 组策略 管理编辑器中作为服务登录的帐户列表。

注意

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

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

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

  1. Microsoft Defender XDR中,转到“设置>标识”。

    显示设置页以及如何访问 Defender for Identity 页的屏幕截图。

  2. 选择 “目录服务帐户 ”,查看哪些帐户与哪些域相关联。

    显示 Defender 门户中的“目录服务帐户”页的屏幕截图。

  3. 选择 “添加凭据”

  4. 输入以下详细信息:

    • 帐户名
    • Password
  5. 可以选择它是组 托管服务帐户 (gMSA) ,还是属于 单标签域

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

    字段 Comments
    帐户名称 (必需) 输入只读 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支持
  6. 选择“保存”

  7. (可选) 选择帐户以打开详细信息窗格并查看其设置。

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

注意

可以使用相同的过程更改标准 Active Directory 用户帐户的密码。 gMSA 帐户不需要密码。

疑难解答

有关详细信息,请参阅 传感器无法检索 gMSA 凭据

后续步骤