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

executor,infoschema: check privilege for 'show processlist' #7858

Merged
merged 4 commits into from
Oct 10, 2018
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
2 changes: 2 additions & 0 deletions executor/executor_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/auth"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/ranger"
Expand Down Expand Up @@ -78,6 +79,7 @@ func (s *testExecSuite) TestShowProcessList(c *C) {
}
sctx := mock.NewContext()
sctx.SetSessionManager(sm)
sctx.GetSessionVars().User = &auth.UserIdentity{Username: "test"}

// Compose executor.
e := &ShowExec{
Expand Down
14 changes: 14 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ func (e *ShowExec) fetchShowProcessList() error {
return nil
}

loginUser := e.ctx.GetSessionVars().User
var hasProcessPriv bool
if pm := privilege.GetPrivilegeManager(e.ctx); pm != nil {
if pm.RequestVerification("", "", "", mysql.ProcessPriv) {
hasProcessPriv = true
}
}

pl := sm.ShowProcessList()
for _, pi := range pl {
var info string
Expand All @@ -197,6 +205,12 @@ func (e *ShowExec) fetchShowProcessList() error {
info = fmt.Sprintf("%.100v", pi.Info)
}

// If you have the PROCESS privilege, you can see all threads.
// Otherwise, you can see only your own threads.
if !hasProcessPriv && pi.User != loginUser.Username {
continue
}

e.appendRow([]interface{}{
pi.ID,
pi.User,
Expand Down
14 changes: 14 additions & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,23 @@ func dataForProcesslist(ctx sessionctx.Context) [][]types.Datum {
return nil
}

loginUser := ctx.GetSessionVars().User
var hasProcessPriv bool
if pm := privilege.GetPrivilegeManager(ctx); pm != nil {
if pm.RequestVerification("", "", "", mysql.ProcessPriv) {
hasProcessPriv = true
}
}

var records [][]types.Datum
pl := sm.ShowProcessList()
for _, pi := range pl {
// If you have the PROCESS privilege, you can see all threads.
// Otherwise, you can see only your own threads.
if !hasProcessPriv && pi.User != loginUser.Username {
continue
}

var t uint64
if len(pi.Info) != 0 {
t = uint64(time.Since(pi.Time) / time.Second)
Expand Down