| Start |
|---|
How to configure a ReplicaSet to support TLS/SSL? Create the Root CertificateThe Root Certificate (aka CA File) will be used to sign and identify your certificate. To generate it, run the command below. Keep the root certificate and its key carefully, both will be used to sign your certificates. The root certificate might be used by your client as well. Generate the Certificate Requests and the Private KeysWhen generating the Certificate Signing Request (aka CSR), input the exact hostname (or IP) of your node in the Common Name (aka CN) field. The others fields must have exactly the same value. You might need to modify your /etc/hosts file. The commands below will generate the CSR files and the RSA Private Keys (4096 bits). You must generate one CSR for each node of your ReplicaSet. Remember that the Common Name is not the same from one node to another. Don't base multiple CSRs on the same Private Key. You must now have 3 CSRs and 3 Private Keys. Sign your Certificate RequestsUse the CA File (ca.pem) and its Private Key (ca.key) generated previously to sign each Certificate Request by running the commands below. You must sign each CSR. Your must now have 3 CSRs, 3 Private Keys and 3 self-signed Certificates. Only the Private Keys and the Certificates will be used by MongoDB. Each certificate corresponds to one node. Remember carefully which CN / hostname your gave to each CSR. Concat each Node Certificate with its keyRun the commands below to concat each Node Certificate with its key in one file (MongoDB requirement). Your must now have 3 PEM files. Deploy your ReplicaSetWe will assume that your pem files are located in your current folder as well as data/data1, data/data2 and data/data3. Run the commands below to deploy your 3 Nodes ReplicaSet listening on port 27017, 27018 and 27019. You now have a 3 Nodes ReplicaSet deployed on your local environment and all their transactions are encrypted. You cannot connect to this ReplicaSet without using TLS. Deploy your ReplicaSet for Mutual SSL / Mutual TrustTo force your client to provide a Client Certificate (Mutual SSL), you must add the CA File when running your instances. You now have a 3 Nodes ReplicaSet deployed on your local environment and all their transactions are encrypted. You cannot connect to this ReplicaSet without using TLS or without providing a Client Certificate trusted by your CA. |
How to connect your Client (Mongo Shell) to a ReplicaSet? No Mutual SSLIn this example, we might use the CA File (ca.pem) that you generated during the "How to configure a ReplicaSet to support TLS/SSL?" section. We will assume that the CA file is located in your current folder. We will assume that your 3 nodes are running on mongo1:27017, mongo2:27018 and mongo3:27019. (You might need to modify your /etc/hosts file.) From MongoDB 3.2.6, if your CA File is registered in your Operating System Trust Store, you can connect to your ReplicaSet without providing the CA File. Otherwise you must provide the CA File. You are now connected to your ReplicaSet and all the transactions between your Mongo Shell and your ReplicaSet are encrypted. With Mutual SSLIf your ReplicaSet asks for a Client Certificate, you must provide one signed by the CA used by the ReplicaSet Deployment. The steps to generate the Client Certificate are almost the same as the ones to generate the Server Certificate. Indeed, you just need to modify the Common Name Field during the CSR creation. Instead of providing 1 Node Hostname in the Common Name Field, you need to provide all the ReplicaSet Hostnames separated by a comma. You might face the Common Name size limitation if the Common Name field is too long (more than 64 bytes long). To bypass this limitation, you must use the SubjectAltName when generating the CSR. Then you sign the CSR using the CA certificate and key. Finally, you concat the key and the signed certificate. To connect to your ReplicaSet, you can now provide the newly generated Client Certificate. You are now connected to your ReplicaSet and all the transactions between your Mongo Shell and your ReplicaSet are encrypted. |
Read Article
https://develop.horje.com/learn/1434/reference