(ヽ´ω`) < slapd.confはオワコン
流石にお金払ってProにしたのに記事を書かないのもアレなので、まずは一本目。
(ヽ´ω`) < っていうかolcってなんだよ
数年ぶりにOpenLDAPを触ってみたところ、slapd.confによる設定がオワコンになっていた。 代わりになにやらolcというのを使う必要があるらしい。 これはなんだと調べてみると、どうやらOpenLDAPサーバの設定値をOpenLDAPサーバ自体で保持する仕組みらしい。
OpenLDAP 2.3 and later have transitioned to using a dynamic runtime configuration engine, slapd-config(5). slapd-config(5)
- is fully LDAP-enabled
- is managed using the standard LDAP operations
- stores its configuration data in an LDIF database, generally in the /usr/local/etc/openldap/slapd.d directory.
- allows all of slapd's configuration options to be changed on the fly, generally without requiring a server restart for the changes to take effect.
という感じでOpenLDAPの設定をLDAP操作で、LDIF形式で、さらに設定変更の反映をサーバの再起動無しで行えるとのこと。 MySQLのVARIABLESみたいなものか。
olcとはOpenLDAP Configurationの略で動的コンフィグで使用されるobjectClassやattributeのprefixの値らしい。
Configuration directives are specified as values of individual attributes. Most of the attributes and objectClasses used in the slapd configuration have a prefix of "olc" (OpenLDAP Configuration) in their names.
(ヽ´ω`) < 実際の設定方法は?
さて、olcというか動的コンフィグが何かはわかったのでその設定方法だ。
ということで、みんな大好きCentOS7に試しに入れてみると、 /etc/openldap/
配下に slapd.d
というディレクトリが存在する。
slapd.conf残っとるやんけ! と思ったらldap.confだった。
slapd.dを覗いて見ると、何やらよくわからない命名規則のディレクトリとファイルが並んでいる。 ファイルの中身を見てみると、たしかにLDIFファイルだ。 なるほど、ではこのファイルを編集して初期設定を行うのかと思ったらどうやらそうではないらしい。
Note: Although the slapd-config(5) system stores its configuration as (text-based) LDIF files, you should never edit any of the LDIF files directly. Configuration changes should be performed via LDAP operations, e.g. ldapadd(1), ldapdelete(1), or ldapmodify(1).
で、多くの日本語の解説ページは「エラーは出ますけど直接編集します」とか書いてあったりするので、このあたりもうちょい調べてみた。
上記Quick Start Guideの項番9によると
Import the configuration database You are now ready to import your configration database for use by slapd(8), by running the command: su root -c /usr/local/sbin/slapadd -n 0 -F /usr/local/etc/slapd.d -l /usr/local/etc/openldap/slapd.ldif
LDIFファイルの内容を元にconfiguration databaseを作成できるとのこと。
しかし /etc/openldap/
にそれらしいLDIFファイルは見当たらない、ということで探してみると /usr/share/openldap-servers/slapd.ldif
がそれっぽい。
試しにolcSuffixとolcRootDNの値を変更してみる。
--- /usr/share/openldap-servers/slapd.ldif.org 2019-08-22 13:46:45.604588841 +0000 +++ /usr/share/openldap-servers/slapd.ldif 2019-08-22 13:48:50.928660767 +0000 @@ -141,8 +141,8 @@ objectClass: olcDatabaseConfig objectClass: olcHdbConfig olcDatabase: hdb -olcSuffix: dc=my-domain,dc=com -olcRootDN: cn=Manager,dc=my-domain,dc=com +olcSuffix: dc=tsugihagi,dc=net +olcRootDN: cn=Manager,dc=tsugihagi,dc=net olcDbDirectory: /var/lib/ldap olcDbIndex: objectClass eq,pres olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub
更新したLDIFファイルはslapaddコマンドで、slapd.dディレクトリ配下に書き出しできる。 のだが、どうやら上書きはできないらしく、予めslapd.dの中を消さないとだめっぽい。 slapaddで書き出しを行う際にはslapd、つまりOpenLDAPのプロセスは停止しておいたほうが良いとのこと。(初期設定のタイミングのみ。設定の変更は稼働中のOpenLDAPに対してldapadd/ldapmodifyを使う)
slapadd -n0 -l /usr/share/openldap-servers/slapd.ldif -F /etc/openldap/slapd.d
-l
オプションでLDIFファイルを、-F
オプションで書き出し先のディレクトリを指定する。 -n0
はLDAPデータベースの設定順序とかそのあたりの理解が必要なので、また別のエントリで。殆どの場合では -n0
で設定しておけばOK。
で、上記コマンドで生成されたファイルから、変更箇所のdiffを抜き出しものがこちら。
diff -ur slapd.d/cn=config/olcDatabase={2}hdb.ldif slapd.d.new/cn=config/olcDatabase={2}hdb.ldif --- slapd.d/cn=config/olcDatabase={2}hdb.ldif 2019-08-22 13:18:29.316749668 +0000 +++ slapd.d.new/cn=config/olcDatabase={2}hdb.ldif 2019-08-22 13:52:34.375781992 +0000 @@ -1,18 +1,18 @@ # AUTO-GENERATED FILE - DO NOT EDIT!! Use ldapmodify. -# CRC32 e7a20b3c +# CRC32 78d1520c dn: olcDatabase={2}hdb objectClass: olcDatabaseConfig objectClass: olcHdbConfig olcDatabase: {2}hdb olcDbDirectory: /var/lib/ldap -olcSuffix: dc=my-domain,dc=com -olcRootDN: cn=Manager,dc=my-domain,dc=com +olcSuffix: dc=tsugihagi,dc=net +olcRootDN: cn=Manager,dc=tsugihagi,dc=net olcDbIndex: objectClass eq,pres olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub structuralObjectClass: olcHdbConfig -entryUUID: 13823ef0-592b-1039-9ce6-2f4b436ed340 +entryUUID: d6756af0-592f-1039-83ee-d772cea2dae7 creatorsName: cn=config -createTimestamp: 20190822131829Z -entryCSN: 20190822131829.327604Z#000000#000#000000 +createTimestamp: 20190822135234Z +entryCSN: 20190822135234.386164Z#000000#000#000000 modifiersName: cn=config -modifyTimestamp: 20190822131829Z +modifyTimestamp: 20190822135234Z
CRCやUUID、タイムスタンプが更新されて、その差分が出ているため少し見にくいが、想定通りolcSuffixとolcRootDNが指定した値に書き換わっている。
ということで、これで起動すれば ldif_read_file: checksum error on "/etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif"
などと怒られなくて済む。
(ヽ´ω`) < slapd.confからの移行はどうしたらええの?
ちなみに、slapd.confでの設定も実はできたりする。
The older style slapd.conf(5) file is still supported, but its use is deprecated and support for it will be withdrawn in a future OpenLDAP release. Configuring slapd(8) via slapd.conf(5) is described in the next chapter.
とのことで2.4ではまだサポートするけど、Deprecatedだし将来的には廃止するよとのこと。
実際に slapd --help
を実行してみると。
slapd --help slapd: invalid option -- '-' usage: slapd options -4 IPv4 only -6 IPv6 only -T {acl|add|auth|cat|dn|index|passwd|test} Run in Tool mode -c cookie Sync cookie of consumer -d level Debug level -f filename Configuration file -F dir Configuration directory -g group Group (id or name) to run as -h URLs List of URLs to serve -l facility Syslog facility (default: LOCAL4) -n serverName Service name -o <opt>[=val] generic means to specify options; supported options: slp[={on|off|(attrs)}] enable/disable SLP using (attrs) -r directory Sandbox directory to chroot to -s level Syslog level -u user User (id or name) to run as -V print version info (-VV exit afterwards, -VVV print info about static overlays and backends)
と、 -f
オプションでslapd.confを指定することで使えるようだが、いつ使用できなくなるかわからないものを使い続けるのも心臓に悪い。
slapd.confの内容を元に、slapd.ldifを書き直すのが無難だろう。
実は
Configuration directives are specified as values of individual attributes. Most of the attributes and objectClasses used in the slapd configuration have a prefix of "olc" (OpenLDAP Configuration) in their names. Generally there is a one-to-one correspondence between the attributes and the old-style slapd.conf configuration keywords, using the keyword as the attribute name, with the "olc" prefix attached.
とあるように、slapd.confのキーワードをパスカルケースにして olc
をprefixとして付与してやることで、ほとんどの設定はそのまま移行が可能。( suffix
-> olcSuffix,
rootdn->
olcRootDN`)
更にもっと簡単な方法として、slapd.confを元にslapd.dディレクトリに書き出す方法がある。
先述のslapaddコマンドでは -l
オプションでLDIFファイルを指定したが、これを -f
でslapd.confを渡してやればOK。
-f slapd.conf specify an alternative slapd.conf(5) file.
-F confdir specify a config directory. If both -f and -F are specified, the config file will be read and converted to config directory format and written to the specified directory.
さらにさらに、既に初期設定を完了して運用してしまっているが、万が一の再構築に備えてLDIFに落としておきたい場合は slapcat -n0
で、現在の設定を元にLDIFファイルを出力してくれる。
(ヽ´ω`) < 結局、動的コンフィグは嬉しいのか
confファイルを廃してLDIFの文法一本に絞れること、ldapmodifyなどの統一されたツールで操作が行えること、特に再起動不要で設定が反映できることなんかは良いと思う。 OpenLDAPは歴史が長く、slapd.conf時代の解説ページが多いので少し戸惑うかもしれないが、次のバージョンでslapd.confのサポートが完全に切られたりしても大丈夫なように備えておきましょう。