Mongo URI with self signed certificate

Viewed 4020

Im trying to get Mongo URI connections to work with a self signed cert.

Command line works just fine, so the following connects:

mongo mongodb://Qlik:Password1@mongobox.test:27017 --ssl --sslAllowInvalidCertificates

However, per the docs, there is no sslAllowInvalidCertificates=true option for URI connections, nor is there any way to feed a cert in (which would be a problem anyway on my stack)

The URI equivalent:

mongo "mongodb://Qlik:Password1@mongobox.test:27017/?ssl=true&sslAllowInvalidCertificates=true"

Results in:

2019-10-17T07:19:00.490+0000 E QUERY    [js] Error: couldn't connect to server mongobox.test:27017, connection attempt failed: SSLHandshakeFailed: SSL peer certificate validation failed: unable to get local issuer certificate :
connect@src/mongo/shell/mongo.js:344:17
@(connect):2:6
exception: connect failed

How do you get URI connections to work with self signed certs?

2 Answers
mongo --host example.test \
      --ssl \
      --tlsAllowInvalidCertificates \
      --username myUsername

Try this option:

tlsInsecure=true

The URI will be like this:

mongodb://Qlik:Password1@mongobox.test:27017/?tls=true&tlsInsecure=true&tlsCertificateKeyFile=PATH_TO_CLIENT_CERT&tlsCAFile=PATH_TO_CA_CERT
Related