前提:openldap server已配置好
目标:需要对apache的目录使用openldap用户和群组认证
步骤:
1,启用ldap模块:mod_authnz_ldap 和 mod_ldap
httpd.conf 中默认是注释掉了(如下两行),取消注释就行:
LoadModule authnz_ldap_module libexec/apache2/mod_authnz_ldap.so
LoadModule ldap_module libexec/apache2/mod_ldap.so
2,Options 加上或改为 Indexes,方便直接访问目录
#Options FollowSymLinks Multiviews
Options Indexes
3,对限制路径增加openldap 服务器信息和搜索信息:
特殊配置解释:
1)如果只需要限制到ldap用户就可以了,不想细分,那群组信息就不用配置了,直接用 Require valid-user 即可;
2)群组如果有嵌套,需要加上 AuthLDAPMaxSubGroupDepth,默认参数是0,即不递归查找。
3)AuthLDAPGroupAttributeIsDN,是否把用户输入uid当做群组的cn来查找,默认是on,我这里要求必须是用户登陆,而非群组,所以关掉了。
# Enable the LDAP connection pool and shared
# memory cache. Enable the LDAP cache status
# handler. Requires that mod_ldap and mod_authnz_ldap
# be loaded.
LDAPSharedCacheSize 500000
LDAPCacheEntries 1024
LDAPCacheTTL 600
LDAPOpCacheEntries 1024
LDAPOpCacheTTL 600
<AuthnProviderAlias ldap ldap-test>
AuthLDAPURL "ldap://address:389/ou=users,dc=test,dc=com?uid?sub?(objectClass=*)"
AuthLDAPBindDN "cn=admin,dc=test,dc=com"
AuthLDAPBindPassword "password"
</AuthnProviderAlias>
<Location "/ldap-status">
SetHandler ldap-status
Require host localhost
Satisfy any
AuthType Basic
AuthName "LDAP Protected"
AuthBasicProvider ldap-test
Require valid-user
</Location>
<Directory "/Library/WebServer/Documents/test">
Order Allow,Deny
Satisfy any
AuthType Basic
AuthName "LDAP Protected"
AuthBasicProvider ldap-test
#Require valid-user
AuthLDAPGroupAttribute memberUid
AuthLDAPGroupAttributeIsDN off
Require ldap-group cn=group1,ou=groups,dc=test,dc=com
AuthLDAPMaxSubGroupDepth 3
</Directory>