Skip to content

Commit 55e84ff

Browse files
authored
lightning: redact external storage url (pingcap#59256) (pingcap#59380)
close pingcap#59086
1 parent f471bdf commit 55e84ff

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

br/pkg/lightning/config/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ go_library(
1616
"//br/pkg/lightning/log",
1717
"//br/pkg/version/build",
1818
"//pkg/config",
19+
"//pkg/parser/ast",
1920
"//pkg/parser/mysql",
2021
"//pkg/util",
2122
"//pkg/util/mathutil",
@@ -43,7 +44,7 @@ go_test(
4344
],
4445
embed = [":config"],
4546
flaky = True,
46-
shard_count = 48,
47+
shard_count = 49,
4748
deps = [
4849
"//br/pkg/lightning/common",
4950
"@com_github_burntsushi_toml//:toml",

br/pkg/lightning/config/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/pingcap/tidb/br/pkg/lightning/common"
3838
"github.com/pingcap/tidb/br/pkg/lightning/log"
3939
tidbcfg "github.com/pingcap/tidb/pkg/config"
40+
"github.com/pingcap/tidb/pkg/parser/ast"
4041
"github.com/pingcap/tidb/pkg/parser/mysql"
4142
"github.com/pingcap/tidb/pkg/util"
4243
"github.com/pingcap/tidb/pkg/util/mathutil"
@@ -272,6 +273,16 @@ func (cfg *Config) String() string {
272273
return string(bytes)
273274
}
274275

276+
// Redact redacts the sensitive information.
277+
func (cfg *Config) Redact() string {
278+
originDir := cfg.Mydumper.SourceDir
279+
defer func() {
280+
cfg.Mydumper.SourceDir = originDir
281+
}()
282+
cfg.Mydumper.SourceDir = ast.RedactURL(cfg.Mydumper.SourceDir)
283+
return cfg.String()
284+
}
285+
275286
// ToTLS creates a common.TLS from the config.
276287
func (cfg *Config) ToTLS() (*common.TLS, error) {
277288
hostPort := net.JoinHostPort(cfg.TiDB.Host, strconv.Itoa(cfg.TiDB.StatusPort))

br/pkg/lightning/config/config_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,3 +1322,30 @@ func TestAdjustConflict(t *testing.T) {
13221322
cfg.Conflict.MaxRecordRows = 1
13231323
require.ErrorContains(t, cfg.Conflict.adjust(&cfg.TikvImporter, &cfg.App), `cannot record duplication (conflict.max-record-rows > 0) when use tikv-importer.backend = "tidb" and conflict.strategy = "replace"`)
13241324
}
1325+
1326+
func TestRedactConfig(t *testing.T) {
1327+
tests := []struct {
1328+
origin string
1329+
redact string
1330+
}{
1331+
{"", ""},
1332+
{":", ":"},
1333+
{"~/file", "~/file"},
1334+
{"gs://bucket/file", "gs://bucket/file"},
1335+
{"gs://bucket/file?access-key=123", "gs://bucket/file?access-key=123"},
1336+
{"gs://bucket/file?secret-access-key=123", "gs://bucket/file?secret-access-key=123"},
1337+
{"s3://bucket/file", "s3://bucket/file"},
1338+
{"s3://bucket/file?other-key=123", "s3://bucket/file?other-key=123"},
1339+
{"s3://bucket/file?access-key=123", "s3://bucket/file?access-key=xxxxxx"},
1340+
{"s3://bucket/file?secret-access-key=123", "s3://bucket/file?secret-access-key=xxxxxx"},
1341+
{"s3://bucket/file?access_key=123", "s3://bucket/file?access_key=xxxxxx"},
1342+
{"s3://bucket/file?secret_access_key=123", "s3://bucket/file?secret_access_key=xxxxxx"},
1343+
}
1344+
for _, tt := range tests {
1345+
cfg := NewConfig()
1346+
cfg.Mydumper.SourceDir = tt.origin
1347+
1348+
require.Contains(t, cfg.Redact(), tt.redact)
1349+
require.Contains(t, cfg.String(), tt.origin)
1350+
}
1351+
}

br/pkg/lightning/lightning.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func getKeyspaceName(db *sql.DB) (string, error) {
429429

430430
func (l *Lightning) run(taskCtx context.Context, taskCfg *config.Config, o *options) (err error) {
431431
build.LogInfo(build.Lightning)
432-
o.logger.Info("cfg", zap.Stringer("cfg", taskCfg))
432+
o.logger.Info("cfg", zap.String("cfg", taskCfg.Redact()))
433433

434434
utils.LogEnvVariables()
435435

0 commit comments

Comments
 (0)