Repository navigation
feat(security): sign in with SCRAM-SHA-256 on the wire protocol - #112
Merged
Merged
Conversation
The wire protocol now signs in with SCRAM-SHA-256 (RFC 5802, RFC 7677), with tls-server-end-point channel binding (SCRAM-SHA-256-PLUS) over TLS. The password never crosses the connection, the client checks that the server knows the user's verifier, and a relayed exchange fails. - Users are stored as SCRAM verifiers in the PostgreSQL format. The first open converts the PBKDF2 hashes of older versions in place, without the passwords. - Unknown users get a salt derived from the name and a per-database secret and fail only at the last step, like a wrong password. - AUTHENTICATE ... PASSWORD over the wire protocol is refused with a message to upgrade the client; it still works in embedded sessions and in Studio. hstore connect turns a typed AUTHENTICATE into SCRAM. - CREATE USER and ALTER USER accept a verifier in place of a password, and hstore verifier prints one. - The sign-in throttle is split into reserve and complete so a two-step exchange holds its slot. - Version 0.2.0, because 0.1.0 clients cannot sign in any more.
… hashes The client now refuses a server that does not ask for the password, answers the first SASL message with anything but a challenge, names another user, or skips or fails its proof, and disconnects. A stored 0.1 hash equals SCRAM's SaltedPassword, so it is no longer turned into a verifier: such users are refused over SCRAM and get a fresh salt on their next clear-text sign-in through Studio or the embedded API. AUTHENTICATE wrapped in AT GENERATION or AS OF is refused, verifiers must use 4096 to 10000000 iterations, and passwords go through SASLprep on both sides.
…ins to the record - The shell refuses any script that mentions AUTHENTICATE unless it is a single statement it can turn into a SCRAM exchange, and answers 'disconnected' after it dropped a connection whose proof failed. - A SCRAM exchange only succeeds while the user's record is the one its verifier came from, and clear-text sign-ins keep the exact record they checked, so a password change or a drop and re-create during a sign-in is caught. - The Python client in the docs normalizes like the server; both agree on every code point. - Parse errors of scripts with AUTHENTICATE are not logged verbatim, and the old-password warning is logged once per user per 10 minutes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #109 (merge order: #111, #108, #109, then this). The diff against #109 is the SCRAM work only.
The wire protocol used to take
AUTHENTICATE user PASSWORD '…', so without TLS the password crossed the network in clear text. It now signs in with SCRAM-SHA-256 (RFC 5802, RFC 7677), the mechanism PostgreSQL uses:SCRAM-SHA-256-PLUSwithtls-server-end-pointchannel binding, so an exchange relayed through a man in the middle fails. The server rejects a client that announces binding support without using it on a TLS connection.SCRAM-SHA-256$iterations:salt$StoredKey:ServerKey). The old PBKDF2 hashes were exactly SCRAM'sSaltedPassword, so the first open converts them in place without the passwords; nobody has to reset anything. A version before this one cannot read converted records.AUTHENTICATE … PASSWORDover the wire is refused, without checking the password, withthis server no longer accepts passwords in clear text; upgrade your HStore client to version 0.2.0 or later, which signs in with SCRAM-SHA-256. The project version is now 0.2.0 for that reason.AUTHENTICATEkeeps working in embedded sessions and in Studio's console;hstore connectturns one typed at its prompt into a SCRAM exchange.CREATE USER/ALTER USERaccept a verifier in place of a password, and the newhstore verifierprints one, so a password need not reach the server even without TLS.Tests
ScramTest: the RFC 7677 example vector exactly (client-first, server-first, proof, server signature); wrong passwords and unknown users rejected alike, with a stable salt for unknown users; channel binding accepted with the right certificate hash and rejected with another; downgrade (yover TLS,-PLUSwithout TLS) rejected; 13 malformed messages; replays; verifier parse/encode; legacy hash conversion; our PBKDF2 matches a hand-written PBKDF2 over UTF-8 for a non-ASCII password.SecurityTest: stored verifiers, legacy records upgraded on reopen (and a second reopen writes nothing), verifier passwords inCREATE USER, weak verifiers rejected, SCRAM throughSessionwith throttling.ServerTest: clear-textAUTHENTICATEgets the upgrade message, unsupported mechanism and bad base64 are refused, SCRAM over TLS with channel binding, and every existing client test now signs in with SCRAM.hashlib/hmac) signs in against a running server over plain TCP (method=SCRAM-SHA-256) and over TLS with channel binding (method=SCRAM-SHA-256-PLUS), and is refused with a wrong password.ChangeLogReplayTestnow counts the one commit a new database makes when first opened (the SCRAM secret).