On this page本页内容
MongoDB Enterprise supports querying an LDAP server for the LDAP groups to which the authenticated user belongs. 支持在LDAP服务器上查询经过身份验证的用户所属的LDAP组。MongoDB maps the distinguished names (DN) of each returned group to roles on the MongoDB将每个返回组的可分辨名称(DN)映射到admin
database. admin
数据库上的角色。MongoDB authorizes the user based on the mapped roles and their associated privileges. MongoDB根据映射的角色及其相关权限对用户进行授权。See LDAP Authorization for more information.有关更多信息,请参阅LDAP授权。
The LDAP Authorization process is summarized below:LDAP授权过程总结如下:
A client connects to MongoDB and performs authentication with any authentication mechanism that supports external authentication.客户端连接到MongoDB,并使用支持外部身份验证的任何身份验证机制执行身份验证。
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字节。
MongoDB binds to the LDAP server specified with MongoDB使用security.ldap.servers
using the credentials specified with security.ldap.bind.queryUser
and security.ldap.bind.queryPassword
.security.ldap.bind.queryUser
和security.ldap.bind.queryPassword
指定的凭据绑定到security.ldap.servers
指定的LDAP服务器。
MongoDB uses simple binding by default, but can use 默认情况下,MongoDB使用简单绑定,但如果在sasl
binding instead if configured in security.ldap.bind.method
and security.ldap.bind.saslMechanisms
.security.ldap.bind.method
和security.ldap.bind.saslMechanisms
中配置,则可以使用sasl
绑定。
MongoDB constructs an LDAP query using the MongoDB使用security.ldap.authz.queryTemplate
and queries the LDAP server for the authenticated user's group membership.security.ldap.authz.queryTemplate
构造LDAP查询,并向LDAP服务器查询经过身份验证的用户的组成员身份。
MongoDB can use the MongoDB可以使用security.ldap.userToDNMapping
option to transform the username for supporting the query template.security.ldap.userToDNMapping
选项转换用户名以支持查询模板。
admin
database. admin
数据库上的角色,授权用户在服务器上执行操作。admin
database, MongoDB grants the user the roles and privileges assigned to that role. admin
数据库中现有角色的名称完全匹配,MongoDB将向用户授予分配给该角色的角色和权限。ldapUserCacheInvalidationInterval
, MongoDB flushes the $external
cache. ldapUserCacheInvalidationInterval
定义的间隔,MongoDB刷新$external
缓存。A full description of LDAP is beyond the scope of this documentation. LDAP的完整描述超出了本文档的范围。This page assumes prior knowledge of LDAP.本页假定您已了解LDAP。
This documentation only describes MongoDB LDAP authorization, and does not replace other resources on LDAP. 本文档仅描述MongoDB LDAP授权,不替换LDAP上的其他资源。We encourage you to thoroughly familiarize yourself with LDAP and its related subject matter before configuring LDAP authentication.我们鼓励您在配置LDAP身份验证之前彻底熟悉LDAP及其相关主题。
MongoDB can provide professional services for optimal configuration of LDAP authorization for your MongoDB deployment.MongoDB可以为您的MongoDB部署提供优化LDAP授权配置的专业服务。
The following authentication mechanisms are compatible with MongoDB LDAP authorization:以下身份验证机制与MongoDB LDAP授权兼容:
Starting in version 4.2.0, when connecting to the LDAP server for authentication/authorization, MongoDB, by default:从4.2.0版开始,连接LDAP服务器进行身份验证/授权时,默认情况下为MongoDB:
Uses connection pooling if run:在以下情况下使用连接池:
Does not use connection pooling if run:在以下情况下不使用连接池:
To change the connection pooling behavior, update the 要更改连接池行为,请更新ldapUseConnectionPool
parameter.ldapUseConnectionPool
参数。
libldap
and libldap_r
For MongoDB 4.2 (and 4.0.9) 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(和4.0.9)企业二进制文件(例如在RHEL上运行时),对libldap的访问是同步的,会产生一些性能/延迟成本。
For MongoDB 4.2 (and 4.0.9) Enterprise binaries linked against 对于与libldap_r
, there is no change in behavior from earlier MongoDB versions.libldap_r
链接的MongoDB 4.2(和4.0.9)企业二进制文件,其行为与早期的MongoDB版本没有变化。
With LDAP authorization, user creation and management occurs on the LDAP server. 通过LDAP授权,用户创建和管理在LDAP服务器上进行。MongoDB requires creation of roles on the MongoDB要求在admin
database, with the name of each role exactly matching a LDAP group Distinguished Name (DN). admin
数据库上创建角色,每个角色的名称与LDAP组可分辨名称(DN)完全匹配。This is in contrast to MongoDB managed authorization, which requires creating users on the 这与MongoDB托管授权不同,后者需要在$external
database.$external
数据库上创建用户。
To manage roles on the MongoDB server, authenticate as a user whose group membership corresponds to a 要管理MongoDB服务器上的角色,请以用户身份进行身份验证,该用户的组成员资格对应于具有角色管理权限(如admin
database role with role administration privileges, such as those provided by userAdmin
. userAdmin
提供的权限)的admin
数据库角色。Create or update roles corresponding to LDAP group DNs such that users with membership in that group receive the appropriate roles and privileges.创建或更新与LDAP组DNs对应的角色,以使该组中的成员资格用户获得适当的角色和权限。
For example, an LDAP group for database administrators might have a role with administrative roles and privileges. 例如,数据库管理员的LDAP组可能具有具有管理角色和权限的角色。An LDAP group for marketing or analytics users may have a role with only have read privileges on certain databases.市场营销或分析用户的LDAP组可能具有仅对某些数据库具有读取权限的角色。
When configuring a role for a corresponding LDAP Group, remember that all users with membership in that group can receive the configured roles and privileges. 为相应的LDAP组配置角色时,请记住,在该组中具有成员资格的所有用户可以接收配置的角色和权限。Consider applying the principle of least privilege when configuring MongoDB roles, LDAP groups, or group membership.在配置MongoDB角色、LDAP组或组成员身份时,请考虑应用最小权限原则。
If no role with role administration privileges exists AND no non-如果不存在具有角色管理权限的角色,并且不存在具有这些权限的非$external
user with these privileges exists, you effectively cannot perform user management, as no new or existing roles can be altered to reflect additions or changes to groups or group membership on the LDAP server.$external
用户,则实际上无法执行用户管理,因为不能更改任何新的或现有的角色,以反映对LDAP服务器上的组或组成员身份的添加或更改。
To remedy a scenario where you cannot manage roles on the MongoDB server, perform the following procedure:要纠正无法管理MongoDB服务器上角色的情况,请执行以下过程:
admin
database whose name corresponds to the appropriate LDAP group Distinguished Name. admin
数据库上创建一个角色,其名称对应于相应的LDAP组可分辨名称。A MongoDB server using LDAP for authorization makes any existing users on the 使用LDAP进行授权的MongoDB服务器使$external
database inaccessible. $external
数据库上的任何现有用户都无法访问。If there are existing users in 如果$external
database, you must meet the following requirements for each user on the $external
database to ensure continued access:$external
database中有现有用户,则必须满足$external
database中每个用户的以下要求,以确保继续访问:
admin
database named for the user's LDAP groups, such that the granted roles and privileges are identical to those granted to the non-$external
user.admin
数据库上有角色,因此授予的角色和权限与授予非$external
用户的角色和权限相同。If you want to continue allowing access by users not on the 如果要继续允许不在$external
database, ensure the authenticationMechanisms
parameter includes SCRAM-SHA-1
and/or SCRAM-SHA-256
as appropriate. $external
数据库上的用户访问,请确保authenticationMechanisms
参数包括SCRAM-SHA-1
和/或SCRAM-HA-256
(视情况而定)。Alternatively, apply the requirements listed above for transitioning those users to LDAP authorization.或者,应用上面列出的要求将这些用户转换为LDAP授权。
For replica sets, configure LDAP authorization on the secondary and arbiter members first before configuring the primary. 对于副本集,在配置主成员之前,首先在辅助成员和仲裁器成员上配置LDAP授权。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.一次配置一个副本集成员,以保持大多数成员的写可用性。
In sharded clusters, you must configure LDAP authorization on the config servers for cluster-level users. 在分片集群中,必须在配置服务器上为集群级用户配置LDAP授权。You can optionally configure LDAP authorization on each shard for shard-local users.您可以选择在每个分片上为分片本地用户配置LDAP授权。
You must configure the following settings to use LDAP Authorization:必须配置以下设置才能使用LDAP授权:
To use LDAP for authorization 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 | host[:port] format.host[:port] 格式附上逗号分隔的LDAP服务器列表。
| YES |
security.ldap.authz.queryTemplate |
| YES |
security.ldap.bind.queryUser |
| YES |
security.ldap.bind.queryPassword | queryUser .queryUser 时用于绑定到LDAP服务器的密码。
| YES |
security.ldap.bind.method |
Defaults to | sasl for binding to the LDAP server.sasl 绑定到LDAP服务器。 |
security.ldap.bind.saslMechanisms |
| method to sasl , and you need different or additional SASL mechanisms.method 设置为sasl ,并且您需要不同的或附加的sasl机制。
|
security.ldap.bind.useOSDefaults | queryUser and queryPassword for authenticating or binding as when connecting to the LDAP server.queryUser 和queryPassword 进行身份验证或绑定,就像连接到LDAP服务器一样。
| queryUser and queryPassword .queryUser 和queryPassword 。 |
security.ldap.userToDNMapping | queryTemplate , the authenticated client username may require transformation to support the LDAP query URL. queryTemplate ,经过身份验证的客户端用户名可能需要转换以支持LDAP查询URL。userToDNMapping |
MongoDB uses the MongoDB使用security.ldap.authz.queryTemplate
to create an RFC4516 formatted LDAP query URL. security.ldap.authz.queryTemplate
创建RFC4516格式的LDAP查询URL。In the template, you can use either:
{USER}
userToDNMapping
, MongoDB replaces the {USER}
token with the transformed username when constructing the LDAP query URL.userToDNMapping
转换用户名,则在构造LDAP查询URL时,MongoDB会用转换后的用户名替换{USER}
标记。{PROVIDED_USER}
Design the query template to retrieve the user's groups.设计查询模板以检索用户的组。
The following query template returns any groups listed in the LDAP user object's 以下查询模板返回LDAP用户对象的memberOf
attribute. memberOf
属性中列出的任何组。This query assumes the 此查询假设memberOf
attribute exists - your specific LDAP deployment may use a different attribute or methodology for tracking group membership. memberOf
属性存在——您的特定LDAP部署可能会使用不同的属性或方法来跟踪组成员身份。This query also assumes the user authenticates using their full LDAP DN as their username.此查询还假设用户使用完整的LDAP DN作为用户名进行身份验证。
"{USER}?memberOf?base"
The LDAP query URL must conform to the format defined in RFC4516:LDAP查询URL必须符合RFC4516中定义的格式:
[ dn [ ? [attributes] [ ? [scope] [ ? [filter] [ ? [Extensions] ] ] ] ] ]
Consider the definition of each component, as quoted from RFC4516:考虑RFC4516中引用的每个组件的定义:
Thedn
is an LDAP Distinguished Name using the string format described in RFC4514.dn
是使用RFC4514中描述的字符串格式的LDAP可分辨名称。It identifies the base object of the LDAP search or the target of a non-search operation.它标识LDAP搜索的基本对象或非搜索操作的目标。
Theattributes
construct is used to indicate which attributes should be returned from the entry or entries.attributes
构造用于指示应该从一个或多个条目返回哪些属性。
Thescope
construct is used to specify the scope of the search to perform in the given LDAP server.scope
构造用于指定要在给定LDAP服务器中执行的搜索范围。The allowable scopes are "base" for a base object search, "one" for a one-level search, or "sub" for a subtree search.允许的范围是基本对象搜索的“基本”,一级搜索的“一”,或子树搜索的“子”。
Thefilter
is used to specify the search filter to apply to entries within the specified scope during the search.filter
用于指定搜索期间应用于指定范围内的条目的搜索筛选器。It has the format specified in [RFC4515].它具有[RFC4515]中指定的格式。
Theextensions
construct provides the LDAP URL with an extensibility mechanism, allowing the capabilities of the URL to be extended in the future.extensions
构造为LDAP URL提供了可扩展性机制,允许将来扩展URL的功能。
If the query includes an 如果查询包含一个attribute
, MongoDB assumes the query retrieves a the DNs which this entity is member of.attribute
,MongoDB将假定查询检索该实体所属的DNs。
If the query does not include an attribute, MongoDB assumes the query retrieves all entities for which the user is member of.如果查询不包含属性,MongoDB将假定查询检索用户所属的所有实体。
MongoDB currently ignores any extensions specified in the LDAP query.MongoDB目前会忽略LDAP查询中指定的任何扩展。
A full description of RFC4516 or LDAP query URL construction is out of scope for this documentation.RFC4516或LDAP查询URL构造的完整描述不在本文档范围内。
The following tutorials contain procedures for connecting to an LDAP server via the Operating System LDAP libraries:以下教程包含通过操作系统LDAP库连接到LDAP服务器的过程:
When using LDAP for authorization, users connecting via 使用LDAP进行授权时,通过mongosh
must:mongosh
连接的用户必须:
--authenticationDatabase
to $external
.--authenticationDatabase
设置为$external
。set 将--authenticationMechanism
to the appropriate authentication mechanism.--authenticationMechanism
设置为适当的身份验证机制。
If using LDAP authentication, set this to 如果使用LDAP身份验证,请将其设置为PLAIN
.PLAIN
。
If using Kerberos authentication, set this to 如果使用Kerberos身份验证,请将其设置为GSSAPI
.GSSAPI
。
If using x.509, set this to 如果使用x.509,则将其设置为MONGODB-X.509
.MONGODB-x.508
。
--username
to a username that respects the security.ldap.authz.queryTemplate
, or any configured security.ldap.userToDNMapping
template.--username
设置为符合security.ldap.authz.queryTemplate
或任何配置的security.ldap.userToDNMapping
模板的用户名。--password
to the appropriate password.--password
设置为适当的密码。Include the 包括MongoDB服务器的--host
and --port
of the MongoDB server, along with any other options relevant to your deployment.--host
和--port
,以及与部署相关的任何其他选项。
For example, the following operation authenticates to a MongoDB server running with LDAP authentication and authorization:例如,以下操作对运行LDAP身份验证和授权的MongoDB服务器进行身份验证:
mongosh --username alice@dba.example.com --password --authenticationDatabase '$external' --authenticationMechanism "PLAIN" --host "mongodb.example.com" --port 27017
If you do not specify the password to the 如果没有为-password
command-line option, mongosh
prompts for the password.-password
命令行选项指定密码,mongosh
会提示输入密码。
The $external
argument must be placed in single quotes, not double quotes, to prevent the shell from interpreting $external
as a variable.$external
参数必须放在单引号中,而不是双引号中,以防止shell将$external
解释为变量。
MongoDB maps each returned group distinguished name (DN) returned by the LDAP MongoDB将LDAP查询返回的每个返回的组可分辨名称(DN)映射到query
to a role on the admin
database.admin
数据库上的一个角色。
If MongoDB acquires a group whose DN exactly matches the name of an existing role, MongoDB grants the authenticated user roles and privileges associated with that role. 如果MongoDB获取的组的DN与现有角色的名称完全匹配,MongoDB将授予经过身份验证的用户角色以及与该角色关联的权限。If MongoDB cannot map any of the returned groups to a role, MongoDB grants no privileges to the user.如果MongoDB无法将任何返回的组映射到角色,则MongoDB不会向用户授予任何权限。
LDAP and 和kerberos authentication normally require creating users in the 身份验证通常需要在$external
database. $external
数据库中创建用户。If you also use LDAP for authorization, you do not need to create users in the 如果还使用LDAP进行授权,则不需要在$external
database. $external
数据库中创建用户。You only need to create the appropriate roles in the 您只需要在admin
database. admin
数据库中创建适当的角色。Users still authenticate against the 用户仍然通过$external
database.$external
数据库进行身份验证。
A database has the following roles configured on the 数据库在admin
database:admin
数据库上配置了以下角色:
{ role: "CN=dba,CN=Users,DC=example,DC=com", privileges: [], roles: [ "dbAdminAnyDatabase", "clusterAdmin" ] } { role: "CN=analytics,CN=Users,DC=example,DC=com" privileges: [], roles: [ { role : "read", db : "web_statistics" }, { role : "read", db : "user_statistics" } ] }
After authenticating a user 验证用户身份后alice@dba.example.com
against the $external
database, the MongoDB server performs a query derived from the configured query template
to retrieve the groups which include the authenticated user as a member. alice@dba.example.com
对于$external
数据库,MongoDB服务器执行一个从配置的查询模板派生的查询,以检索包括身份验证用户作为成员的组。In this example, the MongoDB server retrieves the following group DNs for the user:在本例中,MongoDB服务器为用户检索以下组DNs:
dn:CN=dba,CN=Users,dc=example,dc=com dn:CN=admin,CN=Users,dc=example,dc=com
MongoDB maps these group DNs to roles on the MongoDB将这些组DNs映射到admin
database. admin
数据库上的角色。The first group DN matches the first role, and MongoDB grants the authenticated user its roles and privileges. 第一个组DN与第一个角色匹配,MongoDB向经过身份验证的用户授予其角色和权限。The second group DN does not match to any role on the server, so MongoDB grants no additional permissions.第二个组DN与服务器上的任何角色都不匹配,因此MongoDB不授予其他权限。
A new user 新用户bob@analytics.example.com
authenticates against the $external
database. bob@analytics.example.com
根据$external
数据库进行身份验证。The MongoDB server repeats the query process, using the provided username in the query template. MongoDB服务器使用查询模板中提供的用户名重复查询过程。In this example, the MongoDB server retrieves the following group DNs for the user:在本例中,MongoDB服务器为用户检索以下组DNs:
dn:cn=analytics,CN=Users,dc=example,dc=com
MongoDB maps these group DNs to roles on the MongoDB将这些组DNs映射到管理数据库上的角色,并向经过身份验证的用户授予第二个角色的角色和权限。admin
database and grants the authenticated user the roles and privileges of the second role.
A new user 新用户workstation@guest.example.com
authenticates against the $external
database. workstation@guest.example.com
根据$external
数据库进行身份验证。The MongoDB server repeats the query process, using the provided username in the query template. MongoDB服务器使用查询模板中提供的用户名重复查询过程。In this example, the MongoDB server retrieves the following group DNs for the user:在本例中,MongoDB服务器为用户检索以下组DNs:
dn:cn=guest,CN=Users,dc=example,dc=com
MongoDB maps the group to a role on the MongoDB将组映射到admin
database and, because no matching roles exist, grants the user no additional permissions.admin
数据库上的一个角色,并且由于不存在匹配的角色,因此不授予用户额外的权限。