Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix drop database issue after MVU to PG17 #474

Conversation

sumitj824
Copy link
Contributor

@sumitj824 sumitj824 commented Nov 13, 2024

Description

After performing MVU to PG17, we weren't able to drop the existing database because a new dependency was getting added between the dbo system role and physical babelfish database. This dependency is getting introduced when running the TSQL upgrade script babelfishpg_tsql--3.4.0--4.0.0.sql, which grants permissions to the bbf_role_admin role. The new dependency is expected and is a result of a community change 514a3de. However, even though there is a function RemoveRoleFromInitPriv() to clean up these dependencies when executing DROP OWNED BY commands, it is not working correctly for system roles. This is because the function assumes the grantor of rights is always the same as the owner, which is not the case for system roles, where the grantor should be sysadmin.

This commit made changes to use sysadmin as grantor when generating ACLs for physical babelfish database while removing role from initial privileges.

Signed-off-by: Sumit Jaiswal [email protected]

Related Task: BABEL-5410

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 5015 to 5020
if (bbf_get_sysadmin_oid_hook &&
classid == DatabaseRelationId &&
is_member_of_role(GetUserId(), sysadminOid = (*bbf_get_sysadmin_oid_hook)()))
{
grantorId = sysadminOid;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Will Grantor always be sysadmin in case of Babelfish? At the time of inserting the init_privs, how are we deciding the grantor? If we see possibility that grantor being diff. from sysadmin then we should utilise select_best_grantor()
  2. Will it by triggered for other physical databases? Ideally it shouldn't. If it is then, I would suggest add check for babelfish physical db oid comparison if possible.
  3. We should check whether it is babelfish role or not as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed it offline and added check for babelfish database.

Signed-off-by: Sumit Jaiswal <[email protected]>
*/
if (bbf_get_sysadmin_oid_hook &&
classid == DatabaseRelationId &&
objid == get_database_oid(GetConfigOption("babelfishpg_tsql.database_name", true, false), true) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

What if GetConfigOption("babelfishpg_tsql.database_name", true, false) returns NULL?
Can you please include some manual testing from PG endpoint in the description which makes sure that it is not interfering when hitting this code path from different physical database?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added check for that as well.

Signed-off-by: Sumit Jaiswal <[email protected]>
@shardgupta shardgupta merged commit f9e9557 into babelfish-for-postgresql:BABEL_5_X_DEV__PG_17_X Nov 14, 2024
2 checks passed
@shardgupta shardgupta deleted the sumiji-fix-mvu-issue branch November 14, 2024 14:41
HarshLunagariya added a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Nov 21, 2024
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.

3 participants