-
Notifications
You must be signed in to change notification settings - Fork 841
feat: object warehouse support rbac #17262
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b9fcf3d
feat: object warehouse support rbac
TCeason e727c40
add WAREHOUSE as ident
TCeason 7d2b5cf
add new privilege type forward test
TCeason ce9a14f
add new ident parse func: grant_ident
TCeason 1c41631
1. Normalize the code
TCeason 8db8cc6
fix warehouse uid modify to id
TCeason a6c818b
add CreateWarehouse in available_privileges_on_global
TCeason File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/meta/proto-conv/tests/it/v120_warehouse_ownershipobject.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright 2023 Datafuse Labs. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| use std::collections::HashSet; | ||
|
|
||
| use chrono::DateTime; | ||
| use chrono::Utc; | ||
| use databend_common_meta_app as mt; | ||
| use databend_common_meta_app::principal::OwnershipObject; | ||
| use databend_common_meta_app::principal::UserGrantSet; | ||
| use databend_common_meta_app::principal::UserPrivilegeType; | ||
| use enumflags2::make_bitflags; | ||
| use fastrace::func_name; | ||
|
|
||
| use crate::common; | ||
|
|
||
| // These bytes are built when a new version in introduced, | ||
| // and are kept for backward compatibility test. | ||
| // | ||
| // ************************************************************* | ||
| // * These messages should never be updated, * | ||
| // * only be added when a new version is added, * | ||
| // * or be removed when an old version is no longer supported. * | ||
| // ************************************************************* | ||
| // | ||
|
|
||
| #[test] | ||
| fn test_decode_v120_grant_object() -> anyhow::Result<()> { | ||
| let role_info_v120 = vec![ | ||
| 10, 2, 114, 49, 18, 172, 1, 10, 21, 10, 8, 10, 0, 160, 6, 117, 168, 6, 24, 16, 128, 128, | ||
| 128, 1, 160, 6, 117, 168, 6, 24, 10, 31, 10, 21, 18, 13, 10, 7, 100, 101, 102, 97, 117, | ||
| 108, 116, 18, 2, 100, 98, 160, 6, 117, 168, 6, 24, 16, 2, 160, 6, 117, 168, 6, 24, 10, 35, | ||
| 10, 25, 26, 17, 10, 7, 100, 101, 102, 97, 117, 108, 116, 18, 2, 100, 98, 26, 2, 116, 98, | ||
| 160, 6, 117, 168, 6, 24, 16, 2, 160, 6, 117, 168, 6, 24, 10, 22, 10, 12, 34, 4, 10, 2, 102, | ||
| 49, 160, 6, 117, 168, 6, 24, 16, 1, 160, 6, 117, 168, 6, 24, 10, 24, 10, 12, 42, 4, 10, 2, | ||
| 115, 49, 160, 6, 117, 168, 6, 24, 16, 128, 128, 32, 160, 6, 117, 168, 6, 24, 10, 21, 10, 8, | ||
| 10, 0, 160, 6, 117, 168, 6, 24, 16, 254, 255, 191, 1, 160, 6, 117, 168, 6, 24, 160, 6, 117, | ||
| 168, 6, 24, 26, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 48, | ||
| 48, 32, 85, 84, 67, 34, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, | ||
| 58, 48, 48, 32, 85, 84, 67, 160, 6, 117, 168, 6, 24, | ||
| ]; | ||
| let want = || mt::principal::RoleInfo { | ||
| name: "r1".to_string(), | ||
| grants: UserGrantSet::new( | ||
| vec![ | ||
| mt::principal::GrantEntry::new( | ||
| mt::principal::GrantObject::Global, | ||
| make_bitflags!(UserPrivilegeType::{CreateWarehouse}), | ||
| ), | ||
| mt::principal::GrantEntry::new( | ||
| mt::principal::GrantObject::Database("default".to_string(), "db".to_string()), | ||
| make_bitflags!(UserPrivilegeType::{Create}), | ||
| ), | ||
| mt::principal::GrantEntry::new( | ||
| mt::principal::GrantObject::Table( | ||
| "default".to_string(), | ||
| "db".to_string(), | ||
| "tb".to_string(), | ||
| ), | ||
| make_bitflags!(UserPrivilegeType::{Create}), | ||
| ), | ||
| mt::principal::GrantEntry::new( | ||
| mt::principal::GrantObject::UDF("f1".to_string()), | ||
| make_bitflags!(UserPrivilegeType::{Usage}), | ||
| ), | ||
| mt::principal::GrantEntry::new( | ||
| mt::principal::GrantObject::Stage("s1".to_string()), | ||
| make_bitflags!(UserPrivilegeType::{Write}), | ||
| ), | ||
| // test new global privilege CreateWarehouse | ||
| mt::principal::GrantEntry::new( | ||
| mt::principal::GrantObject::Global, | ||
| make_bitflags!(UserPrivilegeType::{Create | Select | Insert | Update | Delete | Drop | Alter | Super | CreateUser | DropUser | CreateRole | DropRole | Grant | CreateStage | Set | CreateDataMask | Ownership | Read | Write | CreateWarehouse }), | ||
| ), | ||
| ], | ||
| HashSet::new(), | ||
| ), | ||
| created_on: DateTime::<Utc>::default(), | ||
| update_on: DateTime::<Utc>::default(), | ||
| }; | ||
|
|
||
| common::test_pb_from_to(func_name!(), want())?; | ||
| common::test_load_old(func_name!(), role_info_v120.as_slice(), 117, want())?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_decode_v120_ownership() -> anyhow::Result<()> { | ||
| let ownership_info_v120 = vec![ | ||
| 10, 2, 114, 49, 18, 19, 42, 11, 10, 9, 97, 117, 110, 105, 113, 117, 101, 105, 100, 160, 6, | ||
| 117, 168, 6, 24, 160, 6, 117, 168, 6, 24, | ||
| ]; | ||
|
|
||
| let want = || mt::principal::OwnershipInfo { | ||
| role: "r1".to_string(), | ||
| object: OwnershipObject::Warehouse { | ||
| id: "auniqueid".to_string(), | ||
| }, | ||
| }; | ||
| common::test_pb_from_to(func_name!(), want())?; | ||
| common::test_load_old(func_name!(), ownership_info_v120.as_slice(), 117, want())?; | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.