-
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
*: maintain the active users for privilege data #56709
Conversation
Hi @tiancaiamao. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #56709 +/- ##
=================================================
- Coverage 73.3167% 57.4224% -15.8944%
=================================================
Files 1636 1801 +165
Lines 453659 647223 +193564
=================================================
+ Hits 332608 371651 +39043
- Misses 100674 250234 +149560
- Partials 20377 25338 +4961
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/retest |
@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
u := user.Username | ||
h := user.Hostname | ||
if len(user.AuthUsername) > 0 && len(user.AuthHostname) > 0 { | ||
u = user.AuthUsername | ||
h = user.AuthHostname | ||
} | ||
if err := p.Handle.ensureActiveUser(u); err != nil { |
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.
I'm not sure about the future usage. Will something happen between ensureActiveUser
and Get
and evict the active user?
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.
Currently there is no evict operation, evict make thing more complex.
pkg/privilege/privileges/cache.go
Outdated
}) | ||
ret.buildGlobalMap() | ||
|
||
ret.RoleGraph = diff.RoleGraph |
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.
(I will check later if only User and GlobalPriv need dedup, and RoleGraph can be directly used)
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.
RoleGraph is a full load, because I found that the table definitions differ from the others.
Other other tables has the User+Host column, while this table does not have it.
pkg/privilege/privileges/cache.go
Outdated
@@ -1633,12 +1815,48 @@ func (p *MySQLPrivilege) getAllRoles(user, host string) []*auth.RoleIdentity { | |||
|
|||
// Handle wraps MySQLPrivilege providing thread safe access. | |||
type Handle struct { | |||
sctx sessionctx.Context |
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.
Use the type sqlexec.RestrictedSQLExecutor
if we only use the context to execute some SQLs to reduce the dependency.
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.
sqlexec.RestrictedSQLExecutor
is not enough here.
We need something like a sqlexec.RestrictedSQLExecutor pool to avoid the single instance been used by multiple threads. @lcwangchao
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.
If so, keeping a sessionctx.Context
inside has the same problem.
columnsPriv []columnsPrivRecord | ||
defaultRoles []defaultRoleRecord | ||
|
||
globalPriv []globalPrivRecord |
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 need to keep a immutable globalPriv
and a mutable Global
? Any problem to just keep one Global
field?
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 the apply diff logic simpler if we're using one single slice representation...
we can copy and paste a lot code and just handle them the same way.
It's possible to keep different representation for different field, or even using Map for almost all field, but we need to add more code.
/retest |
@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/retest |
@tiancaiamao: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
return cmp | ||
} | ||
switch { | ||
case x.DB > y.DB: |
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.
nit: can use strings.Compare
for i := 0; i < len(p.User); i++ { | ||
record := &p.User[i] | ||
func (p *MySQLPrivilege) matchIdentity(sctx sqlexec.RestrictedSQLExecutor, user, host string, skipNameResolve bool) *UserRecord { | ||
for i := 0; i < len(p.user); i++ { |
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.
nit: for i := range p.User
@@ -1011,8 +1194,8 @@ func (p *MySQLPrivilege) matchIdentity(user, host string, skipNameResolve bool) | |||
|
|||
// matchResoureGroup finds an identity to match resource group. | |||
func (p *MySQLPrivilege) matchResoureGroup(resourceGroupName string) *UserRecord { | |||
for i := 0; i < len(p.User); i++ { | |||
record := &p.User[i] | |||
for i := 0; i < len(p.user); i++ { |
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.
ditto
@@ -1090,8 +1273,8 @@ func (p *MySQLPrivilege) matchTables(user, host, db, table string) *tablesPrivRe | |||
} | |||
|
|||
func (p *MySQLPrivilege) matchColumns(user, host, db, table, column string) *columnsPrivRecord { | |||
for i := 0; i < len(p.ColumnsPriv); i++ { | |||
record := &p.ColumnsPriv[i] | |||
for i := 0; i < len(p.columnsPriv); i++ { |
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.
ditto
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lance6716, lcwangchao The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
It's OK to fix my comments in next PR or ignore them @tiancaiamao |
This commit could make the login process slower, because now we need to load the users data. The general DDL/DML cases should not be affected, this just affects a minority of privileges related. |
What problem does this PR solve?
Issue Number: ref #55563
Problem Summary:
What changed and how does it work?
Add an
activeUsers
field to theprivilege.Handler
.This is a step towrads supporting 2.5M users, later we'll only keep the active users' data in-memory.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.