mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Allow SCRAM authentication, when pg_hba.conf says 'md5'.
If a user has a SCRAM verifier in pg_authid.rolpassword, there's no reason we cannot attempt to perform SCRAM authentication instead of MD5. The worst that can happen is that the client doesn't support SCRAM, and the authentication will fail. But previously, it would fail for sure, because we would not even try. SCRAM is strictly more secure than MD5, so there's no harm in trying it. This allows for a more graceful transition from MD5 passwords to SCRAM, as user passwords can be changed to SCRAM verifiers incrementally, without changing pg_hba.conf. Refactor the code in auth.c to support that better. Notably, we now have to look up the user's pg_authid entry before sending the password challenge, also when performing MD5 authentication. Also simplify the concept of a "doomed" authentication. Previously, if a user had a password, but it had expired, we still performed SCRAM authentication (but always returned error at the end) using the salt and iteration count from the expired password. Now we construct a fake salt, like we do when the user doesn't have a password or doesn't exist at all. That simplifies get_role_password(), and we can don't need to distinguish the "user has expired password", and "user does not exist" cases in auth.c. On second thoughts, also rename uaSASL to uaSCRAM. It refers to the mechanism specified in pg_hba.conf, and while we use SASL for SCRAM authentication at the protocol level, the mechanism should be called SCRAM, not SASL. As a comparison, we have uaLDAP, even though it looks like the plain 'password' authentication at the protocol level. Discussion: https://www.postgresql.org/message-id/6425.1489506016@sss.pgh.pa.us Reviewed-by: Michael Paquier
This commit is contained in:
		@@ -32,8 +32,7 @@ extern PasswordType get_password_type(const char *shadow_pass);
 | 
			
		||||
extern char *encrypt_password(PasswordType target_type, const char *role,
 | 
			
		||||
				 const char *password);
 | 
			
		||||
 | 
			
		||||
extern int get_role_password(const char *role, char **shadow_pass,
 | 
			
		||||
				  char **logdetail);
 | 
			
		||||
extern char *get_role_password(const char *role, char **logdetail);
 | 
			
		||||
 | 
			
		||||
extern int md5_crypt_verify(const char *role, const char *shadow_pass,
 | 
			
		||||
				 const char *client_pass, const char *md5_salt,
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ typedef enum UserAuth
 | 
			
		||||
	uaIdent,
 | 
			
		||||
	uaPassword,
 | 
			
		||||
	uaMD5,
 | 
			
		||||
	uaSASL,
 | 
			
		||||
	uaSCRAM,
 | 
			
		||||
	uaGSS,
 | 
			
		||||
	uaSSPI,
 | 
			
		||||
	uaPAM,
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@
 | 
			
		||||
#define SASL_EXCHANGE_FAILURE		2
 | 
			
		||||
 | 
			
		||||
/* Routines dedicated to authentication */
 | 
			
		||||
extern void *pg_be_scram_init(const char *username, const char *shadow_pass, bool doomed);
 | 
			
		||||
extern void *pg_be_scram_init(const char *username, const char *shadow_pass);
 | 
			
		||||
extern int pg_be_scram_exchange(void *opaq, char *input, int inputlen,
 | 
			
		||||
					 char **output, int *outputlen, char **logdetail);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user