设为首页 收藏本站
查看: 626|回复: 0

[经验分享] Using LDAP for Apache Authentication

[复制链接]

尚未签到

发表于 2017-1-1 07:46:23 | 显示全部楼层 |阅读模式
  
This method authenticates using Apache 2.0/2.2 and the LDAP
authentication modules on Linux (supplied by default with most Linux
distros) and an LDAP server.
LDAP can be used to authenticate user accounts on Linux and other
computer systems as well as web site logins.
  
Try this out with your Apache server authenticating to our open LDAP server
using our Three Stooges example.




Apache LDAP modules:

  
Note that the following configurations work if the LDAP modules are enabled:



  • Apache 2.0 (Red Hat Enterprise 4/CentOS4): mod_ldap
    ,
    mod_auth_ldap
  • Apache 2.2 (Red Hat Enterprise 5/CentOS 5): mod_ldap
    ,
    mod_authnz_ldap
  
These are turned on by default. See /etc/httpd/conf/httpd.conf



  • Apache 2.0:

    LoadModule ldap_module modules/mod_ldap.so
    LoadModule auth_ldap_module modules/mod_auth_ldap.so


  • Apache 2.2:

    LoadModule ldap_module modules/mod_ldap.so
    LoadModule authnz_ldap_module modules/mod_authnz_ldap.so





Apache Authentication Configuration:


Apache 2.0:
  
Authenticate to an Open LDAP server. (No bind name/password required to access LDAP server)



File: httpd.conf
(portion)

..
...
<Directory /var/www/html

>
AuthType Basic
AuthName "Stooges Web Site: Login with email address"
AuthLDAPURL ldap://ldap.yo-linux.com:389/o=stooges?mail
require valid-user
</Directory>
...
..


or create the file /var/www/html/.htaccess

AuthName "Stooges Web Site: Login with email address"
AuthType Basic
AuthLDAPURL ldap://ldap.your-domain

.com:389/o=stooges?mail
require valid-user

  
Point your browser to http://localhost/


Login with the user id "LFine@isp.com" and password "larrysecret".


You will be asked to use a user id (email address) and password to enter the site.


  
Bind with a bind DN: (password protected LDAP repository)



File: httpd.conf
(portion)

..
...
<Directory /var/www/html

>
AuthType Basic
AuthName "Stooges Web Site: Login with email address"
AuthLDAPEnabled on
AuthLDAPURL ldap://ldap.your-domain

.com:389/o=stooges?mail
AuthLDAPBindDN "cn=StoogeAdmin,o=stooges"
AuthLDAPBindPassword secret1

require valid-user
</Directory>
...
..


Examples:


  • require valid-user
    : Allow all users if authentication (password) is correct.

  • require user greg phil bob
    : Allow only greg phil bob to login.

  • require group accounting
    : Allow only users in group "accounting" to authenticate.

  
This example specified the use of the email address as a login id. If using
user id's specify:



AuthLDAPURL ldap://ldap.your-domain
.com:389/o=stooges?uid


Apache 2.2:
  
Authenticate using Apache httpd 2.2 AuthzLDAP:

  
User Authentication:



File: httpd.conf
(portion)

..
...
<Directory /var/www/html

>
AuthType Basic
AuthName "Stooges Web Site: Login with user id"
AuthBasicProvider ldap
AuthzLDAPAuthoritative on
AuthLDAPURL ldap://ldap.your-domain

.com:389/o=stooges?uid?sub
AuthLDAPBindDN "cn=StoogeAdmin,o=stooges"
AuthLDAPBindPassword secret1

require ldap-user lary curley moe joe bob mary
</Directory>
...
..


  
There are two configurations for the directive AuthzLDAPAuthoritative
:



AuthzLDAPAuthoritative on
(default)

AuthzLDAPAuthoritative on
...
require ldap-user lary curley moe joe bob mary


AuthzLDAPAuthoritative off

AuthzLDAPAuthoritative off
...
require valid-user


This configuration allows a waterfall of other authentication methods to be employed along side LDAP.
  
Group Authentication:



LDAP LDIF file:

dn: cn=users,ou=group,o=stooges
cn: users
objectClass: top
objectClass: posixGroup
gidNumber: 100
memberUid: larry
memberUid: moe

  Apache Configuration:



...
<Directory /var/www/html

>
Order deny,allow
Deny from All
AuthType Basic
AuthName "Stooges Web Site: Login with user id"
AuthBasicProvider ldap
AuthzLDAPAuthoritative on
AuthLDAPURL ldap://ldap.your-domain

.com:389/o=stooges?uid?sub
AuthLDAPBindDN "cn=StoogeAdmin,o=stooges"
AuthLDAPBindPassword secret1

AuthLDAPGroupAttribute memberUid
AuthLDAPGroupAttributeIsDN off
Require ldap-group cn=users,ou=group,o=stooges
Require ldap-attribute gidNumber=100
Satisfy any
</Directory>
...


Note:

  • Allow users (LDAP attribute: memberUid
    ) in group gidNumber: 100
    of objectClass: posixGroup
    which match to the login uid
    , authentication approval.


    The directive AuthLDAPGroupAttribute
    identifies the attribute to match with the login uid
    .
  • AuthLDAPGroupAttributeIsDN:

    • on (default): Use DN (Distinguished name) cn=Moe Howard,ou=MemberGroupA,o=stooges
    • off: Use username moe


  • Multiple Require ldap-group ...
    statements may be included to allow multiple groups.
  • Multiple Require ldap-attribute ...
    statements may be included to allow multiple groups.
  • The directive Satisfy any
    is required if testing multiple conditions. Only one positive in any of the conditions is required to authenticate.
    Thus you can combine the following authorization schemes as well:

    • Require ldap-user
    • Require ldap-dn
    • Require ldap-attribute
    • Require ldap-filter



  




Concurrent File and LDAP authentication:

  
Apache can use both File and LDAP authentication concurently.
This is sometimes required to run cron jobs with a login where you do
not want to use a system login or login managed by a directory server in
another department.




<Directory /ABC>
Order deny,allow
Deny from All
AuthType Basic
AuthBasicProvider file ldap
AuthName "Directory services login"
AuthBasicAuthoritative  off
AuthUserFile /srv/htpasswd
AuthGroupFile /dev/null
AuthzLDAPAuthoritative off
AuthLDAPURL "ldap://ldap.megacorp.com:389/ou=person,o=megacorp.com,c=us?uid?sub"
#  This user created for local cron jobs. It is not a system user and allows
#  the cron job to perform its task.
#  This user is not in the LDAP directory but in the password file /srv/htpasswd
Require user cronuserjobx

Require ldap-user usera userb

</Directory>


Note:


  • AuthBasicProvider file ldap
    - Check password "file" authentication then LDAP

  • AuthBasicAuthoritative  off
    - Allows fall back to another auth scheme, in this case LDAP

  • AuthzLDAPAuthoritative off
    - Allows fall back to other auth scheme besides LDAP, in this case file




Debugging Apache Authentication:

  
Set LogLevel debug
when debugging authentication.
This will log all the LDAP connection events and the LDAP attributes requested.


  
Authenticating with Microsoft Active directory using Microsoft's "Unix services for Windows":



AuthLDAPURL ldap://ldap.your-domain
.com:389/ou=Employees,ou=Accounts,dc=sos,dc=com?sAMAccountName?sub
  
Also note that encrypted connections will use the URL prefix "ldaps://
" and the added directives:



  • LDAPTrustedCA directory-path/filename
  • LDAPTrustedCAType type


    Where the "type" is one of:

    • DER_FILE: file in binary DER format
    • BASE64_FILE: file in Base64 format
    • CERT7_DB_PATH: Netscape certificate database file


  
Restart Apache after editing the configuration file: service httpd restart
for configuration changes to take effect.


See /var/log/httpd/error_log
for configuration errors.






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-322150-1-1.html 上篇帖子: PHP+Apache 安装方案 下篇帖子: apache tomcat 集群 分组
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表