Skip to content

Conversation

HarshLunagariya
Copy link
Contributor

@HarshLunagariya HarshLunagariya commented Aug 7, 2025

Description

This commit implements the ownership chaining support for table/view object
references inside view. 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.

The scope of the current commit is to only support scenarios when parent
object is view and child objects are table/view. "[parent] view -> [child]
function" scenarios is out-of-scope for this effort.

Implementation:

  • Add infrastructure changes to support ownership tracking:

    • insideView flag in RTEPermissionInfo for view context tracking
    • parentOwnerId and insideView fields in FuncExpr (for future use)
    • walk_view_rule_hook for extension-specific view rule processing and
      apply view context marking in ApplyRetrieveRule
  • Add walker to traverse view definition parse trees:

    • Mark relations and functions inside views for permission checking
    • Set checkAsUser to view_owner for owned relations to enable chaining
    • Track view context using insideView flag
    • Only applies to user-defined objects created in non-shared schemas in TSQL mode

This enables proper ownership chaining behavior where tables and
views owned by the view owner can be accessed through the view.

Note: While infrastructure for function ownership chaining is included,
the actual implementation of function ownership chaining is out of scope
for this commit.

Issues Resolved

BABEL-6026

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the PostgreSQL license, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Comment on lines +1300 to +1301
/* For Babelfish Ownership Chaining support */
int insideView pg_node_attr(equal_ignore, query_jumble_ignore, read_write_ignore, read_as(0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious why we cannot just set the check as user to table owner when ownership chaininig is formed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for subsequent work where function/procedure ownership chaining will be implemented.

Comment on lines +771 to +773
/* For Babelfish Ownership Chaining support */
Oid parentOwnerId pg_node_attr(equal_ignore, query_jumble_ignore, read_write_ignore, read_as(0));
int insideView pg_node_attr(equal_ignore, query_jumble_ignore, read_write_ignore, read_as(0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason for including these fields in this commit ? I think bringing it along with function/procedures ownership chaining support might be preferrable for git history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants