HowTos/LDAP認証

出典: ScalixWikiJP

Scalix Wiki -> How-Tos -> HowTos/LDAP認証

この文書はScalix Wiki - HowTos/Using_OpenLDAP_for_password_management (米国サイト)を参考にしています。

目次

概要

LDAPサーバなどの外部のディレクトリサーバを利用することにより、パスワードをScalixサーバ内で個別管理するのではなく、組織内で集中管理することができます。

この文書ではOpenLDAPを使った場合のLDAP認証の方法を紹介します。

LDAPサーバの設定

まず最初に、LDAPサーバの基本設定を行います。OpenLDAPの場合は設定ファイルは次のファイルになります。

/etc/openldap/slapd.conf

slapd.confファイルを開いて次のように基本となる4つのスキーマの定義ファイルが登録されていることを確認してください。

include         /etc/openldap/schema/core.schema
include         /etc/openldap/schema/cosine.schema
include         /etc/openldap/schema/nis.schema
include         /etc/openldap/schema/inetorgperson.schema

さらに、suffix, rootdn, rootpw等の設定を利用環境に応じて変更してください。

suffix          "dc=example,dc=com"
rootdn          "cn=Manager,dc=example,dc=com"
rootpw          {SSHA}W6c7QR3NJQteNRuvuWhLsbfoFXXM08Kh
index           objectClass,uid,uidNumber,gidNumber,memberUid   eq
index           cn,mail,surname,givenname                       eq,subinitial

SHAパスワードを生成するためには、slappasswdコマンドを使います。

/usr/sbin/slappasswd

次にアクセス制御を設定します。 アクセス制御は次の条件を満たす必要があります。

  • ユーザは認証ができる
  • パスワードは本人のみ変更可能で、他のユーザは読むことができない
  • 匿名(anonymous)ユーザが認証対象のユーザを検索することができる

そのため、設定ファイルへの記述例は次のようになります。

access to dn.base="" by * read
access to attrs=userPassword
        by self write
        by anonymous auth
        by * none
access to attrs=shadowLastChange
        by self write
        by * read
access to *
        by * read

設定が終わって、保存したら、OpenLDAPサーバを再起動してください。

/etc/init.d/ldap restart

ドメインが正しく設定されているかを確認するためには次のコマンドを実行します。

ldapsearch -x -b  -s base '(objectclass=*)' namingContexts

出力結果は次のようになります。

#
# filter: (objectclass=*)
# requesting: namingContexts
#
#
dn:
namingContexts: dc=example,dc=com
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
where the namingContexts should contain your domain.

次に、初期登録用のinitial.ldifファイルを作成します。 ドメインの情報をあなたの環境に応じて変更してください。

dn: dc=example,dc=com
dc: scalix
objectClass: top
objectClass: domain

dn: ou=users,dc=example,dc=com
ou: users
objectClass: top
objectClass: organizationalUnit

また、ユーザ登録用のusers.ldifファイルも作成します。

dn: uid=hkohl,ou=users,dc=example,dc=com
objectclass: top
objectclass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
uid: hkohl
userPassword: {SSHA}yI6cZwQadOA1e+/f+T+H3eCQQhRzYWx0
cn: Helmut Kohl
sn: Kohl
gn: Helmut

ユーザのエントリに関して、pam_ldapモジュールでパスワードを変更するときには属性userPasswordだけで なく属性shadowLastChangeも変更しますので、次のオブジェクトクラスを満たす属性を追加してください。

objectClass: posixAccount
objectClass: shadowAccount

作成したら、ldapaddコマンドを使ってインポートします。

ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f initial.ldif
ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f users.ldif

次にldapsearchコマンドを使って、ユーザがインポートされたかを確認します。

ldapsearch -xh pdxsrv.example.com -b dc=example,dc=com

これで、ユーザはあなたが選んだパスワードでLDAPサーバに登録されています。 そのユーザがScalixに登録されていないときには、Scalixに登録してください。 Scalix認証IDはLDAPのuid属性に一致します。 Scalixにユーザを登録するためには次のようにomadduコマンドを使います。

omaddu -n "Helmut Kohl/mailnode" -p password hkohl

ユーザがScalixに登録されていれば、omshowuコマンドを使って認証IDを確認することができます。

omshowu –n “Helmut Kohl/mailnode”

出力は次のようになります。

Authentication ID: hkohl
User Name : Helmut Kohl /CN=Helmut Kohl
MailNode : pdxsrv01
Internet Address : "Helmut Kohl" <Helmut.Kohl@example.com>
System Login : 60535
Password : set
Admin Capabilities : NO
Mailbox Admin Capabilities : NO
Language : C
Virtual Vault : Enabled (default)
Mail Account: Unlocked
Last Signon : 02.10.06 11:13:50
Receipt of mail : ENABLED
Service level : 0
Excluded from Tidying : NO
User Class : Limited

認証IDがuidと同じではない場合は、ommoduコマンドで変更する必要があります。

ommodu –o “Helmut Kohl/mailnode” –authid hkohl


Scalixの設定

Scalixの各サービスの認証にはPAMを利用しています。

om_ldapの設定

ScalixではScalix自信が提供しているom_ldapというLDAP用のPAMモジュールを使います。

以下の制限事項があります。

  • LDAPサーバに匿名アクセスできる必要がある
  • パスワードの変更ができない
  • SASL認証ができない

パスワードの変更が行いたい場合はpam_ldapモジュールを利用してください。

このモジュールの設定ファイルは次のファイルです。

/var/opt/scalix/nn/s/sys/om_ldap.conf

複数のメールノードがあって、メールノード毎の設定を行う場合は次のファイル になります。

/var/opt/scalix/nn/s/sys/om_ldap_mailnode.conf

ここで、mailnodeはメールノード名です。

設定オプションには次のものがあり、設定ファイルに"オプション=値"の形式で記述します。

host              接続するLDAPサーバのホスト名とポート番号。
                  スペース区切りで複数のサーバを記述することができる。
                  デフォルト: 0.0.0.0:389
network-timeout   LDAPサーバの応答待ちを行う時間。ミリ秒で記述する。
                  デフォルト: 10000 (10秒)
base              LDAP検索の開始DN
                  デフォルト: なし
search            検索方法。
                  "subtree"は階層下も検索。
                  "one"は一階層のみ。
                  "none"は検索をしない。dnオプションを使うとき。
                  デフォルト: subtree
filter            検索フィルタ。
                  "%s"が認証IDと置き換わる。
                  記述例: (&(objectClass=inetOrgPerson)(uid=%s))
                  デフォルト: uid=%s
dn                DNを指定して直接バインドする場合に記述する。
                  "%s"が認証IDと置き換わる。
                  記述例: cn=%s,dc=example,dc=com
                  デフォルト: %s
tls               TLSを使うかどうかを記述する。

この設定ファイルのオプションの詳細は"man om_ldap"で参照できます。 設定例を二つ紹介します。

(a) ユーザの存在を事前に確認してから接続する場合

host    = ldap.example.com:389
base    = ou=users,dc=example,dc=com
search  = one
filter  = (&(objectclass=inetOrgPerson)(uid=%s))
tls     = off

(b) 直接接続する場合

host    = ldap.example.com:389
base    = ou=users,dc=example,dc=com
search  = none
dn      = cn=%s,ou=users,dc=example,dc=com
tls     = off

ちなみに(b)の方が接続の負荷が少ないです。

次にScalix用のPAMの設定を行います。 PAMの設定ファイルは次のディレクトリにあります。

/var/opt/scalix/nn/s/sys/pam.d

次のファイルを修正する必要があります。

ファイル名   対象
--------------------------------------------------------------------
ual.remote   UALを使うリモートクライアント(Outlook, IMAPサーバ, SWA)
ual.local    UALを使うローカルクライアント
pop3         POP3サーバ
omslapdeng   LDAPサーバ(SWAでのアドレス検索)
smtpd.auth   SMTP RelayのSMTP認証

設定内容はauthサービスに関してom_ldapモジュールを利用するように変更してください。 次の二つの書き方がありますが、LDAP認証を行いたいという観点からいえば(2)の方が間違いないでしょう。

(1) Scalixの標準の認証とLDAP認証のどちらかが認証できればよい方法

auth  sufficient om_auth nullok
auth  sufficient om_ldap use_first_pass
auth  required pam_deny

(2) LDAPにアカウントがない場合だけ標準の認証を行う方法

auth required om_ldap user_unknown=ignore
auth optional om_auth nullok use_first_pass

pam_ldapを使う場合

pam_ldapモジュールはLinuxディストリビューションにほぼ標準で入っています。 入っていなかったら、パッケージシステムを使ってインストールしてください。

まずは、LDAP PAMモジュールの設定ファイル/etc/ldap.confの設定を行います。

次のように変更してください。ドメイン名などあなたの環境に応じて変更してください。

# Your LDAP server. Must be resolvable without using LDAP.
host pdxsrv.example.com

# The distinguished name of the search base.
base dc=example,dc=com

# The LDAP version to use (defaults to 3
# if supported by client library)
ldap_version 3

# The distinguished name to bind to the server with.
# Optional: default is to bind anonymously.
binddn cn=Manager,dc=example,dc=com

# The credentials to bind with.
# Optional: default is no credential.
bindpw password

LDAPサーバがSSLを使うように設定されていない場合は、ここでSSLを使わないように設定してください。

# OpenLDAP SSL mechanism
# start_tls mechanism uses the normal LDAP port, LDAPS typically 636
#ssl start_tls
#ssl on

次にSWAにおけるパスワードの変更を可能にするためにsys/pam.d/ual.remoteファイルを次のように修正します。

auth required om_om2authid
auth sufficient om_auth
auth required /lib/security/pam_ldap.so
account sufficient om_auth
account required /lib/security/pam_ldap.so
password required om_om2authid
password sufficient /lib/security/pam_ldap.so
session required  /lib/security/pam_ldap.so

これでSWAにおいてパスワードの変更ができるはずです。

注意事項

SACにおけるパスワードの設定は内部的にはommoduコマンドを実行するため、Scalix DirectoryのUSERLISTディレクトリ内のパスワードを設定します。 そのため、LDAPサーバに格納されたパスワードを変更しないので注意してください。