Amazon Linux に OpenLDAP サーバをインストールした際の手順をメモしておきます。 LDAP としては問題無いのですが、後述の通り、LDAPS がエラーになってしまい、動作させられませんでした…(課題)
検証環境
検証環境には AmazonLinux 2017.09 を使いました。
# cat /etc/os-release
NAME="Amazon Linux AMI"
VERSION="2017.09"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2017.09"
PRETTY_NAME="Amazon Linux AMI 2017.09"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2017.09:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"
OpenLDAP のパッケージは以下を使いました。
- openldap-clients-2.4.40-12.30.amzn1.x86_64
- openldap-2.4.40-12.30.amzn1.x86_64
- openldap-servers-2.4.40-12.30.amzn1.x86_64
インストール
インストールします。
yum -y install openldap-clients openldap-servers
起動スクリプトは /etc/init.d/slapd
に配置されます。 インストール直後は起動していません(停止した状態です)。
設定ファイルの用意
設定ファイルを所定のディレクトリにコピーし、所有者を ldap
ユーザに変更します。
cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap. /var/lib/ldap/DB_CONFIG
OpenLDAP を起動する
OpenLDAP を起動します。 併せて、自動起動の設定も実施しておきます。
service slapd start
chkconfig slapd on
OpenLDAP はデフォルトで 389/TCP を Listen します。
# lsof -i:389
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
slapd 3203 ldap 7u IPv4 12820 0t0 TCP *:ldap (LISTEN)
slapd 3203 ldap 8u IPv6 12821 0t0 TCP *:ldap (LISTEN)
管理者パスワードを設定する
管理者パスワードを設定します。 まず、slappasswd
を実行してパスワードを生成します。
slappasswd
実行例は以下の通りです。
# slappasswd
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
パスワード設定用の /root/change-root-password.ldif
というファイルを以下の内容で新規作成します。 olcRootPW
には slappasswd
で生成した SSHA 値を指定します。
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ldapadd
を使って反映します。
ldapadd -Y EXTERNAL -H ldapi:/// -f /root/change-root-password.ldif
実行例は以下の通りです。
# ldapadd -Y EXTERNAL -H ldapi:/// -f /root/change-root-password.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={0}config,cn=config"
ドメイン名を設定する
ドメイン名の設定を進める前に、ディレクトリマネージャ用のパスワードを slappasswd
で生成します。 具体的な実行例は以下の通りです。
# slappasswd
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
以下の内容で /root/change-domain.ldif
というファイルを新規作成します。 DN 名の dc=EXAMPLE,dc=COM
部分は自身の環境に併せて変更します。
dn: olcDatabase={1}monitor,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth"
read by dn.base="cn=Manager,dc=EXAMPLE,dc=COM" read by * none
dn: olcDatabase={2}bdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=EXAMPLE,dc=COM
dn: olcDatabase={2}bdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,dc=EXAMPLE,dc=COM
dn: olcDatabase={2}bdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
dn: olcDatabase={2}bdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by
dn="cn=Manager,dc=EXAMPLE,dc=COM" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=Manager,dc=EXAMPLE,dc=COM" write by * read
ldapmodify
で変更を反映します。
ldapmodify -Y EXTERNAL -H ldapi:/// -f /root/change-domain.ldif
次は以下の内容で /root/set-basedomain.ldif
というファイルを新規作成します。
dn: dc=EXAMPLE,dc=COM
objectClass: top
objectClass: dcObject
objectclass: organization
o: EXAMPLE
dc: EXAMPLE
dn: cn=Manager,dc=EXAMPLE,dc=COM
objectClass: organizationalRole
cn: Manager
description: Directory Manager
dn: ou=People,dc=EXAMPLE,dc=COM
objectClass: organizationalUnit
ou: People
dn: ou=Group,dc=EXAMPLE,dc=COM
objectClass: organizationalUnit
ou: Group
ldapadd
で変更を反映します。
ldapadd -x -D cn=Manager,dc=EXAMPLE,dc=COM -W -f /root/set-basedomain.ldif
ログ出力の設定
OpenLDAP はデフォルト状態だと全くログを出力しません。 ログ出力を行いたい場合は、まず /etc/sysconfig/ldap
へ以下のように設定を行います。 今回は OpenLDAP のログを Local4 扱いとしました。
SLAPD_OPTIONS="-l local4 -s 512"
rsyslog 側にも「Local4 は /var/log/ldap.log
にロギングする」よう、設定を行います。
echo "local4.* /var/log/ldap.log" > /etc/rsyslog.d/ldap.conf
OpenLDAP を再起動し、変更を反映します。
service slapd restart
Windows に LDAP Admin をインストールする
Windows から接続確認するには LDAP Admin 等を利用します。
LDAPS を有効化出来ない?
LDAPS を有効化して外部から接続してもエラーになってしまいました… フォーラム等でも同様の事象が報告されているようですが、結局、解決に至りませんでした。 ldapsearch
をデバッグオプション付きで実行した場合、以下のようなエラーが出ていました。
TLS: certdb config: configDir='/etc/openldap' tokenDescription='ldap(0)' certPrefix='cacerts' keyPrefix='cacerts' flags=readOnly
TLS: cannot open certdb '/etc/openldap', error -8018:Unknown PKCS #11 error.
TLS: could not get info about the CA certificate directory /etc/openldap/cacerts - error -5950:File not found.
TLS: error: tlsm_PR_Recv returned 0 - error 2:No such file or directory
TLS: error: connect - force handshake failure: errno 2 - moznss error -5938
TLS: can't connect: TLS error -5938:Encountered end of file.
ldap_err2string
ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1)
参考
/etc/sysconfig/ldap
# Options of slapd (see man slapd)
#SLAPD_OPTIONS=
# At least one of SLAPD_LDAP, SLAPD_LDAPI and SLAPD_LDAPS must be set to 'yes'!
#
# Run slapd with -h "... ldap:/// ..."
# yes/no, default: yes
SLAPD_LDAP=yes
# Run slapd with -h "... ldapi:/// ..."
# yes/no, default: yes
SLAPD_LDAPI=yes
# Run slapd with -h "... ldaps:/// ..."
# yes/no, default: no
SLAPD_LDAPS=no
# Run slapd with -h "... $SLAPD_URLS ..."
# This option could be used instead of previous three ones, but:
# - it doesn't overwrite settings of $SLAPD_LDAP, $SLAPD_LDAPS and $SLAPD_LDAPI options
# - it isn't overwritten by settings of $SLAPD_LDAP, $SLAPD_LDAPS and $SLAPD_LDAPI options
# example: SLAPD_URLS="ldapi:///var/lib/ldap_root/ldapi ldapi:/// ldaps:///"
# default: empty
#SLAPD_URLS=""
# Maximum allowed time to wait for slapd shutdown on 'service ldap stop' (in seconds)
#SLAPD_SHUTDOWN_TIMEOUT=3
# Parameters to ulimit, use to change system limits for slapd
#SLAPD_ULIMIT_SETTINGS=""
コメント