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

adapter: Update privileges when an owner is updated #18777

Merged
merged 11 commits into from
Apr 17, 2023

Conversation

jkosh44
Copy link
Contributor

@jkosh44 jkosh44 commented Apr 14, 2023

This commit will update the privilege of an object whenever the
object's owner is updated, in the following ways:

  • All privileges granted by the old owner are updated so that their
    grantor is the new owner.
  • All privileges granted to the old owner are transferred to the new
    owner.

Part of #11579

Motivation

This PR adds a known-desirable feature.

Tips for Reviewer

  • Hide whitespace and the diff becomes much smaller.
  • This builds off of adapter: Add privileges to objects #18700, only the final commit is unique to this PR. Ideally I'd like to get them in the same release otherwise we may need to write a migration. Almost everything in here is pulled directly from PostgreSQL so hopefully it isn't too controversial.

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered.
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • This PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way) and therefore is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • This PR includes the following user-facing behavior changes:

This commit adds privileges to the following objects:

  - tables
  - views
  - materialized views
  - sources
  - types
  - secrets
  - connections
  - secrets
  - clusters
  - databases
  - schemas

This commit updates the on-disk stash representation and the catalog
tables/views that present this information to users.

Currently, privileges cannot be modified, and they are not looked at
when executing statements. These features will be implemented in a
future commit.

Part of MaterializeInc#11579
This commit will update the privilege of an object whenever the
object's owner is updated, in the following ways:

  - All privileges granted by the old owner are updated so that their
  grantor is the new owner.
  - All privileges granted to the old owner are transferred to the new
  owner.

Part of MaterializeInc#11579
@jkosh44 jkosh44 marked this pull request as ready for review April 14, 2023 21:16
@jkosh44 jkosh44 requested review from a team April 14, 2023 21:16
@jkosh44 jkosh44 requested review from a team as code owners April 14, 2023 21:16
@jkosh44 jkosh44 requested review from def- and removed request for a team April 14, 2023 21:16
…ate-privilege-owners

# Conflicts:
#	src/adapter/src/catalog.rs
#	src/adapter/src/catalog/storage.rs
#	test/sqllogictest/privileges.slt
@jkosh44 jkosh44 enabled auto-merge (squash) April 17, 2023 15:53
@jkosh44 jkosh44 merged commit 9e52f7b into MaterializeInc:main Apr 17, 2023
@jkosh44 jkosh44 deleted the update-privilege-owners branch April 17, 2023 16:43
Copy link
Contributor

@def- def- left a comment

Choose a reason for hiding this comment

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

Sorry for the late review.

I tried out code coverage on this PR: https://buildkite.com/materialize/coverage/builds/26#0187900b-9c08-441b-be29-a36e2d86a3c1
It found some of the added lines were not run in any test, would it make sense and be possible to test them?

if privilege.grantor == old_owner {
privilege.grantor = new_owner;
} else if privilege.grantor == new_owner {
new_present = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems untested

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #18804

if privilege.grantee == old_owner {
privilege.grantee = new_owner;
} else if privilege.grantee == new_owner {
new_present = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems untested

// is inspired by PostgreSQL's algorithm but not identical.
if new_present {
// Group privileges by (grantee, grantor).
let privilege_map: BTreeMap<_, Vec<_>> = privileges.into_iter().fold(
Copy link
Contributor

Choose a reason for hiding this comment

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

This pretty large block seems untested.

@@ -147,6 +147,14 @@ pub struct MzAclItem {
}

impl MzAclItem {
pub fn empty(grantee: RoleId, grantor: RoleId) -> MzAclItem {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this function tested anywhere?

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.

None yet

3 participants