Skip to content

Commit 61a65b0

Browse files
committed
update
1 parent 5181ee5 commit 61a65b0

File tree

9 files changed

+26
-30
lines changed

9 files changed

+26
-30
lines changed

pkg/executor/simple.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,10 +1740,6 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
17401740
if _, err := sqlExecutor.ExecuteInternal(ctx, "BEGIN PESSIMISTIC"); err != nil {
17411741
return err
17421742
}
1743-
defaultAuthPlugin, err := e.Ctx().GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.DefaultAuthPlugin)
1744-
if err != nil {
1745-
return err
1746-
}
17471743

17481744
for _, spec := range s.Specs {
17491745
user := e.Ctx().GetSessionVars().User
@@ -1799,7 +1795,7 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
17991795
RequireAuthTokenOptions
18001796
)
18011797
authTokenOptionHandler := noNeedAuthTokenOptions
1802-
currentAuthPlugin, err := privilege.GetPrivilegeManager(e.Ctx()).GetAuthPlugin(spec.User.Username, spec.User.Hostname, defaultAuthPlugin)
1798+
currentAuthPlugin, err := privilege.GetPrivilegeManager(e.Ctx()).GetAuthPlugin(spec.User.Username, spec.User.Hostname)
18031799
if err != nil {
18041800
return err
18051801
}
@@ -2510,11 +2506,7 @@ func (e *SimpleExec) executeSetPwd(ctx context.Context, s *ast.SetPwdStmt) error
25102506
disableSandboxMode = true
25112507
}
25122508

2513-
defaultAuthPlugin, err := e.Ctx().GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.DefaultAuthPlugin)
2514-
if err != nil {
2515-
return err
2516-
}
2517-
authplugin, err := privilege.GetPrivilegeManager(e.Ctx()).GetAuthPlugin(u, h, defaultAuthPlugin)
2509+
authplugin, err := privilege.GetPrivilegeManager(e.Ctx()).GetAuthPlugin(u, h)
25182510
if err != nil {
25192511
return err
25202512
}

pkg/privilege/privilege.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ type Manager interface {
116116
IsDynamicPrivilege(privNameInUpper string) bool
117117

118118
// GetAuthPluginForConnection gets the authentication plugin used in connection establishment.
119-
GetAuthPluginForConnection(user, host, defaultAuthPlugin string) (string, error)
119+
GetAuthPluginForConnection(user, host string) (string, error)
120120

121121
// GetAuthPlugin gets the authentication plugin for the account identified by the user and host
122-
GetAuthPlugin(user, host, defaultAuthPlugin string) (string, error)
122+
GetAuthPlugin(user, host string) (string, error)
123123
}
124124

125125
const key keyType = 0

pkg/privilege/privileges/cache.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ type MySQLPrivilege struct {
285285
ColumnsPriv []columnsPrivRecord
286286
DefaultRoles []defaultRoleRecord
287287
RoleGraph map[string]roleGraphEdgesTable
288-
289-
defaultAuthPlugin string
290288
}
291289

292290
// FindAllUserEffectiveRoles is used to find all effective roles grant to this user.
@@ -399,9 +397,7 @@ func (p *MySQLPrivilege) LoadAll(ctx sessionctx.Context) error {
399397
}
400398
logutil.BgLogger().Warn("mysql.role_edges missing")
401399
}
402-
403-
p.defaultAuthPlugin, err = ctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.DefaultAuthPlugin)
404-
return err
400+
return nil
405401
}
406402

407403
func noSuchTable(err error) bool {
@@ -669,7 +665,7 @@ func (p *MySQLPrivilege) decodeUserTableRow(row chunk.Row, fs []*resolve.ResultF
669665
if row.GetString(i) != "" {
670666
value.AuthPlugin = row.GetString(i)
671667
} else {
672-
value.AuthPlugin = p.defaultAuthPlugin
668+
value.AuthPlugin = mysql.AuthNativePassword
673669
}
674670
case f.ColumnAsName.L == "token_issuer":
675671
value.AuthTokenIssuer = row.GetString(i)

pkg/privilege/privileges/privileges.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@ func (p *UserPrivileges) GetEncodedPassword(user, host string) string {
328328
}
329329

330330
// GetAuthPluginForConnection gets the authentication plugin used in connection establishment.
331-
func (p *UserPrivileges) GetAuthPluginForConnection(user, host, defaultAuthPlugin string) (string, error) {
331+
func (p *UserPrivileges) GetAuthPluginForConnection(user, host string) (string, error) {
332332
if SkipWithGrant {
333-
return defaultAuthPlugin, nil
333+
return mysql.AuthNativePassword, nil
334334
}
335335

336336
mysqlPriv := p.Handle.Get()
@@ -359,9 +359,9 @@ func (p *UserPrivileges) GetAuthPluginForConnection(user, host, defaultAuthPlugi
359359
}
360360

361361
// GetAuthPlugin gets the authentication plugin for the account identified by the user and host
362-
func (p *UserPrivileges) GetAuthPlugin(user, host, defaultAuthPlugin string) (string, error) {
362+
func (p *UserPrivileges) GetAuthPlugin(user, host string) (string, error) {
363363
if SkipWithGrant {
364-
return defaultAuthPlugin, nil
364+
return mysql.AuthNativePassword, nil
365365
}
366366
mysqlPriv := p.Handle.Get()
367367
record := mysqlPriv.connectionVerification(user, host)

pkg/server/conn.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,8 @@ func (cc *clientConn) checkAuthPlugin(ctx context.Context, resp *handshake.Respo
853853
if err != nil {
854854
return nil, servererr.ErrAccessDenied.FastGenByArgs(cc.user, host, hasPassword)
855855
}
856-
defaultAuthPlugin, err := cc.ctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.DefaultAuthPlugin)
857-
if err != nil {
858-
return nil, err
859-
}
860856
// Get the plugin for the identity.
861-
userplugin, err := cc.ctx.AuthPluginForUser(identity, defaultAuthPlugin)
857+
userplugin, err := cc.ctx.AuthPluginForUser(identity)
862858
if err != nil {
863859
logutil.Logger(ctx).Warn("Failed to get authentication method for user",
864860
zap.String("user", cc.user), zap.String("host", host))

pkg/session/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,10 +2706,10 @@ func (s *session) GetBuildPBCtx() *planctx.BuildPBContext {
27062706
return bctx.(*planctx.BuildPBContext)
27072707
}
27082708

2709-
func (s *session) AuthPluginForUser(user *auth.UserIdentity, defaultAuthPlugin string) (string, error) {
2709+
func (s *session) AuthPluginForUser(user *auth.UserIdentity) (string, error) {
27102710
pm := privilege.GetPrivilegeManager(s)
27112711

2712-
authplugin, err := pm.GetAuthPluginForConnection(user.Username, user.Hostname, defaultAuthPlugin)
2712+
authplugin, err := pm.GetAuthPluginForConnection(user.Username, user.Hostname)
27132713
if err != nil {
27142714
return "", err
27152715
}

pkg/session/types/sesson_interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type Session interface {
7171
Close()
7272
Auth(user *auth.UserIdentity, auth, salt []byte, authConn conn.AuthConn) error
7373
AuthWithoutVerification(user *auth.UserIdentity) bool
74-
AuthPluginForUser(user *auth.UserIdentity, defaultAuthPlugin string) (string, error)
74+
AuthPluginForUser(user *auth.UserIdentity) (string, error)
7575
MatchIdentity(username, remoteHost string) (*auth.UserIdentity, error)
7676
// Return the information of the txn current running
7777
TxnInfo() *txninfo.TxnInfo

tests/integrationtest/r/executor/simple.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,19 @@ id
456456
set autocommit = default;
457457
set global default_authentication_plugin = 'caching_sha2_password';
458458
create user default_sha256_user;
459+
create role default_sha256_role;
459460
show create user default_sha256_user;
460461
CREATE USER for default_sha256_user@%
461462
CREATE USER 'default_sha256_user'@'%' IDENTIFIED WITH 'caching_sha2_password' AS '' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
462463
select plugin from mysql.user where user = 'default_sha256_user';
463464
plugin
464465
caching_sha2_password
466+
show create user default_sha256_role;
467+
CREATE USER for default_sha256_role@%
468+
CREATE USER 'default_sha256_role'@'%' IDENTIFIED WITH 'caching_sha2_password' AS '' REQUIRE NONE PASSWORD EXPIRE ACCOUNT LOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT
469+
select plugin from mysql.user where user = 'default_sha256_role';
470+
plugin
471+
caching_sha2_password
465472
alter user default_sha256_user identified with 'tidb_sm3_password';
466473
show create user default_sha256_user;
467474
CREATE USER for default_sha256_user@%
@@ -484,4 +491,5 @@ select plugin from mysql.user where user = 'default_sha256_user';
484491
plugin
485492
authentication_ldap_sasl
486493
drop user default_sha256_user;
494+
drop user default_sha256_role;
487495
set global default_authentication_plugin = default;

tests/integrationtest/t/executor/simple.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,11 @@ set autocommit = default;
493493
connection default;
494494
set global default_authentication_plugin = 'caching_sha2_password';
495495
create user default_sha256_user;
496+
create role default_sha256_role;
496497
show create user default_sha256_user;
497498
select plugin from mysql.user where user = 'default_sha256_user';
499+
show create user default_sha256_role;
500+
select plugin from mysql.user where user = 'default_sha256_role';
498501

499502
alter user default_sha256_user identified with 'tidb_sm3_password';
500503
show create user default_sha256_user;
@@ -509,4 +512,5 @@ show create user default_sha256_user;
509512
select plugin from mysql.user where user = 'default_sha256_user';
510513

511514
drop user default_sha256_user;
515+
drop user default_sha256_role;
512516
set global default_authentication_plugin = default;

0 commit comments

Comments
 (0)