TODOs
- ユーザごとの INBOX の作成
Known Issues
- OpenLDAP をインストールした後、自動で AppArmor を起動できない。ただし、この現象は Amazon EC2 のインスタンスを使用しているときのみ発生する。原因を特定できていない。
Preface
Ubuntu Linux 9.04 に Dovecot と OpenLDAP をインストールし、OpenLDAP のバックエンドデータベース - HDB - にストアしているアカウントとパスワードを使用して、POP3 の認証を実現する。
Environment
Ubuntu 9.04 Server 32-bit
# Amazon EC2 のインスタンスを利用する。
Installation - Dovecot
まず Dovecot のみをインストールし、Linux アカウントで認証できる部分までを作業する。パッケージをインストールする。
sudo apt-get install dovecot-pop3d dovecot-imapd
Configuration
続いて、Dovecot を設定する。Dovecot の設定ファイルは、/etc/dovecot/dovecot.conf だ。
sudo vi /etc/dovecot/dovecot.conf
許可するプロトコルを記述する。
protocols = pop3 pop3s imap imaps
POP3 を使用する場合、上記の protocols にエントリを記述する以外に pop3_uidl_format を指定する。UIDL (Unique IDentification Listing) は、個々のメールに付与されるユニークな ID だ。
pop3_uidl_format = %08Xu%08Xv
メールボックスのフォーマットを指定する。Maildir または mbox のどちらかを指定する。どちらの形式も Dovecot はサポートしている。それぞれに利点が存在するため、詳細を MailboxFormat - Dovecot Wiki で確認できる。
#for maildir
mail_location = maildir:~/Maildir
or
# for mbox
mail_location = mbox:~/mail:INBOX=/var/mail/%u
Test
ここまで作業したら、続いてテストする。まず、Dovecot の daemon を起動する。
sudo /etc/init.d/dovecot start
プロセスの存在を確認する。
ps -ef | grep 'dovecot'
netstat コマンドを実行し、LISTEN しているかを確認する。POP3 なら 110 ポートだ。
netstat -an | grep 'LISTEN'
ローカルホストの 110 ポートに telnet で接続してみる。
telnet localhost 110
このコマンドラインから POP3 認証をテストする場合、以下のように作業する。なお、事前に一般ユーザ satoshiabe を作成してあり、このユーザのパスワードは mypassword である。
% telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
+OK Dovecot ready.
user satoshiabe
+OK
pass mypassword
+OK Logged in.
list
+OK 0 messages:
.
quit
+OK Logging out.
Connection closed by foreign host.
%
Installation - OpenLDAP
ここまで正常に作業できたら、続いて OpenLDAP を設定する。Getting Started With OpenLDAP on Ubuntu Linux を参考に OpenLDAP にストアした情報で POP3 認証できるよう設定する。必要なコマンドと最小限の説明のみ列記する。
OpenLDAP をインストールする。
sudo apt-get install slapd ldap-utils
様々な情報を設定する。
sudo dpkg-reconfigure slapd
ldapscripts をインストールし、ユーザを操作する手間を軽減する。
sudo apt-get install ldapscripts
sudo vi /etc/ldapscripts/ldapscripts.conf
sudo sh -c "echo -n 'ldapadmin' > /etc/ldapscripts/ldapscripts.passwd"
sudo chmod 400 /etc/ldapscripts/ldapscripts.passwd
OpenLDAP 経由で HDB にユーザを追加する。
sudo ldapadduser george example
パスワードを変更する。
sudo ldapsetpasswd george
nsswitch 関連の設定をする。
sudo apt-get install libnss-ldap
auth-client-config -t nss -p lac_ldap
sudo pam-auth-update
Configuration - Dovecot
/etc/dovecot/dovecot-ldap.conf
Dovecot に LDAP の設定を記述する。
sudo vi /etc/dovecot/dovecot-ldap.conf
Space separated list of LDAP hosts to use. host:port is allowed too.
hosts = localhost
Distinguished Name - the username used to login to the LDAP server.
dn = cn=admin,dc=satoshiabe,dc=jp
Password for LDAP server, if dn is specified.
dnpass = ldapadmin
Use authentication binding for verifying password's validity.
auth_bind = yes
If you use this setting, it's a good idea to use a different dovecot-ldap.conf for userdb.
auth_bind_userdn = cn=%u,ou=People,dc=satoshiabe,dc=jp
LDAP protocol version to use. Likely 2 or 3.
ldap_version = 3
LDAP base.
base = ou=People,dc=satoshiabe,dc=jp
Search scope: base, onelevel, subtree
scope = subtree
There are also other special fields which can be returned, see http://wiki.dovecot.org/UserDatabase/ExtraFields
user_attrs = homeDirectory=home,uidNumber=uid,gidNumber=gid
Filter for user lookup.
user_filter = (&(objectClass=posixAccount)(uid=%u))
Password checking attributes.
pass_attrs = uid=user,userPassword=password
Filter for password lookups
pass_filter = (&(objectClass=posixAccount)(uid=%u))
/etc/dovecot/dovecot.conf
コメントアウトされていたら UN-comment-out する。
# LDAP database
passdb ldap {
# Path for LDAP configuration file
args = /etc/dovecot/dovecot-ldap.conf
}
# LDAP database
userdb ldap {
# Path for LDAP configuration file
args = /etc/dovecot/dovecot-ldap.conf
}
Test
Dovecot をリスタートする。
/etc/init.d/dovecot restart
OpenLDAP をデバックモードで起動する。
/etc/init.d/slapd stop (this will stop slapd in case it's already running)
slapd -f /etc/ldap/slapd.conf -d -1
or
/usr/sbin/slapd -h ldap:/// ldapi:/// -g openldap -u openldap -F /etc/ldap/slapd.d/ -d -1
もうひとつターミナルを起動し、telnet にてログインできるかを確認する。OpenLDAP のログを注視しておく。
telnet localhost 110
Resources
Dovecot - Community Ubuntu Documentation
DovecotLDAP - Community Ubuntu Documentation
No comments:
Post a Comment