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

为传感器 v2.x 创建和配置组托管服务帐户(gMSA),以便在读取Active Directory数据时使用(查询对象、跟踪更改、解析实体)。 这与用于执行修正操作 的操作帐户 (例如禁用用户或重置密码)不同。

重要

此配置仅适用于传感器 v2.x。 传感器 v3.x 对所有 AD 交互使用 LocalSystem,不需要 gMSA 或任何其他目录服务帐户。 如果所有传感器均为 v3.x,请跳过此页面。

先决条件

在创建 gMSA 帐户之前,请确保满足以下先决条件:

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

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

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

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

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

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

    • 单森林单域部署

      • 如果您不在 Active Directory 联合身份验证服务(AD FS)或 Active Directory 证书服务(AD CS)服务器上安装传感器,请使用内置的域控制器安全组。
    • 拥有多域的森林

      • 如果您使用单一目录服务账户(DSA),建议创建一个通用组,并将每个域控制器和 AD FS 或 AD CS 服务器添加到该通用组中。

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

      • 选项一:每个域名使用一个 gMSA。 在每个域创建一个域本地组,只包含该域传感器计算机账户,这样只有这些传感器能获取gMSA的密码并执行本地域认证。

      • 选项二:在所有域中使用共享的 gMSA。 在森林根创建一个包含所有传感器计算机账户的通用组,这样所有传感器都能获取 gMSA 的密码并执行跨域认证。

创建 gMSA 帐户

重要

如果你在一个拥有多个域或子域的单一森林中工作,并且打算在根级使用单一 gMSA 账户和单一组,那么本节中的步骤必须在拥有企业管理员权限的账户下执行。

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

    Add-KdsRootKey -EffectiveImmediately
    

    虽然命令名称表明密钥会立即生效,但请等待10小时,让KDS根密钥复制并可在所有域控制器上使用。

    如果你的测试域只有一个域控制器,可以通过将密钥的生效时间提前10小时来加快流程。

    重要

    不要在生产环境中使用这种技术。

    # For single-DC test environments only
    Add-KdsRootKey -EffectiveTime (Get-Date).AddHours(-10)
    
  2. 以管理员身份运行 PowerShell 命令。 此脚本将:

    • 创建 gMSA 帐户。
    • 为 gMSA 帐户创建组。
    • 将指定的计算机帐户添加到该组。
    • 配置gMSA使用AES128和AES256 Kerberos加密。
  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 {
	# If this group is being created at the root of a forest and will be used across multiple domains or subdomains then the -GroupScope parameter should be changed to Universal
    $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 $_ }
}

# Specify the Kerberos encryption type as AES.
$kerberosEncType = ('AES128','AES256')

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

更改组成员身份信息后刷新 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 门户中配置目录服务帐户

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

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

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

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

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

  3. 选择 “添加凭据”

  4. 输入以下详细信息:

    • 帐户名
    • Password
  5. 可以选择它是组 托管服务帐户 (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 对单标签域的支持
  6. 选择“保存”

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

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

注意

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

疑难解答

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