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

Feature request: Add support for SCRAM-SHA-256 password authentication #817

Closed
tinproject opened this issue Dec 14, 2018 · 14 comments
Closed

Comments

@tinproject
Copy link

Since PostgreSQL password authentication with SCRAM-SHA-256 method is available: https://www.postgresql.org/docs/10/auth-methods.html.

Currently this library fails to connect when trying to authenticate to a server that enforces scram-sha-256 method with: unknown authentication response: 10

Note: I'm currently having this problem with a project that vendors this library, but code at https://github.com/lib/pq/blob/master/conn.go#L1135 also lacks this authentication method.

@suppadeliux
Copy link

Hello,

I am also working with SCRAM-SHA-256, and i would love to be able to use it in my project.

it gives the error pq: unknown authentication response: 10

My project is developped with go and angular, and i am using Buffalo framework and Postgresql.

At the moment i am using md5, but seems to be deprecated.

I am hoping to fix this issue soon.

Thanks for the help.

@raz-varren
Copy link
Contributor

raz-varren commented Mar 4, 2019

Submitted a pull request for this: #833

@ptman
Copy link

ptman commented Apr 16, 2019

has now been added?

@raz-varren
Copy link
Contributor

Yes: #833

@raz-varren
Copy link
Contributor

There is nothing special you need to do on the client side to make a connection using scram-sha-256.

import(
	"database/sql"
	_ "github.com/lib/pq"
)

func main() {
	connstr := "dbname=mydb host=localhost port=5432 user=myuser password='mypassword'"
	pgdb, err := sql.Open("postgres", connstr)
	if err != nil {
		panic(err)
	}
	defer pgdb.Close()

	err = pgdb.Ping()
	if err != nil {
		panic(err)
	}
}

However your postgres database server will need to support scram-sha-256. I think it's only supported in version 10 and up. To enable scram-sha-256 connections, your pg_hba.config file needs to look something like this:

local    all    postgres                trust
host     all    all        0.0.0.0/0    scram-sha-256

@adubkov
Copy link

adubkov commented Jun 22, 2019

@raz-varren Thanks for reply.

But I still getting an error FATAL: password authentication failed for user "XXX"

This is section of my pg_hba.conf

local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust
local    all    postgres                trust
host all all all md5
host all all 0.0.0.0/0 scram-sha-256

This is how I create new user:

CREATE USER myuser WITH
  LOGIN
  NOSUPERUSER
  NOCREATEDB
  NOCREATEROLE
  INHERIT
  NOREPLICATION
  CONNECTION LIMIT -1
  ENCRYPTED
  PASSWORD 'scram-sha-256XXXXXXXXXXXX';

I can normally login with psql -U myuser -W but not with go or pgAdmin4...

@adubkov
Copy link

adubkov commented Jun 22, 2019

All right, apparently I create user in wrong way and the reason it worked with psql is because I run it locally.

I did this way and it solve the problem:

SET password_encryption = 'scram-sha-256';
ALTER ROLE myuser SET password_encryption = 'scram-sha-256';
ALTER ROLE myuser WITH PASSWORD 'mypassword';

@mnencia
Copy link

mnencia commented Jul 29, 2021

Why this issue is still open?

glours pushed a commit to docker/awesome-compose that referenced this issue Oct 12, 2021
pq updated due to issue with the latest postgress image "unknown authentication response: 10"
lib/pq#817

Signed-off-by: GanjMonk <solov333@gmail.com>
@joeycumines
Copy link

I believe I ran into the same thing as @adubkov, on upgrade from postgres 11 -> 14 by way of pg_dumpall. I'm using the default config bundled with the official docker image. My existing users had md5 password hashes. Once restored, I found that only things using this library were unable to connect.

The client side failed with the same error as mentioned above, while the server side logged this:

        Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
2021-12-29 04:23:31.871 UTC [74] FATAL:  password authentication failed for user "postgres"
2021-12-29 04:23:31.871 UTC [74] DETAIL:  User "postgres" does not have a valid SCRAM secret.

Yay maintenance-only project 😞

@Neustradamus
Copy link

Neustradamus commented Jan 11, 2022

@knz: Can you close this issue?

It has been merged here: #833.

Thanks in advance.

@jordanlewis
Copy link
Contributor

Hi @mjibson, could you please close this? Thank you!

@jordanlewis
Copy link
Contributor

cc @rafiss @otan? Sorry, I don't know who has permissions on this repo!

@jordanlewis
Copy link
Contributor

Thanks Matt!

Vixen0219 added a commit to Vixen0219/awesome_compose that referenced this issue May 6, 2024
pq updated due to issue with the latest postgress image "unknown authentication response: 10"
lib/pq#817

Signed-off-by: GanjMonk <solov333@gmail.com>
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

No branches or pull requests

10 participants