sosedoff / pgweb

Cross-platform client for PostgreSQL databases
https://sosedoff.github.io/pgweb
MIT License
8.56k stars 723 forks source link

pgweb usage (connecting to database) #565

Closed GeertsP closed 1 year ago

GeertsP commented 2 years ago

Hi ,

I have installed pgweb on ubuntu 16.04.6 and by the looks of it succesfully. Subsequently I want to connect to a database instance created by the (crunchy) postgres operator (v5) and that runs as a pod within a namespace. If I do a port forward to this container like ">kubectl -n postgres-operator port-forward "pod/hippo-instance1-7n8f-0" 5432:5432" I can subsequently do a connect from a terminal like so ">psql -h localhost -U postgres" and after supplying my password I can access my database(s) in the cluster. Trying to do a similar thing with pgweb like ">pgweb --host localhost --user postgres --db oin_ms" (or variants thereof) it keeps complaining about "Error: pq: no pg_hba.conf entry for host "127.0.0.1", user "postgres", database "postgres", no encryption".
I don't see this described anywhere so please help me out on this. What should its contents be, where should I locate it to have it picked up by pgweb etc.

sosedoff commented 2 years ago

hello @GeertsP , could you try connecting via --host 127.0.0.1 ?

GeertsP commented 2 years ago

hello,
yes I tried, no difference

pgweb --host 127.0.0.1 --user postgres Pgweb v0.11.11 (git: db2a7a8aa5bc449e4efa78cada9c76c3fe33bc39) (go: go1.17.6) (build time: 2022-03-30T04:36:12Z) Connecting to server... Error: pq: no pg_hba.conf entry for host "127.0.0.1", user "postgres", database "postgres", no encryption

animentork commented 2 years ago

Could you show the relevant portion from pg_hba.conf?

The error message refers to the host trying to establish the connection, so it rejects this connection attempt from within the postgres container. I understand that you call pgweb from your Ubuntu host, from outside the container, that's why I find this error message a bit odd.

sosedoff commented 2 years ago

@animentork is right - there's gotta be something on the server side that does not allow connections. If you're running vanilla postgres from ubuntu os (or similar) it will only accept local connections using unix socket, extra configuration will be required in order to allow other types of connections. That's pretty easy to do though.

GeertsP commented 2 years ago

As I indicated earlier the server side of things is configured and deployed by the Crunchy Postges Operator and currently running in a container. I understand that the referenced pg_hba.conf should be located somewhere in that environment? If so I will try to connect into that with bash and see if I can find it. What I find a bit puzzling however is that the psql command which I think also connects from 127.0.0.1/localhost and user "postgres" is allowed and pgweb is not.
Will attach the requested file as soon as I have extracted it. Thanks Peter

GeertsP commented 2 years ago

please find pg_hba.conf file attached [pg_hba.txt](https://github.com/sosedoff/pgweb/files/8976349/pg_hba.txt)

sosedoff commented 2 years ago

Does your setup use any TLS for postgres?

animentork commented 2 years ago

Either one of these lines would be enough to accept the connection:

host    all             all              127.0.0.1/32           md5
host    all             all              0.0.0.0/0              md5
  1. Your connection is somehow interpreted as coming from 127.0.0.1/localhost. I still find this kind of NAT weird – but let's put that aside for a moment. What matters is that connections from 127.0.0.1 are explicitely and implicitely accepted.
  2. You try to connect to the database postgres with the user postgres, both of which are covered by the two all keywords.
  3. According to the error message and your pgweb call, you try to connect with SSL disabled, but the host keyword accepts both encrypted and unencrypted connections.

Of course, you can add --ssl=require to your pgweb call and see what happens. But from my view, it should work without it.

I'm beginning to think, your psql and pgweb aren't talking to the same database clusters. Does pgweb also live in a container, or is it on the same host as psql?

sosedoff commented 1 year ago

Closing since this is not a pgweb issue but a networking one. Feel free to reopen if you need extra help with triage.