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

privileges: add SkipWithGrant check for RBAC methods #10681

Merged
merged 5 commits into from
Jun 5, 2019

Conversation

imtbkcat
Copy link

@imtbkcat imtbkcat commented Jun 3, 2019

What problem does this PR solve?

RBAC methods in privileges package did not check SkipWithGrant. This cause panic when enable --skip-grant-table.

What is changed and how it works?

add check for SkipWithGrant, when SkipWithGrant is enabled, calling for RBAC method will be ignored.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

@codecov
Copy link

codecov bot commented Jun 3, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@f7a8f4e). Click here to learn what that means.
The diff coverage is 60%.

@@             Coverage Diff             @@
##             master     #10681   +/-   ##
===========================================
  Coverage          ?   79.6625%           
===========================================
  Files             ?        414           
  Lines             ?      87656           
  Branches          ?          0           
===========================================
  Hits              ?      69829           
  Misses            ?      12650           
  Partials          ?       5177

@@ -185,6 +185,10 @@ func (p *UserPrivileges) UserPrivilegesTable() [][]types.Datum {

// ShowGrants implements privilege.Manager ShowGrants interface.
func (p *UserPrivileges) ShowGrants(ctx sessionctx.Context, user *auth.UserIdentity, roles []*auth.RoleIdentity) (grants []string, err error) {
if SkipWithGrant {
grants, err = nil, errNonexistingGrant.GenWithStackByArgs()
Copy link
Member

@jackysp jackysp Jun 3, 2019

Choose a reason for hiding this comment

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

why not

Suggested change
grants, err = nil, errNonexistingGrant.GenWithStackByArgs()
return nil, errNonexistingGrant.GenWithStackByArgs()

Copy link
Member

Choose a reason for hiding this comment

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

what will this error look like?

Copy link
Author

Choose a reason for hiding this comment

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

PTAL @jackysp

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

Could you add some test cases?

@@ -185,6 +185,9 @@ func (p *UserPrivileges) UserPrivilegesTable() [][]types.Datum {

// ShowGrants implements privilege.Manager ShowGrants interface.
func (p *UserPrivileges) ShowGrants(ctx sessionctx.Context, user *auth.UserIdentity, roles []*auth.RoleIdentity) (grants []string, err error) {
if SkipWithGrant {
return nil, errNonexistingGrant.GenWithStackByArgs()
Copy link
Member

Choose a reason for hiding this comment

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

What will this error look like?

@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao tiancaiamao added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 4, 2019
Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

LGTM

@jackysp
Copy link
Member

jackysp commented Jun 4, 2019

/run-all-tests

@jackysp
Copy link
Member

jackysp commented Jun 4, 2019

Please cherry-pick this PR to release 3.0.

@jackysp
Copy link
Member

jackysp commented Jun 5, 2019

/run-unit-test

@jackysp
Copy link
Member

jackysp commented Jun 5, 2019

/run-integration-ddl-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/privilege status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants