Search code examples
mongodbsslgrails

Grails: how to access mongodb via SSL


I wrote a grails 3.3 + mongo 4.0.4 app but in production the mongo server only accepts connections via SSL (self signed cert). I haven't found anywhere documentation on how to configure GORM for mongo (http://gorm.grails.org/latest/mongodb/manual/). There is an option (sslEnabled and I assume I should use the socketFactory) for using SSL enabled connections in grails but I'm not sure how to configure the connection


Solution

  • To whom it has the exact same issue with me, I still don't have a proper way of connecting to a mongodb from grails directly using SSL. The indirect solution that I've found is to deploy on the machine that runs grails a mongos client (mongo sharding client) enable SSL in order to connect to the database but leave the local connection without encryption. Thus, I can access the remote database securely via SSL but still connect using clear connection between mongos and grails. The mongos config should look like this:

    net:
      ssl:
        mode: preferSSL
        PEMKeyFile: /installDir/cert.pem
        CAFile: /installDir/chain.pem
        clusterFile: /installDir/cert.pem
    
      port: 27017
      bindIp: 0.0.0.0
    
    security:
      clusterAuthMode: x509
    

    The preferSSL allows mongos to connect using SSL to the database and still allow the grails app to connect cleartext to mongos