Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session/variable: forbid changing @@global.require_secure_transport to 'on' with SEM enabled #47677 #47689

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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