Apache Directory Studio を利用してユーザをOpenLDAPに登録します。 OpenLDAPに登録されたユーザでApacheのBasic認証を行えるようにします。 ディレクトリ別の認証とか難しいことはまずは無視します。 【OpenLDAPサーバ】 OS: CentOS 6.3(64-bit) openldap-servers: 2.4.23-26.el6_3.2 hostname: openldap IP: 192.168.77.146 【Webサーバ】 OS: CentOS 6.3(64-bit) Apache: 2.2.15 hostname: web03 IP: 192.168.77.147
■ApacheにLDAPモジュールがインストールされているか確認
[root@web03 ~]# grep ldap /etc/httpd/conf/httpd.conf
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
[root@web03 ~]#
※ mod_authnz_ldap:Apache-2.2系でLDAP認証を実現する※ mod_ldap:LDAPサーバとの接続プールやキャッシュ用に使用される(mod_authnz_ldapから利用される)
■Apache Directory Studio にてエントリー作成
ベースDN: dc=open_ldap,dc=comOrganization Unit(部署): unit01
ユーザID: en2011001
※ユーザIDの文字列はEmployee Numberの略のつもり。2011年度入社001番みたいな。
⇒ベースDN作成
objectClassは「dcObject」と「organization」を設定
※objectClassの「top」は自動的に追加される。






⇒Organization Unit(部署)作成
objectClassは「organizationalUnit」を設定






⇒ユーザ作成
objectClassは「account」と「posixAccount」を設定
※作成手順はobjectClassが異なるだけでouとほぼ同等のため省略

⇒ユーザにパスワードを設定する



■OpenLDAPサーバで作成状況確認
[root@openldap ~]# ldapsearch -x -h localhost -b "dc=open_ldap,dc=com"
# extended LDIF
#
# LDAPv3
# base with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
# open_ldap.com
dn: dc=open_ldap,dc=com
dc: open_ldap
o: open_ldap
objectClass: dcObject
objectClass: top
objectClass: organization
# unit01, open_ldap.com
dn: ou=unit01,dc=open_ldap,dc=com
ou: unit01
objectClass: organizationalUnit
objectClass: top
# en2011001, unit01, open_ldap.com
dn: uid=en2011001,ou=unit01,dc=open_ldap,dc=com
uid: en2011001
gidNumber: 1000
cn: en2011001
homeDirectory: /home/en2011001
objectClass: account
objectClass: top
objectClass: posixAccount
uidNumber: 1001
userPassword:: e1NTSEF9RkdNenFHdzJlalExUFlYUHRHUllxQmtFWnJUNjJ5azltR20yRXc9PQ=
=
# search result
search: 2
result: 0 Success
# numResponses: 4
# numEntries: 3
[root@openldap ~]#
■Webサーバ確認用ページ準備
[root@web03 ~]# mkdir /var/www/html/unit01
[root@web03 ~]# vi /var/www/html/unit01/index.html
[root@web03 ~]# cat /var/www/html/unit01/index.html
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#dddddd">
<h2>unit01へログインしました。</h2>
</body>
</html>
[root@web03 ~]#
※表示の都合上タグを"<"と">"で記載。(以下同様)■WebサーバBasic認証設定
⇒httpd.confの最下行に下記を追加
[root@web03 ~]# tail -8 /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/unit01/">
AuthName "UserID/Password"
AuthType Basic
AuthBasicProvider ldap
AuthzLDAPAuthoritative off
AuthLDAPURL ldap://192.168.77.146:389/ou=unit01,dc=open_ldap,dc=com?uid?sub?(objectClass=account)
Require valid-user
</Directory>
[root@web03 ~]#
※「AuthzLDAPAuthoritative off」→LDAP認証で失敗しても他の認証サービスを利用しない。※ポート番号(389)の指定は省略可能。
⇒apache再起動
[root@web03 ~]# /etc/init.d/httpd restart
■ブラウザで確認
http://192.168.77.147/unit01/

⇒その時のWebサーバのログ
[root@web03 ~]# tail -f /var/log/httpd/access_log
---
192.168.77.21 - - [26/Jan/2013:04:04:21 +0900] "GET /unit01/ HTTP/1.1" 401 481 "-" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)"
192.168.77.21 - en2011001 [26/Jan/2013:04:06:00 +0900] "GET /unit01/ HTTP/1.1" 200 187 "-" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)"
192.168.77.21 - - [26/Jan/2013:04:06:01 +0900] "GET /favicon.ico HTTP/1.1" 404 289 "-" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)"
最後までお読みいただきありがとうございます。この情報が何かのお役にたてれば幸いです。m(_ _)m
0 件のコメント:
コメントを投稿