Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCRAM authentication fails #155

Closed
brockhaywood opened this issue Feb 5, 2022 · 1 comment · Fixed by #193
Closed

SCRAM authentication fails #155

brockhaywood opened this issue Feb 5, 2022 · 1 comment · Fixed by #193

Comments

@brockhaywood
Copy link

Hi there,

I'm trying to setup on dyno pgbouncers connecting to our external timescaledb (postgres) instances. It seems as though something on the postgres side of things is not compatible with this pgbouncer.

I'm seeing the following in the logs:

 2022-02-05 03:23:51.296 UTC [59] LOG S-0x556d5e181b30: db1/tsdbadmin@34.231.255.115:34451 new connection to server (from 172.17.142.26:57916)
2022-02-05T03:23:51.301451+00:00 app[web.1]: 2022-02-05 03:23:51.301 UTC [59] LOG S-0x556d5e181b30: db1/tsdbadmin@34.231.255.115:34451 SSL established: TLSv1.3/TLS_AES_256_GCM_SHA384/ECDH=prime256v1
2022-02-05T03:23:51.302486+00:00 app[web.1]: 2022-02-05 03:23:51.302 UTC [59] ERROR S-0x556d5e181b30: db1/tsdbadmin@34.231.255.115:34451 cannot do SCRAM authentication: wrong password type
2022-02-05T03:23:51.302490+00:00 app[web.1]: 2022-02-05 03:23:51.302 UTC [59] LOG S-0x556d5e181b30: db1/tsdbadmin@34.231.255.115:34451 closing because: failed to answer authreq (age=0s)
2022-02-05T03:23:51.324906+00:00 app[web.1]: 2022-02-05 03:23:51.324 UTC [59] LOG C-0x556d5e17ad90: db1/tsdbadmin@127.0.0.1:53106 login attempt: db=db1 user=tsdbadmin tls=no
2022-02-05T03:23:51.324928+00:00 app[web.1]: 2022-02-05 03:23:51.324 UTC [59] LOG C-0x556d5e17ad90: db1/tsdbadmin@127.0.0.1:53106 closing because: pgbouncer cannot connect to server (age=0s)
2022-02-05T03:23:51.324944+00:00 app[web.1]: 2022-02-05 03:23:51.324 UTC [59] WARNING C-0x556d5e17ad90: db1/tsdbadmin@127.0.0.1:53106 pooler error: pgbouncer cannot connect to server
2022-02-05T03:23:51.326682+00:00 app[web.1]: 2022-02-05 03:23:51.326 UTC [59] LOG C-0x556d5e17ad90: db1/tsdbadmin@127.0.0.1:53108 login attempt: db=db1 user=tsdbadmin tls=no

I would assume the important bit is the cannot do SCRAM authentication: wrong password type.

Any suggestions on a workaround?

@mrrooijen
Copy link

Ran into this exact issue today.

PostgreSQL 14 changed the default password hashing algorithm from MD5 to SCRAM-SHA-256.

To set it back to md5:

set password_encryption TO 'md5';

Then change a new password (or re-enter the existing one):

\password

Alternatively, if you're using Timescale Cloud you can do this in their UI.

Sidebar > Services > (Your Service) > Operations > Service Management > Reset Password

When resetting it'll provide the option to hash using either SCRAM-SHA-256 or MD5. Select MD5 for compatibility with pgbouncer.


Are there any plans to make the pgbouncer buildpack scram-sha-256 compatible?

mble-sfdc added a commit that referenced this issue May 21, 2024
In order to support SCRAM support for the new Heroku Postgres
"Essential" plans, we need to shift from MD5 hashed passwords in
`auth_file` to plain text. This does not materially change the threat
model, as anyone with dyno access can read the passwords from the
environment just as well as the file.

See: https://www.pgbouncer.org/config.html#authentication-file-format
for more.

This commit switches the `auth_type` to `scram-sha-256` and also pushes
`server_tls_sslmode` up to `require` over `prefer`.

Why not use a method like `auth_query`? Exposing something like
`pg_authid` or `pg_shadow` in a safe way via a `SECURITY DEFINER`
function is extremely challenging in a multi-tenant environment. This
may change in the future.

Fixes #155.

Ref: https://gus.my.salesforce.com/a07EE00001rjvVBYAY
mble-sfdc added a commit that referenced this issue May 21, 2024
In order to support SCRAM support for the new Heroku Postgres
"Essential" plans, we need to shift from MD5 hashed passwords in
`auth_file` to plain text. This does not materially change the threat
model, as anyone with dyno access can read the passwords from the
environment just as well as the file.

See: https://www.pgbouncer.org/config.html#authentication-file-format
for more.

This commit switches the `auth_type` to `scram-sha-256` and also pushes
`server_tls_sslmode` up to `require` over `prefer`.

Why not use a method like `auth_query`? Exposing something like
`pg_authid` or `pg_shadow` in a safe way via a `SECURITY DEFINER`
function is extremely challenging in a multi-tenant environment. This
may change in the future.

Fixes #155.

Ref: https://gus.my.salesforce.com/a07EE00001rjvVBYAY
troycoll pushed a commit that referenced this issue May 23, 2024
* maint: enable SCRAM support

In order to support SCRAM support for the new Heroku Postgres
"Essential" plans, we need to shift from MD5 hashed passwords in
`auth_file` to plain text. This does not materially change the threat
model, as anyone with dyno access can read the passwords from the
environment just as well as the file.

See: https://www.pgbouncer.org/config.html#authentication-file-format
for more.

This commit switches the `auth_type` to `scram-sha-256` and also pushes
`server_tls_sslmode` up to `require` over `prefer`.

Why not use a method like `auth_query`? Exposing something like
`pg_authid` or `pg_shadow` in a safe way via a `SECURITY DEFINER`
function is extremely challenging in a multi-tenant environment. This
may change in the future.

Fixes #155.

Ref: https://gus.my.salesforce.com/a07EE00001rjvVBYAY

* update tests

* add updates from feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants