Skip to content

Commit

Permalink
lightning: Don't log "received task config" in server mode (#52336)
Browse files Browse the repository at this point in the history
close #36374
  • Loading branch information
kennytm committed Apr 3, 2024
1 parent c8a5740 commit 555ce02
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 44 deletions.
3 changes: 1 addition & 2 deletions lightning/pkg/server/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,7 @@ func (l *Lightning) handlePostTask(w http.ResponseWriter, req *http.Request) {
writeJSONError(w, http.StatusBadRequest, "cannot read request", err)
return
}
filteredData := common.HideSensitive(string(data))
log.L().Info("received task config", zap.String("content", filteredData))
log.L().Info("received task config")

cfg := config.NewConfig()
if err = cfg.LoadFromGlobal(l.globalCfg); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/lightning/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ go_test(
],
embed = [":common"],
flaky = True,
shard_count = 30,
shard_count = 29,
deps = [
"//br/pkg/errors",
"//pkg/ddl",
Expand Down
9 changes: 0 additions & 9 deletions pkg/lightning/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"net"
"net/http"
"os"
"regexp"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -697,11 +696,3 @@ func IsRaftKV2(ctx context.Context, db *sql.DB) (bool, error) {
}
return false, rows.Err()
}

var passwordRegexp = regexp.MustCompile(`(password[\s]*=[\s]*(\\")?)(.*?)((\\")?\\n)`)

// HideSensitive replace password with ******.
func HideSensitive(input string) string {
output := passwordRegexp.ReplaceAllString(input, "$1******$4")
return output
}
32 changes: 0 additions & 32 deletions pkg/lightning/common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,35 +302,3 @@ CREATE TABLE multi_indexes (
require.Equal(t, tt.multiSQLs, multiSQLs)
}
}

func TestHideSensitive(t *testing.T) {
strs := []struct {
old string
new string
}{
{
`host = "127.0.0.1"\n user = "root"\n password = "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs="\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password = ******\n port = 3306\n`,
},
{
`host = "127.0.0.1"\n user = "root"\n password = ""\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password = ******\n port = 3306\n`,
},
{
`host = "127.0.0.1"\n user = "root"\n password= "/Q7B9DizNLLTTfiZHv9WoEAKamfpIUs="\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password= ******\n port = 3306\n`,
},
{
`host = "127.0.0.1"\n user = "root"\n password =""\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password =******\n port = 3306\n`,
},
{
`host = "127.0.0.1"\n user = "root"\n password=""\n port = 3306\n`,
`host = "127.0.0.1"\n user = "root"\n password=******\n port = 3306\n`,
},
}
for i, str := range strs {
t.Logf("case #%d\n", i)
require.Equal(t, str.new, common.HideSensitive(str.old))
}
}

0 comments on commit 555ce02

Please sign in to comment.