RocketChat / Docker.Official.Image

Docker hub - community managed image
293 stars 218 forks source link

Support for mongo db ssl connection? #134

Closed ripreal closed 2 years ago

ripreal commented 3 years ago

I'd like to use specific third-party mongo cloud provider. The povider that i've chosen support only one way to make connection - via ssl. For example my connection string looks something similar to this.

mongodb://user:pwd@host:27017/?replicaSet=rs01&authSource=database&ssl=true

In addition i also have to pass certificate inside connection options. (*.pem file) My questions is how can i pass certificate file with rocketchat dockerfile?

Without certificate when i run rocketchat docker container i get error:

 MongoNetworkError: failed to connect to server [rc1c-5g5vr3tzsfdxjdz9.mdb.yandexcloud.net:27018] on first connect [Error: self signed certificate in certificate chain
 at TLSSocket.onConnectSecure (_tls_wrap.js:1501:34)
 at TLSSocket.emit (events.js:315:20)
 at TLSSocket._finishInit (_tls_wrap.js:936:8)
 at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:710:12) {
 name: 'MongoNetworkError'

My docker-compose:

version: '3.6'
services:

  rocketchat:
    image: rocket.chat:latest
    environment:
      - ROOT_URL=http://localhost
      - MONGO_URL=mongodb://user:pwd@host:27017/?replicaSet=rs01&authSource=database&ssl=true
    ports:
      - "3020:3000"
ripreal commented 3 years ago

UPDATE

I found out about MONGO_OPTIONS environment variable https://docs.rocket.chat/installation/manual-installation/mongo-options but still cannot understand how to pass path to SSL certificate correctly

iraj465 commented 3 years ago

@ripreal They provided this.

export TLS_CRT=$(cat /pems/tls.crt | awk '{printf "%s\\n",$0} END {print ""}')
export PEM=$(cat /pems/mongo.pem | awk '{printf "%s\\n",$0} END {print ""}')
export KEY=$(cat /pems/mongo.key | awk '{printf "%s\\n",$0} END {print ""}')
# now insert all the credentials into the JSON OPTIONS string
export MONGO_OPTIONS='{"sslCA":["'${TLS_CRT}'"],"sslCert":"'${PEM}'","sslKey":"'${KEY}'"}' 

Have you tried exporting this variables for the MONGO OPTIONS environment variable to work? You need to replace your SSL certificate, PEM and KEY by renaming the path to the export variables TLS_CRT, PEM , KEY noted above.

arifulislamat commented 2 years ago

Hello @ripreal do you able to solved it? I am having the same issue.

ripreal commented 2 years ago

No. Now i'm using plain connection instead with another mongo provider