かいていちゅう
LDAPサーバを作る
CentOS8で作ってみる
過去記事 LDAP/サーバ構築
インストール †
CentOS8からどうやらopenldap-serversパッケージが削除された模様. 代替品として「389-ds」が提供されている.
従来のOpenLDAPを使うなら別途コンパイルとなるが、面倒なのでこの「389-ds」を採用します.
epelにも「389-ds」が提供されていて、こちらは名称が「389-directory-server」となっている.
どちらも使っても構わないが、dnfのmodule形式で提供され、そのインストール方法に注意が必要
[root@ldap ~]# dnf module list 389-directory-server 389-ds
Last metadata expiration check: 0:11:27 ago on Thu 24 Sep 2020 01:45:48 AM JST.
CentOS-8 - AppStream
Name Stream Profiles Summary
389-ds 1.4 389 Directory Server (base)
Extra Packages for Enterprise Linux Modular 8 - x86_64
Name Stream Profiles Summary
389-directory-server stable default [d], legacy, minimal 389 Directory Server
389-directory-server testing default [d], legacy, minimal 389 Directory Server
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@ldap ~]#
OS提供の「389-ds」にはProfilesがない. 方や「389-directory-server」にはprofilesがある.
- OS提供を採用するなら
[root@ldap ~]# dnf module enable 389-ds
[root@ldap ~]# dnf install 389-ds-base
*「389-ds-base」ってどっから出てきた?ってなるが、そうするみたい
- EPEL提供を使用するなら
[root@ldap ~]# dnf module enable 389-directory-server:stable
[root@ldap ~]# dnf module install 389-directory-server/default
セットアップ †
「dscreate」コマンドを使って設定を行う.
インターラクティヴでセットアップができるようで「dscreate interactive」で進めることができる.
「dscreate create-template」で何が定義されるか一通り確認するもの宜しいかと
[root@ldap ~]# dscreate interactive
Install Directory Server (interactive mode)
===========================================
Enter system's hostname [ldap.sybyl.local]:
Enter the instance name [ldap]: ds
Enter port number [389]:
Create self-signed certificate database [yes]:
Enter secure port number [636]:
Enter Directory Manager DN [cn=Directory Manager]: cn=DirectoryManager <--- 既定の値にはスペースがあるのでそれを外した
Enter the Directory Manager password:
Confirm the Directory Manager Password:
Enter the database suffix (or enter "none" to skip) [dc=ldap,dc=sybyl,dc=local]: dc=sybyl,dc=local <-- domain名にしてみた
Create sample entries in the suffix [no]:
Create just the top suffix entry [no]: yes
Do you want to start the instance after the installation? [yes]:
Are you ready to install? [no]: yes
Starting installation...
Completed installation for ds
[root@ldap ~]#
インスタンス名を「ds」としたのでsystemctlで制御されるデーモン名は「dirsrv@ds.service」となる。
「systemctl status dirsrv@ds.service」
でLDAPサービスの状態が分かります。
- 「Create sample entries in the suffix [no]:」にてyesとするとLdapAdminからは下記のように見えます

ご丁寧にサンプルのグループ/ユーザが用意されます
- 「Create sample entries in the suffix [no]:」をnoにして「Create just the top suffix entry [no]:」をyesにすると

Topの器だけがあります
- 「Create sample entries in the suffix [no]:」をnoにして「Create just the top suffix entry [no]:」もnoにすると

何もない状態
「Create just the top suffix entry [no]:」をyesにすればいいのかなと思います。
一方、一度作ったインスタンスを削除したい場合は、「dsctl ds remove --do-it」とします。
[root@ldap ~]# systemctl stop dirsrv@ds.service
[root@ldap ~]# dsctl ds remove --do-it
Removing instance ...
Completed instance removal
[root@ldap ~]#
サービスデーモン †
デーモン名は「dirsrv@<instance名>.service」となる.
[root@ldap ~]# systemctl status dirsrv@ds.service
● dirsrv@ds.service - 389 Directory Server ds.
Loaded: loaded (/usr/lib/systemd/system/dirsrv@.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/dirsrv@.service.d
mqcustom.conf
Active: active (running) since Thu 2020-09-24 04:12:34 JST; 42min ago
Process: 9169 ExecStartPre=/usr/libexec/dirsrv/ds_systemd_ask_password_acl /etc/dirsrv/slapd-ds/dse.ldif (code=exited, status=0/SUCCESS)
Main PID: 9174 (ns-slapd)
Status: "slapd started: Ready to process requests"
Tasks: 25 (limit: 5036)
Memory: 27.2M
CGroup: /system.slice/system-dirsrv.slice/dirsrv@ds.service
mq9174 /usr/sbin/ns-slapd -D /etc/dirsrv/slapd-ds -i /run/dirsrv/slapd-ds.pid
:
:
[root@ldap ~]#
問題なく動いているみたい
停止/起動は下記のようにする
(停止)
[root@ldap ~]# systemctl stop dirsrv@ds.service
(起動)
[root@ldap ~]# systemctl start dirsrv@ds.service
自分のドメインの設計(その1) †
まずは、ディレクトリの管理者とデータへのアクセス権をLDIFで定義する
ここではドメインは dc=sybyl,dc=local
ディレクトリ管理者は cn=Manager,dc=sybyl,dc=local
としています。
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=sybyl,dc=local" read by * none <--- ここ
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=sybyl,dc=local <--- ここ
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,dc=sybyl,dc=local <--- ここ
dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxx <--- slappasswdで再度作る
dn: olcDatabase={2}hdb,cn=config <--- ここ
changetype: modify
add: olcAccess
olcAccess: {0}to attrs=userPassword,shadowLastChange by
dn="cn=Manager,dc=sybyl,dc=local" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=Manager,dc=sybyl,dc=local" write by * read <--- ここ
これを「ldapdomain.ldif」と保存して下記によりLDAPに反映させる。
[root@ldap ~]# ldapmodify -H ldapi:/// -f ldapdomain.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={1}monitor,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
ldapmodify: wrong attributeType at line 16, entry "olcDatabase={2}hdb,cn=config"
[root@ldap ~]#
っが、ldapdomain.ldifの16行目に問題がるとされた。ここらはodコマンドで確認します。
すると、
[root@ldap ~]# od -c ldapdomain.ldif
:
0000560 t y p e : m o d i f y \n r e p <-- [type: modify<br>rep]
0000600 l a c e : o l c R o o t D N \n <-- [lace: olcRootDN<br>]
0000620 o l c R o o t D N : c n = M a <-- [olcRootDN: cn=Ma]
0000640 n a g e r , d c = s y b y l , d <-- [nager,dc=sybyl,d]
0000660 c = l o c a l \n \n d n : o l <-- [c=local<br> <br>dn: ol]「\n \n」と余計な空白がある
0000700 c D a t a b a s e = { 2 } h d b <-- [cDatabase={2}hdb]
:
と「ldapdomain.ldif」に余計な空白があると分かる。ここを修正して再度登録しなおします。
[root@ldap ~]# ldapmodify -H ldapi:/// -f ldapdomain.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={1}monitor,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
modifying entry "olcDatabase={2}hdb,cn=config"
[root@ldap ~]#
で完了。
自分のドメインの設計(その2) †
トップドメインを用意します。
下記ファイル(domain.ldif)には、
- トップドメインの定義(dn: dc=sybyl,dc=local)
- 管理者の定義(dn: cn=Manager,dc=sybyl,dc=local)
- ユーザの定義枠(dn: ou=People,dc=sybyl,dc=local)
- グループの定義枠(dn: ou=Group,dc=sybyl,dc=local)
が含まれてます。
[root@ldap ~]# cat domain.ldif
#TOPドメインの定義
dn: dc=sybyl,dc=local
objectClass: top
objectClass: dcObject
objectclass: organization
dc: sybyl
o: sybyl local
description: sybyl Ldap
#管理者の定義
dn: cn=Manager,dc=sybyl,dc=local
objectClass: organizationalRole
cn: Manager
description: Directory Manager
#people(/etc/passwdなもの)の定義
dn: ou=People,dc=sybyl,dc=local
objectClass: organizationalUnit
ou: People
#group(/etc/groupなもの)の定義
dn: ou=Group,dc=sybyl,dc=local
objectClass: organizationalUnit
ou: Group
[root@ldap ~]#
これは新規追加となるので「ldapadd」を使います。
「Enter LDAP Password:」とパスワードを問われるが、これはディレクトリ管理者のパスワード.
[root@ldap ~]# ldapadd -x -D cn=Manager,dc=sybyl,dc=local -W -f domain.ldif
Enter LDAP Password:
adding new entry "dc=sybyl,dc=local"
adding new entry "cn=Manager,dc=sybyl,dc=local"
adding new entry "ou=People,dc=sybyl,dc=local"
adding new entry "ou=Group,dc=sybyl,dc=local"
[root@ldap ~]#
これで枠が完成した。
スキーマ拡張 †
ActiveDirectoryでautofsスキーマ拡張を行ったがそれと同じ感じ. ここでは基本的なスキーマの拡張(追加)です。
既定で用意されているスキーマは「/etc/openldap/schema/」にある。
DBで言えば、、、SYSTEM側のテーブル追加って感じかな. 何を登録できるかは「/etc/openldap/schema/」の「*.schema」を参照
ここでは下記を追加する
- cosine.ldif
attributetype: personalTitle, mobileTelephoneNumber, buildingName,,
objectclass: newPilotPerson,,.
- nis.ldif
attributetype: gecos, homeDirectory, loginShell,,
objectclass: posixAccount, posixGroup,,.
- inetorgperson.ldif
attributetype: departmentNumber, employeeNumber, employeeType,,
objectclass: inetOrgPerson
一筆書きで実行
[root@ldap ~]# for def in cosine.ldif nis.ldif inetorgperson.ldif; do ldapadd -H ldapi:/// -f /etc/openldap/schema/$def; done
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=cosine,cn=schema,cn=config"
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=nis,cn=schema,cn=config"
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=inetorgperson,cn=schema,cn=config"
[root@ldap ~]#
Cockpit UI Plugin †
389-ds向けのインターフェースが用意されている。
[root@ldap ~]# systemctl start cockpit.socket
その後に他のPCでブラウザを立ち上げて、「ldap.sybyl.local:9090」にアクセスすると下記のような画面が表示される

ここでldap.sybyl.localのrootアカウントでログインすると389-ds向けのUIが見える
やれることは、、、すくないかと
|