试验了一天,网上各类文档操做(基本上都是同样的。。。),而后偶得一份英文的文档,上手作了下,我了个擦,居然都调通了。可是最后的调试仍是不能作好(调试和部署)php
本人openldap文档首页apache
下面是一条典型的LDAP用户信息(ldif格式):bash
PS:该实验环境为yum所装。服务器
# yanzong chen,People, shuyun.com dn: cn=yanzongchen,ou=People,dc=shuyun,dc=com objectClass:posixAccount objectClass: inetOrgPerson objectClass:organizationalPerson objectClass: person homeDirectory:/home/yanzong.chen loginShell: /bin/bash uid: yanzong.chen cn: yanzong chen uidNumber: 10000 gidNumber: 10001 userPassword:: e1NTSEF9ampCT0JTc0d3d2llN1lySVdzMHZQZUlIREV4SU5sQTU= sn: chen givenName: yanzong
你可使用一些命令行工具(ldapsearch)来查询LDAP数据,可是若是你和我同样,刚入行,那么可能你须要抽出点时间学习下LDAP搜索语法!架构
配置Apache 2.2ide
Apache 对于LDAP的相关模块在1.3的时候已经出现。这里用的是2.2版本的Apache。工具
这里我使用的Apache为yum安装的(包括ldap),因此默认的模块安装、加载的都比较全,这里就不在演示如何加载ldap模块,你能够查看httpd.conf file 来确认他们是否被加载:学习
LoadModuleldap_module /path/to/mod_ldap.so测试
LoadModuleauthnz_ldap_module /path/to/mod_authnz_ldap.soui
当模块被加载,你能够经过ldap验证来访问特定的目录。 AuthLDAPUrl 指向LDAP服务器,它通常是这样来写的:
AuthLDAPUrl ldap://ldap.shuyun.com/ou=People,dc=shuyun,dc=com?uid
他定义了LDAP服务器的地址,其余的不在着了说,复杂的定义策略、搜索策略能够经过理解LDAP树形结构来定义。。。
接下来的几节如何配置各类APACHE的访问策略(经过ldap),这些配置文件为Apache.conf,放在你习惯放的位置。
容许任何有效用户
这个配置首先会去查找是否为ldap的有效用户,若是经过则可访问。当你访问的时候,Apache会要求用户输入用户名、密码,而后去检验。若是你熟悉Apache的基自己份验证,这里很容易看懂。Or 你不太懂Apache的身份验证语法,sorry,Google 能够帮助人(不要怕,其实我写这个的时候,我也不太懂)。
<Location /> Order deny,allow Deny from All AuthName "Welcometo shuyun ldap . Use your info to pass in !" AuthType Basic AuthBasicProvider ldap AuthzLDAPAuthoritative off AuthLDAPUrlldap://ldap.shuyun.com/ou=People,dc=shuyun,dc=com?uid Require valid-user Satisfy any </Location>
AuthBasicProvider ldap 是必须滴,以便让Apache种地查询的是其余地址的LDAP服务器,而不是本地的。
AuthzLDAPAuthoritative off 必须在此处配置出来,由于这玩意儿默认是“开”。若是你要求验证的用户必须为LDAP用户,就设置此项为“ON”。例如:Require ldap-user, 须要设置为 "on." 设置为 off 则可使用混合用户验证。
Satisfy any (off时,2套验证机制)这个指令不在此处使用。
用户列表(认证用户)
Require ldap-user 这个指令做用是:ldap-user列表中的用户能够经过此认证
Order deny,allow Deny from All AuthName " Welcometo shuyun ldap . Use your info to pass in !" AuthType Basic AuthBasicProvider ldap AuthzLDAPAuthoritative on AuthLDAPUrlldap://ldap.shuyun.com/ou=People,dc=shuyun,dc=com?uid Require ldap-user yanzong.chen Satisfy any
AuthzLDAPAuthoritative on 默认为”ON”,这里写出来是为了更清晰。
注意: AuthLDAPUrl 没有更改,和前边例子同样,他在目录中搜索匹配到的UID
组成员
经过 Require ldap-group 来按照组划分认证.
组配置多是由目录的架构设计(从NIS转换(as mine was)),而后参照最开始yanzong的lidf记录来配置相关(以下)。 gidNumber 和 memberUid 请仔细看
dn: cn=SysOps,ou=group,dc=shuyun,dc=com objectClass:posixGroup gidNumber: 10001 cn: SysOps memberUid: yanzong.chen memberUid: … memberUid: … ...
咱们进行另外一个测试, Require ldap-attribute, 去匹配组中的用户下面是Apache配置:
Order deny,allow Deny from All AuthName " Welcometo shuyun ldap . Use your info to pass in !" AuthType Basic AuthBasicProvider ldap AuthzLDAPAuthoritative on AuthLDAPUrlldap://ldap.shuyun.com/ou=People,dc=shuyun,dc=com?uid AuthLDAPGroupAttribute memberUid AuthLDAPGroupAttributeIsDN off Require ldap-group cn=SysOps,ou=Group,dc=company,dc=com Require ldap-attribute gidNumber=10001 Satisfy any
AuthzLDAPAuthoritative on 默认为”ON”,这里写出来是为了更清晰。
AuthLDAPGroupAttribute memberUid 表示LDAP组记录有哪些属性,以配合UID。在这种状况下,一个memberUid 包含其组中每个成员。
AuthLDAPGroupAttributeIsDN off 告诉Apache验证用户时,使用客户端的distinguished name(标示名好比:cn=yanzong.chen,ou=SysOps,dc=shuyun,dc=com)。不然,用户名会被使用。在个人LDAP目录中,用户名来自NIS,因此须要关闭(默认为ON)。LDAP目录中能够存储整个转有名称,所以你能够根据你的需求更改此选项。
Require ldap-group 授予得到”SysOps”的组成员,对于多个组,添加一个额外的命令”each(也多是for each)”。
Require ldap-attribute gidNumber=10001 处理(ID:10001)、”SysOps”组,若是没有此选项,用户访问将被拒绝。对于多个组,添加额外命令“each”。
Satisfy any 这个指令是必须的。由于咱们正在测试多个条件,并但愿任何条件授予访问权限都能成功。
用户和组的结合
例子以下,各类选项你都能看懂的应该是,因此你看看吧而后测试测试。
Order deny,allow Deny from All AuthName " Welcometo shuyun ldap . Use your info to pass in !" AuthType Basic AuthBasicProvider ldap AuthzLDAPAuthoritative on AuthLDAPUrl ldap://ldap.shuyun.com/ou=People,dc=shuyun,dc=com?uid AuthLDAPGroupAttribute memberUid AuthLDAPGroupAttributeIsDN off Require ldap-group cn=SysOps,ou=Group,dc=company,dc=com Require ldap-attribute gidNumber=10001 Require ldap-user yanzong.chen Satisfy any
调试和部署
Testing LDAP authentication from a Web browser can be frustrating, becausethe only thing you know is whether access was granted or not. You don't get anykind of feedback on why something did not work. For verbose information on eachstep in the process, set theLogLeveldebug option inApache. With debugging active, Apache will record the connection status to theLDAP server, what attributes and values were requested, what was returned, andwhy conditions were met or not met. This information can be invaluable infine-tuning LDAP access controls.
我保留了这段话,由于这段话我虽然看懂了,可是实话是不知道咋操做。由于个人LDAP目前为止除了终端启动模式,我并不知道如何输出日志到文件(我系统的缘由貌似。)我猜测多是要将apache日志的loglevel调整下,而后观察Apache的日志吧。这个你们能够试一下。也能够留言给我。
PS:源英文地址:http://www.opendigest.org/article.php/490 下面文档已作适当修改