对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

配置单集群LDAP身份验证

MongoDB Enterprise支持:

  • 将身份验证请求代理到轻量级目录访问协议 (LDAP) 服务。

  • 与 LDAP 服务器的简单 SASL 绑定。 MongoDB Enterprise 可以通过saslauthd或操作系统库绑定到 LDAP 服务器。

要学习;了解更多信息,请参阅MongoDB Server文档中的LDAP代理身份验证和LDAP授权部分。

您可以使用 Kubernetes 操作符 配置 LDAP,对连接到 MongoDB 部署的应用程序进行身份验证。本指南介绍如何配置从客户端应用程序到 MongoDB 部署的 LDAP 身份验证。

注意

你无法在 Kubernetes 集群中保护 MongoDB 的独立实例。

  • 要在 CustomResourceDefinitions 中配置LDAP ,请使用 spec.security.authentication.ldap 下的参数以及Kubernetes Operator MongoDB资源规范中特定于MongoDB 助手的其他安全LDAP设置。本部分中的过程描述了所需的设置,并提供了LDAP配置的示例。

  • 为了提高安全性,请考虑部署 TLS 加密的副本集或 TLS 加密的分片集群。使用 TLS 加密是可选的。默认下, LDAP流量以纯文本形式发送。这意味着用户名和密码会受到网络威胁。许多现代目录服务(例如Microsoft Active Directory)都需要加密连接。考虑使用LDAP over TLS 对Kubernetes Operator MongoDB部署中的身份验证请求进行加密。

在为 MongoDB 部署配置 LDAP 身份验证之前,请完成以下任务:

  • 确保部署 MongoDB Enterprise 数据库资源。 MongoDB Community 数据库不支持 LDAP 身份验证。

  • 部署副本集 或部署要使用 LDAP 保护其客户端身份验证安全 的分片集群 。

1

更改此 YAML文件的设置以匹配所需的副本集配置。

1---
2apiVersion: mongodb.com/v1
3kind: MongoDB
4metadata:
5 name: <my-replica-set>
6spec:
7 members: 3
8 version: "8.0.0"
9 opsManager:
10 configMapRef:
11 # Must match metadata.name in ConfigMap file
12 name: <configMap.metadata.name>
13 credentials: <mycredentials>
14 type: ReplicaSet
15 persistent: true
16 security:
17 tls:
18 ca: <custom-ca>
19 certsSecretPrefix: <prefix>
20...
2

打开首选文本编辑器,将对象规范粘贴到资源文件末尾的 spec 部分。

3

要在部署中启用LDAP ,请在Kubernetes对象中配置以下设置:

键
类型和必要性
说明
例子

布尔值,
必需

设置为true可启用 LDAP 身份验证。

true

string,
必需

指定连接到 LDAP 服务器时 MongoDB 绑定到的 LDAP 标识名。

cn=admin,dc=example,dc=org

string,
必需

指定包含LDAP绑定标识名密码的密钥名称, MongoDB在连接到LDAP服务器时使用该密码进行绑定。

<secret-name>

string、
可选

添加 ConfigMap 的名称,该名称存储用于签署您部署的 TLS 证书的自定义 CA。

<configmap-name>

string、
可选

添加用于存储验证 LDAP 服务器的 TLS 证书的 CA 的字段名称。

<configmap-key>

字符串数组,
必需

指定一个或多个 LDAP 服务器的hostname:port组合列表。 对于每个服务器,使用单独的一行。

<example.com:636>

string、
可选

设置为tls可使用 LDAPS (LDAP over TLS )。 如果 LDAP 服务器不接受 TLS,请留空。 在部署数据库资源时,必须启用 TLS 才能使用此设置。

tls

string,
必需

指定映射,将提供给 mongod 或 mongos 进行身份验证的用户名映射到LDAP标识名 (DN)。

要了解更多信息,请参阅security.ldap.userToDNMapping 和LDAP LDAP MongoDB Server文档中的 查询模板 。

<match: "(.+)",substitution: "uid={0},ou=groups,dc=example,dc=org">

string,
必需

设置为LDAP可通过 LDAP 启用身份验证。

LDAP

生成的配置可能类似于以下示例:

security:
authentication:
enabled: true
# Enabled LDAP Authentication Mode
modes:
- "LDAP"
- "SCRAM"
# LDAP related configuration
ldap:
# Specify the hostname:port combination of one or
# more LDAP servers
servers:
- "ldap1.example.com:636"
- "ldap2.example.com:636"
# Set to "tls" to use LDAP over TLS. Leave blank if
# the LDAP server doesn't accept TLS. You must enable TLS when you deploy the database resource to use this setting.
transportSecurity: "tls"
# If TLS is enabled, add a reference to a ConfigMap that
# contains a CA certificate that validates the LDAP server's
# TLS certificate.
caConfigMapRef:
name: "<configmap-name>"
key: "<configmap-entry-key>"
# Specify the LDAP Distinguished Name to which
# MongoDB binds when connecting to the LDAP server
bindQueryUser: "cn=admin,dc=example,dc=org"
# Specify the password with which MongoDB binds
# when connecting to an LDAP server. This is a
# reference to a Secret Kubernetes Object containing
# one "password" key.
bindQueryPasswordSecretRef:
name: "<secret-name>"

有关 LDAP 设置的完整列表,请参阅 Kubernetes 操作符 MongoDB 资源规范中的安全设置。另请参阅启用 LDAP 的 Kubernetes 操作符 部署中 MongoDB Agent 用户的spec.security.authentication.agents.automationUserName设置。

4

使用 Kubernetes Operator MongoDB 资源规范中特定于助手的安全设置更新 MongoDB资源。 生成的配置可能类似于以下示例:

security:
authentication:
agents:
automationPasswordSecretRef:
key: automationConfigPassword
name: automation-config-password
automationUserName: mms-automation-agent
clientCertificateSecretRef:
name: agent-client-cert
mode: LDAP
enabled: true
ldap:
bindQueryPasswordSecretRef:
name: bind-query-password
bindQueryUser: cn=admin,dc=example,dc=org
servers:
- openldap.namespace.svc.cluster.local:389
userToDNMapping: '[{match: "(.+)",substitution: "uid={0},ou=groups,dc=example,dc=org"}]'
modes:
- LDAP
- SCRAM
requireClientTLSAuthentication: false
5
6

调用以下 Kubernetes 命令来更新副本集:

kubectl apply -f <replica-set-conf>.yaml
7

要检查 MongoDB 资源的状态,请使用以下命令:

kubectl get mdb <resource-name> -o yaml -w

设置 -w (观看) 标志后,当配置更改时,输出将立即刷新,直到状态阶段达到 Running 状态。要了解有关资源部署状态的详情,请参阅 Kubernetes Operator 故障排除。

1

更改此 YAML文件的设置以匹配所需的分片集群配置。

1---
2apiVersion: mongodb.com/v1
3kind: MongoDB
4metadata:
5 name: <my-sharded-cluster>
6spec:
7 shardCount: 2
8 mongodsPerShardCount: 3
9 mongosCount: 2
10 configServerCount: 3
11 version: "8.0.0"
12 opsManager:
13 configMapRef:
14 name: <configMap.metadata.name>
15 # Must match metadata.name in ConfigMap file
16 credentials: <mycredentials>
17 type: ShardedCluster
18 persistent: true
19 security:
20 tls:
21 ca: <custom-ca>
22 certsSecretPrefix: <prefix>
23...
2

打开首选文本编辑器,将对象规范粘贴到资源文件末尾的 spec 部分。

3

要在部署中启用LDAP ,请在Kubernetes对象中配置以下设置:

键
类型和必要性
说明
例子

布尔值,
必需

设置为true可启用 LDAP 身份验证。

true

string,
必需

指定连接到 LDAP 服务器时 MongoDB 绑定到的 LDAP 标识名。

cn=admin,dc=example,dc=org

string,
必需

指定包含LDAP绑定标识名密码的密钥名称, MongoDB在连接到LDAP服务器时使用该密码进行绑定。

<secret-name>

string、
可选

添加 ConfigMap 的名称,该名称存储用于签署您部署的 TLS 证书的自定义 CA。

<configmap-name>

string、
可选

添加用于存储验证 LDAP 服务器的 TLS 证书的 CA 的字段名称。

<configmap-key>

字符串数组,
必需

指定一个或多个 LDAP 服务器的hostname:port组合列表。 对于每个服务器,使用单独的一行。

<example.com:636>

string、
可选

设置为tls可使用 LDAPS (LDAP over TLS )。 如果 LDAP 服务器不接受 TLS,请留空。 在部署数据库资源时,必须启用 TLS 才能使用此设置。

tls

string,
必需

指定映射,将提供给 mongod 或 mongos 进行身份验证的用户名映射到LDAP标识名 (DN)。

要了解更多信息,请参阅security.ldap.userToDNMapping 和LDAP LDAP MongoDB Server文档中的 查询模板 。

<match: "(.+)",substitution: "uid={0},ou=groups,dc=example,dc=org">

string,
必需

设置为LDAP可通过 LDAP 启用身份验证。

LDAP

生成的配置可能类似于以下示例:

security:
authentication:
enabled: true
# Enabled LDAP Authentication Mode
modes:
- "LDAP"
- "SCRAM"
# LDAP related configuration
ldap:
# Specify the hostname:port combination of one or
# more LDAP servers
servers:
- "ldap1.example.com:636"
- "ldap2.example.com:636"
# Set to "tls" to use LDAP over TLS. Leave blank if
# the LDAP server doesn't accept TLS. You must enable TLS when you deploy the database resource to use this setting.
transportSecurity: "tls"
# If TLS is enabled, add a reference to a ConfigMap that
# contains a CA certificate that validates the LDAP server's
# TLS certificate.
caConfigMapRef:
name: "<configmap-name>"
key: "<configmap-entry-key>"
# Specify the LDAP Distinguished Name to which
# MongoDB binds when connecting to the LDAP server
bindQueryUser: "cn=admin,dc=example,dc=org"
# Specify the password with which MongoDB binds
# when connecting to an LDAP server. This is a
# reference to a Secret Kubernetes Object containing
# one "password" key.
bindQueryPasswordSecretRef:
name: "<secret-name>"

有关 LDAP 设置的完整列表,请参阅 Kubernetes 操作符 MongoDB 资源规范中的安全设置。另请参阅启用 LDAP 的 Kubernetes 操作符 部署中 MongoDB Agent 用户的spec.security.authentication.agents.automationUserName设置。

4

使用 Kubernetes Operator MongoDB 资源规范中特定于助手的安全设置更新 MongoDB资源。 生成的配置可能类似于以下示例:

security:
authentication:
agents:
automationPasswordSecretRef:
key: automationConfigPassword
name: automation-config-password
automationUserName: mms-automation-agent
clientCertificateSecretRef:
name: agent-client-cert
mode: LDAP
enabled: true
ldap:
bindQueryPasswordSecretRef:
name: bind-query-password
bindQueryUser: cn=admin,dc=example,dc=org
servers:
- openldap.namespace.svc.cluster.local:389
userToDNMapping: '[{match: "(.+)",substitution: "uid={0},ou=groups,dc=example,dc=org"}]'
modes:
- LDAP
- SCRAM
requireClientTLSAuthentication: false
5
6

调用以下 Kubernetes 命令来更新分片集群:

kubectl apply -f <sharded-cluster-conf>.yaml
7

要检查 MongoDB 资源的状态,请使用以下命令:

kubectl get mdb <resource-name> -o yaml -w

设置 -w (观看) 标志后,当配置更改时,输出将立即刷新,直到状态阶段达到 Running 状态。要了解有关资源部署状态的详情,请参阅 Kubernetes Operator 故障排除。