0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LDAP Managerを使ってみた! 9. LDAP→ODBC、ODBC→LDAP反映編

Last updated at Posted at 2025-03-06

前回の続きです。

LDAP→ODBC反映とは

LDAPフィルタの条件に合致したユーザをODBCデータソースを介してDBに反映するプラグインです。

事前準備

MySQLの準備

LDAP Managerのサポートリストより、MySQL 8.4を反映先DBとしました。
RHEL 9.4のリポにはMySQL 8.4がないので、リポを追加します。

$ dnf install https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm

追加後、インストールを実施します。

$ dnf install mysql-server

MySQLサービスを開始します。

$ systemctl start mysqld

MySQLのrootユーザの初期パスワードを確認します。

$ cat /var/log/mysqld.log
2024-12-18T08:29:50.980903Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2024-12-18T08:29:50.982771Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.4.3) initializing of server in progress as process 29048
2024-12-18T08:29:51.035404Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-12-18T08:29:55.098009Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-12-18T08:29:59.226056Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: yTBFuj=3737*
2024-12-18T08:30:03.192714Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
2024-12-18T08:30:03.265782Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2024-12-18T08:30:03.526420Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.4.3) starting as process 29086
2024-12-18T08:30:03.566004Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-12-18T08:30:05.431772Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-12-18T08:30:06.184268Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-12-18T08:30:06.184352Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2024-12-18T08:30:06.302704Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2024-12-18T08:30:06.303189Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.4.3'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.

yTBFuj=3737*が初期パスワードのようです。
MySQLの初期設定を行います。
以下のコマンドを実行します。

$ mysql_secure_installation
mysql_secure_installation

最初にrootユーザのパスワードを聞かれるので、先ほど確認した初期パスワードを入力します。

Securing the MySQL server deployment.
Enter password for user root:

次に、再設定するrootユーザのパスワードを入力します。

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:

先ほどパスワード検証コンポーネントの検証に耐えるパスワードをrootユーザに設定したのでここはNとします。

The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N

 ... skipping.

匿名ユーザを削除します。

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

リモートからのrootユーザでの接続は不許可とします。

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

testデータベースは削除します。

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

資格情報テーブルをリロードします。

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

MySQLがリッスンするアドレスとポートを/etc/my.cnfに指定してMySQLを再起動します。

+ port=3306
+ bind-address = 0.0.0.0
$ systemctl restart mysqld

ユーザ、データベース、テーブルを作成します。

$ mysql -p 
Enter password:

mysql> create user 'odbcuser'@'%' IDENTIFIED BY 'P@sw0rd+';
Query OK, 0 rows affected (0.02 sec)

mysql> create database lmodbc;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on lmodbc.* to odbcuser;
Query OK, 0 rows affected (0.00 sec)

mysql> create table lmodbc.ldapuser (
    -> employeenumber varchar(10) PRIMARY KEY,
    -> passwordexpirationtime time,
    -> passwordexpirationdate date,
    -> commonname varchar(15),
    -> surname varchar(15),
    -> givenname varchar(15),
    -> userid varchar(44),
    -> ldapm varchar(2)
    -> );
Query OK, 0 rows affected (0.04 sec)

ODBCデータソースの準備

提供サイトからインストーラーをダウンロードし、LDAP Managerがインストールされているサーバにインストールします。
インストール後、ODBC データ ソース アドミニストレーター(64ビット)より、ODBCドライバのセットアップを行います。
Unicode版のODBCドライバを使用します。
MySQL上に設定したユーザとデータベースを設定し、接続を確認して保存します。
pic (1).png

プラグインの設定

LDAP Manager コンソールから「環境設定」 > 「LDAP -> ODBC反映1」を選択します。
まず、抽出元LDAPサーバとデータソース情報を設定します。
pic (2).png
次に、テーブル情報の「追加」を押下し、反映先テーブルに関する設定を行います。
LDAPサーバからの抽出フィルタと、対象テーブル名を指定します。
pic (3).png
その後、ODBC属性名の「属性インポート」を押下し、テーブルの列情報を読み込みます。
取得した列情報からレコード識別属性を指定します。(必要な場合)
pic (4).png
マッピングは以下のように行いました。
pic (5).png

確認

プラグインを手動実行します。
pic (6).png
レコードがDBに挿入されます。
pic (7).png

mysql> select * from lmodbc.ldapuser;
+----------------+------------------------+------------------------+------------+----------+-----------+----------------------------------------------+-------+
| employeenumber | passwordexpirationtime | passwordexpirationdate | commonname | surname  | givenname | userid                                       | ldapm |
+----------------+------------------------+------------------------+------------+----------+-----------+----------------------------------------------+-------+
| 1              | 09:58:33               | 3024-04-21             | user1      | Tanaka   | Jiro      | Q5LRABncLhvWgoOQteHF9ib6iyDRQFUBWwUklrCoK3o= | LM    |
| 2              | 09:58:49               | 3024-04-21             | user2      | Nakamura | Tomoki    | YvVzDsmeC70Ai+eHp6e3tLfEXdX5+1qVlk4xBqqKudc= | LM    |
| 3              | 09:59:02               | 3024-04-21             | user3      | Koga     | Yujiro    | QJvfnol2ktrLqwTMWeQJ2P5LU8o9JB6YssMOrdierU8= | LM    |
+----------------+------------------------+------------------------+------------+----------+-----------+----------------------------------------------+-------+
3 rows in set (0.00 sec)

ユーザ情報を変更、削除して実行します。
pic (8).png
pic (10).png

この通り、変更情報や削除が反映されています。

mysql> select * from lmodbc.ldapuser;
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
| employeenumber | passwordexpirationtime | passwordexpirationdate | commonname | surname | givenname | userid                                       | ldapm |
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
| 1              | 09:58:33               | 3024-04-21             | user1      | Tanaka  | Jiro      | Q5LRABncLhvWgoOQteHF9ib6iyDRQFUBWwUklrCoK3o= | LM    |
| 2              | 10:16:45               | 3024-04-21             | user2      | Yasuda  | Tomoki    | YvVzDsmeC70Ai+eHp6e3tLfEXdX5+1qVlk4xBqqKudc= | LM    |
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
2 rows in set (0.00 sec)

レコード識別属性について確認します。
以下のように、レコード識別属性ldapmに指定の属性値LMが含まれないようにします。

mysql> update lmodbc.ldapuser SET ldapm = 'NO' where employeenumber = '2';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from lmodbc.ldapuser;
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
| employeenumber | passwordexpirationtime | passwordexpirationdate | commonname | surname | givenname | userid                                       | ldapm |
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
| 1              | 18:58:33               | 3024-04-21             | user1      | Tanaka  | Jiro      | F8vW6uFbjqtWuLgrGD1uASrfJPPl9zVOP/W5UhiqfJQ= | LM    |
| 2              | 19:16:45               | 3024-04-21             | user2      | Yasuda  | Tomoki    | HfBnEJiOitSW9g9ik5YdN5nMWeCPnGuR+MJrOhxev6o= | NO    |
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
2 rows in set (0.00 sec)

ユーザ情報を変更します。
pic (11).png
ここでLDAP→ODBC反映を実行すると、更新処理がスキップされます。
pic (12).png

mysql> select * from lmodbc.ldapuser;
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
| employeenumber | passwordexpirationtime | passwordexpirationdate | commonname | surname | givenname | userid                                       | ldapm |
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
| 1              | 18:58:33               | 3024-04-21             | user1      | Tanaka  | Jiro      | F8vW6uFbjqtWuLgrGD1uASrfJPPl9zVOP/W5UhiqfJQ= | LM    |
| 2              | 19:16:45               | 3024-04-21             | user2      | Yasuda  | Tomoki    | HfBnEJiOitSW9g9ik5YdN5nMWeCPnGuR+MJrOhxev6o= | NO    |
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
2 rows in set (0.00 sec)

最後に、抽出フィルタを変更します。
pic (13).png
このようにフィルタに合致しなくなったユーザが削除されます。

mysql> select * from lmodbc.ldapuser;
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
| employeenumber | passwordexpirationtime | passwordexpirationdate | commonname | surname | givenname | userid                                       | ldapm |
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
| 1              | 09:58:33               | 3024-04-21             | user1      | Tanaka  | Jiro      | Q5LRABncLhvWgoOQteHF9ib6iyDRQFUBWwUklrCoK3o= | LM    |
+----------------+------------------------+------------------------+------------+---------+-----------+----------------------------------------------+-------+
1 row in set (0.01 sec)

ODBC → LDAP反映とは

データベースからODBCを介してユーザ情報をLDAPサーバに連携するプラグインです。

事前準備

SQL Server Expressの準備

抽出元DBにはSQL Server 2022 Expressを使用します。
提供サイトからインストーラーをダウンロードして実行します。
SSMSもインストールしています。
SQL Server構成マネージャー > SQL Server ネットワークの構成 > SQLEXPRESSのプロトコル > TCP/IPを「有効」とします。
pic (14).png
IPAllのTCPポートを指定します。
pic (15).png

データベースの準備

SSMSを起動してSQL Serverに接続します。
pic (16).png
SQL Server認証モードを有効にします。
pic (17).png
新しいデータベースを作成します。
pic (18).png
UTF-8に対応させるため照合順序を変更します。
pic (19).png
ログインを作成します。
「既定のデータベース」をodbclmにします。
pic (20).png
次に、データベースユーザを作成します。
データベースユーザとログインをマッピングし、既定のスキーマを設定します。
pic (21).png
今回は既定のdboを使用するので他にスキーマは設定しません。
pic (22).png
メンバーシップ(ロール)db_ownerを割り当ててしまいます。
pic (23).png
セキュリティ保護は特にしないので設定しません。
pic (24).png
これで、ログインodbclmでSQL Serverに接続できます。
最後にテーブルを作成します。プラグインの設定でRDN属性とする属性とマッピングされる列を必ず作成する必要があります。

create table employees (
employeenumber varchar(10) PRIMARY KEY,
surname varchar(50),
givenname varchar(50)
);

ODBCデータソースの準備

提供サイトからインストーラーをダウンロード、インストールします。
ODBC データ ソース アドミニストレーター(64 ビット)より、SQL Server用のデータソースを追加します。
pic (25).png
pic (26).png
pic (27).png
pic (28).png
pic (29).png
pic (30).png

プラグインの設定

プラグインをインストールします。
pic (31).png
LDAP Managerコンソール「環境設定」 > 「ODBC -> LDAP反映1」を開きます。
まず「基本設定」を行います。
ODBC、LDAPの情報を設定します。抽出条件用SQLにはselect * from employeesを指定しました。
pic (32).png
次に、「ODBC属性名設定」から「属性インポート」します。
pic (33).png
「マッピング設定」は以下のようにしました。先述の通り、RDN属性(ここではcn)にマッピングするODBC属性(列)が存在する必要があります。
pic (34).png

確認

現在、データベースにはレコードがなく、LDAPサーバには2つのユーザエントリが存在する状態です。
pic (35).png
pic (36).png
この状態で実行すると、LDAPサーバ側のユーザエントリは削除(無効化)されます。
pic (37).png
データベースにデータを挿入してからプラグインを実行します。
pic (38).png
データがLDAPに反映されます。
pic (39).png
pic (40).png
DB側のデータを更新して再度プラグインを実行します。

update employees 
SET surname = 'Watanabe'
where employeenumber = '4'
;

LDAP側の更新が確認できます。
pic (41).png
抽出条件を変更します。
pic (42).png
'4'というemployeenumberを持つユーザが抽出されなくなり、以下の通り無効化処理が実施されます。
pic (43).png

まとめ

LDAPから/LDAPへDBの情報を連携する2つのプラグインについての検証でした。
次の記事では、LDAP Managerのワークフローシステムである IDワークフロー について検証します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?