Overview概述
This document helps you to configure a new MongoDB instance to support TLS/SSL. For instructions on upgrading a cluster currently not using TLS/SSL to using TLS/SSL, see Upgrade a Cluster to Use TLS/SSL instead.本文档帮助您配置新的MongoDB实例以支持TLS/SSL。有关将当前未使用TLS/SSL的群集升级为使用TLS/SSL的说明,请参阅将群集升级为改用TLS/SSL。
To set up a local development environment with TLS/SSL, see Developing MongoDB Locally with TLS.要使用TLS/SSL设置本地开发环境,请参阅使用TLS在本地开发MongoDB。
MongoDB uses the native TLS/SSL OS libraries:MongoDB使用本机TLS/SSL操作系统库:
| TLS/SSL | |
|---|---|
| Windows | |
| Linux/BSD | OpenSSL |
| macOS |
Note
MongoDB disables support for TLS 1.0 encryption on systems where TLS 1.1+ is available.MongoDB在TLS 1.1+可用的系统上禁用对TLS 1.0加密的支持。MongoDB's TLS/SSL encryption only allows the use of strong TLS/SSL ciphers with a minimum of 128-bit key length for all connections.MongoDB的TLS/SSL加密只允许对所有连接使用最小128位键长度的强TLS/SSL密码。The Linux 64-bit legacy x64 builds of MongoDB do not include support for TLS/SSL.MongoDB的Linux 64位旧x64版本不包括对TLS/SSL的支持。
Prerequisites先决条件
Important
A full description of TLS/SSL, PKI (Public Key Infrastructure) certificates, and Certificate Authority is beyond the scope of this document. This page assumes prior knowledge of TLS/SSL as well as access to valid certificates.TLS/SSL、PKI(公钥基础设施)证书和证书颁发机构的完整描述超出了本文档的范围。本页假设您已具备TLS/SSL的先验知识以及有效证书的访问权限。
Certificate Authorities证书颁发机构
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. Obtaining and managing certificates is beyond the scope of this documentation.对于生产使用,MongoDB部署应该使用由证书颁发机构生成和签名的有效证书。您或组织可以生成和维护独立的证书颁发机构,或使用第三方TLS供应商生成的证书。获取和管理证书超出了本文档的范围。
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验证所有成员证书中的条目是否完全匹配。如果列出多个OUvalues, all certificates must use an identical list.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.attributesand use matching values. Attribute order doesn't matter. The following example setsOandOU, but notDC:net.tls.clusterAuthX509.attributes,并使用匹配的值。属性顺序并不重要。以下示例设置了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 parameter to false, run the following command during startup:enforceUserClusterSeparation参数设置为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) entries must match the server hostname used by other cluster members. When comparingSANs, 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 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
mongod and mongos Certificate Key Filemongod和mongos证书键文件
mongod and mongos Certificate Key FileWhen establishing a TLS/SSL connection, the 在建立TLS/SSL连接时,mongod / mongos presents a certificate key file to its clients to establish its identity. mongod/mongos向其客户端提供证书键文件以建立其身份。[1] The certificate key file contains a public key certificate and its associated private key, but only the public component is revealed to the client.证书键文件包含公钥证书及其关联的私钥,但只向客户端显示公共组件。
MongoDB can use any valid TLS/SSL certificate issued by a certificate authority, or a self-signed certificate. MongoDB可以使用证书颁发机构颁发的任何有效TLS/SSL证书或自签名证书。If you use a self-signed certificate, although the communications channel will be encrypted to prevent eavesdropping on the connection, there will be no validation of server identity. 如果您使用自签名证书,尽管通信通道将被加密以防止连接被窃听,但不会对服务器身份进行验证。This leaves you vulnerable to a man-in-the-middle attack. Using a certificate signed by a trusted certificate authority will permit MongoDB drivers to verify the server's identity.这会使您容易受到中间人攻击。使用由受信任的证书颁发机构签名的证书将允许MongoDB驱动程序验证服务器的身份。
In general, avoid using self-signed certificates unless the network is trusted.一般来说,除非网络是可信的,否则避免使用自签名证书。
With regards to certificates for replica set and sharded cluster members, it is advisable to use different certificates on different servers. This minimizes exposure of the private key and allows for hostname validation.关于副本集和分片集群成员的证书,建议在不同的服务器上使用不同的证书。这最大限度地减少了私钥的暴露,并允许主机名验证。
Note
If a MongoDB deployment is not configured to use a CA file, it bypasses client certificate validation.如果MongoDB部署未配置为使用CA文件,则会绕过客户端证书验证。
| [1] | openssl pkcs8 and others.openssl pkcs8等。 |
Procedures (Using net.tls Settings)程序(使用net.tls设置)
net.tls Settings)Note
MongoDB provides MongoDB提供了与net.tls settings (and --tls command-line options) that correspond to the net.ssl settings (and --ssl command-line options). net.tls设置(和--ssl命令行选项)相对应的net.ssl设置(和--tls命令行参数)。The new 新的tls settings provide identical functionality as the ssl settings since MongoDB has always supported TLS 1.0 and later.tls设置提供了与ssl设置相同的功能,因为MongoDB一直支持tls 1.0及更高版本。
The procedures in this section use the 本节中的程序使用net.tls settings. For procedures using the net.ssl alias, see Procedures (Using net.ssl Settings).net.tls设置。有关使用net.ssl别名的过程,请参阅过程(使用net.ssl设置)。
Set Up mongod and mongos with TLS/SSL Certificate and Key使用TLS/SSL证书和键设置mongod和mongos
mongod and mongos with TLS/SSL Certificate and KeyThe following section configures 以下部分将配置mongod / mongos to use TLS/SSL connections. mongod/mongos以使用TLS/SSL连接。With these TLS/SSL settings, 通过这些TLS/SSL设置,mongod / mongos presents its certificate key file to the client. mongod/mongos向客户端提供其证书键文件。However, the 但是,mongod / mongos does not require a certificate key file from the client to verify the client's identity. mongod/mongos不需要客户端的证书键文件来验证客户端的身份。To require client's certificate key file, see Set Up 要要求客户端的证书键文件,请参阅使用客户端证书验证设置mongod and mongos with Client Certificate Validation instead.mongod和mongos。
Note
The procedure uses the 该程序使用net.tls settings. For procedures that use the net.ssl settings, see Procedures (Using net.ssl Settings).net.tls设置。有关使用net.ssl设置的过程,请参阅过程(使用net.ssl设定)。
To use TLS/SSL connections, include the following TLS/SSL settings in your 要使用TLS/SSL连接,请在mongod / mongos instance's configuration file:mongod/mongos实例的配置文件中包含以下TLS/SSL设置:
PEMKeyFile(Linux/Windows/macOS)
net.tls.mode |
|
net.tls.certificateKeyFile |
|
For example, consider the following configuration file for a 例如,考虑以下mongod instance:mongod实例的配置文件:
net:
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongodb.pem
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
dbPath: "/var/lib/mongodb"
processManagement:
fork: true
net:
bindIp: localhost,mongodb0.example.net
port: 27017System SSL Certificate Store(Windows/macOS)
You can use system SSL certificate stores for Windows and macOS. To use the system SSL certificate store, specify 您可以使用Windows和macOS的系统SSL证书存储。要使用系统SSL证书存储,请指定net.tls.certificateSelector instead of specifying the certificate key file.net.tls.certificateSelector,而不是指定证书键文件。
net.tls.mode |
|
net.tls.certificateSelector |
|
For example, consider the following configuration file for a 例如,考虑以下mongod instance:mongod实例的配置文件:
net:
tls:
mode: requireTLS
certificateSelector: subject="<CertificateCommonName>"
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
dbPath: "/var/lib/mongodb"
processManagement:
fork: true
net:
bindIp: localhost,mongodb0.example.net
port: 27017A 使用上述配置的mongod instance that uses the above configuration can only accept TLS/SSL connections:mongod实例只能接受TLS/SSL连接:
mongod --config <path/to/configuration/file>
See Connect to MongoDB Instances Using Encryption for more information on connecting with TLS/SSL.有关使用TLS/SSL连接的更多信息,请参阅使用加密连接到MongoDB实例。
Tip
You can also configure 您还可以使用命令行选项而不是配置文件来配置mongod and mongos using command-line options instead of the configuration file:mongod和mongos:
For对于mongod, see:--tlsMode;mongod,请参阅:--tlsMode、--tlsCertificateKeyFile; and和--tlsCertificateSelector。For对于mongos, see:--tlsMode;--tlsCertificateKeyFile; and--tlsCertificateSelector.mongos,请参阅:--tlsMode、--tlsCertificateKeyFile和--tlsCertificateSelector。
Set Up mongod and mongos with Client Certificate Validation使用客户端证书验证设置mongod和mongos
mongod and mongos with Client Certificate ValidationThe following section configures 以下部分将配置mongod / mongos to use TLS/SSL connections and perform client certificate validation. With these TLS/SSL settings:mongod/mongos以使用TLS/SSL连接并执行客户端证书验证。使用这些TLS/SSL设置:
mongod/mongospresents its certificate key file to the client for verification.将其证书键文件呈现给客户端进行验证。mongod/mongosrequires a certificate key file from the client to verify the client's identity.需要来自客户端的证书键文件来验证客户端的身份。
Note
The procedure uses the 该过程使用net.tls settings For procedures that use the net.ssl settings, see Procedures (Using net.ssl Settings).net.tls设置。有关使用net.ssl设置的过程,请参阅过程(使用net.ssl设定)。
To use TLS/SSL connections and perform client certificate validation, include the following TLS/SSL settings in your 要使用TLS/SSL连接并执行客户端证书验证,请在mongod / mongos instance's configuration file:mongod/mongos实例的配置文件中包含以下TLS/SSL设置:
Note
You can use system SSL certificate stores for Windows and macOS. To use the system SSL certificate store, specify 您可以使用Windows和macOS的系统SSL证书存储。要使用系统SSL证书存储,请指定net.ssl.certificateSelector instead of specifying the certificate key file.net.ssl.certificateSelector,而不是指定证书键文件。
net.tls.mode |
|
net.tls.certificateKeyFile |
|
net.tls.CAFile |
|
Important
When starting a 启动启用了TLS/SSL的mongod instance with TLS/SSL enabled, you must specify a value for the --tlsCAFile flag, the net.tls.CAFile configuration option, or the tlsUseSystemCA parameter.mongod实例时,必须为--tlsCAFile标志、net.tls.CAFile配置选项或tlsUseSystemCA参数指定一个值。
--tlsCAFile, tls.CAFile, and tlsUseSystemCA are all mutually exclusive.--tlsCAFile、tls.CAFile和tlsUseSystemCA都是互斥的。
For example, consider the following configuration file for a 例如,考虑以下mongod instance:mongod实例的配置文件:
net:
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/caToValidateClientCertificates.pem
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
dbPath: "/var/lib/mongodb"
processManagement:
fork: true
net:
bindIp: localhost,mongodb0.example.net
port: 27017
A 使用上述配置的mongod instance that uses the above configuration can only accept TLS/SSL connections and requires a valid certificate from its clients:mongod实例只能接受TLS/SSL连接,并要求其客户端提供有效证书:
mongod --config <path/to/configuration/file>
Clients must specify TLS/SSL connections and present their certificate key file to the instance. 客户端必须指定TLS/SSL连接,并向实例提供其证书键文件。See Connect to MongoDB Instances that Require Client Certificates for more information on connecting with TLS/SSL.有关使用TLS/SSL连接的更多信息,请参阅连接到需要客户端证书的MongoDB实例。
Tip
You can also configure 您还可以使用命令行选项而不是配置文件来配置mongod and mongos using command-line options instead of the configuration file:mongod和mongos:
- For
mongod, see--tlsMode,--tlsCertificateKeyFile, and--tlsCAFile. - For
mongos, see--tlsMode,--tlsCertificateKeyFile,--tlsCAFile.
Block Revoked Certificates for Clients阻止客户端的吊销证书
Note
The procedure uses the 该程序使用net.tls settings. For procedures that use the net.ssl settings, see Procedures (Using net.ssl Settings).net.tls设置。有关使用net.ssl设置的过程,请参阅过程(使用net.ssl设定)。
To prevent clients with revoked certificates from connecting to the 为了防止证书被吊销的客户端连接到mongod or mongos instance, you can use a Certificate Revocation List (CRL).mongod或mongos实例,您可以使用证书吊销列表(CRL)。
To specify a CRL file, include 要指定CRL文件,请将net.tls.CRLFile set to a file that contains revoked certificates.net.tls.CRLFile设置为包含已吊销证书的文件。
For example:例如:
net:
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/caToValidateClientCertificates.pem
CRLFile: /etc/ssl/revokedCertificates.pem
Clients that present certificates that are listed in the 提供/etc/ssl/revokedCertificates.pem file are not able to connect./etc/ssl/revokedCertificates.pem文件中列出的证书的客户端无法连接。
Tip
You can also configure the revoked certificate list using the command-line option.您还可以使用命令行选项配置吊销的证书列表。
For关于mongod, see--tlsCRLFile.mongod,请参阅--tlsCRLFile。For关于mongos, see--tlsCRLFile.mongos,请参阅--tlsCRLFile。
Validate Only if a Client Presents a Certificate仅在客户端出示证书时进行验证
In most cases, it is important to ensure that clients present valid certificates. However, if you have clients that cannot present a client certificate or are transitioning to using a certificate, you may only want to validate certificates from clients that present a certificate.在大多数情况下,确保客户端出示有效证书非常重要。但是,如果客户端无法提供客户端证书或正在转换为使用证书,您可能只想验证提供证书的客户端的证书。
Note
The procedure uses the 该程序使用net.tls settings. For procedures using the net.ssl settings, see Procedures (Using net.ssl Settings).net.tls设置。有关使用net.ssl设置的过程,请参阅过程(使用net.ssl设定)。
To bypass client certificate validation for clients that do not present a certificate, include 要绕过未提供证书的客户端的客户端证书验证,请将net.tls.allowConnectionsWithoutCertificates set to true.net.tls.allowConnectionsWithoutCertificates证书设置为true。
For example:例如:
net:
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/caToValidateClientCertificates.pem
allowConnectionsWithoutCertificates: true
A 使用这些设置运行的mongod / mongos running with these settings allows connection from:mongod/mongos允许从以下位置连接:
Clients that do not present a certificate.不提供证书的客户端。Clients that present a valid certificate.提供有效证书的客户端。
Note
If the client presents a certificate, the certificate must be a valid certificate.如果客户端提供证书,则证书必须是有效的证书。
All connections, including those that have not presented certificates, are encrypted using TLS/SSL.所有连接,包括那些没有提供证书的连接,都使用TLS/SSL进行加密。
See TLS/SSL Configuration for Clients for more information on TLS/SSL connections for clients.有关客户端TLS/SSL连接的更多信息,请参阅客户端的TLS/SSL配置。
Tip
You can also configure using the command-line options:您还可以使用命令行选项进行配置:
For对于mongod, see--tlsAllowConnectionsWithoutCertificates.mongod,请参阅--tlsAllowConnectionsWithoutCertificates。For对于mongos, see--tlsAllowConnectionsWithoutCertificates.mongos,请参阅--tlsAllowConnectionsWithoutCertificates。
Disallow Protocols不允许协议
Note
The procedure uses the 该程序使用net.tls settings. For procedures using the net.ssl settings, see Procedures (Using net.ssl Settings).net.tls设置。有关使用net.ssl设置的过程,请参阅过程(使用net.ssl设定)。
To prevent MongoDB servers from accepting incoming connections that use specific protocols, include 为了防止MongoDB服务器接受使用特定协议的传入连接,请将net.tls.disabledProtocols set to the disallowed protocols.net.tls.disabledProtocols设置为不允许的协议。
For example, the following configuration prevents 例如,以下配置阻止mongod / mongos from accepting incoming connections that use either TLS1_0 or TLS1_1mongod/mongos接受使用TLS1_0或TLS1_1的传入连接
net:
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/caToValidateClientCertificates.pem
disabledProtocols: TLS1_0,TLS1_1
Tip
You can also configure using the command-line options:您还可以使用命令行选项进行配置:
For关于mongod, see--tlsDisabledProtocols.mongod,请参阅--tlsDisabledProtocols。For关于mongos, see--tlsDisabledProtocols.mongos,请参阅--tlsDisabledProtocols。
TLS/SSL Certificate Passphrase证书密码
If the certificate key files for 如果mongod / mongos are encrypted, include net.tls.certificateKeyFilePassword set to the passphrase.mongod/mongos的证书键文件已加密,请将net.tls.certificateKeyFilePassword设置为密码。
Tip
To avoid specifying the passphrase in cleartext, you can use an expansion value in the configuration file.为了避免以明文形式指定密码,您可以在配置文件中使用扩展值。
Tip
You can also configure using the command-line options:您还可以使用命令行选项进行配置:
For关于mongod, see--tlsCertificateKeyFilePassword.mongod,请参阅--tlsCertificateKeyFilePassword。For对于mongos, see--tlsCertificateKeyFilePassword.mongos,请参阅--tlsCertificateKeyFilePassword。
Online Certificate Rotation在线证书轮换
Starting in MongoDB 5.0, you can rotate the following certificate key files on-demand:从MongoDB 5.0开始,您可以按需轮换以下证书键文件:
TLS CertificatesCRL (Certificate Revocation List) files(on Linux and Windows platforms)(在Linux和Windows平台上)CA (Certificate Authority) files
To rotate one or more of these certificates:要轮换其中一个或多个证书,请执行以下操作:
Replace the certificate or certificates you wish to rotate on the filesystem, noting the following constraints:替换您希望在文件系统上轮换的一个或多个证书,注意以下限制:Each new certificate must have the same filename and same filepath as the certificate it is replacing.每个新证书必须具有与其替换的证书相同的文件名和文件路径。If rotating an encrypted如果轮换加密的TLS证书,其密码必须与旧证书的密码相同(如TLS Certificate, its password must be the same as the password for the old certificate (as specified to thecertificateKeyFilePasswordconfiguration file setting).certificateKeyFilePassword配置文件设置中指定的)。Certificate rotation does not support the interactive password prompt.证书轮换不支持交互式密码提示。
Connect将mongoshto themongodormongosinstance that you wish to perform certificate rotation on.mongosh连接到要对其执行证书轮换的mongod或mongos实例。Run the运行rotateCertificatescommand or thedb.rotateCertificates()shell method to rotate the certificates used by themongodormongosinstance.rotateCertificates命令或db.rotateCertificates()shell方法来轮换mongod或mongos实例使用的证书。
When certificate rotation takes place:证书轮换时:
Existing connections to the与mongodormongosinstance are not terminated, and will continue to use the old certificates.mongod或mongos实例的现有连接不会终止,并将继续使用旧证书。Any new connections will use the new certificates.任何新连接都将使用新证书。
Incorrect, expired, revoked, or missing certificate files will cause the certificate rotation to fail, but will not invalidate the existing TLS configuration or terminate the running 不正确、过期、吊销或丢失的证书文件将导致证书轮换失败,但不会使现有的TLS配置无效或终止正在运行的mongod or mongos process.mongod或mongos进程。
Previous to MongoDB 5.0, certificate rotation required downtime, and was typically performed during maintenance windows.在MongoDB 5.0之前,证书轮换需要停机,通常在维护窗口期间执行。
See 有关其他注意事项和完整使用说明,请参阅rotateCertificates or db.rotateCertificates() for additional considerations and full usage instructions.rotateCertificates或db.rotateCertificates()。
Run in FIPS Mode在FIPS模式下运行
Note
FIPS-compatible TLS/SSL is available only in MongoDB Enterprise. See Configure MongoDB for FIPS for more information.FIPS兼容的TLS/SSL仅在MongoDB Enterprise中可用。有关更多信息,请参阅配置MongoDB for FIPS。
See Configure MongoDB for FIPS for more details.有关更多详细信息,请参阅配置MongoDB for FIPS。
Next Steps后续步骤
To configure TLS/SSL support for clients, see TLS/SSL Configuration for Clients.要为客户端配置TLS/SSL支持,请参阅客户端的TLS/SSL配置。
Procedures (Using net.ssl Settings)程序(使用net.ssl设置)
net.ssl Settings)Note
MongoDB provides MongoDB提供了与net.tls settings (and --tls command-line options) that correspond to the net.ssl settings (and --ssl command-line options). net.tls设置(和--tls命令行选项)相对应的net.ssl设置(和--ssl命令行参数)。The new 新的tls settings provide identical functionality as the ssl settings since MongoDB has always supported TLS 1.0 and later.tls设置提供了与ssl设置相同的功能,因为MongoDB一直支持tls 1.0及更高版本。
The procedures in this section use the 本节中的过程使用net.ssl settings. For procedures using the net.tls aliases, see Procedures (Using net.tls Settings).net.ssl设置。有关使用net.tls别名的过程,请参阅过程(使用net.tls设置)。
Set Up mongod and mongos with TLS/SSL Certificate and Key使用TLS/SSL证书和键设置mongod和mongos
mongod and mongos with TLS/SSL Certificate and KeyThe following section configures 以下部分将配置mongod / mongos to use TLS/SSL connections. mongod/mongos以使用TLS/SSL连接。With these TLS/SSL settings, 通过这些TLS/SSL设置,mongod / mongos presents its certificate key file to the client. mongod/mongos向客户端提供其证书键文件。However, the 但是,mongod / mongos does not require a certificate key file from the client to verify the client's identity. mongod/mongos不需要客户端的证书键文件来验证客户端的身份。To require client's certificate key file, see Set Up 要要求客户端的证书键文件,请参阅使用客户端证书验证设置mongod and mongos with Client Certificate Validation instead.mongod和mongos。
To use TLS/SSL connections, include the following TLS/SSL settings in your 要使用TLS/SSL连接,请在mongod / mongos instance's configuration file:mongod/mongos实例的配置文件中包含以下TLS/SSL设置:
System SSL Certificate Store(Windows/macOS)
net.ssl.mode |
|
net.ssl.PEMKeyFile |
|
For example, consider the following configuration file for a 例如,考虑以下mongod instance:mongod实例的配置文件:
net:
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb.pem
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
dbPath: "/var/lib/mongodb"
processManagement:
fork: true
net:
bindIp: localhost,mongodb0.example.net
port: 27017System SSL Certificate Store(Windows/macOS)
You can use system SSL certificate stores for Windows and macOS. To use the system SSL certificate store, specify 您可以使用Windows和macOS的系统SSL证书存储。要使用系统SSL证书存储,请指定net.ssl.certificateSelector instead of specifying the certificate key file.net.ssl.certificateSelector,而不是指定证书键文件。
net.ssl.mode |
|
net.ssl.certificateSelector | Set to the property (either
|
For example, consider the following configuration file for a 例如,考虑以下mongod instance:mongod实例的配置文件:
net:
ssl:
mode: requireSSL
certificateSelector: subject="<CertificateCommonName>"
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
dbPath: "/var/lib/mongodb"
processManagement:
fork: true
net:
bindIp: localhost,mongodb0.example.net
port: 27017A 使用上述配置的mongod instance that uses the above configuration can only accept TLS/SSL connections:mongod实例只能接受TLS/SSL连接:
mongod --config <path/to/configuration/file>
See Connect to MongoDB Instances Using Encryption for more information on connecting with TLS/SSL.有关使用TLS/SSL连接的更多信息,请参阅使用加密连接到MongoDB实例。
Set Up mongod and mongos with Client Certificate Validation使用客户端证书验证设置mongod和mongos
mongod and mongos with Client Certificate ValidationThe following section configures 以下部分将配置mongod / mongos to use TLS/SSL connections and perform client certificate validation. With these TLS/SSL settings:mongod/mongos以使用TLS/SSL连接并执行客户端证书验证。使用这些TLS/SSL设置:
mongod/mongospresents its certificate key file to the client for verification.将其证书键文件呈现给客户端进行验证。mongod/mongosrequires a certificate key file from the client to verify the client's identity.需要来自客户端的证书键文件来验证客户端的身份。
To use TLS/SSL connections, include the following TLS/SSL settings in your 要使用TLS/SSL连接,请在mongod / mongos instance's configuration file:mongod/mongos实例的配置文件中包含以下TLS/SSL设置:
Note
You can use system SSL certificate stores for Windows and macOS. To use the system SSL certificate store, specify 您可以使用Windows和macOS的系统SSL证书存储。要使用系统SSL证书存储,请指定net.ssl.certificateSelector instead of specifying the certificate key file.net.ssl.certificateSelector,而不是指定证书键文件。
net.ssl.mode | Set to
|
net.ssl.PEMKeyFile |
|
net.ssl.CAFile |
|
For example, consider the following configuration file for a 例如,考虑以下mongod instance:mongod实例的配置文件:
net:
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/caToValidateClientCertificates.pem
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
dbPath: "/var/lib/mongodb"
processManagement:
fork: true
net:
bindIp: localhost,mongodb0.example.net
port: 27017
A 使用上述配置的mongod instance that uses the above configuration can only accept TLS/SSL connections and requires a valid certificate from its clients:mongod实例只能接受TLS/SSL连接,并要求其客户端提供有效证书:
mongod --config <path/to/configuration/file>
Clients must specify TLS/SSL connections and present their certificate key file to the instance. 客户端必须指定TLS/SSL连接,并向实例提供其证书键文件。See Connect to MongoDB Instances that Require Client Certificates for more information on connecting with TLS/SSL.有关使用TLS/SSL连接的更多信息,请参阅连接到需要客户端证书的MongoDB实例。
Tip
Block Revoked Certificates for Clients阻止客户端的吊销证书
To prevent clients with revoked certificates from connecting to the 为了防止证书被吊销的客户端连接到mongod or mongos instance, you can use a Certificate Revocation List (CRL).mongod或mongos实例,您可以使用证书吊销列表(CRL)。
To specify a CRL file, include 要指定CRL文件,请将net.ssl.CRLFile set to a file that contains revoked certificates.net.ssl.CRLFile设置为包含已吊销证书的文件。
For example:例如:
net:
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/caToValidateClientCertificates.pem
CRLFile: /etc/ssl/revokedCertificates.pem
Clients that present certificates that are listed in the 提供/etc/ssl/revokedCertificates.pem file are not able to connect./etc/ssl/revokedCertificates.pem文件中列出的证书的客户端无法连接。
Validate Only if a Client Presents a Certificate仅在客户端出示证书时进行验证
In most cases, it is important to ensure that clients present valid certificates. However, if you have clients that cannot present a client certificate or are transitioning to using a certificate, you may only want to validate certificates from clients that present a certificate. 在大多数情况下,确保客户端出示有效证书非常重要。但是,如果客户端无法提供客户端证书或正在转换为使用证书,您可能只想验证提供证书的客户端的证书。If the client presents a certificate, the certificate must be a valid certificate. All connections, including those that have not presented certificates, are encrypted using TLS/SSL.如果客户端提供证书,则证书必须是有效的证书。所有连接,包括那些没有提供证书的连接,都使用TLS/SSL进行加密。
To bypass client certificate validation for clients that do not present a certificate, include 若要绕过未提供证书的客户端的客户端证书验证,请将net.ssl.allowConnectionsWithoutCertificates set to true.net.ssl.allowConnectionsWithoutCertificates设置为true。
For example:例如:
net:
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/caToValidateClientCertificates.pem
allowConnectionsWithoutCertificates: true
A 使用这些设置运行的mongod / mongos running with these settings allows connection from:mongod/mongos允许从以下位置连接:
Clients that do not present a certificate.不提供证书的客户端。Clients that present a valid certificate.提供有效证书的客户端。
Note
To use 要将mongot with TLS, net.tls.allowConnectionsWithoutCertificates must be set to true. mongot与TLS一起使用,必须将net.tls.allowConnectionsWithoutCertificates证书设置为true。For details, see 有关详细信息,请参阅syncSource.replicaSet.tls.syncSource.replicaSet.tls。
See TLS/SSL Configuration for Clients for more information on TLS/SSL connections for clients.有关客户端TLS/SSL连接的更多信息,请参阅客户端的TLS/SSL配置。
Disallow Protocols不允许协议
To prevent MongoDB servers from accepting incoming connections that use specific protocols, include 为了防止MongoDB服务器接受使用特定协议的传入连接,请将net.ssl.disabledProtocols set to the disallowed protocols.net.ssl.disabledProtocols设置为不允许的协议。
For example, the following configuration prevents 例如,以下配置阻止mongod / mongos from accepting incoming connections that use either TLS1_0 or TLS1_1mongod/mongos接受使用TLS1_0或TLS1_1的传入连接
net:
ssl:
mode: requireSSL
PEMKeyFile: /etc/ssl/mongodb.pem
CAFile: /etc/ssl/caToValidateClientCertificates.pem
disabledProtocols: TLS1_0,TLS1_1
TLS/SSL Certificate PassphraseTLS/SSL证书密码
If the certificate key files for 如果mongod / mongos are encrypted, include net.ssl.PEMKeyPassword set to the passphrase.mongod/mongos的证书键文件已加密,请将net.ssl.PEMKeyPassword设置为密码。
Run in FIPS Mode在FIPS模式下运行
Note
FIPS-compatible TLS/SSL is available only in MongoDB Enterprise. See Configure MongoDB for FIPS for more information.FIPS兼容的TLS/SSL仅在MongoDB Enterprise中可用。有关更多信息,请参阅配置MongoDB for FIPS。
See Configure MongoDB for FIPS for more details.有关更多详细信息,请参阅配置MongoDB for FIPS。
Next Steps后续步骤
To configure TLS/SSL support for clients, see TLS/SSL Configuration for Clients.要为客户端配置TLS/SSL支持,请参阅客户端的TLS/SSL配置。