MongoDB Enterprise supports proxying authentication requests to a Lightweight Directory Access Protocol (LDAP) service.支持将身份验证请求代理到轻量级目录访问协议(LDAP)服务。
MongoDB supports simple and SASL binding to LDAP servers:MongoDB支持简单和SASL绑定到LDAP服务器:
| Via | |
|---|---|
| |
saslauthd |
|
Considerations注意事项
A full description of LDAP is beyond the scope of this documentation. This page assumes prior knowledge of LDAP.LDAP的完整描述超出了本文档的范围。本页假定您对LDAP有先验知识。
This documentation only describes MongoDB LDAP authentication, and does not replace other resources on LDAP. We encourage you to thoroughly familiarize yourself with LDAP and its related subject matter before configuring LDAP authentication.本文档仅描述MongoDB LDAP身份验证,并不取代LDAP上的其他资源。我们建议您在配置LDAP身份验证之前彻底熟悉LDAP及其相关主题。
MongoDB can provide professional services for optimal configuration of LDAP authentication for your MongoDB deployment.MongoDB可以为MongoDB部署提供最佳配置LDAP身份验证的专业服务。
Connection Pool连接池
When connecting to the LDAP server for authentication/authorization, MongoDB, by default:当连接到LDAP服务器进行身份验证/授权时,默认情况下为MongoDB:
Uses connection pooling if run:如果运行,则使用连接池:on Windows or在Windows或on Linux where MongoDB Enterprise binaries are linked against libldap_r.在Linux上,MongoDB Enterprise二进制文件与libldap_r链接。
Does not use connection pooling if run:如果运行以下命令,则不使用连接池:
To change the connection pooling behavior, update the 要更改连接池行为,请更新ldapUseConnectionPool parameter.ldapUseConnectionPool参数。
saslauthd and Directory Permissions和目录权限
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成功进行身份验证。
libldap and 和libldap_r
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版本相比,行为没有变化。
Managing LDAP Users on the MongoDB server管理MongoDB服务器上的LDAP用户
When using LDAP authentication without LDAP authorization, user management requires managing users both on the LDAP server and the MongoDB server. 当在没有LDAP授权的情况下使用LDAP身份验证时,用户管理需要管理LDAP服务器和MongoDB服务器上的用户。For each user authenticating via LDAP, MongoDB requires a user on the 对于通过LDAP进行身份验证的每个用户,MongoDB需要$external database whose name exactly matches the authentication username. $external数据库上的一个用户,其名称与身份验证用户名完全匹配。Changes to a user on the LDAP server may require changes to the corresponding MongoDB 更改LDAP服务器上的用户可能需要更改相应的MongoDB$external 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字节。
Example示例
A user authenticates as 用户身份验证为sam@dba.example.com. The MongoDB server binds to the LDAP server and authenticates the user, respecting any username transformations. sam@dba.example.com。MongoDB服务器绑定到LDAP服务器并对用户进行身份验证,尊重任何用户名转换。On successful authentication, the MongoDB server then checks the 成功通过身份验证后,MongoDB服务器会检查$external database for a user sam@dba.example.com and grants the authenticated user the roles and privileges associated to that user.$external数据库中的用户sam@dba.example.com并向经过身份验证的用户授予与该用户相关联的角色和权限。
To manage users on the MongoDB server, you must authenticate as an LDAP user whose corresponding MongoDB 要管理MongoDB服务器上的用户,您必须作为LDAP用户进行身份验证,其对应的MongoDB$$external user has user administrative privileges on the $external database, such as those provided by userAdmin.$external用户在$external数据库上具有用户管理权限,例如userAdmin提供的权限。
Important
If no 如果没有$external users have user administrative privileges on $external database, you cannot perform user management for LDAP authentication. This scenario may occur if you configure users prior to enabling LDAP authentication, but do not create the appropriate user administrators.$external用户对$external数据库具有用户管理权限,则无法对LDAP身份验证执行用户管理。如果在启用LDAP身份验证之前配置用户,但没有创建适当的用户管理员,则可能会出现这种情况。
Managing existing non-LDAP users管理现有的非LDAP用户
If there are existing users not on the 如果$external database, you must meet the following requirements for each user to ensure continued access:$external数据库上没有现有用户,则必须满足每个用户的以下要求,以确保持续访问:
User has a corresponding user object on the LDAP server用户在LDAP服务器上有一个相应的用户对象User exists on the用户在$externaldatabase with equivalent roles and privileges$external数据库上具有相同的角色和权限
If you want to continue allowing access by users not on the $external database, you must configure setParameter authenticationMechanisms to include SCRAM-SHA-1 and/or SCRAM-SHA-256 as appropriate. Users must then specify --authenticationMechanism SCRAM-SHA-1 or SCRAM-SHA-256 when authenticating.
Deploying LDAP authentication on a replica set在副本集上部署LDAP身份验证
For replica sets, configure LDAP authentication on secondary and arbiter members first before configuring the primary. This also applies to shard replica sets, or config server replica sets. Configure one replica set member at a time to maintain a majority of members for write availability.
Deploying LDAP authentication on a sharded cluster在分片集群上部署LDAP身份验证
In sharded clusters, you must configure LDAP authentication on the config servers and each 在分片集群中,您必须在配置服务器和集群级用户的每个mongos for cluster-level users. mongos上配置LDAP身份验证。You can optionally configure LDAP authorization on each shard for shard-local users.您可以选择在每个分片上为分片本地用户配置LDAP授权。
LDAP Authentication via the Operating System LDAP libraries通过操作系统LDAP库进行LDAP身份验证
The LDAP authentication via OS libraries process is summarized below:通过操作系统库进行LDAP身份验证的过程总结如下:
A client authenticates to MongoDB, providing a user's credentials.客户端向MongoDB进行身份验证,提供用户的凭据。If the username requires mapping to an LDAP DN prior to binding against the LDAP server, MongoDB can apply transformations based on the configured如果用户名在绑定到LDAP服务器之前需要映射到LDAP DN,MongoDB可以根据配置的security.ldap.userToDNMappingsetting.security.ldap.userToDNMapping设置应用转换。MongoDB binds to an LDAP server specified inMongoDB使用提供的用户名绑定到security.ldap.serversusing the provided username or, if a transformation was applied, the transformed username.security.ldap.servers中指定的LDAP服务器,或者如果应用了转换,则使用转换后的用户名。MongoDB uses simple binding by default, but can also use默认情况下,MongoDB使用简单绑定,但如果在saslbinding if configured insecurity.ldap.bind.methodandsecurity.ldap.bind.saslMechanisms.security.ldap.bind.method和security.ldap.bind.saslMechanisms中配置,也可以使用sasl绑定。If a transformation requires querying the LDAP server, or if the LDAP server disallows anonymous binds, MongoDB uses the username and password specified to如果转换需要查询LDAP服务器,或者如果LDAP服务器不允许匿名绑定,MongoDB将使用为security.ldap.bind.queryUserandsecurity.ldap.bind.queryPasswordto bind to the LDAP server before attempting to authenticate the provided user credentials.security.ldap.bind.queryUser和security.ldap.bind.queryPassword指定的用户名和密码绑定到LDAP服务器,然后再尝试验证提供的用户凭据。The LDAP server returns the result of the bind attempt to MongoDB. On success, MongoDB attempts to authorize the user.LDAP服务器将绑定尝试的结果返回给MongoDB。成功后,MongoDB会尝试授权用户。The MongoDB server attempts to map the username to a user on theMongoDB服务器尝试将用户名映射到$externaldatabase, assigning the user any roles or privileges associated to a matching user. If MongoDB cannot find a matching user, authentication fails.$external数据库上的用户,为该用户分配与匹配用户相关的任何角色或权限。如果MongoDB找不到匹配的用户,则身份验证失败。The client can perform those actions for which MongoDB granted the authenticated user roles or privileges.客户端可以执行MongoDB授予经过身份验证的用户角色或权限的操作。
To use LDAP for authentication via operating system libraries, specify the following settings as a part of your 要通过操作系统库使用LDAP进行身份验证,请在mongod or mongos configuration file:mongod或mongos配置文件中指定以下设置:
| Required | ||
|---|---|---|
security.ldap.servers |
If your connection string specifies If your connection string specifies | YES |
security.ldap.bind.method | Used to specify the method the Defaults to | NO, unless using sasl for binding to the LDAP server. |
security.ldap.bind.saslMechanisms | Used to specify the SASL mechanisms Defaults to | NO, unless setting method to sasl and you need different or additional SASL mechanisms. |
security.ldap.bind.queryUser | The LDAP entity, identified by its distinguished name (DN) or SASL name, with which the MongoDB server authenticates, or binds, when connecting to an LDAP server. Use with The user specified must have the appropriate privileges to execute queries on the LDAP server. | NO, unless specifying a query as part of a userToDNMapping transformation, or if the LDAP server's security settings disallow anonymous binds. |
security.ldap.bind.queryPassword | The password used to authenticate to an LDAP server when using queryUser. | NO, unless specifying queryUser. |
security.ldap.bind.useOSDefaults | Windows MongoDB deployments can use the operating system credentials in place of queryUser and queryPassword for authenticating or binding as when connecting to the LDAP server. | NO, unless replacing queryUser and queryPassword. |
security.ldap.userToDNMapping | Clients may authenticate using a username whose format is incompatible with the format expected by the configured
If you specify a | NO, unless client authenticate using usernames that require transformation. |
LDAP Authentication via saslauthd
Warning
MongoDB Enterprise for Windows does not support binding via MongoDB Enterprise for Windows不支持通过saslauthd.saslauthd进行绑定。
Considerations注意事项
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加密的连接或受信任的有线网络。
Configuration配置
To configure the MongoDB server to bind to the LDAP server using via 要使用saslauthd, start the mongod using either the following command line options or the following configuration file settings:saslauthd将MongoDB服务器配置为绑定到LDAP服务器,请使用以下命令行选项或以下配置文件设置启动mongod:
Command Line Options命令行选项
--authto enable access control,为了实现访问控制,--setParameterwith the且authenticationMechanismsset toPLAIN, andauthenticationMechanisms设置为PLAIN,以及--setParameterwith the将saslauthdPathparameter set to the path to the Unix-domain Socket of thesaslauthdinstance.saslauthdPath参数设置为saslauthd实例的Unix域Socket的路径。Specify an empty string指定一个空字符串""to use the default Unix-domain socket path.""以使用默认的Unix域套接字路径。
Include any other command line options required for your deployment. 包括部署所需的任何其他命令行选项。For complete documentation on 有关mongod command line options, see mongod.mongod命令行选项的完整文档,请参阅mongod。
Configuration File Settings配置文件设置
security.authorizationset to设置为enabled,enabled,setParameterwith theauthenticationMechanismsparameter set toPLAIN, andsetParameterwith thesaslauthdPathset to the path to the Unix-domain Socket of the saslauthd instance. Specify an empty string""to use the default Unix-domain socket path.
Include any other configuration file settings required for your deployment. 包括部署所需的任何其他配置文件设置。For complete documentation on configuration files, see YAML configuration file.有关配置文件的完整文档,请参阅YAML配置文件。
You need to create or update the 您需要使用适用于LDAP服务器的参数创建或更新saslauthd.conf file with the parameters appropriate for your LDAP server. Documenting saslauthd.conf is out of scope for this documentation.saslauthd.conf文件。记录saslauthd.conf超出了本文档的范围。
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 如果没有对saslaund目录及其内容的指定权限,mongod or mongos cannot successfully authenticate via saslauthd without the specified permission on the saslauthd directory and its contents.mongod或mongos无法通过saslauthd成功进行身份验证。
The following tutorials provide basic information on configuring 以下教程提供了有关配置saslauthd.conf to work with two popular LDAP services:saslauthd.conf以使用两种流行LDAP服务的基本信息:
Authenticate Using Self-Managed SASL and LDAP with OpenLDAP通过OpenLDAP使用自管理SASL和LDAP进行身份验证Authenticate Using Self-Managed SASL and LDAP with ActiveDirectory通过活动目录使用自管理SASL和LDAP进行身份验证
Please see the documentation for 请参阅saslauthd as well as your specific LDAP service for guidance.saslauthd的文档以及特定LDAP服务以获取指导。
Connect to a MongoDB server via LDAP authentication通过LDAP身份验证连接到MongoDB服务器
To authenticate to a MongoDB server via LDAP authentication, use 要通过LDAP身份验证向MongoDB服务器进行身份验证,请在db.auth() on the $external database with the following parameters:$external数据库上使用db.auth(),并使用以下参数:
username | |
password | |
mechanism | PLAIN.PLAIN。 |