user icon

メールサーバでLDAPを利用する

前回のLDAP設定後に、PostfixとDovecotでLDAPのユーザを認証します。
メールの環境は、以前書いた記事の設定に変更を加える形とします。

LDAP

SSLの自己証明書エラーで、Dovecotではそのままでは接続エラーになったため、もうちょっと設定を追加します(Postfixはその辺無視出来るようで、接続出来ますが)。
server.crtの[ハッシュ化された証明書のサブジェクト名.0]でリンク名を作成します。例えば、059fe35b.0のようなリンク名を作ります。
ln -s /etc/openldap/certs/server.crt /etc/openldap/certs/`openssl x509 -noout -hash -in /etc/openldap/certs/server.crt`.0
次に、ldap.confにTLS_CACERTDIRを追記。
  • /etc/openldap/ldap.conf
TLS_CACERTDIR   /etc/openldap/certs/
リスタートしてSSL接続にエラーが出ない事を確認。
systemctl restart slapd
ldapsearch -H ldaps://virtual.localdomain:636 -d 1  -b o=virtual.localdomain -D "" -s base "(objectclass=*)"

Postfix

postfix-ldapが必要ですので、入っていなければインストールします。
dnf -y install postfix-ldap
systemctl reload postfix
Postfixはvirtual_aliasとvirtual_mailboxをLDAPで記載します。
  • /etc/postfix/main.cf
virtual_alias_maps = ldap:/etc/postfix/ldap-alias.cf
#virtual_mailbox_maps = pgsql:/etc/postfix/pgsql_mailbox.cf
virtual_mailbox_maps = ldap:/etc/postfix/ldap-mailbox.cf
  • /etc/postfix/ldap-alias.cf
server_host = ldaps://virtual.localdomain:636
search_base = OU=people,DC=virtual,DC=localdomain
bind = yes
bind_dn = CN=Manager,DC=virtual,DC=localdomain
bind_pw = testpass
scope = one
query_filter = (&(objectClass=inetOrgPerson)(mail=%s))
result_attribute = mail
version = 3
ユーザが存在するか確認し、存在する場合はメールアドレスを返します。
  • /etc/postfix/ldap-mailbox.cf
server_host = ldaps://virtual.localdomain:636
search_base = OU=people,DC=virtual,DC=localdomain
bind = yes
bind_dn = CN=Manager,DC=virtual,DC=localdomain
bind_pw = testpass
scope = one
query_filter = (&(objectClass=inetOrgPerson)(mail=%s))
result_attribute = description
result_format = %u/Maildir/
version = 3
scope=oneはsearch_baseの一つ下の階層だけをサーチします。階層が分かれるならsubを使います。
以前の設定でvirtual_mailbox_base = /var/mail/vhosts だったので、LDAPのdescriptionはvirtual.localdomain/yamadaとし、result_formatで最終的にvirtual.localdomain/yamada/Maildir/と返す事になります。
※LDAPにdescriptionではない別属性名も追加出来ますが、面倒なので今回は空き属性を利用します。
それぞれ、上手く取得出来るかを以下で確認します。
postalias -q yamada@virtual.localdomain ldap:/etc/postfix/ldap-alias.cf
postmap -q yamada@virtual.localdomain ldap:/etc/postfix/ldap-mailbox.cf

Dovecot

LDAPの認証はPassword lookupsとAuthentication bindsの二方式あるようですが、今回はPassword lookups方式を採用します。
まずは認証方式のSQLを外し、LDAPを追加します。
  • conf.d/10-auth.conf
!include auth-ldap.conf.ext
#!include auth-sql.conf.ext
ユーザのuidやgid等はLDAPに無いので、userdbにデフォルト値を設定します。
  • conf.d/auth-ldap.conf.ext
userdb {
  #...
  default_fields = uid=vmb gid=vmb home=/var/mail/vhosts/%d/%n quota_rule=*:storage=100M
auth-ldap.conf.ext内に記載されている、args = /etc/dovecot/dovecot-ldap.conf.extはサンプルが有る筈なので、コピーして編集します。
cp /usr/share/doc/dovecot/example-config/dovecot-ldap.conf.ext /etc/dovecot/
  • /etc/dovecot/dovecot-ldap.conf.ext
uris = ldaps://virtual.localdomain:636
# admin user dn
dn = cn=Manager,dc=virtual,dc=localdomain
dnpass = testpass
# auth_bind
auth_bind = no
# suffix(base dn)
base = ou=people, dc=virtual, dc=localdomain
# user
user_attrs = mail=user,userPassword=password
user_filter = (&(objectClass=inetOrgPerson)(mail=%u))
# pass
pass_attrs = mail=user,userPassword=password
pass_filter = (&(objectClass=inetOrgPerson)(mail=%u))
default_pass_scheme = MD5
# iterator
iterate_attrs = mail=user
iterate_filter = (objectClass=inetOrgPerson)
dn,dnpassはvirtual.localdomainの管理者ログイン用でdnpassは平文で記載しなければいけません。
BIND DNを使うのにauth_bindはnoです。この辺ややこしい。
attrsやfilterは未指定デフォルトでposixUser用になっているので、virtual環境用に上書き指定する必要が有ります。LDAP属性=Dovecot値となるようですので、例ではLDAPのmail属性がDovecotにおけるuser名に当たる等の指定となります。
LDAP認証を確認してみます。
doveadm auth test yamada@virtual.localdomain
これでLDAPのuserPasswordを入力して、auth succeeded が出ればOKです。

Dovecot設定補足

  • もしLDAPのSSL証明書設定でエラーを修正出来ない場合は、tls_require_cert = neverでcrtを確認せず通すようにも出来ます。
  • tls = yesにする場合は、STARTTLSを使い通信経路でなく通信の中身を暗号化するようで、ldapsを使えません(ldapsだとdovecot.logにDon’t use both tls=yes and ldaps URI とエラーが出ます)。
  • debug_levelについては0-7で、それぞれ、0:EMERGE, 1:ALERT, 2:CRIT, 3:ERR, 4:WARNING, 5:NOTICE, 6:INFO, 7:DEBUGまでを出力するようです。デバッグする場合、通常は3で十分かと思います。
Facebooktwitterlinkedintumblrmail
名前
E-mail
URL
コメント

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)