当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

作者:精品下载站 日期:2024-12-14 23:10:04 浏览:14 分类:玩电脑

使用 MaxTokenSize 参数配置 Kerberos 令牌大小


最近,我遇到了一个非常有趣的问题,一些用户由于超出了 Kerberos 票证的最大大小而无法在某些域服务上进行身份验证。在本文中,我们将向您展示如何确定特定用户的Kerberos 票证的大小,并使用 MaxTokenSize 参数增加存储令牌的缓冲区。

在我们的例子中,问题就以这种方式显现出来。部分用户无法访问部分域服务。

[玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

  • 特别是,尝试连接到 RDS 场时出现错误(“访问被拒绝”错误)。您可能会在 RDS 主机日志中看到以下错误:事件 ID:

    6

    来源:

    Microsoft-Windows-Security-Kerberos
    The Kerberos SSPI package generated an output token of size 21043 bytes, which was too large to fit in the token buffer of size 12000 bytes, provided by process id 4.
    The output SSPI token being too large is probably the result of the user user@domain  being a member of a large number of groups.
    It is recommended to minimize the number of groups a user belongs to. If the problem can not be corrected by reduction of the group memberships of this user, please contact your system administrator to increase the maximum token size, which in term is configured machine-wide via the following registry value: HKLM\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters\MaxTokenSize.
  • 尝试连接到 SQL Server 时,事件日志中出现以下错误:
    事件 ID:

    40960
    SQL State: HY000, SQL Error Code:0
    Cannot generate SSPI context.
  • IIS网站出现错误:

    Bad Request - Request header too long
    HTTP Error 400. The size of the request headers is too long.
  • 在事件查看器中检查以下事件:
    事件 ID:

    40960

    来源:

    LSA (LsaSrv)
    The Security System detected an authentication error for the server XXXXXX. The failure code from authentication protocol Kerberos was “{Buffer Too Small}
    The buffer is too small to contain the entry. No information has been written to the buffer.(0xc0000023).
  • 组策略不适用于用户。

在排查问题时,我们注意到所有问题用户都属于大量 Active Directory 安全组(包括嵌套组在内超过 200 个)。与SSPI 令牌太大错误一起,这清楚地表明已超出用于验证用户身份的 Kerberos 票证的最大长度。

Kerberos 令牌大小

Kerberos 令牌的大小取决于以下因素:

  • 用户所属的 Active Directory 安全组(包括嵌套组)的数量(启用邮件的通用通讯组不包括在令牌中);

  • SIDHistory的使用;

    注意。当用户在 Active Directory 域之间迁移并且使用 SIDHistory 访问旧域资源时,经常会出现票证过大问题。

  • 使用的身份验证类型(常用密码或多因素,如智能卡);

  • 该帐户是否可信任进行委派。

Kerberos 使用缓冲区来存储身份验证数据并将其大小传输到使用 Kerberos 的应用程序。系统参数MaxTokenSize定义缓冲区的大小。缓冲区大小很重要,因为某些协议(例如 RPC 或 HTTP)在分配内存块进行身份验证时会使用缓冲区大小。如果用户认证数据的大小大于MaxTokenSize中的值,则认证失败。这可以解释访问 IIS 时的身份验证错误,同时保留对共享网络资源的文件访问权限。

默认情况下,Kerberos 缓冲区的大小 (MaxTokenSize) 为:

  • Windows 7 和 Windows Server 2008R2 中12 KB

  • 在 Windows 8 和 Windows Server 2012 及更高版本(最高 Windows Server 2022 和 Windows 11)中扩展至 48 KB

因此,如果用户是不适合 MaxTokenSize 令牌缓冲区的大量组的成员,则在访问某些资源时身份验证会失败。

Active Directory 的最大组成员限制

用户可以加入的 AD 组的数量存在硬性限制。限制为 1015 个组(包括嵌套组)。如果超出组数,用户登录 Windows 时会出现错误。如果您将用户添加到超过 1015 个组,那么他将无法登录 Windows,并出现错误:

During a logon attempt, the user’s security context accumulated too many security IDs.

[玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

来源:

LSA (LsaSrv)

事件ID:

6035
During a logon attempt, the user’s security context accumulated too many security IDs. This is a very unusual situation. Remove the user from some global or local groups to reduce the number of security IDs to incorporate into the security context.

[玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

您可以使用 AD PowerShell 模块中的 Get-ADUser cmdlet 了解用户是多少个组的成员。

$user=Get-ADUser jsmith
$token=(Get-ADUser $user -Properties tokengroups).tokengroups
$token.count

使用 PowerShell 脚本获取 Kerberos 令牌大小

Windows 没有方便的内置工具可让您获取特定用户的 Kerberos 令牌大小。要获取当前的 Kerberos 票证大小,您可以使用 Powershell 脚本 CheckMaxTokenSize.ps1(该脚本最初由 Tim Springston 编写,并上传到 TechNet 上的脚本库)。但现在该脚本在那里不可用,因此我将其复制到我的 GitHub 存储库 (https://github.com/maxbakhub/winposh/blob/main/CheckMaxTokenSize.ps1)。

该脚本允许您获取指定用户令牌的当前大小、包含该令牌的安全组数量、用户 SIDHistory 中存储的 SID 数量以及该帐户是否受信任委派。

下载脚本文件并将其另存为 CheckMaxTokenSize.ps1。允许未签名的脚本在当前会话的 PowerShell 执行策略中运行:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

转到包含脚本的目录:

Cd c:\install\ps

并获取用户 jsmith 的 Kerberos 票证大小:

.\CheckMaxTokenSize.ps1 -Principals 'jsmith' -OSEmulation $true -Details $true

[玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

该脚本提示指定必须计算用户令牌大小的环境。有以下三种选择:

  • [1] 使用 Windows 7/Windows Server 2008 R2 和更早版本的默认令牌大小 12K 测量 Kerberos 令牌大小;

  • [4] 使用 Windows 8/Windows Server 2012 默认令牌大小 48K 测量 Kerberos 令牌大小。注意:对于许多早期的 Windows 版本,&48K 设置是可选配置的;

  • [6] 使用 Windows 10 及更高版本测量 Kerberos 令牌大小。

如果您的网络上仍然有旧版 Windows Server 2008 R2 和 Windows 7,则需要选择选项 1 并按 Enter。一段时间(3-4分钟)后,脚本将返回以下信息:

Token Details for user jsmith
**********************************
User’s domain is CORP.
Total estimated token size is 22648.
For access to DCs and delegatable resources the total estimated token delegation size is 45269.
Effective MaxTokenSize value is: 12000
Problem detected. The token was too large for consistent authorization. Alter the maximum size per KB http://support.microsoft.com/kb/327825 and consider reducing direct and transitive group memberships.
*Token Details for jsmith*
There are 957 groups in the token.
There are SIDs in the users SIDHistory.
There are 248 SIDs in the users groups SIDHistory attributes.
There are 248 total SIDHistories for user and groups user is a member of.
1088 are domain global scope security groups.
37 are domain local security groups.
86 are universal security groups inside of the users domain.
0 are universal security groups outside of the users domain.
Group Details included in output file at C:\Windows\temp\TokenSizeDetails.txt
SIDHistory details included in output file at C:\Windows\temp\TokenSizeDetails.txt

[玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

在本例中,jsmith 是 957 域安全组的成员,其 Kerberos 票证大小为 22648,几乎是 Windows 7 和 Windows Server 2008 R 中默认最大 Kerberos 令牌大小的 2 倍。

因此,要解决身份验证问题,您必须减少用户令牌大小或增加所有主机上的缓冲区大小,其中会出现 Kerberos 身份验证问题。

如果可能,请尝试通过以下方式减小用户 Kerberos 令牌的大小:

  • 减少用户所属组的数量;

  • 清除SID历史属性;

  • 在帐户属性中禁用 Kerberos 约束委派(显着减小令牌大小)。

如何增加Kerberos票证的MaxTokenSize?

您可以使用 MaxTokenSize 注册表值增加 Kerberos 令牌的最大缓冲区大小。

Microsoft 不建议将 MaxTokenSize 设置为超过 64 KB。建议首先将限制增加到48Kb(Windows 8和Windows Server 2012的限制)并检查服务的运行情况。要增加缓冲区大小:

  1. 打开注册表编辑器并转到注册表项HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Kerberos\Parameters

  2. 创建一个名为 MaxTokenSize; 的新 DWORD(32 位)值参数

  3. 指定最大缓冲区大小的必要值(我们指定了十进制值48000,因为用户令牌的大小不超过该值);

    [玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

  4. 重新启动计算机。

您可以通过使用以下 PowerShell 命令从注册表获取值来查明 Kerberos 令牌的当前缓冲区大小:

Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\Kerberos\Parameters|select maxtokensize

应在所有存在身份验证问题的主机上执行此更改。

您还可以使用最大 Kerberos SSPI 上下文令牌缓冲区大小组策略选项设置 MaxTokenSize。它位于以下 GPO 部分下:计算机配置 -> 策略 -> 管理模板 -> 系统 -> Kerberos。

[玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

通过使用针对大型 Kerberos 票证的警告策略,您可以将超大票证警报写入事件日志。

[玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

更新组策略设置后,如果 Windows 检测到已超出 Kerberos 票证阈值大小,将记录事件 31

A ticket to the service ldap/"DC Name"/"DomainName" is issued for account "AccountName"@"DomainName". The size of the encrypted part of this ticket is 22648 bytes, which is close or greater than the configured ticket size threshold (12000 bytes). This ticket or any additional tickets issued from this ticket might result in authentication failures if the client or server application allocates SSPI token buffers bounded by a value that is close to the threshold value.

The size of the ticket is largely determined by the size of authorization data it carries. The size of authorization data is determined by the groups the account is a member of, the claims data the account is setup for, and the resource groups resolved in the resource domain.

使用 Kerberos 的 HTTP 400 错误请求(请求标头太长)

使用 Kerberos 身份验证的 Internet 信息服务 (IIS) 网站上会出现另一个 Kerberos 令牌过大问题。在 IIS 中使用 Kerberos 身份验证时,用户的安全组成员身份信息存储在

WWW-Authenticate

标头。如果用户是大量安全组的成员,则可能会超出此类标头的大小,并且用户将无法通过身份验证。

[玩转系统] 使用 MaxTokenSize 参数配置 Kerberos 令牌大小

要解决此问题,需要增加reg键中以下注册表参数的值

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters
  • MaxFieldLength - 每个标头的最大大小(IIS 中默认标头大小为 16 KB,最大值为65536

  • MaxRequestBytes - 查询字符串和标头的最大大小(最大值16777216

不建议立即设置这些注册表参数的最大可用值。较大的标头会大大降低 IIS Web 服务器的性能和安全性。

建议每个参数的起始值均为 32 KB (32000)。进行更改后,您需要重新启动 IIS 服务器。

如果问题仍然存在,请尝试逐渐将限制大小增加到 48000 字节。

如果将 MaxFieldLength 设置为最大大小 (64KB),则需要使用 48KB 作为 MaxTokenSize (

3/4*64 KB

)。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯