首页 > 解决方案 > InitializeSecurityContext:指定的目标未知或无法到达

问题描述

总体目标:我正在尝试在 Windows 上使用 Kerberos 通过 LDAP 向 Active Directory 进行身份验证。由于依赖关系,我无法使用python-ldapor python-gssapi,因此我正在使用此答案中找到ldap3的补丁来使用 Kerberos (通过代替)。winkerberospython-gssapi

示例代码:

from ldap3 import Connection, Server, ALL, IP_V4_PREFERRED, SASL, GSSAPI

domain_controller = input("DC: ")

SERVER = Server(domain_controller,
                allowed_referral_hosts=[('*', True)],
                get_info=ALL,
                mode=IP_V4_PREFERRED)

CONNECTION = {"authentication": SASL,
              "sasl_mechanism": GSSAPI,
              "check_names": True}

c = Connection(SERVER, **CONNECTION)
c.bind()

抛出:

  File "ldap3\core\connection.py", line 550, in bind
    response = self.do_sasl_bind(controls)
  File "ldap3\core\connection.py", line 1252, in do_sasl_bind
    result = sasl_gssapi(self, controls)
  File "ldap3\protocol\sasl\kerberos.py", line 54, in sasl_gssapi
    base64.b64encode(in_token).decode('ascii')
winkerberos.GSSError: SSPI: InitializeSecurityContext: The specified target is unknown or unreachable

我已经尝试从这里的解决方案@更改为没有任何区别。套接字正在正确解析 dc fqdn,dc 支持 SASL/GSSAPI 机制,我也可以传递用户名/密码以成功绑定。此处失败的部分听起来是特定于 kerberos 的。/

问题:是什么导致了这个错误,我该如何补救?

标签: pythonpython-3.xactive-directoryldapkerberos

解决方案


推荐阅读