Skip to content

Commit a42351f

Browse files
dimitrivkj-db
andauthored
[Hadron] Always run databricks auth hook (#27) (#694)
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 7cf4a33 commit a42351f

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
@@ -781,32 +781,58 @@ CheckPasswordAuth(Port *port, const char **logdetail)
781781
int result;
782782
char *shadow_pass;
783783

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

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

790-
shadow_pass = get_role_password(port->user_name, logdetail);
791-
if (shadow_pass)
803+
/* BEGIN HADRON */
804+
elog(DEBUG1, "Databricks: before authentication hook");
805+
806+
if (DatabricksAuthentication_hook)
792807
{
793-
result = plain_crypt_verify(port->user_name, shadow_pass, passwd,
794-
logdetail);
808+
result = (*DatabricksAuthentication_hook) (port, passwd, &skip_password_auth, logdetail);
795809
}
796810
else
811+
{
812+
/* If hook is not set, do the password auth by default */
813+
skip_password_auth = false;
797814
result = STATUS_ERROR;
815+
}
798816

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

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

805-
elog(LOG, "DatabricksAuthentication_hook returned: %d", result);
832+
if (shadow_pass)
833+
pfree(shadow_pass);
806834
}
807-
808-
if (shadow_pass)
809-
pfree(shadow_pass);
835+
/* END HADRON */
810836
pfree(passwd);
811837

812838
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)