Skip to content

Commit 2aaab3b

Browse files
dimitrivkj-db
andauthored
[Hadron] Always run databricks auth hook (#27) (#696)
Change to always allow auth hook to run because we want to reject password based login for databricks identities. Corresponding hadron PR for CI: https://github.com/databricks-eng/hadron/pull/752 Co-authored-by: Vikas Jain <[email protected]>
1 parent 6795145 commit 2aaab3b

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

src/backend/libpq/auth.c

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -782,32 +782,58 @@ CheckPasswordAuth(Port *port, const char **logdetail)
782782
int result;
783783
char *shadow_pass;
784784

785+
/* BEGIN HADRON */
786+
787+
/*
788+
* this flag is passed to databricks auth hook and is updated by the hook
789+
* to false if we should continue with password auth. This is by default
790+
* true so that we don't accidentally do password auth if there is some
791+
* bug in the hook. It's better to rely on the hook to set it explicitly
792+
* false to continue with password auth.
793+
*/
794+
bool skip_password_auth = true;
795+
796+
/* END HADRON */
797+
785798
sendAuthRequest(port, AUTH_REQ_PASSWORD, NULL, 0);
786799

787800
passwd = recv_password_packet(port);
788801
if (passwd == NULL)
789802
return STATUS_EOF; /* client wouldn't send password */
790803

791-
shadow_pass = get_role_password(port->user_name, logdetail);
792-
if (shadow_pass)
804+
/* BEGIN HADRON */
805+
elog(DEBUG1, "Databricks: before authentication hook");
806+
807+
if (DatabricksAuthentication_hook)
793808
{
794-
result = plain_crypt_verify(port->user_name, shadow_pass, passwd,
795-
logdetail);
809+
result = (*DatabricksAuthentication_hook) (port, passwd, &skip_password_auth, logdetail);
796810
}
797811
else
812+
{
813+
/* If hook is not set, do the password auth by default */
814+
skip_password_auth = false;
798815
result = STATUS_ERROR;
816+
}
799817

800-
if (result != STATUS_OK && DatabricksAuthentication_hook)
801-
{
802-
elog(LOG, "Calling DatabricksAuthentication_hook");
818+
elog(DEBUG1, "Databricks: after authentication hook");
803819

804-
result = (*DatabricksAuthentication_hook)(port, passwd);
820+
/* only try PG password auth if the hook didn't return STATUS_OK and */
821+
/* the hook set the skip_password_auth flag to false */
822+
if (result != STATUS_OK && !skip_password_auth)
823+
{
824+
shadow_pass = get_role_password(port->user_name, logdetail);
825+
if (shadow_pass)
826+
{
827+
result = plain_crypt_verify(port->user_name, shadow_pass, passwd,
828+
logdetail);
829+
}
830+
else
831+
result = STATUS_ERROR;
805832

806-
elog(LOG, "DatabricksAuthentication_hook returned: %d", result);
833+
if (shadow_pass)
834+
pfree(shadow_pass);
807835
}
808-
809-
if (shadow_pass)
810-
pfree(shadow_pass);
836+
/* END HADRON */
811837
pfree(passwd);
812838

813839
if (result == STATUS_OK)

src/include/libpq/auth.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@ typedef char *(*auth_password_hook_typ) (char *input);
3434
/* Default LDAP password mutator hook, can be overridden by a shared library */
3535
extern PGDLLIMPORT auth_password_hook_typ ldap_password_hook;
3636

37-
/* Hook for databricks authentication */
38-
typedef int (*DatabricksAuthentication_hook_type) (Port *, char *);
37+
/* Hook for databricks authentication
38+
* returns STATUS_OK on success, STATUS_ERROR on failure
39+
* skip_passwd_auth is set to true/false if password authentication should be tried or not on STATUS_ERROR
40+
* */
41+
typedef int (*DatabricksAuthentication_hook_type) (Port *port,
42+
const char *passwd,
43+
bool *skip_passwd_auth,
44+
const char **logdetail);
3945
extern PGDLLIMPORT DatabricksAuthentication_hook_type DatabricksAuthentication_hook;
4046

4147
#endif /* AUTH_H */

0 commit comments

Comments
 (0)