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

catalog: Allow for more builtin roles #14128

Merged
merged 9 commits into from
Aug 10, 2022

Conversation

jkosh44
Copy link
Contributor

@jkosh44 jkosh44 commented Aug 8, 2022

This commit updates role ids to have two separate namespaces. One for
builtin roles and one for user roles. This will allow us to more easily
add builtin roles in the future.

This is a breaking change.

Motivation

This PR refactors existing code.

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered.

  • This PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way) and therefore is tagged with a T-protobuf label.

  • This PR includes the following user-facing behavior changes:

    • Changes role ids to be a string, which changes the id column of mz_roles.

@jkosh44 jkosh44 force-pushed the role-id-namespace branch 3 times, most recently from 1c11c30 to 10ff954 Compare August 8, 2022 21:13
This commit updates role ids to have two separate namespaces. One for
builtin roles and one for user roles. This will allow us to more easily
add builtin roles in the future.

This is a breaking change.
@jkosh44 jkosh44 marked this pull request as ready for review August 8, 2022 21:37
Materialized(options=mz_options)
# This commit added the missing column rolconnlimit to pg_authid.
Materialized(
image="materialize/materialized:devel-438ea318093b3a15a924fbdae70e0db6d379a921",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm real sad if this needs to happen, because it effectively means this test will never test any code in a PR, but just run exactly the same code over and over.

This test has caught migration bugs from other PRs before, and seems kinda good to have maybe? At least, I'd argue that if we want to hard code this we should maybe just...remove the test because it's doing nothing and replace it with a real migration test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I deleted it, it had a good run but with a breaking change it will no longer work. I'll open up an issue tonight about making adding a new upgrade test for this feature.

@@ -1601,8 +1609,8 @@ impl_codec!(ItemValue);

#[derive(Clone, Message, PartialOrd, PartialEq, Eq, Ord, Hash)]
struct RoleKey {
#[prost(uint64)]
id: u64,
#[prost(string)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Oooh our first protobuf migration. The code here will cause any existing stash to fail on startup. We need to decide if we're ok with breaking the world again or not. I don't know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per slack discussion, next release will have another breaking change, so we're going to piggy back off of that.

@jkosh44 jkosh44 closed this Aug 9, 2022
@jkosh44 jkosh44 reopened this Aug 9, 2022
@jkosh44 jkosh44 added the T-proto Theme: `$T ⇔ Proto$T` conversions and `*.proto` files label Aug 9, 2022
@benesch
Copy link
Member

benesch commented Aug 10, 2022

Skimmed the test changes and I love it. Deferring the actual review to @mjibson though.

@jkosh44
Copy link
Contributor Author

jkosh44 commented Aug 10, 2022

@mjibson In case you already started reviewing, I just changed the name of the added user from "mz_system_external" to "http_default_user" because I thought the old name was really non-descriptive.

@jkosh44
Copy link
Contributor Author

jkosh44 commented Aug 10, 2022

@mjibson In case you already started reviewing, I just changed the name of the added user from "mz_system_external" to "http_default_user" because I thought the old name was really non-descriptive.

Oops didn't follow my own rule and gave it a bad name without a "mz_" prefix. Just fixed the name of the role.

@@ -2288,11 +2293,13 @@ pub static BUILTINS_STATIC: Lazy<Vec<Builtin<NameReference>>> = Lazy::new(|| {

builtins
});
pub static BUILTIN_ROLES: Lazy<Vec<BuiltinRole>> = Lazy::new(|| vec![MZ_SYSTEM]);
pub static BUILTIN_ROLES: Lazy<Vec<BuiltinRole>> =
Lazy::new(|| vec![MZ_SYSTEM, MZ_HTTP_DEFAULT_USER]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it required that the order of this doesn't change should we add more? That is, new entries must be added at the end instead of being alphabetically sorted? If so, document that with a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The order for this doesn't matter. It's only used on startup to persist any new roles that haven't already been persisted.

@@ -112,12 +114,18 @@ async fn migrate<S: Append>(
)?;
txn.id_allocator.insert(
IdAllocKey {
name: ROLE_ID_ALLOC_KEY.into(),
name: USER_ROLE_ID_ALLOC_KEY.into(),
Copy link
Contributor

@maddyblue maddyblue Aug 10, 2022

Choose a reason for hiding this comment

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

If this is a breaking change to which we aren't providing an upgrade path, the cloud team should be flagged, unless there's some other breaking change they already know about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -234,86 +232,3 @@ def workflow_test_drop_default_cluster(c: Composition) -> None:

c.sql("DROP CLUSTER default CASCADE")
c.sql("CREATE CLUSTER default REPLICAS (default (SIZE '1'))")


def workflow_test_builtin_migration(c: Composition) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

rip

id: 0,
pub const MZ_SYSTEM: BuiltinRole = BuiltinRole { name: "mz_system" };

pub const MZ_HTTP_DEFAULT_USER: BuiltinRole = BuiltinRole {
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 unused? Should it be added in a later PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it might be good to test a second builtin role, but you're probably right. I should save this for a later PR.

@jkosh44 jkosh44 enabled auto-merge (squash) August 10, 2022 22:14
…e-id-namespace

� Conflicts:
�	src/adapter/src/catalog.rs
@jkosh44 jkosh44 merged commit d370474 into MaterializeInc:main Aug 10, 2022
@jkosh44 jkosh44 deleted the role-id-namespace branch August 10, 2022 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-proto Theme: `$T ⇔ Proto$T` conversions and `*.proto` files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants