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

[ISSUE-2779] Add user in session #2986

Merged
merged 9 commits into from
Nov 24, 2021

Conversation

flaneur2020
Copy link
Member

@flaneur2020 flaneur2020 commented Nov 23, 2021

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

Summary

this PR adds a user record in the session, which recorded on the authenticate phase of mysql & clickhouse. it also adds a user field in the system.processes table.

Changelog

  • Improvement

Related Issues

Fixes #2779

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.

@flaneur2020 flaneur2020 marked this pull request as draft November 23, 2021 13:17
@@ -30,6 +30,7 @@ pub struct MutableStatus {
abort: AtomicBool,
current_database: RwLock<String>,
session_settings: RwLock<Settings>,
current_user: RwLock<Option<String>>,
Copy link
Member

@BohuTANG BohuTANG Nov 23, 2021

Choose a reason for hiding this comment

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

it will be the UserInfo in the future not only a user name?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm taking UserInfo at first but reverted it back to a simple user name, in the current code base UserInfo is a fat object:

  pub struct UserInfo {
      pub name: String,
      pub hostname: String,
      pub password: Vec<u8>,
      pub auth_type: AuthType,
      pub privileges: UserPrivilege,
      pub quota: UserQuota,
  }

the fields inside UserInfo might get mutated on the fly (like quota, privileges, even password), or mutated by another query instance. a conservative usage of UserInfo might be always fetching UserInfo from the metasrv, and make it transactional with the user-related operations.

in the case about session privilege, we can construct a unique identifier for the privilege grants by user_name + client_address.

@flaneur2020 flaneur2020 changed the title WIP: [ISSUE-2779] Add user in session [ISSUE-2779] Add user in session Nov 23, 2021
@flaneur2020 flaneur2020 marked this pull request as ready for review November 23, 2021 13:51
@flaneur2020 flaneur2020 requested a review from BohuTANG November 23, 2021 13:53
@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2021

Codecov Report

Merging #2986 (eeeb8cd) into main (f6a5903) will decrease coverage by 0%.
The diff coverage is 25%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #2986   +/-   ##
=====================================
- Coverage     68%     68%   -1%     
=====================================
  Files        649     649           
  Lines      34018   34022    +4     
=====================================
  Hits       23181   23181           
- Misses     10837   10841    +4     
Impacted Files Coverage Δ
query/src/sql/plan_parser_test.rs 100% <ø> (ø)
...src/datasources/database/system/processes_table.rs 33% <25%> (-1%) ⬇️
common/management/src/cluster/cluster_mgr.rs 80% <0%> (-1%) ⬇️
query/src/clusters/cluster.rs 54% <0%> (-1%) ⬇️
common/mem-allocator/src/malloc_size.rs 73% <0%> (+1%) ⬆️

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 f6a5903...eeeb8cd. Read the comment docs.

@@ -72,6 +74,18 @@ impl MutableStatus {
*lock = db
}

// Set the current user after authentication
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to add a unit test in test crate we have some MutableStatus tests there

Copy link
Member Author

Choose a reason for hiding this comment

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

@BohuTANG thank you for remind, i've added a test case on the getter/setter for current user

Copy link
Member Author

Choose a reason for hiding this comment

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

to test the behaviour of session's current user, i'd split another PR to add a current_user() function

@BohuTANG
Copy link
Member

/lgtm

@databend-bot
Copy link
Member

Wait for another reviewer approval

@BohuTANG BohuTANG merged commit 518fdfa into databendlabs:main Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bind user to session
4 participants