Skip to content

Commit 2155cb1

Browse files
dimitrivkj-db
andauthored
[Hadron] Always run databricks auth hook (#27) (#695)
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 3009750 commit 2155cb1

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

src/backend/libpq/auth.c

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -791,32 +791,59 @@ CheckPasswordAuth(Port *port, char **logdetail)
791791
int result;
792792
char *shadow_pass;
793793

794+
/* BEGIN NEON */
795+
796+
/*
797+
* This flag is passed to databricks auth hook and is updated by the hook
798+
* to false if we should continue with password auth. This is by default
799+
* true so that we don't accidentally do password auth if there is some
800+
* bug in the hook. It's better to rely on the hook to set it explicitly
801+
* false to continue with password auth.
802+
*/
803+
bool skip_password_auth = true;
804+
805+
/* END NEON */
806+
794807
sendAuthRequest(port, AUTH_REQ_PASSWORD, NULL, 0);
795808

796809
passwd = recv_password_packet(port);
797810
if (passwd == NULL)
798811
return STATUS_EOF; /* client wouldn't send password */
799812

800-
shadow_pass = get_role_password(port->user_name, logdetail);
801-
if (shadow_pass)
813+
/* BEGIN NEON */
814+
elog(DEBUG1, "Databricks: before authentication hook");
815+
816+
if (DatabricksAuthentication_hook)
802817
{
803-
result = plain_crypt_verify(port->user_name, shadow_pass, passwd,
804-
logdetail);
818+
result = (*DatabricksAuthentication_hook)
819+
(port, passwd, &skip_password_auth, (const char **) logdetail);
805820
}
806821
else
822+
{
823+
/* If hook is not set, do the password auth by default */
824+
skip_password_auth = false;
807825
result = STATUS_ERROR;
826+
}
808827

809-
if (result != STATUS_OK && DatabricksAuthentication_hook)
810-
{
811-
elog(LOG, "Calling DatabricksAuthentication_hook");
828+
elog(DEBUG1, "Databricks: after authentication hook");
812829

813-
result = (*DatabricksAuthentication_hook)(port, passwd);
830+
/* only try PG password auth if the hook didn't return STATUS_OK and */
831+
/* the hook set the skip_password_auth flag to false */
832+
if (result != STATUS_OK && !skip_password_auth)
833+
{
834+
shadow_pass = get_role_password(port->user_name, logdetail);
835+
if (shadow_pass)
836+
{
837+
result = plain_crypt_verify(port->user_name, shadow_pass, passwd,
838+
logdetail);
839+
}
840+
else
841+
result = STATUS_ERROR;
814842

815-
elog(LOG, "DatabricksAuthentication_hook returned: %d", result);
843+
if (shadow_pass)
844+
pfree(shadow_pass);
816845
}
817-
818-
if (shadow_pass)
819-
pfree(shadow_pass);
846+
/* END NEON */
820847
pfree(passwd);
821848

822849
if (result == STATUS_OK)

src/include/libpq/auth.h

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

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

3945
#endif /* AUTH_H */

0 commit comments

Comments
 (0)