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: unix socket should verify user's authentication #8381

Merged
merged 10 commits into from
Nov 22, 2018
15 changes: 8 additions & 7 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,17 @@ func (cc *clientConn) openSessionAndDoAuth(authData []byte) error {
if err != nil {
return errors.Trace(err)
}
if !cc.server.skipAuth() {
// Do Auth.
host := "localhost"
if !cc.server.isUnixSocket() {
addr := cc.bufReadConn.RemoteAddr().String()
host, _, err1 := net.SplitHostPort(addr)
if err1 != nil {
// Do Auth.
host, _, err = net.SplitHostPort(addr)
if err != nil {
return errors.Trace(errAccessDenied.GenWithStackByArgs(cc.user, addr, "YES"))
}
if !cc.ctx.Auth(&auth.UserIdentity{Username: cc.user, Hostname: host}, authData, cc.salt) {
return errors.Trace(errAccessDenied.GenWithStackByArgs(cc.user, host, "YES"))
}
}
if !cc.ctx.Auth(&auth.UserIdentity{Username: cc.user, Hostname: host}, authData, cc.salt) {
return errors.Trace(errAccessDenied.GenWithStackByArgs(cc.user, host, "YES"))
}
if cc.dbname != "" {
err = cc.useDB(context.Background(), cc.dbname)
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (s *Server) newConn(conn net.Conn) *clientConn {
return cc
}

func (s *Server) skipAuth() bool {
func (s *Server) isUnixSocket() bool {
return s.cfg.Socket != ""
}

Expand Down
3 changes: 3 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ func (dbt *DBTest) mustQueryRows(query string, args ...interface{}) {

func runTestRegression(c *C, overrider configOverrider, dbName string) {
runTestsOnNewDB(c, overrider, dbName, func(dbt *DBTest) {
// Show the user
dbt.mustExec("select user()")

// Create Table
dbt.mustExec("CREATE TABLE test (val TINYINT)")

Expand Down