> For AI agents: the complete documentation index is available at /resource/ucidm/docs/on-premise/llms.txt, the full documentation bundle is available at /resource/ucidm/docs/on-premise/llms-full.txt.

# 連携元 OpenLDAP の構築 \{#ucidm-quickstart-source-ldap}

UCIDM サーバーに OSSTech 社 OpenLDAP (osstech-openldap) をインストールし、連携元の OpenLDAP を構築します。
あわせて、連携元の OpenLDAP のパスワード変更を UCIDM に連携する、OpenLDAP 向け PassSync Agent を設定します。
作業はすべて UCIDM サーバーで root ユーザーとして行います。

このページでは、次の値で構築します。
お使いの環境に合わせて変えてもかまいません。
変えたときは、[基本設定](/resource/ucidm/docs/on-premise/quickstart/setting-basic.md) の sourceOpenLDAP にも同じ値を設定してください。

| 項目               | 値                              |
| ---------------- | ------------------------------ |
| サフィックス           | `dc=example,dc=com`            |
| 管理者の DN (rootDN) | `cn=Manager,dc=example,dc=com` |
| ユーザーの置き場所        | `ou=users,dc=example,dc=com`   |
| グループの置き場所        | `ou=groups,dc=example,dc=com`  |

## osstech-openldap のインストール \{#install-osstech-openldap}

osstech-openldap の配布物 (tar.gz のアーカイブ) は、弊社のサポート担当者からお受け取りください。
UCIDM サーバーの OS のバージョン (RHEL 9 または RHEL 10) とアーキテクチャ (x86_64 または aarch64) に合うものを使います。

アーカイブを展開し、同梱の `install.sh` を実行します。
`install.sh` は、アーカイブに含まれる osstech-openldap、osstech-openldap-servers、osstech-openldap-clients などのパッケージを dnf でインストールします。
次の例のファイル名は、受け取ったアーカイブの名前に読み替えてください。

```console
# tar xzf osstech-openldap-2.6.15-8.el10.x86_64.tar.gz
# sh osstech-openldap-2.6.15-8.el10.x86_64/install.sh
```

## slapd の設定 \{#slapd-settings}

### 管理者のパスワードのハッシュ \{#root-password-hash}

管理者 (rootDN) のパスワードを決め、`slappasswd` でハッシュにします。
パスワードを 2 回入力すると、最後の行にハッシュが出力されます。
入力したパスワードは、このあとのエントリの投入と、基本設定の sourceOpenLDAP の `bindPasswd` で使います。

```console
# /opt/osstech/sbin/slappasswd -h {ARGON2}
```

### slapd.conf \{#slapd-conf}

`/opt/osstech/etc/openldap/slapd.conf` を次の内容に書き換えます。
`rootpw` には、`slappasswd` が出力したハッシュを書きます。

```text
include /opt/osstech/etc/openldap/schema/core.schema
include /opt/osstech/etc/openldap/schema/cosine.schema
include /opt/osstech/etc/openldap/schema/inetorgperson.schema
include /opt/osstech/etc/openldap/schema/nis.schema

loglevel stats

moduleload argon2.la
moduleload ppolicy.la
password-hash {ARGON2}

database  mdb
maxsize   1073741824
suffix    "dc=example,dc=com"
rootdn    "cn=Manager,dc=example,dc=com"
rootpw    <slappasswd が出力したハッシュ>
directory /opt/osstech/var/lib/ldap

index objectClass                  eq
index entryCSN,entryUUID           eq
index ou,cn,mail,surname,givenname eq,pres,sub

access to attrs=userPassword
    by self write
    by anonymous auth
    by * none

access to *
    by self write
    by users read
    by * none

overlay syncprov
syncprov-checkpoint 128 5
syncprov-sessionlog 100

overlay ppolicy
ppolicy_hash_cleartext on
```

この設定のうち、UCIDM に関わるのは次の 2 つです。

- **syncprov**：UCIDM の Agent は、syncprov が提供する同期の仕組み (Content Sync) で連携元の変更を検知します。`entryCSN` と `entryUUID` のインデックスも、syncprov が使います。
- **ppolicy_hash_cleartext**：平文で投入したパスワードを、slapd が `password-hash` の形式 (ARGON2) のハッシュにして保存します。

> \[!WARNING]
> slapd.conf は書く位置に意味があります。
> `database` の行より後ろはそのデータベースの設定になり、`overlay` の行より後ろはその overlay の設定になります。
> 行の順序は変えないでください。

書式を確かめます。

```console
# /opt/osstech/sbin/slaptest -u -f /opt/osstech/etc/openldap/slapd.conf
config file testing succeeded
```

### 待ち受けるアドレス \{#slapd-listen}

クイックスタートでは、連携元の OpenLDAP には同じサーバーの UCIDM だけが接続します。
`/opt/osstech/etc/sysconfig/slapd` に次の行を追加し、slapd がローカルホストだけで待ち受けるようにします。
追加しないときは、すべてのアドレスで待ち受けます。

```ini
SLAPD_SERVICES="ldap://127.0.0.1/"
```

slapd を起動します。

```console
# systemctl enable --now slapd.service
```

## 試験用のエントリの投入 \{#load-entries}

UCIDM に連携する試験用のユーザーとグループを入れます。
次の内容で `quickstart.ldif` を作ります。

ユーザーは、[基本設定](/resource/ucidm/docs/on-premise/quickstart/setting-basic.md#default-user-attributes) の既定の属性定義に合わせて、`inetOrgPerson` と `posixAccount` で作ります。
グループは `posixGroup` で作り、メンバーを `memberUid` に書きます。
`memberUid` は、sourceOpenLDAP の `groupMemberAttribute` の既定の値です。

```text
dn: dc=example,dc=com
objectClass: dcObject
objectClass: organization
dc: example
o: UCIDM quickstart

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

dn: ou=groups,dc=example,dc=com
objectClass: organizationalUnit
ou: groups

dn: uid=user1,ou=users,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
uid: user1
cn: Ichiro Sato
sn: Sato
givenName: Ichiro
mail: user1@example.com
uidNumber: 10001
gidNumber: 10000
homeDirectory: /home/user1
loginShell: /bin/bash
userPassword: password

dn: uid=user2,ou=users,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
uid: user2
cn: Yuki Tanaka
sn: Tanaka
givenName: Yuki
mail: user2@example.com
uidNumber: 10002
gidNumber: 10000
homeDirectory: /home/user2
loginShell: /bin/bash
userPassword: password

dn: cn=staff,ou=groups,dc=example,dc=com
objectClass: posixGroup
cn: staff
gidNumber: 10000
memberUid: user1
memberUid: user2
```

管理者の DN でエントリを投入します。
パスワードを尋ねられたら、`slappasswd` で入力したパスワードを入力します。

```console
# /opt/osstech/bin/ldapadd -x -H ldap://127.0.0.1/ -D "cn=Manager,dc=example,dc=com" -W -f quickstart.ldif
```

投入したエントリを確かめます。

```console
# /opt/osstech/bin/ldapsearch -x -H ldap://127.0.0.1/ -D "cn=Manager,dc=example,dc=com" -W -b "dc=example,dc=com" -LLL dn
```

## パスワード連携の設定 \{#password-sync-settings}

連携元の OpenLDAP のパスワード変更を UCIDM に連携するため、追加で次の設定をします。

- PassSync Agent (osstech-ucidm-passsync) をインストールします。
- slapd.conf に ucidmpsync オーバーレイを追加します。ucidmpsync はパスワードの変更を受け取り、PassSync Agent を通して UCIDM API に送ります。

> \[!WARNING]
> ucidmpsync は、[試験用のエントリの投入](#load-entries) が済んでから有効にしてください。
> ucidmpsync を有効にしたあとでパスワードを持つエントリを入れると、そのパスワードも UCIDM API に送られます。
> その時点ではエントリがまだ UCIDM に連携されていないので、送信が失敗します。
> 失敗したパスワードはリカバリディレクトリに残り、再送が繰り返されます。

> \[!NOTE]
> OpenLDAP を UCIDM サーバーとは別のサーバーに置く構成では、PassSync Agent の手順が異なります。
> その構成の手順は、[PassSync Agent パッケージ - Linux サーバー向け](/resource/ucidm/docs/on-premise/install/passsync-agent.md#for-linux-server) と [OpenLDAP 向け PassSync Agent](/resource/ucidm/docs/on-premise/configuration/passsync/openldap.md) をご参照ください。

### PassSync Agent のインストール \{#install-passsync-agent}

UCIDM のリポジトリは、UCIDM のインストールで設定済みです。
PassSync Agent のパッケージをインストールします。

```console
# dnf install osstech-ucidm-passsync
```

PassSync Agent は、UCIDM API の接続先と agent アカウントを UCIDM の `common.env` と `secret.env` から読みます。
`/opt/osstech/etc/ucidm-passsync/` の設定ファイルは編集しません。

### ucidmpsync オーバーレイの追加 \{#add-ucidmpsync-overlay}

[slapd.conf](#slapd-conf) に、ucidmpsync オーバーレイの設定を 2 か所追加します。

1. `moduleload ppolicy.la` の次の行に、`moduleload ucidmpsync.la` を追加します。
2. ファイルの最後 (`ppolicy_hash_cleartext on` の後ろ) に、`overlay ucidmpsync` と `ucidmpsync-sender` の 2 行を追加します。
   overlay は書いた順と逆の順に呼ばれるので、パスワードの変更を最初に受け取れるよう、ucidmpsync を最後に書きます。

```text
...
moduleload argon2.la
moduleload ppolicy.la
moduleload ucidmpsync.la
...
overlay ppolicy
ppolicy_hash_cleartext on

overlay ucidmpsync
ucidmpsync-sender "/opt/osstech/lib64/osstech-ucidm-passsync/sender"
```

書式を確かめます。

```console
# /opt/osstech/sbin/slaptest -u -f /opt/osstech/etc/openldap/slapd.conf
config file testing succeeded
```

> \[!NOTE]
> slapd に PassSync の環境変数を渡す設定は、パッケージが行います。
> `systemctl edit slapd.service` で設定を書く必要はありません。

### サービスの起動 \{#start-passsync-agent}

slapd から呼ばれる sender は、PassSync Agent が作るソケットに接続します。
そのため、PassSync Agent、slapd の順に起動します。

```console
# systemctl daemon-reload
# systemctl enable --now osstech-ucidm-passsync.service
# systemctl restart slapd.service
```

以上で、連携元の OpenLDAP の構築とパスワード連携の設定は完了です。
パスワード連携は、[基本設定](/resource/ucidm/docs/on-premise/quickstart/setting-basic.md#check-password-sync) で連携元を UCIDM に接続したあとに確かめます。
