Skip to content

Commit 96c49f0

Browse files
Eric Peitristan957
authored andcommitted
[BRC-3414] Add hook for backup token access check on SCHEMAs (#59)
See parent PR https://github.com/databricks-eng/hadron/pull/1441
1 parent d61583a commit 96c49f0

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/backend/catalog/namespace.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "utils/snapmgr.h"
5959
#include "utils/syscache.h"
6060
#include "utils/varlena.h"
61+
#include "catalog/objectaccess.h"
6162

6263

6364
/*
@@ -2960,8 +2961,22 @@ LookupExplicitNamespace(const char *nspname, bool missing_ok)
29602961

29612962
aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
29622963
if (aclresult != ACLCHECK_OK)
2964+
{
2965+
/* BEGIN HADRON
2966+
* If we don't have the necessary native Postgres permission, check if
2967+
* our Databricks OAuth token grants us permission.
2968+
*/
2969+
if (NamespaceUnityCatalogAccess_hook != NULL
2970+
&& (*NamespaceUnityCatalogAccess_hook) (namespaceId, nspname, ACL_USAGE))
2971+
{
2972+
aclresult = ACLCHECK_OK;
2973+
}
2974+
/* END HADRON */
2975+
29632976
aclcheck_error(aclresult, OBJECT_SCHEMA,
29642977
nspname);
2978+
}
2979+
29652980
/* Schema search hook for this lookup */
29662981
InvokeNamespaceSearchHook(namespaceId, true);
29672982

src/backend/catalog/objectaccess.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
*/
2222
object_access_hook_type object_access_hook = NULL;
2323

24+
/* Backup hook to check for Unity Catalog namespace access after native permissions check fails */
25+
NamespaceUnityCatalogAccess_hook_type NamespaceUnityCatalogAccess_hook = NULL;
26+
27+
2428
/*
2529
* RunObjectPostCreateHook
2630
*

src/include/catalog/objectaccess.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef OBJECTACCESS_H
1111
#define OBJECTACCESS_H
1212

13+
#include "nodes/parsenodes.h"
14+
1315
/*
1416
* Object access hooks are intended to be called just before or just after
1517
* performing certain actions on a SQL object. This is intended as
@@ -142,6 +144,10 @@ extern void RunObjectPostAlterHook(Oid classId, Oid objectId, int subId,
142144
extern bool RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation);
143145
extern void RunFunctionExecuteHook(Oid objectId);
144146

147+
/* Backup hook to check for Unity Catalog namespace access after native permissions check fails */
148+
typedef bool (*NamespaceUnityCatalogAccess_hook_type) (Oid namespaceId, const char *nspname, AclMode requiredPerms);
149+
extern PGDLLIMPORT NamespaceUnityCatalogAccess_hook_type NamespaceUnityCatalogAccess_hook;
150+
145151
/*
146152
* The following macros are wrappers around the functions above; these should
147153
* normally be used to invoke the hook in lieu of calling the above functions

0 commit comments

Comments
 (0)