diff --git a/sessionctx/sessionstates/BUILD.bazel b/sessionctx/sessionstates/BUILD.bazel index 901bb54c94dff..98fb59ee8e832 100644 --- a/sessionctx/sessionstates/BUILD.bazel +++ b/sessionctx/sessionstates/BUILD.bazel @@ -31,7 +31,7 @@ go_test( ], embed = [":sessionstates"], flaky = True, - shard_count = 15, + shard_count = 16, deps = [ "//config", "//errno", diff --git a/sessionctx/sessionstates/session_states_test.go b/sessionctx/sessionstates/session_states_test.go index e3eaf89dd3ef9..35d6418b92234 100644 --- a/sessionctx/sessionstates/session_states_test.go +++ b/sessionctx/sessionstates/session_states_test.go @@ -16,6 +16,7 @@ package sessionstates_test import ( "context" + "crypto/tls" "encoding/binary" "fmt" "strconv" @@ -1677,3 +1678,15 @@ func getResetBytes(stmtID uint32) []byte { binary.LittleEndian.PutUint32(buf[pos:], stmtID) return buf } + +func TestIssue47665(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.Session().GetSessionVars().TLSConnectionState = &tls.ConnectionState{} // unrelated mock for the test. + originSEM := config.GetGlobalConfig().Security.EnableSEM + config.GetGlobalConfig().Security.EnableSEM = true + tk.MustGetErrMsg("set @@global.require_secure_transport = on", "require_secure_transport can not be set to ON with SEM(security enhanced mode) enabled") + config.GetGlobalConfig().Security.EnableSEM = originSEM + tk.MustExec("set @@global.require_secure_transport = on") + tk.MustExec("set @@global.require_secure_transport = off") // recover to default value +} diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 7f5c4a6ad337a..a1db9b0484e66 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -1117,6 +1117,14 @@ var defaultSysVars = []*SysVar{ return nil }, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) { if vars.StmtCtx.StmtType == "Set" && TiDBOptOn(normalizedValue) { + // On tidbcloud dedicated cluster with the default configuration, if an user modify + // @@global.require_secure_transport=on, he can not login the cluster anymore! + // A workaround for this is making require_secure_transport read-only for that case. + // SEM(security enhanced mode) is enabled by default with only that settings. + cfg := config.GetGlobalConfig() + if cfg.Security.EnableSEM { + return "", errors.New("require_secure_transport can not be set to ON with SEM(security enhanced mode) enabled") + } // Refuse to set RequireSecureTransport to ON if the connection // issuing the change is not secure. This helps reduce the chance of users being locked out. if vars.TLSConnectionState == nil {