leafo / pgmoon

A pure Lua Postgres driver for use in OpenResty & more
MIT License
390 stars 93 forks source link

authentication exchange unsuccessful in postgresql 15 scram-sha-256 in scram_sha_256_auth #133

Open xiangnanscu opened 1 year ago

xiangnanscu commented 1 year ago

I use pg 15 with md5 auth, and I try to use scram_sha_256 with the following steps: I set password_encryption = scram_sha_256 in postgresql.conf and pg_hba.conf is:

local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

I debug in pgmoon init.lua in method scram_sha_256_auth I found the server_signature is CdDAYPZ7znlXaCStdwSMN+BoKUtbDY3cK5Pgidlg0QQ=, but the msg is SFATALVFATALC28P01Mpassword authentication failed for user "postgres"Fauth.cL326Rauth_failed. so the line local sent_server_signature = msg:match("v=([^,]+)") will be nil.