Skip to content

Commit

Permalink
global sort: fix set tidb_cloud_storage_uri should be redacted (#48593)
Browse files Browse the repository at this point in the history
close #48498
  • Loading branch information
ywqzzy authored Nov 15, 2023
1 parent 4158448 commit 1a27050
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/executor/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ func (e *SetExecutor) setSysVariable(ctx context.Context, name string, v *expres
}
return nil
})
logutil.BgLogger().Info("set global var", zap.Uint64("conn", sessionVars.ConnectionID), zap.String("name", name), zap.String("val", valStr))
showValStr := valStr
if name == variable.TiDBCloudStorageURI {
showValStr = ast.RedactURL(showValStr)
}
logutil.BgLogger().Info("set global var", zap.Uint64("conn", sessionVars.ConnectionID), zap.String("name", name), zap.String("val", showValStr))
if name == variable.TiDBServiceScope {
dom := domain.GetDomain(e.Ctx())
serverID := disttaskutil.GenerateSubtaskExecID(ctx, dom.DDL().GetID())
Expand Down
16 changes: 15 additions & 1 deletion pkg/parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ const (
SetNames = "SetNAMES"
// SetCharset is the const for set charset stmt.
SetCharset = "SetCharset"
// TiDBCloudStorageURI is the const for set tidb_cloud_storage_uri stmt.
TiDBCloudStorageURI = "tidb_cloud_storage_uri"
)

// VariableAssignment is a variable assignment struct.
Expand Down Expand Up @@ -838,7 +840,10 @@ func (n *VariableAssignment) Restore(ctx *format.RestoreCtx) error {
ctx.WriteName(n.Name)
ctx.WritePlain("=")
}
if err := n.Value.Restore(ctx); err != nil {
if n.Name == TiDBCloudStorageURI {
// need to redact the url for safety when `show processlist;`
ctx.WritePlain(RedactURL(n.Value.(ValueExpr).GetString()))
} else if err := n.Value.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore VariableAssignment.Value")
}
if n.ExtendValue != nil {
Expand Down Expand Up @@ -1109,6 +1114,15 @@ func (n *SetStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// SecureText implements SensitiveStatement interface.
// need to redact the tidb_cloud_storage_url for safety when `show processlist;`
func (n *SetStmt) SecureText() string {
redactedStmt := *n
var sb strings.Builder
_ = redactedStmt.Restore(format.NewRestoreCtx(format.DefaultRestoreFlags, &sb))
return sb.String()
}

// SetConfigStmt is the statement to set cluster configs.
type SetConfigStmt struct {
stmtNode
Expand Down

0 comments on commit 1a27050

Please sign in to comment.