Note
Starting in MongoDB 8.0, LDAP authentication and authorization is deprecated. LDAP is available and will continue to operate without changes throughout the lifetime of MongoDB 8. LDAP will be removed in a future major release.从MongoDB 8.0开始,LDAP身份验证和授权被弃用。LDAP是可用的,并将在MongoDB 8的整个生命周期内继续运行而不做任何更改。LDAP将在未来的主要版本中删除。
For details, see LDAP Deprecation.有关详细信息,请参阅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.MongoDB Enterprise支持用户的代理身份验证。这允许管理员配置MongoDB集群,通过将身份验证请求代理到指定的轻量级目录访问协议(LDAP)服务来对用户进行身份验证。
Note
For MongoDB 4.2 Enterprise binaries linked against 对于与libldap (such as when running on RHEL), access to the libldap is synchronized, incurring some performance/latency costs.libldap链接的MongoDB 4.2 Enterprise二进制文件(例如在RHEL上运行时),对libldap的访问是同步的,这会产生一些性能/延迟成本。
For MongoDB 4.2 Enterprise binaries linked against 对于与libldap_r, there is no change in behavior from earlier MongoDB versions.libldap_r链接的MongoDB 4.2 Enterprise二进制文件,与早期MongoDB版本相比,行为没有变化。
Considerations注意事项
Warning
MongoDB Enterprise for Windows does not support binding via MongoDB Enterprise for Windows不支持通过saslauthd.saslauthd进行绑定。
Linux MongoDB servers support binding to an LDAP server via theLinux MongoDB服务器支持通过saslauthddaemon.saslauthd守护进程绑定到LDAP服务器。Use secure encrypted or trusted connections between clients and the server, as well as between在客户端和服务器之间以及saslauthdand the LDAP server.saslauthd和LDAP服务器之间使用安全的加密或可信连接。The LDAP server uses theLDAP服务器使用SASL PLAINmechanism, sending and receiving data in plain text. You should use only a trusted channel such as a VPN, a connection encrypted with TLS/SSL, or a trusted wired network.SASL PLAIN机制,以纯文本形式发送和接收数据。您应该只使用受信任的通道,如VPN、用TLS/SSL加密的连接或受信任的有线网络。
Configure 配置saslauthd
LDAP support for user authentication requires proper configuration of the LDAP对用户身份验证的支持需要正确配置saslauthd daemon process as well as the MongoDB server.saslauthd守护进程以及MongoDB服务器。
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:/etc/sysconfig/saslauthd文件配置saslauthd的系统上,如Red Hat Enterprise Linux、Fedora、CentOS和Amazon Linux AMI,将机制MECH设置为ldap:
MECH=ldap
On systems that configure 在使用saslauthd with the /etc/default/saslauthd file, such as Ubuntu, set the MECHANISMS option to ldap:/etc/default/saslauthd文件配置saslauthd的系统上,如Ubuntu,将MECHANISMS选项设置为ldap:
MECHANISMS="ldap"Adjust caching behavior.调整缓存行为。
On certain Linux distributions, 在某些Linux发行版上,saslaund从启用身份验证凭据缓存开始。在重新启动或缓存过期之前,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. saslauthd不会联系LDAP服务器以在其身份验证缓存中重新对用户进行身份验证。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.saslauthd在其缓存中成功验证用户,即使在LDAP服务器关闭或缓存的用户凭据被撤销的情况下也是如此。
To set the expiration time (in seconds) for the authentication cache, see the -t option of 要设置身份验证缓存的过期时间(以秒为单位),请参阅saslauthd.saslauthd的-t选项。
Configure LDAP Options with ActiveDirectory.使用活动目录配置LDAP选项。
If the 如果saslauthd.conf file does not exist, create it. saslauthd.conf文件不存在,请创建它。The saslauthd.conf file usually resides in the /etc folder. saslauthd.conf文件通常位于/etc文件夹中。If specifying a different file path, see the -O option of 如果指定不同的文件路径,请参阅saslauthd.saslauthd的-O选项。
To use with ActiveDirectory, start 要与活动目录一起使用,请使用saslauthd with the following configuration options set in the saslauthd.conf file:saslauthd.conf文件中设置的以下配置选项启动saslauthd:
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.<ldap uri>,指定ldap服务器的uri。例如,ldap_servers: ldaps://ad.example.net。
For more information on 有关saslauthd configuration, see http://www.openldap.org/doc/admin24/guide.html#Configuringsaslauthd.saslauthd配置的更多信息,请参阅http://www.openldap.org/doc/admin24/guide.html#Configuringsaslauthd。
Test the saslauthd configuration.测试saslauthd配置。
saslauthd configuration.Use 使用testsaslauthd utility to test the saslauthd configuration. For example:testsaslauthd实用程序测试saslauthd配置。例如:
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.saslauthd目录位置的文件路径。
Important
The parent directory of the 指定给saslauthd Unix domain socket file specified to security.sasl.saslauthdSocketPath or --setParameter saslauthdPath must grant read and execute (r-x) permissions for either:security.sasl.saslauthdSocketPath或--setParameter saslauthdPath的saslauthd Unix域套接字文件的父目录必须为以下任一项授予读取和执行(r-x)权限:
The user starting the启动mongodormongos, ormongod或mongos的用户,或A group to which that user belongs.该用户所属的组。
The 如果没有对mongod or mongos cannot successfully authenticate via saslauthd without the specified permission on the saslauthd directory and its contents.saslauthd目录及其内容的指定权限,mongod或mongos无法通过saslauthd成功进行身份验证。
Configure MongoDB配置MongoDB
Add user to MongoDB for authentication.将用户添加到MongoDB进行身份验证。
Add the user to the 将用户添加到MongoDB中的$external database in MongoDB. To specify the user's privileges, assign roles to the user.$external数据库。要指定用户的权限,请为用户分配角色。
To use Client Sessions and Causal Consistency Guarantees with 要对$external authentication users (Kerberos, LDAP, or X.509 users), usernames cannot be greater than 10k bytes.$external身份验证用户(Kerberos、LDAP或X.509用户)使用客户端会话和因果一致性保证,用户名不能大于10k字节。
For example, the following adds a user with read-only access to the 例如,下面添加了一个对records database.records数据库具有只读访问权限的用户。
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 User Management Commands.根据需要添加其他主体。有关创建和管理用户的详细信息,请参阅用户管理命令。
Configure MongoDB server.配置MongoDB服务器。
To configure the MongoDB server to use the 要将MongoDB服务器配置为使用saslauthd instance for proxy authentication, include the following options when starting mongod:saslauthd实例进行代理身份验证,请在启动mongod时包含以下选项:
--authcommand line option or命令行选项或security.authorizationsetting,设置,authenticationMechanismsparameter set to参数设置为PLAIN, andPLAIN,以及saslauthdPathparameter set to the path to the Unix-domain Socket of the参数设置为saslauthdinstance.saslauthd实例的Unix域Socket的路径。Important
The parent directory of the指定给saslauthdUnix domain socket file specified tosecurity.sasl.saslauthdSocketPathor--setParameter saslauthdPathmust grant read and execute (r-x) permissions for either:security.sasl.saslauthdSocketPath或--setParameter saslauthdPath的saslauthdUnix域套接字文件的父目录必须为以下任一项授予读取和执行(r-x)权限:The user starting the启动mongodormongos, ormongod或mongos的用户,或A group to which that user belongs.该用户所属的组。
The如果没有对mongodormongoscannot successfully authenticate viasaslauthdwithout the specified permission on thesaslauthddirectory and its contents.saslauthd目录及其内容的指定权限,mongod或mongos无法通过saslauthd成功进行身份验证。
If you use the 如果使用authorization option to enforce authentication, you will need privileges to create a user.authorization(授权)选项强制身份验证,则需要权限来创建用户。
Use specific saslauthd socket path.使用特定的saslauthd套接字路径。
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:/<some>/<path>/saslauthd的套接字路径,将saslauthdPath设置为/<some>/<path>/saslauthd/mux,如下命令行示例所示:
mongod --auth --setParameter saslauthdPath=/<some>/<path>/saslauthd/mux --setParameter authenticationMechanisms=PLAIN
Include additional options as required for your configuration. For instance, if you wish remote clients to connect to your deployment or your deployment members are run on different hosts, specify the 根据配置要求,包括其他选项。例如,如果您希望远程客户端连接到部署,或者部署成员在不同的主机上运行,请指定--bind_ip.--bind_ip。
Or if using a YAML format configuration file, specify the following settings in the file:或者,如果使用YAML格式配置文件,请在文件中指定以下设置:
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.使用默认的Unix域套接字路径。
To use the default Unix-domain socket path, set the 要使用默认的Unix域套接字路径,请将saslauthdPath to the empty string "", as in the following command line example:saslauthdPath设置为空字符串"",如下命令行示例所示:
mongod --auth --setParameter saslauthdPath="" --setParameter authenticationMechanisms=PLAIN
Include additional options as required for your configuration. For instance, if you wish remote clients to connect to your deployment or your deployment members are run on different hosts, specify the 根据配置要求,包括其他选项。例如,如果您希望远程客户端连接到部署,或者部署成员在不同的主机上运行,请指定--bind_ip.--bind_ip。
Or if using a YAML format configuration file, specify the following settings in the file:或者,如果使用YAML格式配置文件,请在文件中指定以下设置:
security:
authorization: enabled
setParameter:
saslauthdPath: ""
authenticationMechanisms: PLAIN
Or, if using the older configuration file format:或者,如果使用较旧的配置文件格式:
auth=true
setParameter=saslauthdPath=""
setParameter=authenticationMechanisms=PLAIN
Include additional options as required for your configuration. For instance, if you wish remote clients to connect to your deployment or your deployment members are run on different hosts, specify the 根据配置要求,包括其他选项。例如,如果您希望远程客户端连接到部署,或者部署成员在不同的主机上运行,请指定net.bindIp setting.net.bindIp设置。
Authenticate the user in mongosh.用mongosh对用户进行身份验证。
mongosh.You can authenticate from the command line during connection, or connect first and then authenticate using 您可以在连接期间从命令行进行身份验证,也可以先连接,然后使用db.auth() method.db.auth()方法进行身份验证。
Authenticate during Connection连接期间进行身份验证
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连接时进行身份验证,请使用以下命令行选项运行mongosh,替换<host>和<user>,并在提示时输入密码:
mongosh --host <host> --authenticationMechanism PLAIN --authenticationDatabase '$external' -u <user> -pAuthenticate after Connection连接后进行身份验证
Alternatively, connect without supplying credentials and then call the 或者,在不提供凭据的情况下进行连接,然后在db.auth() method on the $external database. $external数据库上调用db.auth()方法。Specify the value 在"PLAIN" in the mechanism field, the user and password in the user and pwd fields respectively. mechanism字段中指定值"PLAIN",在user和pwd字段中分别指定用户和密码。Use the default 使用默认的digestPassword value (false) since the server must receive an undigested password to forward on to saslauthd, as in the following example:digestPassword值(false),因为服务器必须接收未消化的密码才能转发到saslauthd,如下例所示:
Tip
You can use the 您可以将passwordPrompt() method in conjunction with various user authentication management methods and commands to prompt for the password instead of specifying the password directly in the method or command call. passwordPrompt()方法与各种用户身份验证管理方法和命令结合使用,以提示输入密码,而不是直接在方法或命令调用中指定密码。However, you can still specify the password directly as you would with earlier versions of the 但是,您仍然可以像使用早期版本的mongo shell.mongo shell一样直接指定密码。
db.getSiblingDB("$external").auth(
{
mechanism: "PLAIN",
user: <username>,
pwd: passwordPrompt() // or cleartext password
}
)
Enter the password when prompted.出现提示时输入密码。
The server forwards the password in plain text. In general, use only on a trusted channel (VPN, TLS/SSL, trusted wired network). See Considerations.服务器以纯文本形式转发密码。一般来说,仅在受信任的通道(VPN、TLS/SSL、受信任的有线网络)上使用。请参阅注意事项。