MongoDB Self-signed SSL connection: SSL peer certificate validation failed

你说的曾经没有我的故事 提交于 2019-12-04 08:18:45
Mattis Asp

After some searching, it seems like this error is due to the fact that the hostname "CN" was incorrect.

From digitalocean:

Whenever you generate a CSR, you will be prompted to provide information regarding the certificate. This information is known as a Distinguised Name (DN). An important field in the DN is the Common Name (CN), which should be the exact Fully Qualified Domain Name (FQDN) of the host that you intend to use the certificate with.

Also from MongoDB documentation:

If your MongoDB deployment uses SSL, you must also specify the --host option. mongo verifies that the hostname of the mongod or mongos to which you are connecting matches the CN or SAN of the mongod or mongos‘s --sslPEMKeyFile certificate. If the hostname does not match the CN/SAN, mongo will fail to connect.

SOLUTION:

I regenerated the keys, replaced localhost with any other hostname in the CN = <hostname> and completed the guide by Wan Bachtiar.

Running the following command after completion worked:

$ mongo --port 27017 -u '<_username_>' -p '<_password_>' 
--authenticationDatabase "<_my db_>" --ssl --sslPEMKeyFile 
/etc/ssl/client.pem  --sslCAFile /etc/ssl/ca.pem --host localhost

Note: The MongoDB folows a strict ruling of who has access to what db, a quick test in the mongo shell:

> show dbs

return an error. However, my user actually only have access to the db specified in "<my db>", so looping through the rows in "<my db>" works perfectly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!