Skip to content

Commit 3e22092

Browse files
Support Same-DB Ownership Chaining for object references inside Procedure/Functions (#616)
This commit implements the ownership chaining support for object references inside function/procedure. The basic idea of Ownership chaining is that when one object references another, and both have the same owner, then permissions are only checked when the top-level object is accessed. Core Functionality: Added support for ownership chaining within the same database for procedures and functions Key Components Modified: Added ownership chain validation in permission checks Walker function to mark relations and functions inside view definitions Implementation: Walker function to mark relations and functions inside view definitions Walks through the query parse tree to: Mark relations and functions as being inside a view context For relations: Set checkAsUser to the view_owner when it matches the relation's owner, enabling permission checking to pass at the executor stage (ownership chaining) For procedures/functions: Store the view_owner in the parentOwnerId field to support procedure/function-specific ownership chaining logic during permission checks at the executor stage Extension PR : babelfish-for-postgresql/babelfish_extensions#4057 Task: BABEL-6030 Signed-off-by: Harsh Lunagariya <[email protected]> Co-authored-by: pranav jain <[email protected]>
1 parent 203b537 commit 3e22092

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/backend/commands/functioncmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,7 @@ ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver
23622362
Assert(IsA(fexpr, FuncExpr));
23632363

23642364
if (ExecFuncProc_AclCheck_hook)
2365-
aclresult = ExecFuncProc_AclCheck_hook(fexpr->funcid);
2365+
aclresult = ExecFuncProc_AclCheck_hook(fexpr->funcid, (Expr *)fexpr);
23662366
else
23672367
aclresult = object_aclcheck(ProcedureRelationId, fexpr->funcid, GetUserId(), ACL_EXECUTE);
23682368
if (aclresult != ACLCHECK_OK)

src/backend/executor/execExpr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ ExecInitFunc(ExprEvalStep *scratch, Expr *node, List *args, Oid funcid,
26392639

26402640
/* Check permission to call function */
26412641
if (ExecFuncProc_AclCheck_hook)
2642-
aclresult = ExecFuncProc_AclCheck_hook(funcid);
2642+
aclresult = ExecFuncProc_AclCheck_hook(funcid, node);
26432643
else
26442644
aclresult = object_aclcheck(ProcedureRelationId, funcid, GetUserId(), ACL_EXECUTE);
26452645
if (aclresult != ACLCHECK_OK)

src/backend/executor/execSRF.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ init_sexpr(Oid foid, Oid input_collation, Expr *node,
703703

704704
/* Check permission to call function */
705705
if (ExecFuncProc_AclCheck_hook)
706-
aclresult = ExecFuncProc_AclCheck_hook(foid);
706+
aclresult = ExecFuncProc_AclCheck_hook(foid, node);
707707
else
708708
aclresult = object_aclcheck(ProcedureRelationId, foid, GetUserId(), ACL_EXECUTE);
709709
if (aclresult != ACLCHECK_OK)

src/include/executor/execExpr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef bool (*ExecEvalBoolSubroutine) (ExprState *state,
4646
* Helpful in cases when permissions need to be checked against
4747
* a different user instead of current user.
4848
*/
49-
typedef AclResult (*ExecFuncProc_AclCheck_hook_type) (Oid funcid);
49+
typedef AclResult (*ExecFuncProc_AclCheck_hook_type) (Oid funcid, Expr *fexpr);
5050
extern PGDLLIMPORT ExecFuncProc_AclCheck_hook_type ExecFuncProc_AclCheck_hook;
5151

5252
/* ExprEvalSteps that cache a composite type's tupdesc need one of these */

0 commit comments

Comments
 (0)