【问题标题】:.NET Core Application and System.DirectoryServices in Docker containerDocker 容器中的 .NET Core 应用程序和 System.DirectoryServices
【发布时间】:2020-09-24 13:52:53
【问题描述】:

我正在尝试将列出 AD 组中用户的 .NET Core 3.1 应用程序放入 .NET Core Runtime Docker 容器中。 访问 AD 是在 System.DirectoryServices 命名空间中的 DirectorySearcher 的帮助下完成的。 开箱即用,.NET Core 不支持此命名空间,但通过添加包 System.DirectoryServices(dotnet add package System.DirectoryServices)安装所需的程序集,并且应用程序在 Win10 机器上运行良好。

试图让应用在 Linux .Net Core Runtime 容器中运行会引发异常,因为 DirectoryServices 不支持此平台。

所以我尝试使用基于 Windows 的容器(准确地说是标记 3.1.8-nanoserver-2004),但随后 DirectorySearcher 的 FindAll() 抛出异常

System.DllNotFoundException: Unable to load DLL 'activeds.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

我什至尝试将 DLL 从我的主机复制到容器中应用程序的 bin 目录中,但无济于事。

有人知道如何从容器访问 AD/LDAP?

【问题讨论】:

    标签: docker .net-core directoryservices


    【解决方案1】:

    由于我无法获得 Windows Server 容器来为我的一生添加 Active Directory 功能,我决定切换到不同的东西并找到 LdapForNet

    虽然这在开发机器上运行良好,但我也很难找到一种方法来从容器内部调用所需的 Bind() 到我们的域控制器。 但是经过半天的反复试验,我发现 LdapAuthType.Negotiate 有效,但前提是我也提供了 Realm:

    using (var conn = new LdapConnection()){
        conn.Connect(new Uri("LDAP://the.domain.controller"));
        conn.Bind(LdapForNet.Native.Native.LdapAuthType.Negotiate,
            new LdapCredential {
                Realm = "DC=thedomain,DC=com",
                UserName = "The user to authenticate",
                Password = "Plain text password"
            }
        );
    }
    

    希望这有助于其他尝试在容器内运行 LDAP 查询的人。 下一站:在 Linux 容器中尝试同样的方法。

    【讨论】:

      【解决方案2】:

      DirectoryServices 当前无法在 Nano Server 中运行,因为所需的依赖项不可用。您需要改用 Windows Server Core 映像。没有可用于 Windows Server Core 的官方 .NET Core 映像。 (至少现在还没有。当 .NET 5.0 发布时,Windows Server Core 映像将可供使用。有关该提案,请参阅 GitHub issue。)

      您需要定义自己的 Dockerfile,它使用 Windows Server Core 作为基础映像并在其中安装 .NET Core。有关于如何做到这一点的指导here

      相关链接:

      【讨论】:

      • 太好了,感谢您的及时回复!我将尝试一个完整的服务器核心基础映像。
      • 经过一天的挫折后,我仍然无法让应用程序在容器中运行。服务器核心映像似乎不包含 ad-domain-services 功能,我无法安装此功能,因为 dism 和 install-windowsfeature 找不到源文件。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 2020-08-19
      相关资源
      最近更新 更多