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

privilege: use internal session to run SET DEFAULT ROL ALL (#15525) #15585

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ func (e *SimpleExec) setDefaultRoleAll(s *ast.SetDefaultRoleStmt) error {
return ErrCannotUser.GenWithStackByArgs("SET DEFAULT ROLE", user.String())
}
}
sqlExecutor := e.ctx.(sqlexec.SQLExecutor)
restrictedCtx, err := e.getSysSession()
if err != nil {
return err
}
defer e.releaseSysSession(restrictedCtx)
sqlExecutor := restrictedCtx.(sqlexec.SQLExecutor)
if _, err := sqlExecutor.Execute(context.Background(), "begin"); err != nil {
return err
}
Expand Down
13 changes: 13 additions & 0 deletions executor/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,19 @@ func (s *testSuite3) TestDefaultRole(c *C) {
tk.MustExec(dropRoleSQL)
}

func (s *testSuite3) TestSetDefaultRoleAll(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create user test_all;")
se, err := session.CreateSession4Test(s.store)
c.Check(err, IsNil)
defer se.Close()
c.Assert(se.Auth(&auth.UserIdentity{Username: "test_all", Hostname: "localhost"}, nil, nil), IsTrue)

ctx := context.Background()
_, err = se.Execute(ctx, "set default role all to test_all;")
c.Assert(err, IsNil)
}

func (s *testSuite3) TestUser(c *C) {
tk := testkit.NewTestKit(c, s.store)
// Make sure user test not in mysql.User.
Expand Down