Skip to content

Commit

Permalink
lightning/config: align the behaviour of tidb.tls to doc (pingcap#53140)
Browse files Browse the repository at this point in the history
  • Loading branch information
lance6716 authored and terry1purcell committed May 17, 2024
1 parent 0fc6984 commit 308e9a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/lightning/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,33 @@ func (d *DBStore) adjust(
}

switch d.TLS {
case "skip-verify", "preferred":
case "preferred":
d.Security.AllowFallbackToPlaintext = true
fallthrough
case "skip-verify":
if d.Security.TLSConfig == nil {
/* #nosec G402 */
d.Security.TLSConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
InsecureSkipVerify: true,
NextProtos: []string{"h2", "http/1.1"}, // specify `h2` to let Go use HTTP/2.
}
d.Security.AllowFallbackToPlaintext = true
} else {
d.Security.TLSConfig.InsecureSkipVerify = true
}
case "cluster":
if len(s.CAPath) == 0 {
return common.ErrInvalidConfig.GenWithStack("cannot set `tidb.tls` to 'cluster' without a [security] section")
}
case "", "false":
d.TLS = "false"
case "":
case "false":
d.Security.TLSConfig = nil
d.Security.CAPath = ""
d.Security.CertPath = ""
d.Security.KeyPath = ""
d.Security.CABytes = nil
d.Security.CertBytes = nil
d.Security.KeyBytes = nil
default:
return common.ErrInvalidConfig.GenWithStack("unsupported `tidb.tls` config %s", d.TLS)
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/lightning/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,17 @@ func TestAdjustSecuritySection(t *testing.T) {
`,
expectedCA: "",
hasTLS: true,
fallback2NoTLS: false,
},
{
input: `
[security]
[tidb]
tls = "preferred"
[tidb.security]
`,
expectedCA: "",
hasTLS: true,
fallback2NoTLS: true,
},
{
Expand All @@ -398,6 +409,18 @@ func TestAdjustSecuritySection(t *testing.T) {
hasTLS: false,
fallback2NoTLS: false,
},
{
input: `
[security]
[tidb]
tls = "false"
[tidb.security]
ca-path = "/path/to/ca2.pem"
`,
expectedCA: "",
hasTLS: false,
fallback2NoTLS: false,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 308e9a7

Please sign in to comment.