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

Execute CREATE/GRANT ROLE statements using bbf_role_admin during restore #3082

Open
wants to merge 10 commits into
base: BABEL_4_X_DEV
Choose a base branch
from

Conversation

rishabhtanwar29
Copy link
Contributor

@rishabhtanwar29 rishabhtanwar29 commented Nov 7, 2024

Description

Execute CREATE/GRANT ROLE statements using bbf_role_admin during restore
so that bbf_role_admin becomes the admin/GRANTOR. We will do this only if the
current is superuser since only superuser is allowed to perform dump/restore.
Note that no additional permission checks are needed as superusers can anyway
perform this action.

Additionally, even revoke grants GRANTED by BOOTSTRAP_SUPERUSER since grantor
of GRANTs from previous versions might be bbf_role_admin.

Task: BABEL-5309
Signed-off-by: Rishabh Tanwar ritanwar@amazon.com

Test Scenarios Covered

  • Use case based -

  • Boundary conditions -

  • Arbitrary inputs -

  • Negative test cases -

  • Minor version upgrade tests -

  • Major version upgrade tests -

  • Performance tests -

  • Tooling impact -

  • Client tests -

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 Apache 2.0 and PostgreSQL licenses, 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.

Signed-off-by: Rishabh Tanwar <ritanwar@amazon.com>
Signed-off-by: Rishabh Tanwar <ritanwar@amazon.com>
Signed-off-by: Rishabh Tanwar <ritanwar@amazon.com>
@coveralls
Copy link
Collaborator

coveralls commented Nov 7, 2024

Pull Request Test Coverage Report for Build 11890286888

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 9 of 36 (25.0%) changed or added relevant lines in 1 file are covered.
  • 286 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.03%) to 74.69%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contrib/babelfishpg_tsql/src/pl_handler.c 9 36 25.0%
Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tsql/src/pl_funcs.c 2 19.14%
contrib/babelfishpg_tsql/src/tsqlIface.cpp 284 90.3%
Totals Coverage Status
Change from base Build 11841522137: -0.03%
Covered Lines: 45644
Relevant Lines: 61111

💛 - Coveralls

Signed-off-by: Rishabh Tanwar <ritanwar@amazon.com>
Copy link
Contributor

@shalinilohia50 shalinilohia50 left a comment

Choose a reason for hiding this comment

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

Let's run these tests in the upgrade workflows.

Signed-off-by: Rishabh Tanwar <ritanwar@amazon.com>
Signed-off-by: Rishabh Tanwar <ritanwar@amazon.com>
Signed-off-by: Rishabh Tanwar <ritanwar@amazon.com>
Signed-off-by: Rishabh Tanwar <ritanwar@amazon.com>
Comment on lines +3843 to +3859
/*
* First execute REVOKE statement using bootstrap user.
* This is needed since grantor of GRANTs from previous versions might
* not be bbf_role_admin.
*/
SetUserIdAndSecContext(BOOTSTRAP_SUPERUSERID, save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
PG_TRY();
{
call_prev_ProcessUtility(pstmt, queryString, readOnlyTree, context, params,
queryEnv, dest, qc);
}
PG_FINALLY();
{
/* Clean up. Restore previous state. */
SetUserIdAndSecContext(save_userid, save_sec_context);
}
PG_END_TRY();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we identify those faulty GRANT and correct those in upgrade?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or Is it possible to escalate to BOOTSTRAP_SUPERUSERID in some of the cases only? Are there any alternatives apart from we escalate to BOOTSTRAP_SUPERUSERID -- using somewhat less-privileged user?

Comment on lines +3911 to +3912
if (isadmin)
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please explain this.

if (isadmin)
break;

/* Save the previous user to be restored after creating the login. */
Copy link
Contributor

Choose a reason for hiding this comment

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

after creating the login?

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.

5 participants