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

server: handle clients without authplugin support (#27931) #28734

Merged
merged 3 commits into from
Oct 13, 2021
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
44 changes: 28 additions & 16 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,23 +679,9 @@ func (cc *clientConn) readOptionalSSLRequestAndHandshakeResponse(ctx context.Con
cc.collation = resp.Collation
cc.attrs = resp.Attrs

newAuth, err := cc.checkAuthPlugin(ctx, &resp.AuthPlugin)
err = cc.handleAuthPlugin(ctx, &resp)
if err != nil {
logutil.Logger(ctx).Warn("failed to check the user authplugin", zap.Error(err))
}
if len(newAuth) > 0 {
resp.Auth = newAuth
}

switch resp.AuthPlugin {
case mysql.AuthCachingSha2Password:
resp.Auth, err = cc.authSha(ctx)
if err != nil {
return err
}
case mysql.AuthNativePassword:
default:
return errors.New("Unknown auth plugin")
return err
}

err = cc.openSessionAndDoAuth(resp.Auth)
Expand All @@ -705,6 +691,32 @@ func (cc *clientConn) readOptionalSSLRequestAndHandshakeResponse(ctx context.Con
return err
}

func (cc *clientConn) handleAuthPlugin(ctx context.Context, resp *handshakeResponse41) error {
if resp.Capability&mysql.ClientPluginAuth > 0 {
newAuth, err := cc.checkAuthPlugin(ctx, &resp.AuthPlugin)
if err != nil {
logutil.Logger(ctx).Warn("failed to check the user authplugin", zap.Error(err))
}
if len(newAuth) > 0 {
resp.Auth = newAuth
}

switch resp.AuthPlugin {
case mysql.AuthCachingSha2Password:
resp.Auth, err = cc.authSha(ctx)
if err != nil {
return err
}
case mysql.AuthNativePassword:
default:
logutil.Logger(ctx).Warn("Unknown Auth Plugin", zap.String("plugin", resp.AuthPlugin))
}
} else {
logutil.Logger(ctx).Warn("Client without Auth Plugin support; Please upgrade client")
}
return nil
}

func (cc *clientConn) authSha(ctx context.Context) ([]byte, error) {

const (
Expand Down
35 changes: 35 additions & 0 deletions server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,38 @@ func (ts *ConnTestSuite) TestShowErrors(c *C) {
c.Assert(err, NotNil)
tk.MustQuery("show errors").Check(testkit.Rows("Error 1051 Unknown table 'test.idontexist'"))
}

func (ts *ConnTestSuite) TestHandleAuthPlugin(c *C) {
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
defer func() {
err := store.Close()
c.Assert(err, IsNil)
}()

cfg := newTestConfig()
cfg.Port = 0
cfg.Status.StatusPort = 0
drv := NewTiDBDriver(store)
srv, err := NewServer(cfg, drv)
c.Assert(err, IsNil)

cc := &clientConn{
connectionID: 1,
alloc: arena.NewAllocator(1024),
pkt: &packetIO{
bufWriter: bufio.NewWriter(bytes.NewBuffer(nil)),
},
server: srv,
}
ctx := context.Background()
resp := handshakeResponse41{
Capability: mysql.ClientProtocol41 | mysql.ClientPluginAuth,
}
err = cc.handleAuthPlugin(ctx, &resp)
c.Assert(err, IsNil)

resp.Capability = mysql.ClientProtocol41
err = cc.handleAuthPlugin(ctx, &resp)
c.Assert(err, IsNil)
}