Search code examples
sshsails.jswaterline

Sails js SSH DB connection


I am trying to connect to a remote DB using SSH programatically from a web application.

I have been trying ssh2 module and I can connect to the remote server but what I would like to do is to connect directly to the tables in the DB.

I also tried tunnel-ssh in the bootstrap.js file so I can tunnel to the db but now what I believe is happening is that the db connection is starting before the tunnel is set up and therefore I am getting a Connection refused.

Is it possible to achieve this tunneling using some kind of configuration in the connections.js file of sails js? Any other suggestion?

Thanks


Solution

  • Finally what I did is using a docker-compose with 2 dockers 1) web app and 2) SSH client. My docker-compose file looks something like this:

        services:   
          db:
            image: agonza1/sshclient
            volumes:
              - .:/ssh
            command: "ssh -Ng -L 5432:localhost:5432 -i sshkey.pem -o StrictHostKeyChecking=no [email protected] -p 1234"
    
          web:
            build: .
            env_file:
              - .env
            ports:
              - "443:443"
            links:
              - db
            depends_on:
              - db
    

    where sshclient is just something like this: https://hub.docker.com/r/kroniak/ssh-client/~/dockerfile/