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

User permission manager #1873

Merged
merged 5 commits into from
Mar 19, 2020
Merged

User permission manager #1873

merged 5 commits into from
Mar 19, 2020

Conversation

bright-starry-sky
Copy link
Contributor

1, moved ClientSession to common layer . and rename to Session.
2, Added Permission Manager .
3, Added Permission Check.

This PR depend on #1842 ,I will create more test cases after #1842 is done.

@bright-starry-sky
Copy link
Contributor Author

Ready to review. come on teachers. thanks.

Copy link
Contributor

@dangleptr dangleptr left a comment

Choose a reason for hiding this comment

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

Just skim the pr. It looks good to me totally. Very nice~

src/common/permission/PermissionManager.cpp Outdated Show resolved Hide resolved
src/common/permission/PermissionManager.cpp Outdated Show resolved Hide resolved
src/common/permission/PermissionManager.cpp Show resolved Hide resolved
src/common/session/Session.h Outdated Show resolved Hide resolved
src/meta/client/MetaClient.cpp Outdated Show resolved Hide resolved
src/common/session/Session.h Outdated Show resolved Hide resolved
src/graph/ShowExecutor.cpp Outdated Show resolved Hide resolved
src/meta/client/MetaClient.cpp Outdated Show resolved Hide resolved
src/meta/processors/usersMan/AuthenticationProcessor.cpp Outdated Show resolved Hide resolved
src/common/session/Session.h Show resolved Hide resolved
@bright-starry-sky
Copy link
Contributor Author

Addressed dangleptr's comments as below :
1,Cached user password via meta client;
2,Check god by user name root;
3,Moved FLAGS_enable_authorize to PermissionManager;
4,Skip space check for kDefaultSpaceId when list roles

@jude-zhu jude-zhu requested a review from dangleptr March 17, 2020 09:07
dangleptr
dangleptr previously approved these changes Mar 17, 2020
Copy link
Contributor

@dangleptr dangleptr left a comment

Choose a reason for hiding this comment

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

Well done. The pr looks good to me now.

case Sentence::Kind::kDescribeSpace : {
/**
* Use space and Describe space are special operations.
* Permission checking needs to be done in their executor.
Copy link
Contributor

Choose a reason for hiding this comment

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

why? Miss the spaceId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why? Miss the spaceId?

Yes, Usually we need to get the space id from the session when check permission.
We can't get the space ID form session when Use Space or Describe space , so we need get the space id in their executor.

case Sentence::Kind::kLimit :
case Sentence::Kind::KGroupBy :
case Sentence::Kind::kReturn : {
return permission::PermissionManager::canReadSchemaData(session);
Copy link
Contributor

@dangleptr dangleptr Mar 17, 2020

Choose a reason for hiding this comment

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

Maybe canReadSchemaOrData is a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe canReadSchemaOrData is a better name.

Good idea. Changed method name from canReadSchemaData to canReadSchemaOrData

@codecov-io
Copy link

codecov-io commented Mar 17, 2020

Codecov Report

Merging #1873 into master will increase coverage by 0.13%.
The diff coverage is 93.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1873      +/-   ##
==========================================
+ Coverage   86.90%   87.03%   +0.13%     
==========================================
  Files         636      640       +4     
  Lines       59819    60632     +813     
==========================================
+ Hits        51984    52772     +788     
- Misses       7835     7860      +25     
Impacted Files Coverage Δ
src/graph/DescribeSpaceExecutor.h 0.00% <ø> (ø)
src/graph/GoExecutor.cpp 75.45% <0.00%> (ø)
src/graph/GraphService.h 100.00% <ø> (ø)
src/graph/PrivilegeExecutor.h 69.56% <ø> (+13.04%) ⬆️
src/graph/SequentialExecutor.h 0.00% <ø> (ø)
src/graph/UseExecutor.h 0.00% <ø> (ø)
src/graph/test/TestEnv.h 100.00% <ø> (ø)
src/kvstore/raftex/RaftPart.cpp 77.06% <ø> (-0.88%) ⬇️
src/meta/MetaServiceHandler.h 100.00% <ø> (ø)
src/meta/MetaServiceUtils.h 100.00% <ø> (ø)
... and 71 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 0aebc92...abf0444. Read the comment docs.

dangleptr
dangleptr previously approved these changes Mar 18, 2020
Copy link
Contributor

@dangleptr dangleptr left a comment

Choose a reason for hiding this comment

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

Well done.

}
bool havePermission = false;
switch (session->roleWithSpace(spaceId)) {
case session::Role::GOD :
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference between session->isGod() and session::Role::GOD ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the difference between session->isGod() and session::Role::GOD ?

session->isGod just check if the user is god.
session->roleWithSpace(spaceId) check what role of in this space.
case session::Role::GOD still there because the compilation requirement of switch block .

* Skip special operations check at here. they are :
* kUse, kDescribeSpace, kRevoke and kGrant.
*/
if (!PermissionCheck::permissionCheck(session, sentence)) {
Copy link
Contributor

@critical27 critical27 Mar 19, 2020

Choose a reason for hiding this comment

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

What if the query is "use space test; sth else", can we work? I guess it would fail, although this is a quite usual usage.

I suppose we don't need this code block, because we could check it in each executor just like you did.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if the query is "use space test; sth else", can we work? But this is a quite usual.

Good question. you are right . it's fail when "use space ; sth else" .
because our permission check is in the preparation phase, have not set the space id in the session yet in the preparation phase. so the second statement should be fail.
I originally intended to check permissions in each executor, but this would result in too much code clutter.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok.

@critical27
Copy link
Contributor

Clean code!

critical27
critical27 previously approved these changes Mar 19, 2020
Copy link
Contributor

@critical27 critical27 left a comment

Choose a reason for hiding this comment

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

Great work

std::string account_;
time::Duration idleDuration_;
/*
* map<space name, role>
Copy link
Contributor

Choose a reason for hiding this comment

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

map<space Id, role> ?

}
}
return Role::INVALID_ROLE;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

move toRole to Session.cpp better ?

panda-sheep
panda-sheep previously approved these changes Mar 19, 2020
Copy link
Contributor

@panda-sheep panda-sheep left a comment

Choose a reason for hiding this comment

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

Great work

@dangleptr dangleptr merged commit 3b08e0b into vesoft-inc:master Mar 19, 2020
@bright-starry-sky bright-starry-sky deleted the user_permission_manager branch March 19, 2020 08:04
tong-hao pushed a commit to tong-hao/nebula that referenced this pull request Jun 1, 2021
* user permission manager

* Addressed dangleptr's comments

* 1,cache user pwd; 2,check god by user name root;3,move FLAGS_enable_authorize to PermissionManager;4,skip space check for kDefaultSpaceId when list roles

* Changed the method name from canReadSchemaData to canReadSchemaOrData

* fixed comment typo error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants