MongoDB supports X.509 certificate authentication for client authentication and internal authentication of the members of replica sets and sharded clusters.MongoDB支持X.509证书身份验证,用于客户端身份验证和副本集和分片集群成员的内部身份验证。
X.509 certificate authentication requires a secure TLS/SSL connection.X.509证书身份验证需要安全的TLS/SSL连接。
Certificate Authority证书颁发机构
For production use, your MongoDB deployment should use valid certificates generated and signed by a certificate authority. You or your organization can generate and maintain an independent certificate authority, or use certificates generated by third-party TLS vendors. 对于生产使用,MongoDB部署应该使用由证书颁发机构生成和签名的有效证书。您或组织可以生成和维护独立的证书颁发机构,或使用第三方TLS供应商生成的证书。Obtaining and managing certificates is beyond the scope of this documentation.获取和管理证书超出了本文档的范围。
Client X.509 Certificates客户端X.509证书
To authenticate to servers, clients can use X.509 certificates instead of usernames and passwords.为了向服务器进行身份验证,客户端可以使用X.509证书而不是用户名和密码。
Client Certificate Requirements客户证书要求
Client certificate requirements:客户证书要求:
A single Certificate Authority (CA) must issue the certificates for both the client and the server.单个证书颁发机构(CA)必须为客户端和服务器颁发证书。Each unique MongoDB user must have a unique certificate.每个唯一的MongoDB用户都必须拥有一个唯一的证书。The X.509 certificate must not be expired.X.509证书不得过期。Client certificates must contain the following fields:客户端证书必须包含以下字段:keyUsage = digitalSignature
extendedKeyUsage = clientAuthAt least one of the following client certificate attributes must be different than the attributes in both the以下客户端证书属性中至少有一个必须与net.tls.clusterFileandnet.tls.certificateKeyFileserver certificates:net.tls.clusterFile和net.tls.certificateKeyFile服务器证书中的属性不同:- Organization (
O) - Organizational Unit (
OU) - Domain Component (
DC)
Note
You can also disable the您还可以在启动过程中禁用enforceUserClusterSeparationparameter during startup to automatically disable theO/OU/DCcheck. This allows member certificates to authenticate as users stored in the$externaldatabase.enforceUserClusterSeparation参数,以自动禁用O/OU/DC检查。这允许成员证书作为存储在$external数据库中的用户进行身份验证。- Organization (
The包含可分辨名称(subjectof a client X.509 certificate, which contains the Distinguished Name (DN), must be different than thesubjects of member X.509 certificates.DN)的客户端X.509证书的subject必须与成员X.509证书的subject不同。If the MongoDB deployment has如果MongoDB部署设置了tlsX509ClusterAuthDNOverrideset, the client X.509 certificate's subject must not match that value.tlsX509ClusterAuthDNOverride,则客户端X.509证书的主题不得与该值匹配。Important
If a client X.509 certificate's subject matches the如果客户端X.509证书的主题与成员X.509证书的O,OU, andDCattributes of the Member X.509 Certificate (ortlsX509ClusterAuthDNOverride, if set) exactly, the client connection is accepted, full permissions are granted, and a warning message appears in the log.O、OU和DC属性(或tlsX509ClusterAuthDNOverride,如果已设置)完全匹配,则接受客户端连接,授予完全权限,并在日志中显示警告消息。Only cluster member x509 certificates should use the same只有集群成员x509证书应使用相同的O,OU, andDCattribute combinations.O、OU和DC属性组合。
MongoDB User and $external DatabaseMongoDB用户和$external数据库
$external DatabaseTo authenticate with a client certificate, you must first add the client certificate's 要使用客户端证书进行身份验证,您必须首先将客户端证书的subject as a MongoDB user in the $external database. subject添加为$external数据库中的MongoDB用户。The $external database is the Authentication Database for the user.$external数据库是用户的身份验证数据库。
Each unique X.509 client certificate is for one MongoDB user. You cannot use a single client certificate to authenticate more than one MongoDB user.每个唯一的X.509客户端证书都适用于一个MongoDB用户。您不能使用单个客户端证书对多个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字节。
TLS Connection X509 Certificate Startup WarningTLS连接X509证书启动警告
Starting in MongoDB 5.0, 从MongoDB 5.0开始,当mongod and mongos now issue a startup warning when their certificates do not include a Subject Alternative Name attribute.mongod和mongos的证书不包含Subject Alternative Name属性时,它们会发出启动警告。
The following platforms do not support common name validation:以下平台不支持通用名称验证:
iOS 13 and higheriOS 13及更高版本MacOS 10.15 and higherMacOS 10.15及更高版本Go 1.15 and higher达到1.15及以上
Clients using these platforms will not authenticate to MongoDB servers that use X.509 certificates whose hostnames are specified by CommonName attributes.使用这些平台的客户端将不会向使用X.509证书的MongoDB服务器进行身份验证,这些证书的主机名由CommonName属性指定。
Member X.509 Certificates成员X.509证书
For internal authentication between members of sharded clusters and replica sets, you can use X.509 certificates instead of keyfiles.对于分片集群和副本集成员之间的内部身份验证,您可以使用X.509证书而不是键文件。
Member 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.clusterFile和net.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 multipleMongoDB验证所有成员证书中的条目是否完全匹配。如果列出多个OU值,则所有证书必须使用相同的列表。OUvalues, all certificates must use an identical list.You can specify alternative attributes to use for authentication by setting您可以通过设置net.tls.clusterAuthX509.extensionValue.net.tls.clusterAuthX509.extensionValue来指定用于身份验证的替代属性。- the Organization (
Cluster member configuration must include the same群集成员配置必须包含相同的net.tls.clusterAuthX509.attributesand use matching values.net.tls.clusterAuthX509.attributes属性,并使用匹配的值。Attribute order doesn't matter. The following example sets属性顺序并不重要。以下示例设置了OandOU, but notDC:O和OU,但没有设置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您不能将clusterAuthModeto an option that allows X.509 or the server will not start. The server will only start ifclusterAuthModeiskeyFile.clusterAuthMode设置为允许X.509的选项,否则服务器将无法启动。只有当clusterAuthMode为keyFile时,服务器才会启动。A client can create a user in the客户端可以在$externaldatabase whoseO/OU/DCattributes 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出示成员证书的客户端现在可以作为$externaldatabase.$external数据库中的用户尝试MONGODB-X509身份验证。
To set the 要将enforceUserClusterSeparation参数设置为enforceUserClusterSeparation parameter to false, run the following command during startup:false,请在启动过程中运行以下命令:
mongod --setParameter enforceUserClusterSeparation=falseThe 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)条目必须与其他群集成员使用的服务器主机名匹配。在比较SAN) entries must match the server hostname used by other cluster members. When comparingSANs, MongoDB can compare either DNS names or IP addresses.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 RFC2818subjectAltName,MongoDB会比较通用名(CN)。然而,根据RFC2818,CN的这种用法已被弃用If the certificate used as the如果用作certificateKeyFileincludesextendedKeyUsage, the value must include bothclientAuth("TLS Web Client Authentication") andserverAuth("TLS Web Server Authentication").certificateKeyFile的证书包括extendedKeyUsage,则该值必须同时包括clientAuth(“TLS Web客户端身份验证”)和serverAuth(“TLS Web服务器身份验证”)。extendedKeyUsage = clientAuth, serverAuthIf the certificate used as the如果用作clusterFileincludesextendedKeyUsage, the value must includeclientAuth.clusterFile的证书包括extendedKeyUsage,则该值必须包括clientAuth。extendedKeyUsage = clientAuth
MongoDB Configuration for Membership AuthenticationMongoDB成员身份验证配置
You can use TLS for internal authentication between each member of your replica set (each 您可以使用TLS在副本集的每个成员(每个mongod instance) or sharded cluster (each mongod and mongos instance).mongod实例)或分片集群(每个mongod和mongos实例)之间进行内部身份验证。
To use TLS for internal authentication, use the following settings:要使用TLS进行内部身份验证,请使用以下设置:
security.clusterAuthModeor或--clusterAuthModeset to设置为x509net.tls.clusterFileor或--tlsClusterFile
Important
If you set 如果将--tlsMode to any value other than disabled, MongoDB uses the certificate specified in net.tls.certificateKeyFile for both server and client authentication in internal replica set connections. --tlsMode设置为disabled以外的任何值,MongoDB将在内部副本集连接中使用net.tls.certificateKeyFile中指定的证书进行服务器和客户端身份验证。This certificate setting applies regardless of whether you set 无论您是否将security.clusterAuthMode to X.509.security.clusterAuthMode设置为X.509,此证书设置都适用。
mongod and mongos instances use their certificate key files to prove their identity to clients, but certificate key files can also be used for membership authentication. mongod和mongos实例使用其证书键文件向客户端证明其身份,但证书键文件也可用于成员身份验证。If you do not specify a cluster file, members use their certificate key files for membership authentication. 如果不指定群集文件,成员将使用其证书键文件进行成员身份验证。Specify the certificate key file with 使用net.tls.certificateKeyFile or --tlsCertificateKeyFile.net.tls.certificateKeyFile或--tlsCertificateKeyFile指定证书键文件。
To use the certificate key file for both client authentication and membership authentication, the certificate must either:要将证书键文件用于客户端身份验证和成员身份验证,证书必须:
Omit省略extendedKeyUsageor或Specify指定extendedKeyUsage = serverAuth, clientAuth