Skip to content

Commit 04c7d4f

Browse files
Eric Peitristan957
authored andcommitted
[BRC-3414] Add PG hook for oauth token permission check
We need an additional hook to perform backup permission-checking after the native PG check fails.
1 parent e4030cd commit 04c7d4f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/backend/executor/execMain.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ ExecutorEnd_hook_type ExecutorEnd_hook = NULL;
7070
/* Hook for plugin to get control in ExecCheckPermissions() */
7171
ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook = NULL;
7272

73+
/* Backup hook to check for rte permissions after native permissions check fails */
74+
ExecutorUnityCatalogCheckPerms_hook_type ExecutorUnityCatalogCheckPerms_hook = NULL;
75+
7376
/* decls for local routines only used within this module */
7477
static void InitPlan(QueryDesc *queryDesc, int eflags);
7578
static void CheckValidRowMarkRel(Relation rel, RowMarkType markType);
@@ -613,6 +616,18 @@ ExecCheckPermissions(List *rangeTable, List *rteperminfos,
613616

614617
Assert(OidIsValid(perminfo->relid));
615618
result = ExecCheckOneRelPerms(perminfo);
619+
620+
// BEGIN HADRON
621+
// If we don't have the necessary native Postgres permission,
622+
// check if our Databricks OAuth token grants us permission.
623+
if (!result)
624+
{
625+
if (ExecutorUnityCatalogCheckPerms_hook)
626+
result = (*ExecutorUnityCatalogCheckPerms_hook) (perminfo);
627+
628+
}
629+
// END HADRON
630+
616631
if (!result)
617632
{
618633
if (ereport_on_violation)

src/include/executor/executor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ typedef bool (*ExecutorCheckPerms_hook_type) (List *rangeTable,
9696
bool ereport_on_violation);
9797
extern PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook;
9898

99+
/* Backup hook to check for Unity Catalog permissions after native permissions check fails */
100+
typedef bool (*ExecutorUnityCatalogCheckPerms_hook_type) (RTEPermissionInfo *perminfo);
101+
extern PGDLLIMPORT ExecutorUnityCatalogCheckPerms_hook_type ExecutorUnityCatalogCheckPerms_hook;
102+
99103

100104
/*
101105
* prototypes from functions in execAmi.c

0 commit comments

Comments
 (0)