canonical / pgbouncer-operator

A charmed operator for running PgBouncer on virtual machines.
https://charmhub.io/pgbouncer?channel=1/stable
Apache License 2.0
4 stars 4 forks source link

pgbouncer refuses to authenticate the application under which it is subordinate #245

Closed skatsaounis closed 3 months ago

skatsaounis commented 3 months ago

Steps to reproduce

1. Install postgresql `14/stable`, pgbouncer `1/edge` or `1/stable` with the default settings and relate them with a single Juju Terraform run.
2. Install maas-region latest/edge charm and relate it to pgbouncer.

Expected behavior

The maas-region charm receives the connection details through the dabatase relation and tries to run maas init region+rack --database-uri postgres://relation_id_9:HZjrAAmo5U0i37DVwUEba7FB@localhost:6432/maas_region_db. Details are coming through the relation. MAAS is initialized successfully.

Actual behavior

MAAS fails to initialize since when it receives the connection details and tries to authenticate a refusal error occurs (see logs).

Versions

Operating system: Ubuntu 22.04.4 LTS

Juju CLI: 3.4.3-genericlinux-amd64

Juju agent: 3.4.3

postgresql charm revision: 363 pgbouncer charm revision: 203

LXD: 5.0.3

Log output

2024-06-10 12:40:01 INFO juju.worker.uniter.operation runhook.go:186 ran "api-relation-changed" hook (via hook dispatching script: dispatch)
2024-06-10 12:40:06 INFO juju.worker.uniter.operation runhook.go:186 ran "maas-db-relation-joined" hook (via hook dispatching script: dispatch)
2024-06-10 12:40:09 INFO juju.worker.uniter.operation runhook.go:186 ran "maas-db-relation-changed" hook (via hook dispatching script: dispatch)
2024-06-10 12:40:17 INFO juju.worker.uniter.operation runhook.go:186 ran "maas-db-relation-changed" hook (via hook dispatching script: dispatch)
2024-06-10 12:40:22 INFO unit.maas-region/0.juju-log server.go:325 maas-db:9: endpoints changed on 2024-06-10 12:40:22.992699
2024-06-10 12:40:23 INFO unit.maas-region/0.juju-log server.go:325 maas-db:9: MAAS database endpoints have been changed to: localhost:6432
2024-06-10 12:40:23 INFO juju.worker.uniter.operation runhook.go:186 ran "maas-db-relation-changed" hook (via hook dispatching script: dispatch)
2024-06-10 12:40:25 INFO unit.maas-region/0.juju-log server.go:325 maas-db:9: database created at 2024-06-10 12:40:25.993849
2024-06-10 12:40:26 INFO unit.maas-region/0.juju-log server.go:325 maas-db:9: MAAS database credentials received for user 'relation_id_9'
2024-06-10 12:40:26 INFO unit.maas-region/0.juju-log server.go:325 maas-db:9: DSN: postgres://relation_id_9:HZjrAAmo5U0i37DVwUEba7FB@localhost:6432/maas_region_db
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60 Traceback (most recent call last):
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60   File "/snap/maas/35359/usr/lib/python3/dist-packages/django/db/backends/base/base.py", line 219, in ensure_connection
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60     self.connect()
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60   File "/snap/maas/35359/usr/lib/python3/dist-packages/django/utils/asyncio.py", line 33, in inner
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60     return func(*args, **kwargs)
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60   File "/snap/maas/35359/usr/lib/python3/dist-packages/django/db/backends/base/base.py", line 200, in connect
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60     self.connection = self.get_new_connection(conn_params)
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60   File "/snap/maas/35359/usr/lib/python3/dist-packages/django/utils/asyncio.py", line 33, in inner
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60     return func(*args, **kwargs)
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60   File "/snap/maas/35359/usr/lib/python3/dist-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60     connection = Database.connect(**conn_params)
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60   File "/snap/maas/35359/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 122, in connect
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60 psycopg2.OperationalError: connection to server at "localhost" (::1), port 6432 failed: Connection refused
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60    Is the server running on that host and accepting TCP/IP connections?
2024-06-10 12:40:28 WARNING unit.maas-region/0.maas-db-relation-changed logger.go:60 connection to server at "localhost" (127.0.0.1), port 6432 failed: FATAL:  password authentication failed

Additional context

After 5-10 minutes, if operation is manually performed, the connection is working and MAAS is initialized

github-actions[bot] commented 3 months ago

https://warthogs.atlassian.net/browse/DPE-4595

skatsaounis commented 3 months ago

For what it's worth, all charms are installed in the same machine, so it may relate to: https://github.com/canonical/pgbouncer-operator/issues/206. On the other hand, postgresql and pgbouncer charms are using different ports so I am not sure.

taurus-forever commented 3 months ago

Dear @skatsaounis , it is an provisional update, @dragomirp is investigating this issue on our side.

dragomirp commented 3 months ago

Hi, @skatsaounis, latest 1/edge (rev. 232) should fix the issue.