Overview
MongoDB Enterprise はKerberos サービス を使用する認証をサポートしています。Kerberos は、大規模なクライアント/サーバーシステム向けの業界標準の認証プロトコルです。MongoDB Enterprise はKerberos の MIT実装のみをサポートしています。
前提条件
MongoDB Enterprise を使用していることを確認するには、 --versionコマンドライン オプションをmongodまたはmongosに渡します。
mongod --version
このコマンドの出力で string modules: subscriptionまたはmodules: enterpriseを探し、MongoDB Enterprise バイナリを使用していることを確認します。
レプリカセットとシャーディングされたクラスターの場合は、IP アドレスや修飾されていないホスト名ではなく、構成で完全修飾ドメイン名(FQDN)が使用されていることを確認してください。 Kerberos レルムを正しく解決し、接続できるようにするには、GSSAPI 用の FQDN を使用する必要があります。
Kerberos 配置の セットアップと構成 については、このドキュメントの範囲外です。 MIT Kerberos のドキュメント を参照してください Kerberos 配置の構成方法については、 またはオペレーティング システムのドキュメント を参照してください。
Kerberos とMongoDBを一緒に使用するには、 MongoDBデプロイ内の各mongos と mongodインスタンスの Kerberos サービス プリンシパルを Kerberosデータベースに追加する必要があります。サービス プリンシパルを追加するには、KDC で次のようなコマンドを実行中。
kadmin.local addprinc mongodb/m1.example.com@EXAMPLE.COM
On each system running mongod or mongos, a keytab file must be created for the respective service principal. You can create the keytab file by running a command similar to the following on the system running mongod or mongos:
kadmin.local ktadd mongodb/m1.example.com@EXAMPLE.COM
手順
The following procedure outlines the steps to add a Kerberos user principal to MongoDB, configure a standalone mongod instance for Kerberos support, and connect using mongosh and authenticate the user principal.
mongodKerberos なしで を起動します。
Kerberos ユーザーを初めて追加する場合は、Kerberos サポートなしでmongodを開始します。
Kerberos ユーザーがすでに MongoDB に存在し、 ユーザーの作成に必要な特権 がある場合は、Kerberos サポート付きでmongodを起動できます。
配置に応じて、追加の設定を含めます。
注意
mongod と mongos は、デフォルトで localhost にバインドされます。配置のノードが異なるホスト上で実行されている場合、またはリモート クライアントを配置に接続する場合は、--bind_ip または net.bindIp を指定する必要があります。
mongod に接続します。
Connect mongosh to the mongod instance. If mongod has --auth enabled, ensure you connect with the privileges required to create a user.
MongoDB に Kerberos プリンシパルを追加しました。
Kerberos プリンシパル( <username>@<KERBEROS REALM>または<username>/<instance>@<KERBEROS REALM>を$externalデータベースの MongoDB に追加します。 すべて大文字で Kerberos レルムを指定します。 $externalデータベースでは、 mongodが外部ソース(例: Kerberos)を使用して認証します。 ユーザーの特権を指定するには、ユーザーにロールを割り当てます。
$external認証ユーザー(Kerberos、LDAP、または X.509 ユーザー)でクライアント セッションと因果整合性の保証を使用するには、ユーザー名を 10 k バイトより大きくすることはできません。
次の例では、 recordsデータベースへの読み取り専用アクセス権を持つ Kerberos プリンシパルapplication/reporting@EXAMPLE.NETを追加します。
use $external db.createUser( { user: "application/reporting@EXAMPLE.NET", roles: [ { role: "read", db: "records" } ] } )
必要に応じて、追加のプリンシパルを追加します。 Kerberos を使用して認証するすべてのユーザーごとに、MongoDB で対応するユーザーを作成する必要があります。 ユーザーの作成と管理の詳細については、「ユーザー管理コマンド 」を参照してください。
Kerberos サポートで mongod を起動します。
Kerberos サポートでmongodを起動するには、次の形式で環境変数KRB5_KTNAMEをキータブ ファイルのパスに設定し、 mongodパラメータauthenticationMechanismsをGSSAPIに設定します。
env KRB5_KTNAME=<path to keytab file> \ mongod \ --setParameter authenticationMechanisms=GSSAPI \ <additional mongod options>
構成に必要な追加オプションを含めます。 たとえば、リモート クライアントを配置に接続する場合、または配置ノードを異なるホスト上で実行する場合は、 --bind_ipを指定します。
たとえば、次の例では、Kerberos をサポートするスタンドアロンのmongodインスタンスが起動されます。
env KRB5_KTNAME=/opt/mongodb/mongod.keytab \ /opt/mongodb/bin/mongod --auth \ --setParameter authenticationMechanisms=GSSAPI \ --dbpath /opt/mongodb/data --bind_ip localhost,<hostname(s)|ip address(es)>
mongodとキータブ ファイルへのパスが異なる場合があります。 キータブ ファイルにアクセスできるのは、 mongodプロセスの所有者のみである必要があります。
公式の.deb または.rpm パッケージを使用すると、KRB5_KTNAME 環境設定ファイルで を設定できます。詳細については、 KRB5 _KTNAME を参照してください。
mongosh を mongod に接続し、認証します。
Connect mongosh client as the Kerberos principal application/reporting@EXAMPLE.NET. Before connecting, you must have used Kerberos's kinit program to get credentials for application/reporting@EXAMPLE.NET.
コマンドラインから接続と認証を行うことができます。
mongosh --host hostname.example.net --authenticationMechanism=GSSAPI --authenticationDatabase='$external' --username application/reporting@EXAMPLE.NET
Kerberos 名と一致するホスト名を持つシステムに接続する場合は、IP アドレスや修飾されていないホスト名ではなく、 --hostオプションに完全修飾ドメイン名(FQDN)を指定していることを確認してください。
If you are connecting to a system whose hostname does not match the Kerberos name, first connect mongosh to the mongod, and then from mongosh, use the db.auth() method to authenticate in the $external database.
use $external db.auth( { mechanism: "GSSAPI", user: "application/reporting@EXAMPLE.NET" } )
その他の考慮事項
KRB5_KTNAME
公式の.debパッケージまたは.rpmパッケージのいずれかを使用して MongoDB Enterprise をインストールし、含まれている初期化およびアップサート スクリプトを使用してmongodインスタンスを制御している場合は、デフォルトの 環境設定ファイルでKRB5_KTNAME変数を設定できます毎回 変数を設定するのではなく
Red Hat および Debian ベースのシステムの最近のバージョンでは、 systemdが使用されています。 古いバージョンでは、システム初期化にinitが使用されます。 適切な手順に従って、システムのKRB5_KTNAME変数を構成します。
systemd 構成ファイル
systemd は構成をユニットファイルに保存します。 ユニット ファイルを更新してKRB5_KTNAME変数を設定します。
ユニットファイルを編集する
編集した行を ユニット ファイルに追加します。 編集されたユニットファイルは次のようになります。
[Unit] Description=High-performance, schema-free document-oriented database After=network.target Documentation=https://docs.mongodb.org/manual [Service] User=mongodb Group=mongodb ExecStart=/usr/bin/mongod --config /etc/mongod.conf Environment="KRB5_KTNAME=/etc/mongod.keytab" PIDFile=/var/run/mongodb/mongod.pid file size LimitFSIZE=infinity cpu time LimitCPU=infinity virtual memory size LimitAS=infinity open files LimitNOFILE=64000 processes/threads LimitNPROC=64000 locked memory LimitMEMLOCK=infinity total threads (user+kernel) TasksMax=infinity TasksAccounting=false Recommended limits for for mongod as specified in http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings [Install] WantedBy=multi-user.target
Restart the mongod service
sudo systemctl restart mongod
init 構成ファイル
.rpmインストールの場合、デフォルトの環境設定ファイルは/etc/sysconfig/mongodです。
.debのインストールの場合、ファイルは/etc/default/mongodbです。
次のような行を追加してKRB5_KTNAME値を設定します。
KRB5_KTNAME="<path to keytab>"
Kerberos の mongos を構成する
Kerberos サポートでmongosを起動するには、次の形式で環境変数KRB5_KTNAMEをそのキータブ ファイルのパスに設定し、 mongosパラメータauthenticationMechanismsをGSSAPIに設定します。
env KRB5_KTNAME=<path to keytab file> \ mongos \ --setParameter authenticationMechanisms=GSSAPI \ <additional mongos options>
構成に必要な追加オプションを含めます。 たとえば、リモート クライアントを配置に接続する場合、または配置ノードを異なるホスト上で実行する場合は、 --bind_ipを指定します。
たとえば、次の例では、Kerberos をサポートするmongosインスタンスが起動されます。
env KRB5_KTNAME=/opt/mongodb/mongos.keytab \ mongos \ --setParameter authenticationMechanisms=GSSAPI \ --configdb shard0.example.net, shard1.example.net,shard2.example.net \ --keyFile /opt/mongodb/mongos.keyfile \ --bind_ip localhost,<hostname(s)|ip address(es)>
mongosとキータブ ファイルへのパスが異なる場合があります。 キータブ ファイルにアクセスできるのは、 mongosプロセスの所有者のみである必要があります。
構成に必要な mongos オプションを変更したり、追加したりします。たとえば、シャードされたクラスター ノードの内部認証に --keyFile を使用する代わりに、X.509 ノード認証を使用できます。
構成ファイルの使用
構成ファイルを使用して Kerberos サポート用にmongodまたはmongosを構成するには、構成ファイルでauthenticationMechanisms設定を指定します。
setParameter: authenticationMechanisms: GSSAPI
構成に必要な追加オプションを含めます。 たとえば、リモート クライアントを使用して配置に接続する場合や、配置ノードを異なるホスト上で実行する場合は、 net.bindIp設定を指定します。
たとえば、 /opt/mongodb/mongod.confにスタンドアロンmongodの次の構成設定が含まれている場合:
security: authorization: enabled setParameter: authenticationMechanisms: GSSAPI storage: dbPath: /opt/mongodb/data net: bindIp: localhost,<hostname(s)|ip address(es)>
Kerberos サポートでmongodを起動するには、次の形式を使用します。
env KRB5_KTNAME=/opt/mongodb/mongod.keytab \ /opt/mongodb/bin/mongod --config /opt/mongodb/mongod.conf
mongod 、キータブ ファイル、構成ファイルへのパスが異なる場合があります。 キータブ ファイルにアクセスできるのは、 mongodプロセスの所有者のみである必要があります。
MongoDB の Kerberos 設定のトラブルシューティング
Kerberos 認証を使用してmongodまたはmongosを起動する際に問題が発生した場合は、 「 自己管理型 Kerberos 認証のトラブルシューティング 」を参照してください。
追加の認証メカニズムを含める
Kerberos 認証( GSSAPI (Kerberos))は、次のものと一緒に機能できます。
MongoDB の SCRAM 認証メカニズム 。
MongoDB の LDAP 認証メカニズムは次のとおりです。
- PLAIN(LDAP SASL)
X.509 のMongoDB の認証メカニズム:
次のようにメカニズムを指定します。
--setParameter authenticationMechanisms=GSSAPI,SCRAM-SHA-256
他のメカニズムが使用されている場合のみ、追加してください。 このパラメーター設定は、クラスター ノードの MongoDB の内部認証には影響しません。
テストと検証
構成手順を完了したら、 mongokerberosツールを使用して構成を検証できます。
mongokerberosは、MongoDB で使用するプラットフォームの Kerberos 構成を確認し、MongoDB クライアントからの Kerberos 認証が期待どおりに機能することをテストするのに便利な方法を提供します。 詳しくは、 mongokerberosのドキュメントを参照してください。
mongokerberos は MongoDB Enterprise でのみ利用可能です。