LDAP 代理验证

在本页面

MongoDB Enterprise支持将身份验证请求代理到轻型目录访问协议(LDAP)服务。

MongoDB 3.4 通过以下方式支持对 LDAP 服务器的简单绑定和 SASL 绑定:

  • os 库

3.4 版中的新功能:MongoDB 3.4 支持通过 os 库绑定到 LDAP 服务器。这使 Linux 和 Windows MongoDB 3.4 服务器可以使用 LDAP 服务器进行身份验证。

  • saslauthd

Linux MongoDB 服务器支持通过saslauthd守护程序绑定到 LDAP 服务器。

Important

security.sasl.saslauthdSocketPath--setParameter saslauthdPath指定的saslauthd Unix 域套接字文件的父目录必须授予以下任一项的读取和执行(r-x)权限:

  • 用户启动mongodmongos

  • 该用户所属的组。

没有对saslauthd目录及其内容的指定权限,mongodmongos无法通过saslauthd成功认证。

MongoDB 的早期版本使用saslauthd支持 LDAP 身份验证。 LDAP 身份验证支持仅限于 Linux MongoDB 部署。

早期版本的 Microsoft Windows MongoDB 无法连接到 LDAP 服务器。 Windows 上的 MongoDB 3.4 仍然与saslauthd不兼容。

Considerations

LDAP 的完整描述超出了本文档的范围。该页面假定您具有 LDAP 的先验知识。

本文档仅描述 MongoDB LDAP 身份验证,不会替代 LDAP 上的其他资源。我们鼓励您在配置 LDAP 身份验证之前彻底熟悉 LDAP 及其相关主题。

MongoDB 可以为您的 MongoDB 部署提供professional services以获得 LDAP 身份验证的最佳配置。

在 MongoDB 服务器上 ManagementLDAP 用户

用户 Management 要求同时 ManagementLDAP 服务器和 MongoDB 服务器上的用户。对于每个通过 LDAP 进行身份验证的用户,MongoDB 要求$external数据库上的用户名与身份验证用户名完全匹配。对 LDAP 服务器上的用户进行更改可能需要对相应的 MongoDB $external用户进行更改。

在版本 3.6.3 中更改:要与$external个身份验证用户(即 Kerberos,LDAP,x.509 用户)一起使用会话,用户名不能超过 10k 字节。

Example

用户认证为[email protected]。 MongoDB 服务器绑定到 LDAP 服务器并验证用户身份,但要遵守username transformations。成功认证后,MongoDB 服务器然后在$external数据库中检查用户[email protected]并向已认证的用户授予与该用户关联的角色和特权。

要在 MongoDB 服务器上 Management 用户,您必须以 LDAP 用户身份进行身份验证,其相应的 MongoDB $external用户在$external数据库上具有用户 Management 特权,例如userAdmin提供的特权。

Important

如果没有$external用户对$external数据库具有用户 Management 特权,则无法执行 LDAP 身份验证的用户 Management。如果您在启用 LDAP 身份验证之前配置用户,但是没有创建适当的用户 Management 员,则可能会发生这种情况。

Management 现有的非 LDAP 用户

如果$external数据库上没有现有用户,则必须为每个用户满足以下要求,以确保 continue 访问:

  • 用户在 LDAP 服务器上具有相应的用户对象

  • 用户存在于$external数据库上,具有相同的角色和特权

如果要 continue 允许用户$external数据库上的* not *用户访问,则必须将setParameter authenticationMechanisms配置为包括SCRAM-SHA-1。然后,用户必须在认证时指定--authenticationMechanism SCRAM-SHA-1

在副本集上部署 LDAP 身份验证

对于replica sets,请先在secondaryarbiter成员上配置 LDAP 身份验证,然后再配置primary。这也适用于分片副本集配置服务器副本集。一次配置一个副本集成员,以维护大多数成员的写可用性。

在分片群集上部署 LDAP 身份验证

sharded clusters中,您必须在config servers和每个mongos上为群集级用户配置 LDAP 身份验证。您可以选择在每个shard上为本地本地用户配置 LDAP 授权。

通过 osLDAP 库的 LDAP 认证

3.4 版的新功能。

通过 OS 库进行的 LDAP 身份验证过程总结如下:

  • Client 端向 MongoDB 进行身份验证,并提供用户的凭据。

  • 如果用户名在绑定到 LDAP 服务器之前需要 Map 到 LDAP DN,则 MongoDB 可以基于配置的security.ldap.userToDNMapping设置应用转换。

  • MongoDB 使用提供的用户名或转换后的用户名(如果应用了转换)绑定到security.ldap.servers中指定的 LDAP 服务器。

MongoDB 默认使用简单绑定,但是如果在security.ldap.bind.methodsecurity.ldap.bind.saslMechanisms中配置,也可以使用sasl绑定。

如果转换需要查询 LDAP 服务器,或者 LDAP 服务器不允许匿名绑定,则 MongoDB 在尝试对提供的用户凭据进行身份验证之前,将使用security.ldap.bind.queryUsersecurity.ldap.bind.queryPassword指定的用户名和密码绑定到 LDAP 服务器。

  • LDAP 服务器将绑定尝试的结果返回给 MongoDB。成功后,MongoDB 尝试授权用户。

  • MongoDB 服务器尝试将用户名 Map 到$external数据库上的用户,从而为该用户分配与匹配用户相关的任何角色或特权。如果 MongoDB 找不到匹配的用户,则身份验证失败。

  • Client 端可以执行 MongoDB 授予已认证用户角色或特权的那些操作。

要使用 LDAP 通过 os 库进行身份验证,请在mongodmongos配置文件中指定以下设置:

optiondescriptionrequired
security.ldap.servershost[:port]格式括起来的用引号括起来的逗号分隔的 LDAP 服务器列表。YES
security.ldap.bind.method用于指定mongodmongos用来认证或绑定到 LDAP 服务器的方法。指定sasl以使用security.ldap.bind.saslMechanisms中定义的 SASL 协议之一。


默认为simple ,除非使用sasl绑定到 LDAP 服务器。
| security.ldap.bind.saslMechanisms |用于指定验证或绑定到 LDAP 服务器时可以使用的 SASL 机制mongodmongos。 MongoDB 和 LDAP 服务器必须在至少一种 SASL 机制上达成共识。
默认为DIGEST-MD5。| ,除非将method设置为sasl 并且,您需要其他或其他 SASL 机制。
| security.ldap.bind.queryUser |由其专有名称(DN)或 SASL 名称标识的 LDAP 实体,当连接到 LDAP 服务器时,MongoDB 服务器将使用该实体进行身份验证或绑定。
queryPassword一起使用。
指定的用户必须具有适当的特权才能在 LDAP 服务器上执行查询。 ,除非将查询指定为userToDNMapping转换的一部分,或者 LDAP 服务器的安全设置不允许匿名绑定。
| security.ldap.bind.queryPassword |使用queryUser时用于认证 LDAP 服务器的密码。 ,除非指定queryUser |
| security.ldap.bind.useOSDefaults |与连接到 LDAP 服务器时一样,Windows MongoDB 部署可以使用 os 凭据代替queryUserqueryPassword进行身份验证或绑定。 ,除非替换queryUserqueryPassword
| security.ldap.userToDNMapping |Client 端可以使用用户名进行身份验证,该用户名的格式与配置的bind method期望的格式不兼容。例如,simple绑定可能需要完整的 LDAP DN,而用于向 MongoDB 进行身份验证的用户名可能是电子邮件地址。
userToDNMapping允许 MongoDB 将传入的用户名转换为与 LDAP 模式兼容的格式。 MongoDB 支持使用替换模板或 LDAP 查询模板进行转换。
如果您指定使用 LDAP 查询作为转换的一部分的userToDNMapping转换,则还必须为 LDAP 服务器指定具有适当权限级别的queryUser | ,除非 Client 端使用需要转换的用户名进行身份验证。

通过 saslauthd 进行 LDAP 认证

Warning

Windows 的 MongoDB 企业版不支持通过saslauthd进行绑定。

Considerations

  • Linux MongoDB 服务器支持通过saslauthd守护程序绑定到 LDAP 服务器。

  • 在 Client 端与服务器之间以及saslauthd与 LDAP 服务器之间使用安全的加密或信任连接。 LDAP 服务器使用SASL PLAIN机制,以“纯文本”形式发送和接收数据。您应仅使用可信通道(例如 VPN),使用 TLS/SSL 加密的连接或可信有线网络。

Configuration

要将 MongoDB 服务器配置为通过saslauthd绑定到 LDAP 服务器,请使用以下命令行选项以下配置文件设置启动mongod

Command Line Options
Configuration File Settings

Include any other command line options required for your deployment. For complete documentation on mongod command line options, see mongod.

Include any other configuration file settings required for your deployment. For complete documentation on configuration files, see YAML configuration file.

您需要使用适合您的 LDAP 服务器的参数来创建或更新saslauthd.conf文件。 saslauthd.conf文档超出了本文档的范围。

Important

security.sasl.saslauthdSocketPath--setParameter saslauthdPath指定的saslauthd Unix 域套接字文件的父目录必须授予以下任一项的读取和执行(r-x)权限:

  • 用户启动mongodmongos

  • 该用户所属的组。

没有对saslauthd目录及其内容的指定权限,mongodmongos无法通过saslauthd成功认证。

以下教程提供有关将saslauthd.conf配置为与两种流行的 LDAP 服务一起使用的基本信息:

请参阅saslauthd的文档以及您的特定 LDAP 服务以获得指导。

通过 LDAP 身份验证连接到 MongoDB 服务器

要通过 LDAP 身份验证向 MongoDB 服务器进行身份验证,请使用以下参数在$external数据库上使用db.auth()

:header-rows:1

optiondescription
username验证为的用户名。
password用于验证的密码。
mechanism设置为PLAIN