ActiveDirectory で自己管理型 SASL と LDAP を使用して認証
注意
MongoDB 8.0以降、 LDAP認証と認可は非推奨です。 LDAP は使用可能であり、 MongoDB 8のサポート期間中に変更されずに動作し続けます。 LDAP は将来のメジャー リリースで削除される予定です。
詳細については、「LDAP の非推奨」を参照してください。
MongoDB Enterprise provides support for proxy authentication of users. This allows administrators to configure a MongoDB cluster to authenticate users by proxying authentication requests to a specified Lightweight Directory Access Protocol (LDAP) service.
注意
libldap
にリンクされた MongoDB 4.2 Enterprise バイナリ(RHEL で実行している場合など)の場合、libldap
へのアクセスは同期され、パフォーマンスおよびレイテンシのコストが発生します。
libldap_r
にリンクされた MongoDB 4.2 Enterprise バイナリの場合、前の MongoDB バージョンから動作に変更はありません。
Considerations
警告
MongoDB Enterprise for Windows はsaslauthd
経由のバインディングをサポートしていません。
Linux MongoDB サーバーは、
saslauthd
デーモンを介した LDAP サーバーへのバインディングをサポートしています。クライアントとサーバー間、および
saslauthd
と LDAP サーバー間で安全な暗号化または信頼できる接続を使用します。 LDAP サーバーはSASL PLAIN
メカニズムを使用して、プレーンテキストでデータを送受信します。 VPN などの信頼できるチャネル、TLS/SSL で暗号化された接続、または信頼できるワイヤネットワークのみを使用する必要があります。
構成する saslauthd
LDAP support for user authentication requires proper configuration of
the saslauthd
daemon process as well as the MongoDB server.
Specify the mechanism.
On systems that configure saslauthd
with the
/etc/sysconfig/saslauthd
file, such as Red Hat Enterprise Linux,
Fedora, CentOS, and Amazon Linux AMI, set the mechanism MECH
to
ldap
:
MECH=ldap
On systems that configure saslauthd
with the
/etc/default/saslauthd
file, such as Ubuntu, set the MECHANISMS
option to ldap
:
MECHANISMS="ldap"
Adjust caching behavior.
On certain Linux distributions, saslauthd
starts with the caching
of authentication credentials enabled. Until restarted or until the
cache expires, saslauthd
will not contact the LDAP server to
re-authenticate users in its authentication cache. This allows
saslauthd
to successfully authenticate users in its cache, even in
the LDAP server is down or if the cached users' credentials are revoked.
To set the expiration time (in seconds) for the authentication cache, see
the -t option of
saslauthd
.
Configure LDAP Options with ActiveDirectory.
If the saslauthd.conf
file does not exist, create it.
The saslauthd.conf
file usually resides in the /etc
folder. If specifying a different file path, see the
-O option of
saslauthd
.
To use with ActiveDirectory, start saslauthd
with the following
configuration options set in the saslauthd.conf
file:
ldap_servers: <ldap uri> ldap_use_sasl: yes ldap_mech: DIGEST-MD5 ldap_auth_method: fastbind
For the <ldap uri>
, specify the uri of the ldap server. For
example, ldap_servers: ldaps://ad.example.net
.
For more information on saslauthd
configuration, see
http://www.openldap.org/doc/admin24/guide.html#Configuringsaslauthd.
Test the saslauthd
configuration.
使用 testsaslauthd
utility to test the saslauthd
configuration. For example:
testsaslauthd -u testuser -p testpassword -f /var/run/saslauthd/mux
0: OK "Success"
indicates successful authentication.0: NO "authentication failed"
indicates a username, password, or configuration error.
Modify the file path with respect to the location of the
saslauthd
directory on the host operating system.
重要
security.sasl.saslauthdSocketPath
または
--setParameter saslauthdPath
に指定されたsaslauthd
Unix ドメイン ソケット ファイルの親ディレクトリには、次のいずれかの読み取りおよび実行(
r-x
)権限が付与されている必要があります。
mongod
またはmongos
は、 saslauthd
ディレクトリとその内容に対する指定された権限がなければ、 saslauthd
経由で正常に認証できません。
Configure MongoDB
Add user to MongoDB for authentication.
Add the user to the $external
database in MongoDB. To specify the
user's privileges, assign roles to the
user.
$external
認証ユーザー(Kerberos、LDAP、または X.509 ユーザー)でクライアント セッションと因果整合性の保証を使用するには、ユーザー名を 10k バイトより大きくすることはできません。
For example, the following adds a user with read-only access to
the records
database.
db.getSiblingDB("$external").createUser( { user : <username>, roles: [ { role: "read", db: "records" } ] } )
Add additional principals as needed. For more information about creating and managing users, see ユーザー管理コマンド.
Configure MongoDB server.
To configure the MongoDB server to use the saslauthd
instance for
proxy authentication, include the following options when starting mongod
:
--auth
command line option orsecurity.authorization
setting,authenticationMechanisms
parameter set toPLAIN
, andsaslauthdPath
parameter set to the path to the Unix-domain Socket of thesaslauthd
instance.重要
security.sasl.saslauthdSocketPath
または
--setParameter saslauthdPath
に指定されたsaslauthd
Unix ドメイン ソケット ファイルの親ディレクトリには、次のいずれかの読み取りおよび実行(
r-x
)権限が付与されている必要があります。mongod
またはmongos
は、saslauthd
ディレクトリとその内容に対する指定された権限がなければ、saslauthd
経由で正常に認証できません。
If you use the authorization
option to enforce
authentication, you will need privileges to create a user.
Use specific saslauthd
socket path.
For socket path of /<some>/<path>/saslauthd
, set the
saslauthdPath
to /<some>/<path>/saslauthd/mux
,
as in the following command line example:
mongod --auth --setParameter saslauthdPath=/<some>/<path>/saslauthd/mux --setParameter authenticationMechanisms=PLAIN
構成に必要な追加オプションを含めます。 たとえば、リモート クライアントを配置に接続する場合、または配置ノードを異なるホスト上で実行する場合は、 --bind_ip
を指定します。
Or if using a YAML format configuration file, specify the following settings in the file:
security: authorization: enabled setParameter: saslauthdPath: /<some>/<path>/saslauthd/mux authenticationMechanisms: PLAIN
Or, if using the older configuration file format:
auth=true setParameter=saslauthdPath=/<some>/<path>/saslauthd/mux setParameter=authenticationMechanisms=PLAIN
Use default Unix-domain socket path.
To use the default Unix-domain socket path, set the
saslauthdPath
to the empty string ""
, as in the
following command line example:
mongod --auth --setParameter saslauthdPath="" --setParameter authenticationMechanisms=PLAIN
構成に必要な追加オプションを含めます。 たとえば、リモート クライアントを配置に接続する場合、または配置ノードを異なるホスト上で実行する場合は、 --bind_ip
を指定します。
Or if using a YAML format configuration file, specify the following settings in the file:
security: authorization: enabled setParameter: saslauthdPath: "" authenticationMechanisms: PLAIN
Or, if using the older configuration file format:
auth=true setParameter=saslauthdPath="" setParameter=authenticationMechanisms=PLAIN
構成に必要な追加オプションを含めます。 たとえば、リモート クライアントを使用して配置に接続する場合や、配置ノードを異なるホスト上で実行する場合は、 net.bindIp
設定を指定します。
Authenticate the user in mongosh
.
You can authenticate from the command line during connection, or
connect first and then authenticate using db.auth()
method.
To authenticate when connecting with
mongosh
, run mongosh
with the following
command-line options, substituting <host>
and
<user>
, and enter your password when prompted:
mongosh --host <host> --authenticationMechanism PLAIN --authenticationDatabase '$external' -u <user> -p
Alternatively, connect without supplying credentials and then call
the db.auth()
method on the $external
database. Specify
the value "PLAIN"
in the mechanism
field, the user and
password in the user
and pwd
fields respectively. Use the default
digestPassword
value (false
) since the server must receive an
undigested password to forward on to saslauthd
, as in the
following example:
Tip
passwordPrompt()
メソッドを様々なユーザー認証管理メソッドやコマンドと組み合わせて使用すると、メソッドやコマンドの呼び出しでパスワードを直接指定する代わりに、パスワードの入力を求めるプロンプトが表示されます。ただし、以前のバージョンの mongo
シェルと同様に、パスワードを直接指定することもできます。
db.getSiblingDB("$external").auth( { mechanism: "PLAIN", user: <username>, pwd: passwordPrompt() // or cleartext password } )
パスワードの入力を求められたら、入力します。
The server forwards the password in plain text. In general, use only on a trusted channel (VPN, TLS/SSL, trusted wired network). See Considerations.