Ubuntu23.04に389-ds(LDAP)を構築

はじめに

前回の続きです。
LDAPを構築。RHLEはOpenLDAPを非推奨とし、今後389-dsを利用していくようです。長い物には巻かれていくスタイルなので、389-dsを利用していきたいと思います。
参考

インストール

バージョンにこだわりがなければaptでインストールできます。
apt install 389-ds

準備

infファイルのテンプレートを新規作成します。

cd /etc/ldap/
dscreate create-template main.inf

以下は、dscreateコマンドで作成された初期値のファイルです。grepでコメントを除外しています。

root@389-ldap:/etc/ldap# grep -v -e '^\s*#' -e '^\s*$' main.inf | expand | tr -s [:space:] | sed 's/^\s/    /g'
;
; This is a version 2 ds setup inf file.
; It is used by the python versions of setup-ds-*
; Most options map 1 to 1 to the original .inf file.
; However, there are some differences that I envision
; For example, note the split backend section.
; You should be able to create, one, many or no backends in an install
;
; The special value {instance_name} is substituted at installation time.
;
; By default, all configuration parameters in this file are commented out.
; To use an INF file with dscreate, you must at least set the parameters
; flagged with [REQUIRED].
[general]
;defaults = 999999999
;full_machine_name = 389-ldap
;start = True
;strict_host_checking = False
[slapd]
;instance_name = localhost
;ldapi = /run/slapd-{instance_name}.socket
;port = 389
;root_password = Directory_Manager_Password
;secure_port = 636
;self_sign_cert = True
;self_sign_cert_valid_months = 24
[backend-userroot]
;changelog_max_age = 7d
;changelog_max_entries = -1
;create_suffix_entry = False
;enable_replication = False
;replica_binddn = cn=replication manager,cn=config
;replica_bindgroup =
;replica_bindpw =
;replica_id = 1
;replica_role = supplier
;require_index = False
;sample_entries = no
;suffix =

各項目の意味

[general]

項目 意味
defaults インスタンスのバージョンを指定できる。デフォルトは「999999999」で常に最新を参照する。XXXYYYZZZ(先頭ゼロ埋め必須)でバージョン指定ができる。例としてバージョン1.3.5であれば、「001003005」となる。
full_machine_name デフォルトではサーバのホスト名 (FQDN)が設定されている。ロード バランサーの背後で GSSAPI 認証を使用してこのインスタンスをインストールする場合は、このパラメーターをロード バランサーの FQDN に設定し、さらに「strict_host_checking」を「false」に設定する必要がある。
start 基本Trueでよい。インストールの完了後にインスタンスを起動するかどうかの設定。
strict_host_checking デフォルトはFalse。サーバーが「full_machine_name」パラメータに設定された順方向および逆方向のレコードを検証するかどうかを設定する。

[slapd]

項目 意味
instance_name デフォルトはlocalhostインストール後は変更できないため、何かしら名前を設定する方が良い。
ldapi Directory Server のソケット インターフェイスの場所を設定します。基本デフォルトのままでよい。
port 制約がない限り、基本LDAPのデフォルトポートを利用で良い。
root_password 「cn=Directory Manager」アカウントのパスワードを設定。8文字以上である必要がある。
secure_port インスタンスTLS で保護された LDAP 接続 (LDAPS) に使用する TCP ポートを設定します。デフォルトでよい。
self_sign_cert セットアップで自己署名証明書を作成し、インストール中に TLS 暗号化を有効にするかどうかを設定。今回はインストール中に作成するのでTrue。
self_sign_cert_valid_months 発行された自己署名証明書の有効月数を設定します。デフォルトだと2年。

[backend-userroot]

項目 意味
changelog_max_age エントリーがレプリケーション変更ログに残る期間。デフォルトは 7 日、つまり「7d」です。 (レプリケーションが有効になっている必要があります)。
changelog_max_entries レプリケーション変更ログに保持するエントリの最大数。デフォルトは「-1」で、無制限を意味します。 (レプリケーションが有効になっている必要があります)。
create_suffix_entry このパラメータを「True」に設定すると、データベース内にサフィックスの汎用ルート ノード エントリが作成されます。
enable_replication バックエンドのレプリケーションを有効にします。デフォルトでは、バックエンドはサプライヤーとして設定され、レプリカ ID は 1、レプリケーション バインド名として「cn=replication manager,cn=config」が設定されます。
replica_binddn レプリケーション マネージャーの DN を設定します。
replica_bindgroup レプリケーションバインドグループDNを設定します。
replica_bindpw Replication Manager アカウント (「replica_binddn」パラメーター) のパスワードを設定します。特権のないユーザーがこの INF ファイルを読み取ることができる場合、プレーン テキストのパスワードを設定するとセキュリティ リスクが生じる可能性があることに注意してください。
replica_id このレプリカのデータベースの一意のレプリケーション識別子を設定します (サプライヤーのみ)
replica_role レプリケーションの役割を設定します。 「サプライヤー」、「ハブ」、「コンシューマー」のいずれかを選択してください
require_index このデータベースでのインデックスのない検索を拒否するには、このパラメータを「True」に設定します。
sample_entries このデータベースにサンプル エントリの最新バージョンを追加するには、このパラメータを「yes」に設定します。または、「001003006」を使用して、1.3.6 バージョンのサンプル エントリを使用します。このオプションは、たとえばテスト目的でデータベースを作成する場合に使用します。
suffix このデータベースに保存されているルートサフィックスを設定します。コメントを解除して suffix 属性を設定しない場合、インストール プロセスではバックエンド/サフィックスは作成されません。このセクションを複製して、複数のバックエンド/サフィックスを作成することもできます。

初期設定

main.infの必要な項目を変更します。

[general]
full_machine_name = ldap.example.com

[slapd]
instance_name = main
root_password = password

[backend-userroot]
suffix = dc=example,dc=com

インスタンスの作成と確認

インスタンスを作成します。

root@389-ldap:/etc/ldap# dscreate from-file main.inf
Starting installation ...
Validate installation settings ...
Create file system structures ...
Create self-signed certificate database ...
selinux is disabled, will not relabel ports or files.
selinux is disabled, will not relabel ports or files.
Create database backend: dc=example,dc=com ...
Perform post-installation tasks ...
Completed installation for instance: slapd-ldapmain

root@389-ldap:/etc/ldap#

インスタンスの確認をします。

root@389-ldap:/etc/ldap# systemctl status dirsrv@main.service

● dirsrv@main.service - 389 Directory Server main.
     Loaded: loaded (/lib/systemd/system/dirsrv@.service; enabled; preset: enabled)
    Drop-In: /usr/lib/systemd/system/dirsrv@.service.d
             mqcustom.conf
     Active: active (running) since Mon 20xx-xx-xx 00:00:00 UTC; 3min 19s ago
    Process: 4173 ExecStartPre=/usr/libexec/ds_systemd_ask_password_acl /etc/dirsrv/slapd-main/dse.ldif (code=exited, status=0/SUCCESS)
    Process: 4178 ExecStartPre=/usr/libexec/ds_selinux_restorecon.sh /etc/dirsrv/slapd-main/dse.ldif (code=exited, status=0/SUCCESS)
   Main PID: 4183 (ns-slapd)
     Status: "slapd started: Ready to process requests"
      Tasks: 29 (limit: 4538)
     Memory: 62.1M
        CPU: 2.119s
     CGroup: /system.slice/system-dirsrv.slice/dirsrv@main.service
             mq4183 /usr/sbin/ns-slapd -D /etc/dirsrv/slapd-main -i /run/dirsrv/slapd-main.pid

また、コマンドでLDAPへの接続確認をします。
表示されればOKです。パスワードはmain.infに設定した管理者パスワードです。
また、ldap://ではなくldaps://です。また、ldaps://10.24.2.40IPアドレスでも確認できました。

root@389-ldap:/etc/ldap# ldapsearch ldaps://ldap.example.com -D "cn=Directory Manager" -b cn=config -s base -W
Enter LDAP Password:
# extended LDIF
#
# LDAPv3
# base <cn=config> with scope baseObject
# filter: (objectclass=*)
# requesting: ldaps://ldap.example.com
#

# config
dn: cn=config

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1
root@389-ldap:/etc/ldap#

管理者パスワードの変更

このサイトを参考にしたのですが、コマンドでの変更がなぜかできませんでした。
dse.ldifのパスワードハッシュを編集することでリセットできました。

インスタンスの停止
root@389-ldap:/etc/ldap# dsctl main stop
パスワードハッシュの生成
root@389-ldap:/etc/ldap# pwdhash -D /etc/dirsrv/slapd-main password
{PBKDF2_SHA256}AAAgABU0bKhyjY53NcxY33ueoPjOUWtl4iyYN5uW...
dse.ldifの編集
root@389-ldap:/etc/ldap# vi /etc/dirsrv/slapd-main/dse.ldif

nsslapd-rootpw: {PBKDF2_SHA256}AAAgABU0bKhyjY53NcxY33ueoPjOUWtl4iyYN5uW...
 ABCDEFG....
 A==
インスタンスの起動
root@389-ldap:/etc/ldap# dsctl main start

さいごに

ひとまずLDAPは動きました。次回はPythonでユーザの追加・削除・パスワード変更の操作を行っていきます。