Skip to content

Commit

Permalink
session/variable: forbid changing @@global.require_secure_transport t…
Browse files Browse the repository at this point in the history
…o 'on' with SEM enabled pingcap#47677 (pingcap#47689)

close pingcap#47665
  • Loading branch information
tiancaiamao authored Oct 17, 2023
1 parent c3f0303 commit 7a83625
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sessionctx/sessionstates/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ go_test(
],
embed = [":sessionstates"],
flaky = True,
shard_count = 14,
shard_count = 15,
deps = [
"//config",
"//errno",
Expand Down
13 changes: 13 additions & 0 deletions sessionctx/sessionstates/session_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package sessionstates_test

import (
"context"
"crypto/tls"
"encoding/binary"
"fmt"
"strconv"
Expand Down Expand Up @@ -1484,3 +1485,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
}
9 changes: 9 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,15 @@ 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 {
Expand Down

0 comments on commit 7a83625

Please sign in to comment.