要将当前使用密钥文件身份验证的自管理集群升级到 X.509身份验证,请使用以下滚动升级过程。
注意
MongoDB在支持 TLS 1.2+ 的系统上禁用对 TLS 1.0 和 TLS 1.1加密的支持。
升级过程(使用 tls 选项)
注意
MongoDB 提供与 net.ssl 设置(和 --ssl 命令行选项)相对应的 net.tls 设置(和 --tls 命令行选项)。由于 MongoDB 始终支持 TLS 1.0 及更高版本,因此新的 tls 设置可提供与 ssl 设置相同的功能。
The procedures in this section use the tls settings/options. For procedures using the ssl settings/options, see Upgrade Procedures (Using ssl Options).
tls使用 TLS/SSL 和密钥文件升级(使用 选项)集群
注意
The procedure uses the tls settings/options. For procedures using the ssl settings/options, see Clusters Currently Using TLS/SSL (Using ssl Options).
对于使用 TLS/SSL 和密钥文件身份验证的集群,要升级到 X.509集群身份验证,请使用以下滚动升级进程:
对于集群的每个成员,将以下设置添加到配置文件中并重新启动:
security.clusterAuthMode- 设置为
sendKeyFile。使用此设置值,每个节点将继续发送其密钥文件,以验证自身的成员身份。但是,每个节点都可以从其他节点接收密钥文件或 X.509 证书,以对这些节点进行身份验证。
net.tls.clusterFile- 设置为用于成员身份验证的节点证书密钥文件的相应路径。
mongod/mongos会向集群的其他成员提供此文件,以表明自己的成员身份。
包括其他TLS/SSL 选项以及适合您的特定配置的任何其他选项。
例如:
net: tls: mode: requireTLS certificateKeyFile: /etc/ssl/mongodb.pem CAFile: /etc/ssl/caToValidateReceivedCertificates.pem clusterFile: "/etc/ssl/myReplMembershipCertificateKeyFile.pem" security: clusterAuthMode: sendKeyFile keyFile: /my/securely/located/membershipkey replication: replSetName: myReplicaSet net: bindIp: localhost,mongodb0.example.net port: 27017 systemLog: destination: file path: "/var/log/mongodb/mongod.log" logAppend: true storage: dbPath: "/var/lib/mongodb" processManagement: fork: true 在继续之前,更新集群的所有节点以包含
security.clusterAuthMode和net.tls.clusterFile设置。连接到每个节点并使用
setParameter命令将clusterAuthMode更新为sendX509。 [1]db.adminCommand( { setParameter: 1, clusterAuthMode: "sendX509" } ) 使用
sendX509时,每个节点都会发送其net.tls.clusterFile来验证自己的成员身份。但是,每个节点都可以从其他节点接收密钥文件或 X.509 证书,以对这些节点进行身份验证。在继续之前,将集群的所有节点升级到此设置。
可选但推荐使用。最后,对于集群的每个节点,连接到该节点并使用
setParameter命令将clusterAuthMode更新为x509,以便仅使用 X.509 证书进行身份验证验证。[1]db.adminCommand( { setParameter: 1, clusterAuthMode: "x509" } ) 升级所有节点后,使用适当的 X.509 设置编辑配置文件,以确保在后续重新启动时,集群使用 X.509身份验证。示例:
net: tls: mode: requireTLS certificateKeyFile: /etc/ssl/mongodb.pem CAFile: /etc/ssl/caToValidateReceivedCertificates.pem clusterFile: "/etc/ssl/myReplMembershipCertificateKeyFile.pem" security.clusterAuthMode: x509 replication: replSetName: myReplicaSet net: bindIp: localhost,mongodb0.example.net port: 27017 systemLog: destination: file path: "/var/log/mongodb/mongod.log" logAppend: true storage: dbPath: "/var/lib/mongodb" processManagement: fork: true
提示
您也可以使用命令行选项而不是配置文件来配置 mongod和mongos:
对于
mongod,请参阅:---tlsMode---tlsCertificateKeyFile---tlsCAFile---tlsClusterFile---clusterAuthMode对于
mongos,请参阅:---tlsMode---tlsCertificateKeyFile---tlsCAFile---tlsClusterFile---clusterAuthMode
使用密钥文件而不是 TLS/SSL 更新(使用 tls 选项)集群
注意
The procedure uses the tls options. For procedures using the ssl settings/options, see Clusters Currently Not Using TLS/SSL (Using ssl Options).
对于使用密钥文件身份验证但未使用 TLS/SSL 的集群,要升级到 X.509 成员身份验证和 TLS/SSL 连接:
对于集群的每个成员,将以下设置添加到配置文件中并重新启动:
net.tls.mode- 设置为
allowTLS。 此值允许节点接受 TLS/SSL 和非 TLS/非 SSL 传入连接。 其传出连接不使用 TLS/SSL。
net.tls.certificateKeyFile- 设置为包含 TLS/SSL 证书和密钥的文件的路径。
mongod/mongos将此文件提供给其客户端以确定实例的身份。 使用 TLS/SSL 时必需。
net.tls.clusterFile- 设置为用于成员身份验证的节点证书密钥文件的相应路径。
mongod/mongos会向集群的其他成员提供此文件,以表明自己的成员身份。
net.tls.CAFile- 设置为包含用于验证收到证书的证书链的文件的路径。
security.clusterAuthMode- 设置为
sendKeyFile。这允许每个节点继续发送其密钥文件,以验证自己的成员身份。但是,每个节点都可以从其他节点接收密钥文件或 X.509 证书,以对这些节点进行身份验证。
包括其他TLS/SSL 选项以及适合您的特定配置的任何其他选项。
例如:
net: tls: mode: allowTLS certificateKeyFile: /etc/ssl/mongodb.pem clusterFile: "/etc/ssl/myReplMembershipCertificateKeyFile.pem" CAFile: /etc/ssl/caToValidateReceivedCertificates.pem security: clusterAuthMode: sendKeyFile keyFile: /my/securely/located/membershipkey replication: replSetName: myReplicaSet net: bindIp: localhost,mongodb0.example.net port: 27017 systemLog: destination: file path: "/var/log/mongodb/mongod.log" logAppend: true storage: dbPath: "/var/lib/mongodb" processManagement: fork: true 升级集群的所有节点以包含
net.tls.mode、net.tls.certificateKeyFile、net.tls.clusterFile和security.clusterAuthMode。连接到每个节点并使用
setParameter命令[1]执行以下操作:将
tlsMode更新为preferSSL。 将tlsMode设置为preferTLS时,该节点接受 TLS/SSL 和非 TLS/非 SSL 传入连接,并且其传出连接使用 TLS/SSL。将
clusterAuthMode更新为sendX509。将clusterAuthMode设立为sendX509后,每个节点都会发送其net.tls.clusterFile以验证自身的成员身份。但是,每个节点会继续接受来自其他节点的密钥文件或 X.509 证书,以对这些节点进行身份验证。
db.adminCommand( { setParameter: 1, tlsMode: "preferTLS" } ); db.adminCommand( { setParameter: 1, clusterAuthMode: "sendX509" } ); 在继续之前,将集群的所有节点升级到这些设置。
升级所有节点后,使用适当的 TLS/SSL 和 X.509 设置编辑配置文件,以确保在后续重新启动时,集群使用 X.509 身份验证。
net: tls: mode: preferTLS certificateKeyFile: /etc/ssl/mongodb.pem clusterFile: "/etc/ssl/myReplMembershipCertificateKeyFile.pem" CAFile: /etc/ssl/caToValidateReceivedCertificates.pem security: clusterAuthMode: sendX509 replication: replSetName: myReplicaSet net: bindIp: localhost,mongodb0.example.net port: 27017 systemLog: destination: file path: "/var/log/mongodb/mongod.log" logAppend: true storage: dbPath: "/var/lib/mongodb" processManagement: fork: true 注意
此时,
集群中的节点使用 TLS/SSL 连接。 但是,节点可以接受来自客户端应用程序的非 TLS/SSL 连接。
节点发送其 X.509 证书进行成员身份验证,但也可以接受来自其他节点的 X.509 证书或密钥文件以验证其他节点的成员资格。
要从客户端应用程序实施TLS/SSL 连接以及仅接受 X.509 进行成员身份验证,请参阅下一步。
可选但推荐使用。更新所有节点以仅使用
TLS/SSL连接和 X.509 证书进行成员身份验证。重要
This TLS/SSL connection requirement applies to all connections; that is, with the clients as well as with the members of the cluster. That is, clients must specify TLS/SSL connections and presents its certificate key file when connecting to the cluster. See Connect to a TLS-Enabled Replica Set for more information on connecting with TLS/SSL. See also Validate Only if a Client Presents a Certificate.
将
net.tls.mode更新为requireTLS,并将security.clusterAuthMode更新为x509。例如:
net: tls: mode: requireTLS certificateKeyFile: /etc/ssl/mongodb.pem clusterFile: "/etc/ssl/myReplMembershipCertificateKeyFile.pem" CAFile: /etc/ssl/caToValidateReceivedCertificates.pem security: clusterAuthMode: x509 replication: replSetName: myReplicaSet net: bindIp: localhost,mongodb0.example.net port: 27017 systemLog: destination: file path: "/var/log/mongodb/mongod.log" logAppend: true storage: dbPath: "/var/lib/mongodb" processManagement: fork: true
提示
您也可以使用命令行选项而不是配置文件来配置 mongod和mongos:
对于
mongod,请参阅:---tlsMode---tlsCertificateKeyFile---tlsCAFile---tlsClusterFile---clusterAuthMode对于
mongos,请参阅:---tlsMode---tlsCertificateKeyFile---tlsCAFile---tlsClusterFile---clusterAuthMode
升级过程(使用 ssl 选项)
注意
MongoDB 提供与 net.ssl 设置(和 --ssl 命令行选项)相对应的 net.tls 设置(和 --tls 命令行选项)。由于 MongoDB 始终支持 TLS 1.0 及更高版本,因此新的 tls 设置可提供与 ssl 设置相同的功能。
The procedures in this section use the ssl options. For procedures using the tls options, see Upgrade Procedures (Using tls Options).
当前使用 TLS/SSL 的集群(使用ssl 选项)
注意
The procedure uses the ssl options. For procedures using the tls options, see Clusters Currently Using TLS/SSL (Using ssl Options).
对于使用 TLS/SSL 和密钥文件身份验证的集群,要升级到 X.509集群身份验证,请使用以下滚动升级进程:
对于集群的每个节点,启动节点时,将选项
--clusterAuthMode设置为sendKeyFile,并将选项--sslClusterFile设置为节点证书的相应路径。 包括其他TLS/SSL 选项以及特定配置所需的任何其他选项。 例如:mongod --replSet <name> --sslMode requireSSL --clusterAuthMode sendKeyFile --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)> 通过此设置,每个节点将继续使用其密钥文件来验证自身的成员身份。不过,每个节点现在都可以接受来自其他成员的密钥文件或 X.509 证书,以对这些成员进行身份验证。将集群的所有节点升级到此设置。
然后,对于集群的每个节点,连接到该节点并使用
setParameter命令将clusterAuthMode更新为sendX509。 [1]例如,db.adminCommand( { setParameter: 1, clusterAuthMode: "sendX509" } ) 通过此设置,每个节点都会使用其 X.509 证书(在上一步中通过
--sslClusterFile选项指定)来验证自身的成员身份。但是,每个节点会继续接受来自其他节点的密钥文件或 X.509 证书,以对这些节点进行身份验证。将集群的所有节点升级到此设置。可选但推荐使用。最后,对于集群的每个节点,连接到该节点并使用
setParameter命令将clusterAuthMode更新为x509,以便仅使用 X.509 证书进行身份验证验证。[]示例:1db.adminCommand( { setParameter: 1, clusterAuthMode: "x509" } ) 升级所有节点后,使用适当的 X.509 设置编辑配置文件,以确保在后续重新启动时,集群使用 X.509身份验证。
有关各种模式及其说明,请参阅--clusterAuthMode 。
当前未使用 TLS/SSL 的集群(使用 ssl 选项)
注意
The procedure uses the ssl options. For procedures using the tls options, see Update (Using tls Options) Clusters Using Keyfile but Not TLS/SSL.
对于使用密钥文件身份验证但未使用 TLS/SSL 的集群,要升级到 X.509身份验证,请使用以下滚动升级进程:
对于集群的每个节点,启动节点时,将选项
--sslMode设置为allowSSL,将选项--clusterAuthMode设置为sendKeyFile,并将选项--sslClusterFile设置为节点证书的相应路径。 包括其他TLS/SSL 选项以及特定配置所需的任何其他选项。 例如:mongod --replSet <name> --sslMode allowSSL --clusterAuthMode sendKeyFile --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)> --sslMode allowSSL设置允许节点接受 TLS/SSL 和非 TLS/非 SSL 传入连接。 节点的传出连接不使用 TLS/SSL。--clusterAuthMode sendKeyFile设置允许每个节点继续使用其密钥文件来验证自身的成员身份。不过,每个节点现在都可以接受来自其他成员的密钥文件或 X.509 证书,以对这些成员进行身份验证。将集群的所有节点升级到这些设置。
然后,对于集群的每个节点,连接到该节点并使用
setParameter命令将sslMode更新为preferSSL,并将clusterAuthMode更新为sendX509。 [1]例如:db.adminCommand( { setParameter: 1, sslMode: "preferSSL", clusterAuthMode: "sendX509" } ) 将
sslMode设置为preferSSL时,该节点接受 TLS/SSL 和非 TLS/非 SSL 传入连接,并且其传出连接使用 TLS/SSL。将
clusterAuthMode设立为sendX509时,每个节点都会使用其 X.509 证书(在上一步中使用--sslClusterFile选项指定)来验证自身的成员身份。但是,每个节点会继续接受来自其他节点的密钥文件或 X.509 证书,以对这些节点进行身份验证。将集群的所有节点升级到这些设置。
可选但推荐使用。 最后,对于集群的每个节点,连接到该节点并使用
setParameter命令将sslMode更新为requireSSL,并将clusterAuthMode更新为x509。 [1]例如:db.adminCommand( { setParameter: 1, sslMode: "requireSSL", clusterAuthMode: "x509" } ) 将
sslMode设置为requireSSL时,节点仅使用 TLS/SSL 连接。将
clusterAuthMode设立为x509时,节点仅使用 X.509 证书进行身份验证。
有关各种模式及其说明,请参阅--clusterAuthMode 。
| [1] | ( 1 、 2 、 3 、 4 、 5 、 6 、 7 )作为使用setParameter命令的替代方法,您还可以使用适当的 TLS/SSL 和 x509 选项和值重新启动节点。 |