ClickHouse は、ClickHouse のデータベースユーザーの認証に LDAP を使用するよう設定できます。このガイドでは、公開されているディレクトリに対して認証を行う LDAP システムと ClickHouse を統合する簡単な例を紹介します。
ClickHouse で LDAP 接続設定を行う
-
この公開 LDAP サーバーへの接続をテストします。
$ ldapsearch -x -b dc=example,dc=com -H ldap://ldap.forumsys.com応答は次のようになります。
# 拡張 LDIF # # LDAPv3 # base <dc=example,dc=com>、スコープ subtree # フィルタ: (objectclass=*) # 要求: ALL # # example.com dn: dc=example,dc=com objectClass: top objectClass: dcObject objectClass: organization o: example.com dc: example ... -
config.xmlファイルを編集し、LDAP を設定するために次を追加します。<ldap_servers> <test_ldap_server> <host>ldap.forumsys.com</host> <port>389</port> <bind_dn>uid={user_name},dc=example,dc=com</bind_dn> <enable_tls>no</enable_tls> <tls_require_cert>never</tls_require_cert> </test_ldap_server> </ldap_servers>
上記で使用している基本設定は次のとおりです。
| Parameter | Description | Example |
|---|---|---|
| host | LDAP サーバーのホスト名または IP | ldap.forumsys.com |
| port | LDAP サーバーのディレクトリポート | 389 |
| bind_dn | ユーザーを指定するテンプレートパス | uid={user_name},dc=example,dc=com |
| enable_tls | セキュアな LDAP を使用するかどうか | no |
| tls_require_cert | connection に証明書を必須にするかどうか | never |
-
ユーザーのロールマッピングを設定するため、
<user_directories>セクションに<ldap>セクションを追加します。このセクションでは、ユーザーの認証方法と、認証後に付与されるロールを定義します。この基本例では、LDAP で認証されたすべてのユーザーにscientists_roleが付与されます。これは後の手順で ClickHouse に定義します。セクションは次のようになります。<user_directories> <users_xml> <path>users.xml</path> </users_xml> <local_directory> <path>/var/lib/clickhouse/access/</path> </local_directory> <ldap> <server>test_ldap_server</server> <roles> <scientists_role /> </roles> <role_mapping> <base_dn>dc=example,dc=com</base_dn> <search_filter>(&(objectClass=groupOfUniqueNames)(uniqueMember={bind_dn}))</search_filter> <attribute>cn</attribute> </role_mapping> </ldap> </user_directories>上記で使用している基本設定は次のとおりです。
Parameter Description Example server 前の ldap_servers セクションで定義したラベル test_ldap_server roles ユーザーのマッピング先となる、ClickHouse で定義されたロール名 scientists_role base_dn ユーザーに関連付けられたグループの検索を開始するベースパス dc=example,dc=com search_filter ユーザーをマッピングする対象グループを識別する LDAP 検索フィルタ (&(objectClass=groupOfUniqueNames)(uniqueMember={bind_dn}))attribute どの attribute 名の値を返すか cn -
設定を反映するために ClickHouse server を再起動します。
ClickHouse データベースのロールと権限を設定する
-
config.xmlファイルのロールマッピングセクションで使用したものと同じ名前のロールを ClickHouse に作成しますCREATE ROLE scientists_role; -
ロールに必要な権限を付与します。次のステートメントでは、LDAP 経由で認証できるすべてのユーザーに管理者権限を付与します。
GRANT ALL ON *.* TO scientists_role;
LDAP 設定をテストする
- ClickHouse clientでログインします
$ clickhouse-client --user einstein --password password ClickHouse client version 22.2.2.1. Connecting to localhost:9000 as user einstein. Connected to ClickHouse server version 22.2.2 revision 54455. chnode1 :)
-
ユーザーが
scientists_roleロールに正しくマッピングされ、管理者権限を持っていることを確認しますSHOW DATABASESQuery id: 93b785ff-1482-4eda-95b0-b2d68b2c5e0f ┌─name───────────────┐ │ INFORMATION_SCHEMA │ │ db1_mysql │ │ db2 │ │ db3 │ │ db4_mysql │ │ db5_merge │ │ default │ │ information_schema │ │ system │ └────────────────────┘ 9 rows in set. Elapsed: 0.004 sec.
まとめ
この記事では、ClickHouse を LDAP サーバーに対する認証用に設定し、ロールにマッピングする基本的な方法を説明しました。ClickHouse では個別のユーザーを設定しつつ、自動 ロールマッピング を構成せずに、それらのユーザーを LDAP で認証することも可能です。LDAP モジュールは、Active Directory への接続にも利用できます。