From f377f4fbdc2c0860899830d95e15046dcd64c8f8 Mon Sep 17 00:00:00 2001 From: cbcwestwolf <1004626265@qq.com> Date: Thu, 12 Sep 2024 21:20:37 +0800 Subject: [PATCH] bootstrap: create sysvars for password validation during upgrade --- pkg/session/bootstrap.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/session/bootstrap.go b/pkg/session/bootstrap.go index ec74727a89189..060e57c1cac24 100644 --- a/pkg/session/bootstrap.go +++ b/pkg/session/bootstrap.go @@ -1133,11 +1133,14 @@ const ( // version 213 // create `mysql.tidb_pitr_id_map` table version213 = 213 + + // version214 add global variables for password validation + version214 = 214 ) // currentBootstrapVersion is defined as a variable, so we can modify its value for testing. // please make sure this is the largest version -var currentBootstrapVersion int64 = version213 +var currentBootstrapVersion int64 = version214 // DDL owner key's expired time is ManagerSessionTTL seconds, we should wait the time and give more time to have a chance to finish it. var internalSQLTimeout = owner.ManagerSessionTTL + 15 @@ -3141,6 +3144,22 @@ func upgradeToVer213(s sessiontypes.Session, ver int64) { mustExecute(s, CreatePITRIDMap) } +func upgradeToVer214(s sessiontypes.Session, ver int64) { + if ver >= version214 { + return + } + mustExecute(s, "DELETE FROM mysql.global_variables where VARIABLE_NAME like 'validate_password_%'") + + initGlobalVariableIfNotExists(s, variable.ValidatePasswordCheckUserName, variable.On) + initGlobalVariableIfNotExists(s, variable.ValidatePasswordSpecialCharCount, "1") + initGlobalVariableIfNotExists(s, variable.ValidatePasswordLength, "8") + initGlobalVariableIfNotExists(s, variable.ValidatePasswordNumberCount, "1") + initGlobalVariableIfNotExists(s, variable.ValidatePasswordMixedCaseCount, "1") + initGlobalVariableIfNotExists(s, variable.ValidatePasswordPolicy, "MEDIUM") + initGlobalVariableIfNotExists(s, variable.ValidatePasswordEnable, variable.Off) + initGlobalVariableIfNotExists(s, variable.ValidatePasswordDictionary, "") +} + // initGlobalVariableIfNotExists initialize a global variable with specific val if it does not exist. func initGlobalVariableIfNotExists(s sessiontypes.Session, name string, val any) { ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnBootstrap)