Question

Mongo TLS certificate from ENV

The digital-ocean hosted mongo-DB requires TLS authentication using the -tlsCAFile connection parameter. If possible, I would not like to commit the ca-certificate.crt into my github repo. So, the approach is to outsource the content of ca-certificate.crt into the app ENVs and then re-create the ‘physical’ file upon app start (echo $MONGO_CA_CRT > ca-certificate.crt && node app.js)

So far so good, but then upon connecting the connection gets refused as such:

{ MongoNetworkError: failed to connect to server [private-db-mongodb-mydb-sandbox-123.mongo.ondigitalocean.com:27017] on first connect [MongoNetworkError: self signed certificate in certificate chain] 

Thanks for any feedback.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

Indeed, not committing your certificate to GitHub is a good approach.

Regarding the error, have you specified the path to the certificate file in your connection string as follows tlsCAFile: './ca-certificate.crt'.

Also, can you verify that the certificate file has the correct content? You could use the cat command to check the content of the file.

Let me know how it goes. Best, Bobby