Skip to content

Commit

Permalink
privilege: fix user with % hostname can not show grants. (pingcap#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingyu Song committed Apr 8, 2020
1 parent 662f08b commit 4a21dc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ func (b *executorBuilder) buildShow(v *plannercore.Show) Executor {
// The former determine privileges with roles, while the later doesn't.
vars := e.ctx.GetSessionVars()
e.User = vars.User
e.User.Hostname = vars.User.AuthHostname
e.User.Username = vars.User.AuthUsername
e.Roles = vars.ActiveRoles
}
if e.Tp == ast.ShowMasterStatus {
Expand Down
7 changes: 7 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ func (s *testSuite2) TestShowGrantsPrivilege(c *C) {
tk1.Se = se
err = tk1.QueryToErr("show grants for root")
c.Assert(err.Error(), Equals, executor.ErrDBaccessDenied.GenWithStackByArgs("show_grants", "%", mysql.SystemDB).Error())
// Test show grants for user with auth host name `%`.
tk2 := testkit.NewTestKit(c, s.store)
se2, err := session.CreateSession4Test(s.store)
c.Assert(err, IsNil)
c.Assert(se2.Auth(&auth.UserIdentity{Username: "show_grants", Hostname: "127.0.0.1", AuthUsername: "show_grants", AuthHostname: "%"}, nil, nil), IsTrue)
tk2.Se = se2
tk2.MustQuery("show grants")
}

func (s *testSuite2) TestIssue3641(c *C) {
Expand Down

0 comments on commit 4a21dc1

Please sign in to comment.