DataGrip doesn't apply the correct port with SSH tunnels

Completed

Hi-

I'm trying to SSH tunnel through a bastion server to the database server. The problem is that after correctly setting up the SSH tunnel, DataGrip is connecting to the wrong port:

2018-07-16 16:58:14,291 [7127126] INFO - taSourceSshTunnelConfiguration - SSH tunnel created: 59845:databasehost:5433 
2018-07-16 16:58:14,307 [7127142] INFO - ution.rmi.RemoteProcessSupport - /Applications/DataGrip.app/Contents/jdk/Contents/Home/jre/bin/java -Djava.net.preferIPv4Stack=true -Djava.rmi.server.hostname=127.0.0.1 -Duser.timezone=UTC -Dfile.encoding=UTF-8 -classpath /Applications/DataGrip.app/Contents/lib/util.jar:/Applications/DataGrip.app/Contents/lib/trove4j.jar:/Applications/DataGrip.app/Contents/lib/groovy-all-2.4.12.jar:/Applications/DataGrip.app/Contents/plugins/DatabaseTools/lib/jdbc-console.jar:/Applications/DataGrip.app/Contents/plugins/DatabaseTools/lib/dekaf-single-2.0.0.353.jar:/opt/vertica/java/lib/vertica-jdk5-6.1.2-0.jar com.intellij.database.remote.RemoteJdbcServer com.vertica.jdbc.Driver
2018-07-16 16:58:14,574 [7127409] INFO - ution.rmi.RemoteProcessSupport - Port/ID: 48130/RemoteDriverImpl2845dc40
2018-07-16 16:58:14,598 [7127433] INFO - urce.DatabaseConnectionManager - Connecting as: brian
2018-07-16 16:58:14,599 [7127434] INFO - urce.DatabaseConnectionManager - Connecting to: jdbc:vertica://localhost:59845/mydb 
2018-07-16 16:58:14,685 [7127520] WARN - urce.DatabaseConnectionManager - Connecting to: jdbc:vertica://localhost:59845/mydb 
2018-07-16 16:58:14,686 [7127521] WARN - urce.DatabaseConnectionManager - [HY000][100176] [Vertica][VJDBC](100176) Failed to connect to host localhost on port 5433. Reason: Connection refused (Connection refused)

To connect to Vertica I'm using the JDBC driver and a custom URL template in DataGrip which includes the host and port. Based on the log statements it seems that DataGrip is able to correctly rewrite the connection string to jdbc:vertica://localhost:59845/mydb ... but then the error message from the Vertica driver reveals that it's being given the remote port (5433) after all, rather than the random local port (59845) used by the SSH tunnel.

I can create the tunnel myself manually and hardcode my local tunnel port in the DataGrip data source configuration, and that works fine. But it would be more convenient for DataGrip's ssh tunnel feature to create the tunnel automatically on demand.

5 comments
Comment actions Permalink
Official comment

Since DataGrip 2019.1 DataGrip allows you to provide proxy and local ports for proper connection:

Comment actions Permalink

@Brian Gordon
You need to create ssh config file and then to choose Auth type: `OpenSSH config and authentication agent`


e.g.:

Host jumphost
    HostName 192.168.99.100
    User docker
    Port 22
    IdentityFile ~/.ssh/id_rsa_1

Host 172.17.0.? !172.17.0.3
    User docker
    Port 2222
    ProxyCommand ssh -q -W %h:%p jumphost
0
Comment actions Permalink

Hey vasily-

(Sorry for the long delay in replying)

Yes, I already have my .ssh/config file configured correctly. And I have chosen "OpenSSH config and authentication agent."

Like I said, DataGrip sets up the SSH tunnel and seems to correctly rewrite the connection string to jdbc:vertica://localhost:[local tunnel port]/mydb but the connection string that the vertica driver ends up receiving is jdbc:vertica://localhost:[remote port]/mydb. The driver needs to know how to reach the tunnel, but is given the wrong port. I think this must be a bug in DataGrip. I'm using version 2018.2.4.

0
Comment actions Permalink

These two lines from DataGrip's logs, one right after another, I think demonstrates what I'm saying:

2018-09-04 16:18:25,813 [346213130] WARN - urce.DatabaseConnectionManager - Connecting to: jdbc:vertica://localhost:52001/nv_warehouse 
2018-09-04 16:18:25,813 [346213130] WARN - urce.DatabaseConnectionManager - [HY000][100176] [Vertica][VJDBC](100176) Failed to connect to host localhost on port 5433. Reason: Connection refused (Connection refused)
1
Comment actions Permalink

I am experiencing same issue and it seems like a bug indeed. Setting up the SSH tunnel with default 22 port and also localhost Postgres is running on the server in port 5432. But for some reason when trying to connect to DB via SSH tunnel, DataGrip tries to connect to port 58455:

Connecting to: <jdbc:postgresql://localhost:58455/postgres>
[08001] The connection attempt failed

I am running DataGrip version 2018.3.3 on Windows platform.

0

Please sign in to leave a comment.