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: fix user without process privilege can access cluster's systemInfo, Load, Hardware #26211

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions executor/memtable_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ type clusterServerInfoRetriever struct {

// retrieve implements the memTableRetriever interface
func (e *clusterServerInfoRetriever) retrieve(ctx context.Context, sctx sessionctx.Context) ([][]types.Datum, error) {
// To access TableClusterSystemInfo, TableClusterHardware, TableClusterLoad, PROCESS privileges is needed.
if !hasPriv(sctx, mysql.ProcessPriv) {
return nil, plannercore.ErrSpecificAccessDenied.GenWithStackByArgs("PROCESS")
}
if e.extractor.SkipRequest || e.retrieved {
return nil, nil
}
Expand Down
22 changes: 22 additions & 0 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,28 @@ func (s *testClusterTableSuite) TestForClusterServerInfo(c *C) {
c.Assert(gotAddrs, DeepEquals, cas.addrs, Commentf("sql: %s", cas.sql))
c.Assert(gotNames, DeepEquals, cas.names, Commentf("sql: %s", cas.sql))
}

// More test about the systemInfo's privileges.
tk.MustExec("create user 'testuser'@'localhost'")
c.Assert(tk.Se.Auth(&auth.UserIdentity{
Username: "testuser",
Hostname: "localhost",
}, nil, nil), Equals, true)

err := tk.QueryToErr("select * from information_schema.CLUSTER_SYSTEMINFO")
c.Assert(err, NotNil)
// This error is come from cop(TiDB) fetch from rpc server.
c.Assert(err.Error(), Equals, "[planner:1227]Access denied; you need (at least one of) the PROCESS privilege(s) for this operation")

err = tk.QueryToErr("select * from information_schema.CLUSTER_HARDWARE")
c.Assert(err, NotNil)
// This error is come from cop(TiDB) fetch from rpc server.
c.Assert(err.Error(), Equals, "[planner:1227]Access denied; you need (at least one of) the PROCESS privilege(s) for this operation")

err = tk.QueryToErr("select * from information_schema.CLUSTER_LOAD")
c.Assert(err, NotNil)
// This error is come from cop(TiDB) fetch from rpc server.
c.Assert(err.Error(), Equals, "[planner:1227]Access denied; you need (at least one of) the PROCESS privilege(s) for this operation")
}

func (s *testTableSuite) TestSystemSchemaID(c *C) {
Expand Down