mtxr / vscode-sqltools

Database management for VSCode
https://vscode-sqltools.mteixeira.dev?utm_source=github&utm_medium=homepage-link
MIT License
1.49k stars 299 forks source link

Support connections over SSH #395

Open steffan-c opened 5 years ago

steffan-c commented 5 years ago

Great extension!

A common solution for production environments is to require a connection over an SSH tunnel. It is possible to achieve this by opening the tunnel on the command-line and then creating the DB connection to connect to localhost and whatever port has been used for the near end of the tunnel. However, it would be far more convenient to specify the tunnel as part of the DB connection (and so have SQLTools manage opening and closing the tunnel).

Most any other database UIs support this - for example, see the UI in Valentina Studio for a free example.

cbertozzi commented 5 years ago

+1 votes

mtxr commented 4 years ago

Hey guys, that's something I really want to do, but still have to work in some stuff before that.

Since we have native tunnels as a workaround, I don't consider this high priority for now. See https://github.com/mtxr/vscode-sqltools/issues/230#issuecomment-494624547

I won't close this because I feel we are close to work on this now. But for now, please, try using native tunnels, ok?

NelsWebDev commented 4 years ago

+1

TsimafeiTsykunou commented 4 years ago

+1

1yuv commented 4 years ago

+1 This would be much appreciated. Also have there been any progress or good news for us @mtxr 😄 ?

ianp commented 3 years ago

FYI: at least for Postgres you can do this via the native driver, you'll need to edit the connection in settings.json to add a section like this

"pgOptions": {
  "native": true,
  "ssl": { "rejectUnauthorized": false }
}

(ssl can just be true as well, but those settings are what I use to connect to a DB on Heroku)

Hipska commented 3 years ago

I won't close this because I feel we are close to work on this now. But for now, please, try using native tunnels, ok?

Hi @mtxr, what is the status on this?

pbassut commented 3 years ago

@mtxr well, yeah, you can do ssh tunnels for now but that's just an extra step and it won't be saved into vscode

mtxr commented 3 years ago

Still no updates on this folks, sorry for that.

Has been hard to maintain the project for the past few months, but I'm trying to get back on track.

PR's are welcome if anyone want's to take a chance on this one

elpapi42 commented 3 years ago

This will be a awesome feature, for a normal workflow the workaround is suboptimal

govindasharma1986 commented 3 years ago

+1 It would much appreciated!

pbelosa commented 2 years ago

+1 Needed this feature today and have installed beekeeper instead for now. Would love to see this!

lionslair commented 2 years ago

+1

gjsjohnmurray commented 2 years ago

How about using https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh and connecting VS Code over SSH to your remote server?

jbwl commented 1 year ago

+1

kfirufk commented 1 year ago

+1 still really need this

sluxzer commented 1 year ago

Looking for update for this one :)

I would love to help

tlil commented 1 year ago

How about using https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh and connecting VS Code over SSH to your remote server?

This works great for me :+1:

hunsakerbn commented 1 year ago

For 1 connection, native tunnels might be OK, but when I have many database sources, and want several of them to be active at the same time, then the tunnel information should be part of each databases connection information. Please add this feature.

Thanks.

TheNathanBlake commented 1 year ago

For 1 connection, native tunnels might be OK, but when I have many database sources, and want several of them to be active at the same time, then the tunnel information should be part of each databases connection information. Please add this feature.

Thanks.

+1 I'm in the same boat. Multiple hosts for multiple DB's means using shell to SSH is a mini pain that we don't have to endure with other DB tools.

gitlui commented 11 months ago

Hi there, as this is a feature I would need myself, and it is marked as "help wanted" I would like to try implementing it.

I was thinking about a simple, solution where one can just put some parameters in the configuration that are then passed to https://www.npmjs.com/package/tunnel-ssh to establish a tunnel.

It doesn't sound too bad right now.

What do you think? If you are fine with me trying, I will start on the Weekend.

gjsjohnmurray commented 11 months ago

@gitlui my initial thoughts:

  1. Add an sshTunnel object to the connection settings object, initially with optional properties port and username, e.g.

    {
    "name": "MySQL through tunnel",
    "server": "dbhost",
    "driver": "MySQL",
    "port": 5433,
    "database": "test_db",
    "username": "root",
    "askForPassword": false,
    "password": "root",
    "connectionTimeout": 15,
    "sshTunnel": {
    "port": 22, // default to 22 if not set
    "username": "jdoe" // default to same as connection username if not set
    },
    "mysqlOptions": {
    ...
    },
    }
  2. Enhance this function: https://github.com/mtxr/vscode-sqltools/blob/f7a7b998ab1c14000733a567dfcc1438d0f7f887/packages/plugins/connection-manager/extension-util.ts#L87-L97

adding something like this pseudocode right after line 95, conditional on connInfo.sshTunnel not being undefined and connInfo.server not being localhost (in order to prevent recursion in the event that the function is called on an already-tunnelled connection):

https://github.com/mtxr/vscode-sqltools/blob/f7a7b998ab1c14000733a567dfcc1438d0f7f887/packages/driver.mysql/src/extension.ts#L105-L120

except that I think the scopes (L105) should be ['sshTunnel', connInfo.name, sshUsername)] and the session.accessToken retrieved (L119) would be used for setting up the tunnel, not to update connInfo.password.

gitlui commented 11 months ago

Nice. I will try to do this! (sry, I used the wrong account first)

Dees7 commented 11 months ago

I think you should use both server and ssh-host separately. Cause usually DB listens localhost (not public name\ip). And you can't use localhost for ssh connecting. For me we have jump server (not DB host proper)

"server": "localhost",
"sshTunnel": {
   "sshhost": "my_jump_host",
   "port": 22, // default to 22 if not set
   "username": "jdoe" // default to same as connection username if not set
},
gitlui commented 11 months ago

I already started a bit with this topic but had not much time the last weeks. At work, we often have constellations where I need an SSH tunnel to a server which has a connection to the SQL DB on another server. So I would have treated them like 2 different IPs anyway. Additionally, I would like to add the possibility to select an ssh file to use, as I usually have different ones for different customers I work for. But I still need to invest a bit more time into understanding the project and how the connection will/should work.

lamualfa commented 6 months ago

+1

steal9pro commented 6 months ago

+1

ozkankirik commented 6 months ago

+1

mcmullinboy15 commented 4 months ago

+1

Cremesis commented 3 months ago

I wish this feature were already here :) +1

zazasa commented 3 months ago

+1

Misha-Rubanov commented 3 months ago

+1

liangshen001 commented 2 months ago

+1

paul-kilya commented 2 months ago

+1

Can't use this tool without this... :(

gjsjohnmurray commented 2 months ago

Some people have been able to use the technique mentioned in https://github.com/mtxr/vscode-sqltools/issues/395#issuecomment-1210700610

I know others are not able (or not permitted) to work this way on their target server. I'm not aware of any active development on this repository to implement another way.