pgadmin-org / pgadmin-org/pgadmin4

User input for the bind_address *and* the local port when opening an SSH tunnel

Open
#6,903 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature
Dominant language
Python
Stars
3.8k
Forks
891
Avg merge
4d 7h
Merged PRs (30d)
8

Description

Hello,

when one would like to connect to a database on a remote server which does not expose the database port to the outside world, one usually create an SSH Tunnel, and then connect to the database using the local port of the tunnel.

E.g. with a standard PostgreSQL installation:

$ ssh -f -N -L 5433:127.0.0.1:5432 username@remote.server.org

$ psql -d postgres://postgres@localhost:5433/theremotedatabase

Achieving the same in a dockerized pgadmin4 environment is usually done by filling two different tabs when registering a new server; the "Connection" and the "SSH Tunnel" tabs.

image

image

But there is no way to specify the tunnel local port (5433 in the CLI example above).

What I wish is something as follow:

image

where one can specify the tunnel local port.

And if needed, also the tunnel local interface either by entering interface:port in a single field or by adding a second new field specifically for the interface (which, by default is 0.0.0.0 <- from what I noticed, this value is already the one pgadmin4 uses), because one may want to also specify the interface IP, e.g. : ssh -f -N -L 168.192.0.1:5433:127.0.0.1:5432 username@remote.server.org)

So, to summarize :

image

(maybe the wording to be used has to be adapted; I'm not an SSH expert but according to the help of the sshcommand:
-L [bind_address:]port:host:hostport)

Why am I asking?

Because I try to connect (using SSH tunnels) to two different remote servers, having each the same database setup (one server with a production DB and another with a testing DB). The only difference between those databases is the password (dbname and username are the same). So, because the local forwarding port of the SSH tunnel is randomly assigned by pgadmin4, I have to use a wildcard * in the .pgpass file that I feed into my pgadmin4 docker container. Therefore, the entry in the .pgpass file for the prod server is localhost:*:dbname:username:password_prod and for the testing localhost:*:dbname:username:password_testing.
So I can connect to the production but not to the testing database because the first match of the password in the .pgpass file is for the production database.
Being able to differentiate the servers by specifying the local forwarding port of the SSH tunnel would solve this, but for that, it has to be manually set up by the user. Hence my feature request.

Thanks for reading and also for the great work behind pgadmin4!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Connection and SSH Tunnel tabs and investigate how pgAdmin currently chooses the tunnel's local port. Done means users can specify the local forwarding port and bind address when configuring an SSH tunnel, allowing separate tunnels to use distinct ports.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases, networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.