-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
privilege, executor: add SET ROLE
and CURRENT_ROLE
support
#9581
Conversation
privilege/privileges/cache.go
Outdated
@@ -16,6 +16,7 @@ package privileges | |||
import ( | |||
"context" | |||
"fmt" | |||
"github.com/pingcap/parser/auth" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this line to the third party libs part.
|
||
// evalString evals a builtinCurrentUserSig. | ||
// See https://dev.mysql.com/doc/refman/5.7/en/information-functions.html#function_current-user | ||
func (b *builtinCurrentRoleSig) evalString(row chunk.Row) (string, bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to add some test cases for this built-in function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
Codecov Report
@@ Coverage Diff @@
## master #9581 +/- ##
================================================
- Coverage 67.1706% 67.1505% -0.0202%
================================================
Files 381 381
Lines 79956 80053 +97
================================================
+ Hits 53707 53756 +49
- Misses 21460 21504 +44
- Partials 4789 4793 +4 |
/run-all-tests |
PTAL @tiancaiamao |
executor/simple.go
Outdated
} | ||
e.done = true | ||
return errors.Trace(err) | ||
} | ||
|
||
func (e *SimpleExec) executeSetRole(s *ast.SetRoleStmt) error { | ||
checkDup := make(map[string]*auth.RoleIdentity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make(map[string]*auth.RoleIdentity, len(s.RoleList))
go.mod
Outdated
@@ -23,7 +23,7 @@ require ( | |||
github.com/go-sql-driver/mysql v0.0.0-20170715192408-3955978caca4 | |||
github.com/gogo/protobuf v1.2.0 // indirect | |||
github.com/golang/groupcache v0.0.0-20181024230925-c65c006176ff // indirect | |||
github.com/golang/protobuf v1.2.0 | |||
github.com/golang/protobuf v1.3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why protobuf is changed here?
@@ -104,12 +105,42 @@ type columnsPrivRecord struct { | |||
patTypes []byte | |||
} | |||
|
|||
// RoleGraphEdgesTable is used to cache relationship between and role. | |||
type roleGraphEdgesTable struct { | |||
roleList map[string]bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use roleList map[string]struct{}
here
roleList map[string]struct{}
roleList["xx"] = struct{}{}
if _, ok := roleList["xx"] {
...
}
LGTM |
PTAL @jackysp |
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What problem does this PR solve?
support active role and
SET ROLE
,CURRENT_ROLE
function.What is changed and how it works?
Create an graph data structure to find relationship between role and user quickly, which is always update as other privilege tables. It will load
mysql.role_edges
table, and convert relationship to an graph.When we need to active some roles for current session, we need to check whether these roles has been granted for current user.
RoleGraph
can finish this task quickly.SET ROLE
is just for set active role for current session, more detail: https://dev.mysql.com/doc/refman/8.0/en/set-role.htmlBecause
set default role
is not support yet. some gramma will be added soon.Check List
Tests
Code changes
Side effects