Skip to content
New issue

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

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

Already on GitHub? # to your account

Add priv check #3710

Merged
merged 17 commits into from
Jan 7, 2022
Merged

Add priv check #3710

merged 17 commits into from
Jan 7, 2022

Conversation

flaneur2020
Copy link
Member

@flaneur2020 flaneur2020 commented Dec 31, 2021

I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/

Summary

Summary about this PR

  • add checks on write operations
  • find user identity with client ip on authenticating user.
  • take default@127.0.0.1 to run the stateless tests

Changelog

  • New Feature

Related Issues

Fixes #3170

Test Plan

Unit Tests

Stateless Tests

@databend-bot
Copy link
Member

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@databend-bot databend-bot added pr-feature this PR introduces a new feature to the codebase need-review labels Dec 31, 2021
@vercel
Copy link

vercel bot commented Dec 31, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/databend/databend/Hd845vASwdywbeV498TapZB3WvpH
✅ Preview: https://databend-git-fork-flaneur2020-add-priv-check-databend.vercel.app

[Deployment for 7ad46d1 canceled]

@@ -205,40 +205,27 @@ impl UserGrantSet {
&self.grants
}

pub fn verify_global_privilege(
pub fn verify_privilege(
Copy link
Member

Choose a reason for hiding this comment

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

common/meta/types mainly for type definiton.
Maybe better to put the verify_privilege in other place?

Copy link
Member Author

@flaneur2020 flaneur2020 Dec 31, 2021

Choose a reason for hiding this comment

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

before adding roles, we might need a seperate PrivilegeManager to cache and verify the user privileges (it needs cache all the roles' privileges, and generate an effective grant set with the privileges merged from the roles), maybe the PrivilegeManager could be the better place to verify the privilege, and leaving the types user_grant mod as plain data objects. 🤔

this refactor requires some work, maybe we can make this refactor in a stand-alone PR? q.q

Copy link
Member

Choose a reason for hiding this comment

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

That's OK

@flaneur2020 flaneur2020 changed the title WIP: Add priv check Add priv check Jan 6, 2022
@flaneur2020 flaneur2020 marked this pull request as ready for review January 6, 2022 10:14
@@ -168,6 +170,28 @@ impl Session {
self.mutable_state.set_current_user(user)
}

pub fn validate_privilege(
Copy link
Member

Choose a reason for hiding this comment

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

check_privilege is better?

Copy link
Member Author

@flaneur2020 flaneur2020 Jan 7, 2022

Choose a reason for hiding this comment

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

there're some validate_ and check_ functions in our codebase, as the existing convention, the check_ functions often return a bool and used in an if condition, and the validate_ functions often returns an Result<()>, and mostly used as a short-circuit call with a ?, which breaks the control flow if any error occurred, like:

validate_expression(&expr)?;
   57 fn validate_function_arg(
   58     name: &str,
   59     args_len: usize,
   60     variadic_arguments: Option<(usize, usize)>,
   61     num_arguments: usize,
   62 ) -> Result<()> {

in this case, the validate_privilege function would return an Result<()> and used as a short-circuit call with a ?, i guess naming it as validate_ follows the convension in the current codebase? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Good 👍

@BohuTANG
Copy link
Member

BohuTANG commented Jan 7, 2022

/lgtm

@codecov-commenter
Copy link

Codecov Report

Merging #3710 (7ad46d1) into main (8745add) will increase coverage by 0%.
The diff coverage is 80%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #3710   +/-   ##
=====================================
  Coverage     59%     59%           
=====================================
  Files        711     711           
  Lines      38305   38344   +39     
=====================================
+ Hits       22878   22905   +27     
- Misses     15427   15439   +12     
Impacted Files Coverage Δ
common/meta/types/src/user_grant.rs 62% <ø> (ø)
common/meta/types/src/user_identity.rs 75% <ø> (ø)
common/meta/types/src/user_info.rs 87% <ø> (ø)
common/meta/types/src/user_privilege.rs 33% <ø> (ø)
query/src/interpreters/interpreter_kill.rs 0% <0%> (ø)
query/src/users/user_mgr.rs 83% <64%> (-3%) ⬇️
query/src/functions/context_function.rs 92% <100%> (ø)
...ry/src/interpreters/interpreter_database_create.rs 83% <100%> (+1%) ⬆️
...uery/src/interpreters/interpreter_database_drop.rs 95% <100%> (+<1%) ⬆️
query/src/interpreters/interpreter_insert.rs 82% <100%> (+1%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8745add...7ad46d1. Read the comment docs.

@databend-bot
Copy link
Member

Wait for another reviewer approval

@BohuTANG BohuTANG merged commit 46b89bb into databendlabs:main Jan 7, 2022
@flaneur2020 flaneur2020 deleted the add-priv-check branch January 7, 2022 08:54
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
need-review pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

verify privilege on write statements
4 participants