【问题标题】:LDAP bind to DC in another forest after bind to its domain results in LDAP error 82LDAP 绑定到另一个林中的 DC 后绑定到其域导致 LDAP 错误 82
【发布时间】:2018-05-03 07:52:47
【问题描述】:

我在尝试使用 LdapConnection 类绑定到特定 DC 时遇到了一个奇怪的错误。我设法将代码精简为以下内容:

static void Main(string[] args)
{
    var cred = new NetworkCredential("username", "password", "domainFQDN");
    try
    {
        var ldapConnection = new LdapConnection(new LdapDirectoryIdentifier("domain1.test.local", 389, false, false), cred, AuthType.Kerberos);
        ldapConnection.Bind();
        Console.WriteLine("Connected 1");
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
    }

    try
    {
        var ldapConnection2 = new LdapConnection(new LdapDirectoryIdentifier("dc1.domain1.test.local", 389, true, false), cred, AuthType.Kerberos);
        ldapConnection2.Bind();
        Console.WriteLine("Connected 2");
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
    }

    Console.ReadLine();
}

这个程序的输出是一致的:

Connected 1
System.DirectoryServices.Protocols.LdapException: A local error occurred.
   at System.DirectoryServices.Protocols.LdapConnection.BindHelper(NetworkCredential newCredential, Boolean needSetCredential)
   at System.DirectoryServices.Protocols.LdapConnection.Bind()

调用之间的唯一区别是,在第一个连接中我使用LdapDirectoryIdentifier 中的域 FQDN,而在第二个连接中我使用确切的 DC 地址。当然,我验证了第一个连接与第二个连接到同一个 DC。

该错误仅在我为身份验证方法指定AuthType.Kerberos 时发生。当我尝试连接到不同林中的域时,总是会出现该错误,并且仅在我连接到本地林中的 DC 时才会出现。

我可能可以通过使用该域名两次来解决该错误,但一旦连接到特定 DC,我将无法确保粘性。

如何确保第二个连接转到同一个 DC 而不会出现此错误?

【问题讨论】:

    标签: .net active-directory ldap kerberos


    【解决方案1】:

    该错误仅在我为身份验证方法指定 AuthType.Kerberos 时发生。

    那么您的问题是 Kerberos 身份验证。

    从命令行尝试(使用 DC 的短名称,而不是 FQDN):

    setspn dc1
    

    该列表中应该有一堆,但我认为这里的问题是“ldap/dc1.domain1.test.local/domain1.test.local”。你在列表中看到了吗?

    如果没有,您可以添加它。作为域管理员,从命令行使用它:

    setspn -a ldap/dc1.domain1.test.local/domain1.test.local dc1
    

    这里有更多详细信息,尽管它在那篇文章中谈到的缺少的 SPN 是带有 GUID 的。底部的列表显示了 SPN 列表的外观:https://support.microsoft.com/en-ca/help/308111/a-missing-service-principal-name-may-prevent-domain-controllers-from-r

    如果该 SPN 已列出,那么您可以按照此处的说明打开 Kerberos 日志记录:https://support.microsoft.com/en-ca/help/262177/how-to-enable-kerberos-event-logging

    启用日志记录后,Kerberos 错误将显示在系统事件日志中。它会让您更好地了解失败的原因。

    【讨论】:

    • spn 设置正确。我启用了 Kerberos 日志,我看到的只是常规的 KDC_ERR_PREAUTH_REQUIRED。但是,我确实发现,当我尝试连接到其他森林中的 DC 时,问题主要存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-06
    • 2014-09-24
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2019-04-11
    相关资源
    最近更新 更多