在Docker容器内使用LDAP

4

我有2个Docker容器。 第一个Docker容器内含有PHP-7.3.4,Apache2的LAMP应用程序; 第二个容器内是MySQL数据库。

我尝试连接第一个容器内的LDAP服务器。 我进入“test-project”文件夹并配置了custom_config.inc.php

 $tlCfg->authentication['method'] = 'LDAP';

 $tlCfg->authentication['ldap_server'] = 'ldap.xyz.com';
 $tlCfg->authentication['ldap_port'] = '389';
 $tlCfg->authentication['ldap_version'] = '3';
 $tlCfg->authentication['ldap_root_dn'] = 'dc=xyz,dc=com';
 $tlCfg->authentication['ldap_bind_dn'] = 'uid=tl,ou=staff,dc=xyz,dc=com';
 $tlCfg->authentication['ldap_bind_passwd'] = 'XYZw';
 $tlCfg->authentication['ldap_tls'] = false; // true -> use tls

尝试使用LDAP凭据登录网页时,出现HTTP错误500。

查看日志后,发现以下错误:

Error: https://imgur.com/a/HQEZT3X

PHP Fatal error: Uncaught Error: Call to undefined function 
ldap_connect() in 
var/www/html/testlink/lib/functions/ldap_api.php:42\nStack trace :\n#0                     
/var/www/html/testlink/functions/ldap_api.php(165): 
ldap_connect_bind(Array)\n#1 
var/www/html/testlink/lib/functions/doAuthorize.php(200): 
ldap_authenticate('test_user', 'test')\n#2 
var/www/html/testlink/lib/functions/doAuthorize.php(90): 
auth_does_password_match(Object(tlUser), 'test')\n#3 
var/www/html/testlink/login.php(45): doAuthorize(Object(database), 
'test_user', 'test', Object(stdClass))\n#4 {main}\n thrown in 
var/www/html/testlink/lib/functions/ldap_api.php on line 42, refer: 
http://***.**.com/login.php

我该如何配置LDAP?


欢迎来到stackoverflow。如果您在此处以文本和可搜索的形式粘贴日志消息,我认为您会得到更好的响应。 - Stein
@Stein 我已经更新了日志信息,粘贴了文本变体。 - Artsom
请确保使用适合您版本的LDAP软件包,以安装LDAP扩展程序docker。 - Nigel Ren
@NigelRen,使用php7.3-ldap会得到相同的结果,但我现在不想重建容器。有没有不需要重建容器的其他变体? - Artsom
@NigelRen 我尝试在 Dockerfile 中运行 'docker-php-ext-install ldap',但是遇到了问题:无法找到 ldap.h,返回非零代码:1。 - Artsom
显示剩余2条评论
2个回答

6
您需要将以下行添加到您的php Dockerfile中。
RUN apt-get update && apt-get install -y \
    libldap2-dev

RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/
RUN docker-php-ext-install ldap

真希望我能再多给50个赞!谢谢你! - undefined

0

您的Apache/PHP容器缺少PHP LDAP扩展。 您需要重新构建该容器,使其包含PHP LDAP扩展,或者使用像https://packagist.org/packages/freedsx/LDAP这样的用户空间LDAP库(从未使用过,因此无法对其进行评论)。请注意,用户空间库使用与PHP扩展不同的API,因此您需要重写代码。因此,最终重建容器可能是更简单的解决方案。


我需要在我的容器中使用第一个PHP LDAP扩展,但是当我尝试在Dockerfile中使用docker-php-ext-install ldap进行安装时,出现了问题:找不到ldap.h - Artsom
你可能需要在容器中安装openldap,可能还需要安装openldap-dev包。PHP LDAP扩展仅是一个包装器,用于底层使用的LDAP客户端(通常是openldap,但例如在Windows上也可以使用Microsoft自己的实现)。有关示例,请参见https://github.com/heiglandreas/authLdap/blob/master/dockersetup/Dockerfile_wordpress - heiglandreas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接