Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

MongoNetworkError: unable to get local issuer certificate

SetEnv MONGO_URL mongodb://:@XXXXXXXXX.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=/home/ec2-user/rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false

App 2291 output: MongoNetworkError: failed to connect to server [XXXXXX.docdb.amazonaws.com:27017] on first connect [Error: unable to get local issuer certificate
App 2291 output: at TLSSocket.onConnectSecure (_tls_wrap.js:1474:34)
App 2291 output: at TLSSocket.emit (events.js:310:20)
App 2291 output: at TLSSocket.EventEmitter.emit (domain.js:482:12)
App 2291 output: at TLSSocket._finishInit (_tls_wrap.js:917:8)
App 2291 output: at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:687:12) {
App 2291 output: name: ‘MongoNetworkError’,
App 2291 output: [Symbol(mongoErrorContextSymbol)]: {}
App 2291 output: }]

MongoNetworkError: [Error: unable to get local issuer certificate

Please check this link

I see you have posted on stackexchange too
There are couple of other threads on this error
May be the certificate is not from trusted source or your company rules not allowing it

Certificate is working fine if I connect via SSL to data base. It is not working if I use it from Apache. I am using phusion passenger for Meteor

This is likely a permission/access issue on /home/ec2-user/rds-combined-ca-bundle.pem

Whatever user apache/phusion is running as needs access to that file. Under a user directory this is unlikely to be the case.

@chris Thankyou for the response, I tried below fix, but still getting the same error.

I moved it to /var/www/medapp/rds-combined-ca-bundle.pem
-rwxr-xr-x 1 medappuser medappuser 43888 May 5 11:07 rds-combined-ca-bundle.pem

SetEnv MONGO_URL mongodb://:@XXXXXXXXX.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=/var/www/medapp/rds-combined-ca-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false

Sorry I assumed the driver took care of this.

You need to do something like this:
http://mongodb.github.io/node-mongodb-native/3.5/tutorials/connect/tls/#validate-server-certificate

Thanks a lot @chris, it is fixed now.

I am supposed to use tls=true&tlsCAFile=/var/www/covidapp/rds-combined-ca-bundle.pem instead of ssl=true&ssl_ca_certs=/var/www/medapp/rds-combined-ca-bundle.pem

2 Likes

Oh great, I missed that. :blush: