Skip to content

Commit

Permalink
executor: remove sensitive information in slow-log ... (#18107) (#18128)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Jun 29, 2020
1 parent f588330 commit 4cbe17a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 11 additions & 2 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,12 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
if costTime < threshold && level > zapcore.DebugLevel {
return
}
sql := FormatSQL(a.Text, sessVars.PreparedParams)
var sql stringutil.StringerFunc
if sensitiveStmt, ok := a.StmtNode.(ast.SensitiveStmtNode); ok {
sql = FormatSQL(sensitiveStmt.SecureText(), nil)
} else {
sql = FormatSQL(a.Text, sessVars.PreparedParams)
}

var tableIDs, indexNames string
if len(sessVars.StmtCtx.TableIDs) > 0 {
Expand Down Expand Up @@ -843,9 +848,13 @@ func (a *ExecStmt) SummaryStmt() {
userString = sessVars.User.Username
}

sql := a.Text
if sensitiveStmt, ok := a.StmtNode.(ast.SensitiveStmtNode); ok {
sql = sensitiveStmt.SecureText()
}
stmtsummary.StmtSummaryByDigestMap.AddStatement(&stmtsummary.StmtExecInfo{
SchemaName: strings.ToLower(sessVars.CurrentDB),
OriginalSQL: a.Text,
OriginalSQL: sql,
NormalizedSQL: normalizedSQL,
Digest: digest,
PrevSQL: prevSQL,
Expand Down
19 changes: 19 additions & 0 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,22 @@ func (s *testTableSuite) TestPartitionsTable(c *C) {

tk.MustExec("DROP TABLE `test_partitions`;")
}

func (s *testTableSuite) TestStmtSummarySensitiveQuery(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set global tidb_enable_stmt_summary = 0")
tk.MustExec("set global tidb_enable_stmt_summary = 1")
tk.MustExec("drop user if exists user_sensitive;")
tk.MustExec("create user user_sensitive identified by '123456789';")
tk.MustExec("alter user 'user_sensitive'@'%' identified by 'abcdefg';")
tk.MustExec("set password for 'user_sensitive'@'%' = 'xyzuvw';")
tk.MustQuery("select query_sample_text from `performance_schema`.`events_statements_summary_by_digest` " +
"where query_sample_text like '%user_sensitive%' and " +
"(query_sample_text like 'set password%' or query_sample_text like 'create user%' or query_sample_text like 'alter user%') " +
"order by query_sample_text;").
Check(testkit.Rows(
"alter user {user_sensitive@% password = ***}",
"create user {user_sensitive@% password = ***}",
"set password for user user_sensitive@%",
))
}

0 comments on commit 4cbe17a

Please sign in to comment.