Skip to content

Commit f0f5aec

Browse files
Eric Peimmeent-databricks
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 8d1da1c commit f0f5aec

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
@@ -73,6 +73,9 @@ ExecutorEnd_hook_type ExecutorEnd_hook = NULL;
7373
/* Hook for plugin to get control in ExecCheckPermissions() */
7474
ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook = NULL;
7575

76+
/* Backup hook to check for rte permissions after native permissions check fails */
77+
ExecutorUnityCatalogCheckPerms_hook_type ExecutorUnityCatalogCheckPerms_hook = NULL;
78+
7679
/* decls for local routines only used within this module */
7780
static void InitPlan(QueryDesc *queryDesc, int eflags);
7881
static void CheckValidRowMarkRel(Relation rel, RowMarkType markType);
@@ -622,6 +625,18 @@ ExecCheckPermissions(List *rangeTable, List *rteperminfos,
622625

623626
Assert(OidIsValid(perminfo->relid));
624627
result = ExecCheckOneRelPerms(perminfo);
628+
629+
// BEGIN HADRON
630+
// If we don't have the necessary native Postgres permission,
631+
// check if our Databricks OAuth token grants us permission.
632+
if (!result)
633+
{
634+
if (ExecutorUnityCatalogCheckPerms_hook)
635+
result = (*ExecutorUnityCatalogCheckPerms_hook) (perminfo);
636+
637+
}
638+
// END HADRON
639+
625640
if (!result)
626641
{
627642
if (ereport_on_violation)

src/include/executor/executor.h

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

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

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

0 commit comments

Comments
 (0)