Skip to content

Commit b8ae9a1

Browse files
authored
Merge pull request #2741 from VWagen1989/SeanWu/fix-account-replication
fix: store the hashed password to 'authentication_string' (to #2740)
2 parents 3281d09 + 7536809 commit b8ae9a1

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

enginetest/queries/priv_auth_queries.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,24 @@ FROM ((SELECT 1 as found FROM information_schema.tables WHERE table_schema = 'te
22682268
},
22692269
},
22702270
},
2271+
{
2272+
Name: "Test user creation with hashed password",
2273+
SetUpScript: []string{
2274+
"CREATE USER 'lol'@'%' IDENTIFIED WITH mysql_native_password AS '*91D9861DFC07DD967611B8C96953474EF270AD5E';",
2275+
},
2276+
Assertions: []UserPrivilegeTestAssertion{
2277+
{
2278+
Query: "SELECT User, plugin, authentication_string FROM mysql.user WHERE User = 'lol';",
2279+
Expected: []sql.Row{
2280+
{
2281+
"lol", // User
2282+
"mysql_native_password", // plugin
2283+
"*91D9861DFC07DD967611B8C96953474EF270AD5E", // authentication_string
2284+
},
2285+
},
2286+
},
2287+
},
2288+
},
22712289
}
22722290

22732291
// NoopPlaintextPlugin is used to authenticate plaintext user plugins

sql/plan/create_user_data.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,20 @@ func NewDefaultAuthentication(password string) Authentication {
126126
type AuthenticationOther struct {
127127
password string
128128
plugin string
129+
identity string
129130
}
130131

131-
func NewOtherAuthentication(password, plugin string) Authentication {
132-
return AuthenticationOther{password, plugin}
132+
func NewOtherAuthentication(password, plugin, identity string) Authentication {
133+
return AuthenticationOther{password, plugin, identity}
133134
}
134135

135136
func (a AuthenticationOther) Plugin() string {
136137
return a.plugin
137138
}
138139

139140
func (a AuthenticationOther) Password() string {
141+
if a.password == "" {
142+
return a.identity
143+
}
140144
return string(a.password)
141145
}

sql/planbuilder/priv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (b *Builder) buildAuthenticatedUser(user ast.AccountWithAuth) plan.Authenti
156156
if user.Auth1.Plugin == "mysql_native_password" && len(user.Auth1.Password) > 0 {
157157
authUser.Auth1 = plan.AuthenticationMysqlNativePassword(user.Auth1.Password)
158158
} else if len(user.Auth1.Plugin) > 0 {
159-
authUser.Auth1 = plan.NewOtherAuthentication(user.Auth1.Password, user.Auth1.Plugin)
159+
authUser.Auth1 = plan.NewOtherAuthentication(user.Auth1.Password, user.Auth1.Plugin, user.Auth1.Identity)
160160
} else {
161161
// We default to using the password, even if it's empty
162162
authUser.Auth1 = plan.NewDefaultAuthentication(user.Auth1.Password)

0 commit comments

Comments
 (0)