Database Manual / Self-Managed Deployments / Security / Authentication / Internal

Use X.509 Certificates for Membership Authentication with Self-Managed MongoDB使用X.509证书进行自我管理MongoDB的成员身份验证

MongoDB supports X.509 certificate authentication for use with a secure TLS/SSL connection. MongoDB支持X.509证书身份验证,用于安全的TLS/SSL连接Sharded cluster members and replica set members can use X.509 certificates to verify their membership to the cluster or the replica set instead of using keyfiles. The membership authentication is an internal process.分片集群成员和副本集成员可以使用X.509证书来验证他们对集群或副本集的成员资格,而不是使用键文件。成员身份验证是一个内部过程。

Note

MongoDB disables support for TLS 1.0 encryption on systems where TLS 1.1+ is available.MongoDB在TLS 1.1+可用的系统上禁用对TLS 1.0加密的支持。

Enabling internal authentication also enables Role-Based Access Control in Self-Managed Deployments. Clients must authenticate as a user in order to connect and perform operations in the deployment.启用内部身份验证还可以在自我管理部署中启用基于角色的访问控制。客户端必须以用户身份进行身份验证,才能连接并在部署中执行操作。

Important

A full description of TLS/SSL, PKI (Public Key Infrastructure) certificates, in particular X.509 certificates, and Certificate Authority is beyond the scope of this document. This tutorial assumes prior knowledge of TLS/SSL as well as access to valid X.509 certificates.TLS/SSL、PKI(公钥基础设施)证书(特别是X.509证书)和证书颁发机构的完整描述超出了本文的范围。本教程假设您具备TLS/SSL的先验知识以及有效X.509证书的访问权限。

Member X.509 Certificate成员X.509证书

Note

You must have valid X.509 certificates.您必须拥有有效的X.509证书。

If you specify --tlsAllowInvalidCertificates or net.tls.allowInvalidCertificates: true, an invalid certificate is sufficient only to establish a TLS connection but it is insufficient for authentication.如果指定--tlsAllowInvalidCertificatesnettlsallowInvalidCertificates:true,则无效证书仅足以建立TLS连接,但不足以进行身份验证。

Certificate Requirements证书要求

When TLS is enabled, use member certificates to verify membership to internal connections in a sharded cluster or a replica set. 启用TLS后,使用成员证书验证分片集群或副本集中内部连接的成员资格。You can configure member certificate file paths with the net.tls.clusterFile and net.tls.certificateKeyFile options. 您可以使用net.tls.clusterFilenet.tls.certificateKeyFile选项配置成员证书文件路径。Members have the following configuration requirements:成员具有以下配置要求:

  • Cluster member configuration must specify a non-empty value for at least one of the attributes used for authentication. By default, MongoDB accepts:群集成员配置必须为用于身份验证的至少一个属性指定非null值。默认情况下,MongoDB接受:

    • the Organization (O)
    • the Organizational Unit (OU)
    • the Domain Component (DC)

    MongoDB verifies that entries match exactly across all member certificates. If you list multiple OU values, all certificates must use an identical list.MongoDB验证所有成员证书中的条目是否完全匹配。如果列出多个OU值,则所有证书必须使用相同的列表。

    You can specify alternative attributes to use for authentication by setting net.tls.clusterAuthX509.extensionValue.您可以通过设置net.tls.clusterAuthX509.extensionValue来指定用于身份验证的替代属性。

  • Cluster member configuration must include the same net.tls.clusterAuthX509.attributes and use matching values. 群集成员配置必须包含相同的net.tls.clusterAuthX509.attributes,并使用匹配的值。Attribute order doesn't matter. The following example sets O and OU, but not DC:属性顺序并不重要。以下示例设置了OOU,但没有设置DC

    net:
    tls:
    clusterAuthX509:
    attributes: O=MongoDB, OU=MongoDB Server

Note

If you set the enforceUserClusterSeparation parameter to false, the following behaviors apply:如果将enforceUserClusterSeparation参数设置为false,则将应用以下行为:

  • You cannot set clusterAuthMode to an option that allows X.509 or the server will not start. The server will only start if clusterAuthMode is keyFile.您不能将clusterAuthMode设置为允许X.509的选项,否则服务器将无法启动。只有当clusterAuthModekeyFile时,服务器才会启动。
  • A client can create a user in the $external database whose O/OU/DC attributes match the server's configured attributes for cluster membership.客户端可以在$external数据库中创建一个用户,该用户的O/OU/DC属性与服务器为集群成员资格配置的属性相匹配。
  • A client presenting a member certificate can now attempt MONGODB-X509 authentication as a user in the $external database.出示成员证书的客户端现在可以作为$external数据库中的用户尝试MONGODB-X509身份验证。

To set the enforceUserClusterSeparation parameter to false, run the following command during startup:要将enforceUserClusterSeparation参数设置为false,请在启动过程中运行以下命令:

mongod --setParameter enforceUserClusterSeparation=false

The certificates have the following requirements:证书有以下要求:

  • A single Certificate Authority (CA) must issue all X.509 certificates for the members of a sharded cluster or a replica set.单个证书颁发机构(CA)必须为分片集群或副本集的成员颁发所有X.509证书。
  • At least one of the Subject Alternative Name (SAN) entries must match the server hostname used by other cluster members. When comparing SANs, MongoDB can compare either DNS names or IP addresses.至少有一个主题备选名称(SAN)条目必须与其他群集成员使用的服务器主机名匹配。在比较SAN时,MongoDB可以比较DNS名称或IP地址。

    If you don't specify subjectAltName, MongoDB compares the Common Name (CN) instead. However, this usage of CN is deprecated per RFC2818如果不指定subjectAltName,MongoDB会比较通用名(CN)。然而,根据RFC2818,CN的这种用法已被弃用

  • If the certificate used as the certificateKeyFile includes extendedKeyUsage, the value must include both clientAuth ("TLS Web Client Authentication") and serverAuth ("TLS Web Server Authentication").如果用作certificateKeyFile的证书包括extendedKeyUsage,则该值必须同时包括clientAuth(“TLS Web客户端身份验证”)和serverAuth(”TLS Web服务器身份验证“)。

    extendedKeyUsage = clientAuth, serverAuth
  • If the certificate used as the clusterFile includes extendedKeyUsage, the value must include clientAuth.如果用作clusterFile的证书包括extendedKeyUsage,则该值必须包括clientAuth

    extendedKeyUsage = clientAuth

Configure Replica Set/Sharded Cluster配置副本集/分片群集

Outside of rolling upgrade procedures, every component of a replica set or sharded cluster should use the same --clusterAuthMode setting to ensure it can securely connect to all other components in the deployment.除了滚动升级过程之外,副本集分片集群的每个组件都应该使用相同的--clusterAuthMode设置,以确保它可以安全地连接到部署中的所有其他组件。

For replica set deployments, this includes all mongod members of the replica set.对于副本集部署,这包括副本集的所有mongod成员。

For sharded cluster deployments, this includes all mongod or mongos instances.对于分片集群部署,这包括所有mongodmongos实例。

Note

mongod and mongos bind to localhost by default. If the members of your deployment are run on different hosts or if you wish remote clients to connect to your deployment, you must specify --bind_ip or net.bindIp.mongodmongos默认绑定到localhost。如果部署的成员在不同的主机上运行,或者希望远程客户端连接到部署,则必须指定--bind_ipnet.bindIp

Use Command-line Options使用命令行选项 (tls)

Note

The procedures in this section use the tls settings/option. For procedures using the deprecated ssl aliases, see Use Command-line Options (ssl).本节中的过程使用tls设置/选项。有关使用已弃用的ssl别名的过程,请参阅使用命令行选项(ssl)

The tls settings/options provide identical functionality as the ssl options since MongoDB has always supported TLS 1.0 and later.tls设置/选项提供与ssl选项相同的功能,因为MongoDB一直支持tls 1.0及更高版本。

TLS(Command-Line Options)
mongod --replSet <name> --tlsMode requireTLS --clusterAuthMode x509 --tlsClusterFile <path to membership certificate and key PEM file> --tlsCertificateKeyFile <path to TLS/SSL certificate and key file> --tlsCAFile <path to root CA file> --bind_ip localhost,<hostname(s)|ip address(es)>

Important

To use X.509 authentication, --tlsCAFile or net.tls.CAFile must be specified unless you are using --tlsCertificateSelector or --net.tls.certificateSelector.要使用X.509身份验证,必须指定--tlsCAFilenet.tls.CAFile,除非您使用的是--tlsCertificateSelector--net.tls.certificateSelector

Include any additional options, TLS/SSL or otherwise, that are required for your specific configuration. For包括特定配置所需的任何其他选项,TLS/SSL或其他。因为

TLS(Configuration File)
security:
clusterAuthMode: x509
net:
tls:
mode: requireTLS
certificateKeyFile: <path to its TLS/SSL certificate and key file>
CAFile: <path to root CA PEM file to verify received certificate>
clusterFile: <path to its certificate key file for membership authentication>
bindIp: localhost,<hostname(s)|ip address(es)>

Important

To use X.509 authentication, --tlsCAFile or net.tls.CAFile must be specified unless you are using --tlsCertificateSelector or --net.tls.certificateSelector.要使用X.509身份验证,必须指定--tlsCAFilenet.tls.CAFile,除非您使用的是--tlsCertificateSelector--net.tls.certificateSelector

Include any additional options, TLS/SSL or otherwise, that are required for your specific configuration.包括特定配置所需的任何其他选项,TLS/SSL或其他。

For more information, see Configure mongod and mongos for TLS/SSL on Self-Managed Deployments.有关更多信息,请参阅在自我管理部署上为TLS/SSL配置mongodmongos

Use Command-line Options使用命令行选项 (ssl)

Note

The procedures in this section use the deprecated ssl settings/option. For procedures that use tls aliases, see Use Command-line Options (tls).本节中的过程使用了已弃用的ssl设置/选项。有关使用tls别名的过程,请参阅使用命令行选项(tls)

The tls settings/options provide identical functionality as the ssl options since MongoDB has always supported TLS 1.0 and later.tls设置/选项提供与ssl选项相同的功能,因为MongoDB一直支持tls 1.0及更高版本。

SSL (Command-Line Options)

To specify the X.509 certificate for internal cluster member authentication, append the additional TLS/SSL options --clusterAuthMode and --sslClusterFile, as in the following example for a member of a replica set:要为内部集群成员身份验证指定X.509证书,请附加其他TLS/SSL选项--clusterAuthMode--sslClusterFile,如下例所示:

mongod --replSet <name> --sslMode requireSSL --clusterAuthMode x509 --sslClusterFile <path to membership certificate and key PEM file> --sslPEMKeyFile <path to TLS/SSL certificate and key PEM file> --sslCAFile <path to root CA PEM file> --bind_ip localhost,<hostname(s)|ip address(es)>

Important

To use X.509 authentication, --tlsCAFile or net.tls.CAFile must be specified unless you are using --tlsCertificateSelector or --net.tls.certificateSelector.要使用X.509身份验证,必须指定--tlsCAFilenet.tls.CAFile,除非您使用的是--tlsCertificateSelector--nettlscertificateSelector

Include any additional options, TLS/SSL or otherwise, that are required for your specific configuration.包括特定配置所需的任何其他选项,TLS/SSL或其他。

SSL (Configuration File)
security:
clusterAuthMode: x509
net:
ssl:
mode: requireSSL
PEMKeyFile: <path to TLS/SSL certificate and key PEM file>
CAFile: <path to root CA PEM file>
clusterFile: <path to X.509 membership certificate and key PEM file>
bindIp: localhost,<hostname(s)|ip address(es)>

Important

To use X.509 authentication, --tlsCAFile or net.tls.CAFile must be specified unless you are using --tlsCertificateSelector or --net.tls.certificateSelector.要使用X.509身份验证,必须指定--tlsCAFilenet.tls.CAFile,除非您使用的是--tlsCertificateSelector--net.tls.certificateSelector

Include any additional options, TLS/SSL or otherwise, that are required for your specific configuration.包括特定配置所需的任何其他选项,TLS/SSL或其他。

For more information, see Configure mongod and mongos for TLS/SSL on Self-Managed Deployments.有关更多信息,请参阅在自我管理部署上为TLS/SSL配置mongodmongos

Additional Information附加信息

To upgrade from keyfile internal authentication to X.509 internal authentication, see Upgrade Self-Managed MongoDB from Keyfile Authentication to X.509 Authentication.要从键文件内部身份验证升级到X.509内部身份验证,请参阅将自管理MongoDB从键文件身份验证升级为X.509身份验证

To perform a rolling update of the certificates to new certificates with different DN, see Rotate X.509 Certificates without clusterAuthX509 Attributes on Self-Managed Clusters.要将证书滚动更新为具有不同DN的新证书,请参阅在自管理群集上旋转不带clusterAuthX509属性的X.509证书