MongoDB Enterprise supports querying an LDAP server for the LDAP groups to which an authenticated user belongs. MongoDB maps the LDAP distinguished names (DN) of each returned group to roles on the admin database. MongoDB authorizes the user based on the mapped roles and their associated privileges. See LDAP Authorization for more information.
MongoDB Enterprise はKerberos サービスを使用する認証をサポートしています。 Kerberos は、大規模なクライアント/サーバー システム向けの業界標準の認証プロトコルです。
このチュートリアルでは、Kerberos サーバーを通じて認証を実行し、プラットフォーム ライブラリ経由で Active Directory(AD)サーバーを通じて認可を実行するように MongoDB を構成する方法について説明します。
前提条件
AD の完全な説明は、このチュートリアルの範囲外です。このチュートリアルは、AD に関する事前の知識があることを前提としています。
MongoDB は、MongoDB サーバーとADとの間のバインディングに SASL メカニズムを使用することをサポートしています。 SASL、SASL メカニズム、または特定の SASL メカニズムの具体的なAD構成要件の詳細な説明は、このチュートリアルの範囲外です。 このチュートリアルでは、SASL とそれに関連する事柄に関する事前の知識があることを前提としています。
Kerberos 配置の セットアップと構成 については、このドキュメントの範囲外です。 このチュートリアルでは、MongoDBmongos 配置の各mongod } インスタンスと インスタンスに対して Kerberos サービス プリンシパル を構成し、かつmongod }mongos インスタンスと インスタンスごとに の有効な キータブ ファイル があることを前提としています。
レプリカセットとシャーディングされたクラスターの場合は、IP アドレスや修飾されていないホスト名ではなく、構成で完全修飾ドメイン名(FQDN)が使用されていることを確認してください。 Kerberos レルムを正しく解決し、接続できるようにするには、GSSAPI 用の FQDN を使用する必要があります。
MongoDB Enterprise を使用していることを確認するには、 --versionコマンドライン オプションをmongodまたはmongosに渡します。
mongod --version
このコマンドの出力で string modules: subscriptionまたはmodules: enterpriseを探し、MongoDB Enterprise バイナリを使用していることを確認します。
Considerations
このチュートリアルでは、Kerberos 認証と AD 承認のための MongoDB の構成について説明します。
この手順を独自の MongoDB サーバーで実行するには、独自のインフラストラクチャ、特に Kerberos 構成、 ADクエリの構築、またはユーザーの管理に関して指定された手順を変更する必要があります。
トランスポート層のセキュリティ
デフォルトでは、MongoDB はMongoDBサーバーにバインドするときに TLS/SSL 接続を作成します。 これには、MongoDB サーバーのホストを、AD サーバーの証明機関(CA)証明書にアクセスできるように構成する必要があります。
このチュートリアルでは、必要なホスト構成に関する手順を説明します。
このチュートリアルでは、AD サーバーの CA 証明書にアクセスし、MongoDB サーバー上に証明書のコピーを作成できることを前提としています。
Active Directory スキーマの例
このチュートリアルでは、提供されたクエリ、構成、および出力の基礎として、次の例のADオブジェクトを使用します。 各オブジェクトには、可能な属性のサブセットのみが表示されます。
ユーザー オブジェクト
dn:CN=bob,CN=Users,DC=marketing,DC=example,DC=com userPrincipalName: bob@marketing.example.com memberOf: CN=marketing,CN=Users,DC=example,DC=com dn:CN=alice,CN=Users,DC=engineering,DC=example,DC=com userPrincipalName: alice@engineering.example.com memberOf: CN=web,CN=Users,DC=example,DC=com memberOf: CN=PrimaryApplication,CN=Users,DC=example,DC=com dn:CN=sam,CN=Users,DC=dba,DC=example,DC=com userPrincipalName: sam@dba.example.com memberOf: CN=dba,CN=Users,DC=example,DC=com memberOf: CN=PrimaryApplication,CN=Users,DC=example,DC=com dn:CN=joe,CN=Users,DC=analytics,DC=example,DC=com userPrincipalName: joe@analytics.example.com memberof: CN=marketing,CN=Users,DC=example,DC=com
グループ オブジェクト
dn:CN=marketing,CN=Users,DC=example,DC=com member:CN=bob,CN=Users,DC=marketing,DC=example,DC=com member:CN=joe,CN=Users,DC=analytics,DC=example,DC=com dn:CN=engineering,CN=Users,DC=example,DC=com member:CN=web,CN=Users,DC=example,DC=com member:CN=dba,CN=users,DC=example,DC=com dn:CN=web,CN=Users,DC=example,DC=com member:CN=alice,CN=Users,DC=engineering,DC=example,DC=com dn:CN=dba,CN=Users,DC=example,DC=com member:CN=sam,CN=Users,DC=dba,DC=example,DC=com dn:CN=PrimaryApplication,CN=Users,DC=example,DC=com member:CN=sam,CN=Users,DC=dba,DC=example,DC=com member:CN=alice,CN=Users,DC=engineering,DC=example,DC=com
Active Directory の認証情報
This tutorial uses a username and password for performing queries on the AD server. The credentials provided must have sufficient privileges on the AD server for supporting queries related to security.ldap.userToDNMapping or security.ldap.authz.queryTemplate.
レプリカセット
MongoDB LDAP 認可では、レプリカセット内のすべてのmongodが少なくとも MongoDB 3.4.0 である必要があります。 以降に更新します。
シャーディングされたクラスター
MongoDB LDAP 認可では、シャーディングされたクラスター内のすべてのmongodとmongosが、少なくとも MongoDB 3.4.0以降である必要があります。
手順
MongoDB を実行しているサーバーの TLS/SSL を構成します。
To connect to the AD (AD) server via TLS/SSL, the mongod or mongos require access to the AD server's Certificate Authority (CA) certificate.
On Linux, specify the AD server's CA certificates via the TLS_CACERT or TLS_CACERTDIR option in the ldap.conf file.
プラットフォームのパッケージ マネージャーは、MongoDB Enterprise のlibldap依存関係をインストール中にldap.confファイルを作成します。 構成ファイルまたは参照されるオプションに関する完全なドキュメントについては、 ldap.conf を参照してください 。
Microsoft Windows では、プラットフォームの認証情報管理ツールを使用して、 ADサーバーの証明機関(CA)証明書をロードします。 具体的には、 Windowsのバージョンによって異なります。 ツールを使用するには、ご使用のWindowsバージョン向けのドキュメントを参照してください。
mongodまたはmongosがAD CA ファイルにアクセスできない場合、Active Directory サーバーへの TLS/SSL 接続を作成できません。
オプションとして、 security.ldap.transportSecurityをnoneに設定して、TLS/SSL を無効にします。
警告
transportSecurityをnoneに設定すると、ユーザー認証情報を含むプレーンテキスト情報が MongoDB とADサーバー間で送信されます。
(Windows のみ) MongoDB Windows Service にサービスプリンシパル名を割り当てます。
Windows オペレーティング システムで実行されている MongoDB サーバーの場合は、 setspn.exe を使用する必要があります を使用して、MongoDB サービスを実行しているアカウントにサービスプリンシパル名(SPN)を割り当てます。
setspn.exe -S <service>/<fully qualified domain name> <service account name>
例
たとえば、 mongodがサービスアカウント名mongodb_dev@example.comを使用してmongodbserver.example.comでmongodbという名前のサービスとして実行する場合、SPN を割り当てるコマンドは次のようになります。
setspn.exe -S mongodb/mongodbserver.example.com mongodb_dev@example.com
注意
Windows Server 2003 は setspn.exe -S をサポートしていません。 setspn.exe の完全なドキュメントについては、 setspn.exe を参照してください。
(Linux のみ) MongoDB サーバーのキータブ ファイルを作成します。
Linux プラットフォームで実行されている MongoDB サーバーの場合、そのサーバー上で実行されている MongoDB インスタンスに固有のキータブ ファイルのコピーがサーバーにあることを確認する必要があります。
MongoDB サービスを実行している Linux ユーザーに、キータブ ファイルに対する読み取り権限を付与する必要があります。 キータブ ファイルの場所の完全なパスをメモします。
MongoDB サーバーに接続します。
Connect to the MongoDB server using mongosh using the --host and --port options.
mongosh --host <hostname> --port <port>
If your MongoDB server currently enforces authentication, you must authenticate to the admin database as a user with role management privileges, such as those provided by userAdmin or userAdminAnyDatabase. Include the appropriate --authenticationMechanism for the MongoDB server's configured authentication mechanism.
mongosh --host <hostname> --port <port> --username <user> --password <pass> --authenticationDatabase="admin" --authenticationMechanism="<mechanism>"
ユーザー管理ロールを作成します。
To manage MongoDB users using AD, you need to create at least one role on the admin database that can create and manage roles, such as those provided by userAdmin or userAdminAnyDatabase.
ロールの名前は、 ADグループの識別名と完全に一致する必要があります。 グループには、ノードとして少なくとも 1 人のADユーザーが必要です。
使用可能なActive Directory グループがある場合、次の操作は実行されます。
Creates a role named for the AD group
CN=dba,CN=Users,DC=example,DC=com, andadminデータベースのuserAdminAnyDatabaseロールを割り当てます。
var admin = db.getSiblingDB("admin") admin.createRole( { role: "CN=dba,CN=Users,DC=example,DC=com", privileges: [], roles: [ "userAdminAnyDatabase" ] } )
あるいは、ユーザーがユーザー管理特権を付与する必要があるデータベースごとにuserAdminロールを付与することもできます。 これらのロールは、ロールの作成と管理に必要な特権を提供します。
重要
最小特権の原則 を適用することを検討してください MongoDB ロール、 AD グループ、またはグループ メンバーシップを構成する場合。
MongoDB の構成ファイルを作成します。
MongoDB構成ファイルは、 .confファイル拡張子を持つプレーンテキストの YAML ファイルです。
既存の MongoDB デプロイをアップグレードする場合は、現在の構成ファイルをコピーし、そのコピーから作業します。
(Linux のみ) これが新しい配置で、プラットフォームのパッケージ マネージャーを使用して MongoDB Enterprise をインストールした場合、インストールには
/etc/mongod.confのデフォルト構成ファイルが含まれます。 そのデフォルトの構成ファイルを使用するか、そのファイルのコピーを使用して操作します。そのようなファイルが存在しない場合は、
.conf拡張子を持つ空のファイルを作成し、その新しい構成ファイルを操作します。
Active Directory` に接続するように MongoDB を構成します。
In the MongoDB configuration file, set security.ldap.servers to the host and port of the AD server. If your AD infrastructure includes multiple AD servers for the purpose of replication, specify the host and port of the servers as a comma-delimited list to security.ldap.servers.
例
To connect to an AD server located at activedirectory.example.net, include the following in the configuration file:
security: ldap: servers: "activedirectory.example.net"
MongoDB は、クエリを実行するには、 ADサーバーにバインドする必要があります。 デフォルトでは、MongoDB は単純な認証メカニズムを使用してMongoDBサーバーに自分自身をバインドします。
Alternatively, you can configure the following settings in the configuration file to bind to the AD server using SASL:
security.ldap.bind.methodをsaslに設定は、 AD サーバーがサポートするカンマ区切りの SASL
security.ldap.bind.saslMechanismsメカニズムの を指定します。string
このチュートリアルでは、デフォルトのsimple LDAP 認証メカニズムを使用します。
Kerberos 認証用に MongoDB を構成します。
MongoDB 構成ファイルで、 security.authorizationをenabledに、 setParameter authenticationMechanismsをGSSAPIに設定します
Kerberos 経由の認証を有効にするには、 構成ファイル に以下を含めます。
security: authorization: "enabled" setParameter: authenticationMechanisms: "GSSAPI"
認可用の LDAP クエリ テンプレートを構成します。
MongoDB構成ファイルで、 をsecurity.ldap.authz.queryTemplate RFC4516 形式の LDAP クエリURLテンプレートに設定します。
テンプレートでは、次のいずれかを使用できます。
{USER}プレースホルダーを使用して、認証されたユーザー名を LDAP クエリ URL に置き換えます。{PROVIDED_USER}指定されたユーザー名(つまり、認証または LDAP 変換の前)を LDAP クエリに置き換えるためのプレースホルダー。
ユーザーのグループを取得するためのクエリ テンプレートを設計します。
注意
RFC4515、RFC4516、または AD クエリの完全な説明は、このチュートリアルの範囲外です。このチュートリアルで提供されている queryTemplate は例のみであり、特定の ADD 配置には適用されない可能性があります。
例
The following query template returns any groups that list {USER} as a member, following recursive group memberships. This LDAP query assumes that group objects track user membership by storing full user Distinguished Name (DN) using the member attribute. The query includes the AD specific matching rule OID 1.2.840.113556.1.4.1941 for LDAP_MATCHING_RULE_IN_CHAIN. This matching rule is an AD specific extension to LDAP search filters.
security: ldap: authz: queryTemplate: "DC=example,DC=com??sub?(&(objectClass=group)(member:1.2.840.113556.1.4.1941:={USER}))"
クエリ テンプレートを使用すると、MongoDB は LDAP サーバーをクエリするために、 {USER}を認証されたユーザー名に置き換えます。
For example, a user authenticates as CN=sam,CN=Users,DC=dba,DC=example,DC=com. MongoDB creates an LDAP query based on the queryTemplate, substituting the {USER} token with the authenticated username. The Active Directory server performs a recursive group lookup for any group that either directly or transitively lists the user as a member. Based on the Active Directory groups, the AD server returns CN=dba,CN=Users,DC=example,DC=com and CN=engineering,CN=Users,DC=example,DC=com.
MongoDB maps each returned group DN to a role on the admin database. For each mapped group DN, if there is an existing role on the admin database whose name exactly matches the DN, MongoDB grants the user the roles and privileges assigned to that role.
The matching rule LDAP_MATCHING_RULE_IN_CHAIN requires providing the full DN of the authenticating user. Since Kerberos requires authenticating with a user's userPrincipalName, you must transform the incoming usernames into DNs using security.ldap.userToDNMapping. The next step provides guidance on transforming incoming usernames to support the queryTemplate.
Active Directory 経由の認証用に受信したユーザー名を変換します。
In the MongoDB configuration file, set userToDNMapping to transform the authenticating user's provided username into an AD DN to support the queryTemplate.
例
次のuserToDNMapping構成では、指定されたユーザー名を取得するためにmatch正規表現フィルターを使用します。 MongoDB はクエリを実行する前に、取得されたユーザー名をldapQueryクエリ テンプレートに挿入します。
security: ldap: userToDNMapping: '[ { match : "(.+)", ldapQuery: "DC=example,DC=com??sub?(userPrincipalName={0})" } ]'
指定されたサンプル構成を、配置に合わせて変更する必要があります。 たとえば、 ldapQueryのベースDNは、ユーザー エンティティを含むベースDNと一致する必要があります。 AD配置をサポートするには、他の変更が必要になる場合があります。
例
ユーザーはalice@ENGINEERING.EXAMPLE.COMとして認証します。 MongoDB は、 userToDNMappingで指定された変換を最初に適用します。 提供された構成に基づいて、MongoDB はmatchステージでユーザー名を取得し、LDAP クエリを実行します。
DC=example,DC=com??sub?(userPrincipalName=alice@ENGINEERING.EXAMPLE.COM)
Based on the configured Active Directory users, the AD server should return CN=alice,CN=Users,DC=engineering,DC=example,DC=com.
次に、MongoDB はqueryTemplateで構成された LDAP クエリを実行し、 {USER}トークンを変換されたユーザー名CN=alice,CN=Users,DC=engineering,DC=example,DC=comに置き換えます。
重要
userToDNMappingsubstitutionの パラメーターを使用してグループ名を変換する場合、置換の結果は RFC のエスケープされた文字列である必要があります。4514
クエリ認証情報を構成します。
MongoDB では、 ADサーバーでクエリを実行するために認証情報が必要です。
構成ファイル で次の設定を構成します。
security.ldap.bind.queryUserは、mongodmongosAD サーバーでクエリを実行するための Kerberos ユーザー または バインドを指定します。
security: ldap: bind: queryUser: "mongodbadmin@dba.example.com" queryPassword: "secret123"
On Windows MongoDB servers, you can set security.ldap.bind.useOSDefaults to true to use the credentials of the OS user instead of queryUser and queryPassword.
queryUserには、MongoDB に代わってすべての LDAP クエリを実行する権限が必要です。
任意: 追加の構成設定を追加します。
構成に必要な追加オプションを含めます。 たとえば、リモート クライアントを使用して配置に接続する場合や、配置ノードを異なるホスト上で実行する場合は、 net.bindIp設定を指定します。
Kerberos 認証と Active Directory 認証を使用して MongoDB サーバーを起動します。
--configオプションを使用して MongoDB サーバーを起動し、この手順中に作成された構成ファイルへのパスを指定します。 MongoDB サーバーが現在実行中の場合は、適切な準備をしてサーバーを停止します。
Linux MongoDB Servers
Linux では、 KRB5_KTNAME環境変数を指定して、MongoDB サーバーのキータブ ファイルへのパスを指定する必要があります。
env KRB5_KTNAME <path-to-keytab> mongod --config <path-to-config-file>
Microsoft Windows MongoDB Servers
Windows では、手順の前半で構成されたように、MongoDB サーバーをサービスプリンシパル アカウントとして起動する必要があります。
mongod.exe --config <path-to-config-file>
MongoDB サーバーに接続します。
MongoDB サーバーに接続し、 userAdmin 、 userAdminAnyDatabase 、または同等の権限を持つカスタムロールを持つadminデータベースの MongoDB ロールに対応する直接または推移的なグループ メンバーシップを持つユーザーとして認証します。
Use mongosh to authenticate to the MongoDB server, set the following options:
--hostで、MongoDB サーバーのホスト名が--portと MongoDB サーバーのポート--usernameユーザーのuserPrincipalName--passwordto the user's password (or omit to havemongoshprompt for the password)--authenticationMechanism次の行動をします:"GSSAPI"--authenticationDatabase次の行動をします:"$external"
例
Previously in this procedure, you configured the dn:CN=dba,CN=Users,DC=example,DC=com role on the admin database with the required permissions. This role corresponds to an AD group. Based on the configured AD users, you can authenticate as the user sam@dba.example.com and receive the required permissions.
mongosh --username sam@DBA.EXAMPLE.COM --password --authenticationMechanisms="GSSAPI" --authenticationDatabase "$external" --host <hostname> --port <port>
If you do not specify the password to the -p command-line option, mongosh prompts for the password.
Windows MongoDB deployments must use mongo.exe instead of mongosh.
構成されたActive Directory ユーザーの場合、ユーザーは正常に認証され、適切な権限を受け取ります。
注意
If you want to authenticate as an existing non-$external user, set --authenticationMechanism to a SCRAM authentication mechanism (e.g. SCRAM-SHA-1 or SCRAM-SHA-256). This requires that the MongoDB server's setParameter authenticationMechanisms includes SCRAM-SHA-1 and/or SCRAM-SHA-256 as appropriate.
返された AD グループをマッピングするためのロールを作成します。
For each group on the AD server you wish to use for MongoDB authorization, you must create a matching role on the MongoDB server's admin database.
例
The following operation creates a role named after the AD group DN CN=PrimaryApplication,CN=Users,DC=example,DC=com, assigning roles and privileges appropriate to that group:
db.getSiblingDB("admin").createRole( { role: "CN=PrimaryApplication,CN=Users,DC=example,DC=com", privileges: [], roles: [ { role: "readWrite", db: "PrimaryApplication" } ] } )
Given the configured Active Directory groups, MongoDB grants a user authenticating as either sam@DBA.EXAMPLE.COM or alice@ENGINEERING.EXAMPLE.COM the readWrite role on the PrimaryApplication database.
注意
adminデータベースでロールを管理するには、 adminのuserAdminを持つユーザー、 userAdminAnyDatabase 、または同等の権限を持つ のカスタムロールとして認証される必要があります。
オプション: 既存のユーザーを から$external Active Directoryサーバーに移行します。
$external データベースでユーザーが構成された既存のインストールをアップグレードする場合、Kerberos 認証と AD 承認用に MongoDB を構成した後、アクセスを確保するために、各ユーザーに対して次の要件を満たす必要があります。
ユーザーは、 ADサーバー上に対応するユーザー オブジェクトがあります。
ユーザーは、 ADサーバー上の適切なグループのメンバーシップを持っています。
MongoDB には、認可されたユーザーが特権を保持するように、ユーザーのADグループに対して という名前の
adminデータベース上のロールが含まれています。
例
次のユーザーが$externalデータベースに存在します。
{ user : "joe@ANALYTICS.EXAMPLE.COM", roles: [ { role : "read", db : "web_analytics" }, { role : "read", db : "PrimaryApplication" } ] }
Assuming the user belongs to the AD group CN=marketing,CN=Users,DC=example,DC=com, the following operation creates a matching role with the appropriate privileges:
db.getSiblingDB("admin").createRole( { role: "CN=marketing,CN=Users,DC=example,DC=com", privileges: [], roles: [ { role: "read", db: "web_analytics" } { role: "read", db: "PrimaryApplication" } ] } )
構成されたqueryTemplate に基づいて、MongoDB は、CN=marketing,CN=Users,DC=example,DC=com グループの直接または推移的なメンバーシップを持つすべてのユーザーに、read web_analyticsデータベースとPrimaryApplication データベースで 操作を実行することを許可します。
重要
対応するADグループに対してロールを構成する場合、そのグループのメンバーシップを持つすべてのユーザーが、割り当てられたロールと特権を受け取ることができることを覚えておいてください。 最小特権の原則 を適用することを検討してください MongoDB ロール、 AD グループ、またはグループ メンバーシップを構成する場合。
$external以外のデータベースのユーザーによる MongoDB へのアクセスを引き続き許可する場合は、SCRAM 認証メカニズム(例: { setParameter authenticationMechanisms構成オプションのSCRAM-SHA-1および/またはSCRAM-SHA-256 )。
setParameter: authenticationMechanisms: "GSSAPI,SCRAM-SHA-1,SCRAM-SHA-256"
または、上記の手順に従って、 $external以外のユーザーをADDに移行します。
この手順では、次の構成ファイルが作成されます。
security: authorization: "enabled" ldap: servers: activedirectory.example.net" bind: queryUser: "mongodbadmin@dba.example.com" queryPassword: "secret123" userToDNMapping: '[ { match: "(.+)" ldapQuery: "DC=example,DC=com??sub?(userPrincipalName={0})" } ]' authz: queryTemplate: "DC=example,DC=com??sub?(&(objectClass=group)(member:1.2.840.113556.1.4.1941:={USER}))" setParameter: authenticationMechanisms: "GSSAPI"
重要
指定されたサンプル構成は、 ADスキーマ、ディレクトリ構造、および構成と一致するように変更する必要があります。 配置には追加の構成ファイル オプションも必要になる場合があります。
ロールと特権の設定の詳細については、以下を参照してください。
テストと検証
構成手順を完了したら、 mongokerberosツールを使用して構成を検証できます。
mongokerberosは、MongoDB で使用するプラットフォームの Kerberos 構成を確認し、MongoDB クライアントからの Kerberos 認証が期待どおりに機能することをテストするのに便利な方法を提供します。 詳しくは、 mongokerberosのドキュメントを参照してください。
mongokerberos は MongoDB Enterprise でのみ利用可能です。