Skip to content

Commit e7cdfe2

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 3c95ad7 commit e7cdfe2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/backend/catalog/namespace.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "utils/snapmgr.h"
6161
#include "utils/syscache.h"
6262
#include "utils/varlena.h"
63+
#include "catalog/objectaccess.h"
6364

6465

6566
/*
@@ -3406,8 +3407,23 @@ LookupExplicitNamespace(const char *nspname, bool missing_ok)
34063407

34073408
aclresult = object_aclcheck(NamespaceRelationId, namespaceId, GetUserId(), ACL_USAGE);
34083409
if (aclresult != ACLCHECK_OK)
3409-
aclcheck_error(aclresult, OBJECT_SCHEMA,
3410-
nspname);
3410+
{
3411+
/* BEGIN HADRON
3412+
* If we don't have the necessary native Postgres permission, check if
3413+
* our Databricks OAuth token grants us permission.
3414+
*/
3415+
if (NamespaceUnityCatalogAccess_hook != NULL
3416+
&& (*NamespaceUnityCatalogAccess_hook) (namespaceId, nspname, ACL_USAGE))
3417+
{
3418+
aclresult = ACLCHECK_OK;
3419+
}
3420+
/* END HADRON */
3421+
3422+
if (aclresult != ACLCHECK_OK)
3423+
aclcheck_error(aclresult, OBJECT_SCHEMA,
3424+
nspname);
3425+
}
3426+
34113427
/* Schema search hook for this lookup */
34123428
InvokeNamespaceSearchHook(namespaceId, true);
34133429

src/backend/catalog/objectaccess.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
object_access_hook_type object_access_hook = NULL;
2323
object_access_hook_type_str object_access_hook_str = NULL;
2424

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

2629
/*
2730
* RunObjectPostCreateHook

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
@@ -163,6 +165,10 @@ extern void RunObjectPostAlterHookStr(Oid classId, const char *objectName, int s
163165
extern bool RunNamespaceSearchHookStr(const char *objectName, bool ereport_on_violation);
164166
extern void RunFunctionExecuteHookStr(const char *objectName);
165167

168+
/* Backup hook to check for Unity Catalog namespace access after native permissions check fails */
169+
typedef bool (*NamespaceUnityCatalogAccess_hook_type) (Oid namespaceId, const char *nspname, AclMode requiredPerms);
170+
extern PGDLLIMPORT NamespaceUnityCatalogAccess_hook_type NamespaceUnityCatalogAccess_hook;
171+
166172

167173
/*
168174
* The following macros are wrappers around the functions above; these should

0 commit comments

Comments
 (0)