You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/07/22 14:51:18 UTC

[GitHub] [servicecomb-service-center] little-cui opened a new pull request #1104: Change: DON'T check root exist if pass root token

little-cui opened a new pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104


   Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/SCB) filed for the change (usually before you start working on it).  Trivial changes like typos do not require a JIRA issue.  Your pull request should address just this issue, without pulling in other changes.
    - [ ] Each commit in the pull request should have a meaningful subject line and body.
    - [ ] Format the pull request title like `[SCB-XXX] Fixes bug in ApproximateQuantiles`, where you replace `SCB-XXX` with the appropriate JIRA issue.
    - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [ ] Run `go build` `go test` `go fmt` `go vet` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
    - [ ] Never comment source code, delete it.
    - [ ] UT should has "context, subject, expected result" result as test case name, when you call t.Run().
   ---
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
little-cui commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r676010021



##########
File path: server/service/rbac/authr_plugin.go
##########
@@ -102,19 +99,6 @@ func (a *EmbeddedAuthenticator) Authenticate(ctx context.Context, tokenStr strin
 		}
 		return nil, err
 	}
-	accountNameI := claims[rbac.ClaimsUser]
-	n, ok := accountNameI.(string)
-	if !ok {
-		return nil, rbac.ErrConvert
-	}
-	exist, err := datasource.GetAccountManager().AccountExist(ctx, n)

Review comment:
       并没有删除,只是这个函数是解析jwt的claims信息,我觉得把账号存在性耦合不合适,单独抽离到server/plugin/auth/buildin/buildin.go:73,这也是为了完成root不校验的关键修改点,ROOT场景,jwt身份鉴权,但账号存在性跳过




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r675327312



##########
File path: server/plugin/auth/buildin/buildin.go
##########
@@ -60,51 +64,76 @@ func (ba *TokenAuthenticator) Identify(req *http.Request) error {
 		return nil
 	}
 
-	claims, err := ba.VerifyToken(req)
+	account, err := ba.readAccount(req)
 	if err != nil {
-		log.Errorf(err, "verify request token failed, %s %s", req.Method, req.RequestURI)
 		return err
 	}
 
-	m, ok := claims.(map[string]interface{})
-	if !ok {
-		log.Error("claims convert failed", rbacmodel.ErrConvertErr)
-		return rbacmodel.ErrConvertErr
-	}
-	account, err := rbacmodel.GetAccount(m)
+	// if account not exist should return auth failure
+	err = accountExist(req.Context(), account.Name)
 	if err != nil {
-		log.Error("get account from token failed", err)
 		return err
 	}
-	util.SetRequestContext(req, rbacsvc.CtxRequestClaims, m)
+
 	// user can change self password
-	if isChangeSelfPassword(pattern, account, req) {
+	if isChangeSelfPassword(pattern, account.Name, req) {
 		return nil
 	}
 
+	matchedLabels, err := checkPerm(account.Roles, req)
+	if err != nil {
+		return err
+	}
+
+	util.SetRequestContext(req, authHandler.CtxResourceLabels, matchedLabels)
+	return nil
+}
+
+func (ba *TokenAuthenticator) readAccount(req *http.Request) (*rbacmodel.Account, error) {
+	claims, err := ba.VerifyToken(req)

Review comment:
       不能在名字为readxx的函数签名内干验证+读数据+校验的工作,把函数签名改为VerifyHttpReq我觉得很准确




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
little-cui commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r676010700



##########
File path: server/plugin/auth/buildin/buildin.go
##########
@@ -60,51 +64,76 @@ func (ba *TokenAuthenticator) Identify(req *http.Request) error {
 		return nil
 	}
 
-	claims, err := ba.VerifyToken(req)
+	account, err := ba.readAccount(req)
 	if err != nil {
-		log.Errorf(err, "verify request token failed, %s %s", req.Method, req.RequestURI)
 		return err
 	}
 
-	m, ok := claims.(map[string]interface{})
-	if !ok {
-		log.Error("claims convert failed", rbacmodel.ErrConvertErr)
-		return rbacmodel.ErrConvertErr
-	}
-	account, err := rbacmodel.GetAccount(m)
+	// if account not exist should return auth failure
+	err = accountExist(req.Context(), account.Name)
 	if err != nil {
-		log.Error("get account from token failed", err)
 		return err
 	}
-	util.SetRequestContext(req, rbacsvc.CtxRequestClaims, m)
+
 	// user can change self password
-	if isChangeSelfPassword(pattern, account, req) {
+	if isChangeSelfPassword(pattern, account.Name, req) {
 		return nil
 	}
 
+	matchedLabels, err := checkPerm(account.Roles, req)
+	if err != nil {
+		return err
+	}
+
+	util.SetRequestContext(req, authHandler.CtxResourceLabels, matchedLabels)
+	return nil
+}
+
+func (ba *TokenAuthenticator) readAccount(req *http.Request) (*rbacmodel.Account, error) {
+	claims, err := ba.VerifyToken(req)

Review comment:
       DONE




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r675327312



##########
File path: server/plugin/auth/buildin/buildin.go
##########
@@ -60,51 +64,76 @@ func (ba *TokenAuthenticator) Identify(req *http.Request) error {
 		return nil
 	}
 
-	claims, err := ba.VerifyToken(req)
+	account, err := ba.readAccount(req)
 	if err != nil {
-		log.Errorf(err, "verify request token failed, %s %s", req.Method, req.RequestURI)
 		return err
 	}
 
-	m, ok := claims.(map[string]interface{})
-	if !ok {
-		log.Error("claims convert failed", rbacmodel.ErrConvertErr)
-		return rbacmodel.ErrConvertErr
-	}
-	account, err := rbacmodel.GetAccount(m)
+	// if account not exist should return auth failure
+	err = accountExist(req.Context(), account.Name)
 	if err != nil {
-		log.Error("get account from token failed", err)
 		return err
 	}
-	util.SetRequestContext(req, rbacsvc.CtxRequestClaims, m)
+
 	// user can change self password
-	if isChangeSelfPassword(pattern, account, req) {
+	if isChangeSelfPassword(pattern, account.Name, req) {
 		return nil
 	}
 
+	matchedLabels, err := checkPerm(account.Roles, req)
+	if err != nil {
+		return err
+	}
+
+	util.SetRequestContext(req, authHandler.CtxResourceLabels, matchedLabels)
+	return nil
+}
+
+func (ba *TokenAuthenticator) readAccount(req *http.Request) (*rbacmodel.Account, error) {
+	claims, err := ba.VerifyToken(req)

Review comment:
       不能再名字为readxx的函数签名内干验证加读的工作,把函数签名改为VerifyAndRead




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r676258457



##########
File path: server/service/rbac/resource.go
##########
@@ -112,19 +112,27 @@ func initAuthResources() {
 	scopes := strings.Split(config.GetString("rbac.scope", "*"), ",")

Review comment:
       role account两个资源必须不可以配置,而是代码写死决定的,这两个资源必须受到校验和保护。否则可以通过不配置这两个资源,而导致出现安全漏洞。也就是说用户对系统缺乏理解而导致的,我们尽可能进行一些防呆设计,减少用户自己分析安全问题




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r675327312



##########
File path: server/plugin/auth/buildin/buildin.go
##########
@@ -60,51 +64,76 @@ func (ba *TokenAuthenticator) Identify(req *http.Request) error {
 		return nil
 	}
 
-	claims, err := ba.VerifyToken(req)
+	account, err := ba.readAccount(req)
 	if err != nil {
-		log.Errorf(err, "verify request token failed, %s %s", req.Method, req.RequestURI)
 		return err
 	}
 
-	m, ok := claims.(map[string]interface{})
-	if !ok {
-		log.Error("claims convert failed", rbacmodel.ErrConvertErr)
-		return rbacmodel.ErrConvertErr
-	}
-	account, err := rbacmodel.GetAccount(m)
+	// if account not exist should return auth failure
+	err = accountExist(req.Context(), account.Name)
 	if err != nil {
-		log.Error("get account from token failed", err)
 		return err
 	}
-	util.SetRequestContext(req, rbacsvc.CtxRequestClaims, m)
+
 	// user can change self password
-	if isChangeSelfPassword(pattern, account, req) {
+	if isChangeSelfPassword(pattern, account.Name, req) {
 		return nil
 	}
 
+	matchedLabels, err := checkPerm(account.Roles, req)
+	if err != nil {
+		return err
+	}
+
+	util.SetRequestContext(req, authHandler.CtxResourceLabels, matchedLabels)
+	return nil
+}
+
+func (ba *TokenAuthenticator) readAccount(req *http.Request) (*rbacmodel.Account, error) {
+	claims, err := ba.VerifyToken(req)

Review comment:
       不能在名字为readxx的函数签名内干验证+读数据+校验的工作,把函数签名改为Verify




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r675327312



##########
File path: server/plugin/auth/buildin/buildin.go
##########
@@ -60,51 +64,76 @@ func (ba *TokenAuthenticator) Identify(req *http.Request) error {
 		return nil
 	}
 
-	claims, err := ba.VerifyToken(req)
+	account, err := ba.readAccount(req)
 	if err != nil {
-		log.Errorf(err, "verify request token failed, %s %s", req.Method, req.RequestURI)
 		return err
 	}
 
-	m, ok := claims.(map[string]interface{})
-	if !ok {
-		log.Error("claims convert failed", rbacmodel.ErrConvertErr)
-		return rbacmodel.ErrConvertErr
-	}
-	account, err := rbacmodel.GetAccount(m)
+	// if account not exist should return auth failure
+	err = accountExist(req.Context(), account.Name)
 	if err != nil {
-		log.Error("get account from token failed", err)
 		return err
 	}
-	util.SetRequestContext(req, rbacsvc.CtxRequestClaims, m)
+
 	// user can change self password
-	if isChangeSelfPassword(pattern, account, req) {
+	if isChangeSelfPassword(pattern, account.Name, req) {
 		return nil
 	}
 
+	matchedLabels, err := checkPerm(account.Roles, req)
+	if err != nil {
+		return err
+	}
+
+	util.SetRequestContext(req, authHandler.CtxResourceLabels, matchedLabels)
+	return nil
+}
+
+func (ba *TokenAuthenticator) readAccount(req *http.Request) (*rbacmodel.Account, error) {
+	claims, err := ba.VerifyToken(req)

Review comment:
       不能在名字为readxx的函数签名内干验证+读数据+校验的工作,把函数签名改为Verify我觉得很准确

##########
File path: server/plugin/auth/buildin/buildin.go
##########
@@ -60,51 +64,76 @@ func (ba *TokenAuthenticator) Identify(req *http.Request) error {
 		return nil
 	}
 
-	claims, err := ba.VerifyToken(req)
+	account, err := ba.readAccount(req)
 	if err != nil {
-		log.Errorf(err, "verify request token failed, %s %s", req.Method, req.RequestURI)
 		return err
 	}
 
-	m, ok := claims.(map[string]interface{})
-	if !ok {
-		log.Error("claims convert failed", rbacmodel.ErrConvertErr)
-		return rbacmodel.ErrConvertErr
-	}
-	account, err := rbacmodel.GetAccount(m)
+	// if account not exist should return auth failure
+	err = accountExist(req.Context(), account.Name)
 	if err != nil {
-		log.Error("get account from token failed", err)
 		return err
 	}
-	util.SetRequestContext(req, rbacsvc.CtxRequestClaims, m)
+
 	// user can change self password
-	if isChangeSelfPassword(pattern, account, req) {
+	if isChangeSelfPassword(pattern, account.Name, req) {
 		return nil
 	}
 
+	matchedLabels, err := checkPerm(account.Roles, req)
+	if err != nil {
+		return err
+	}
+
+	util.SetRequestContext(req, authHandler.CtxResourceLabels, matchedLabels)
+	return nil
+}
+
+func (ba *TokenAuthenticator) readAccount(req *http.Request) (*rbacmodel.Account, error) {
+	claims, err := ba.VerifyToken(req)

Review comment:
       不能在名字为readxx的函数签名内干验证+读数据+校验的工作,把函数签名改为Verify(request)我觉得很准确




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r676258457



##########
File path: server/service/rbac/resource.go
##########
@@ -112,19 +112,27 @@ func initAuthResources() {
 	scopes := strings.Split(config.GetString("rbac.scope", "*"), ",")

Review comment:
       role account两个资源必须不可以配置,而是代码写死决定的,这两个资源必须受到校验和保护。否则可以通过不配置这两个资源,而导致出现安全漏洞。也就是说用户对系统缺乏理解而导致的。原则上,我们尽可能进行一些防呆设计,减少用户自己分析安全问题




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r675327312



##########
File path: server/plugin/auth/buildin/buildin.go
##########
@@ -60,51 +64,76 @@ func (ba *TokenAuthenticator) Identify(req *http.Request) error {
 		return nil
 	}
 
-	claims, err := ba.VerifyToken(req)
+	account, err := ba.readAccount(req)
 	if err != nil {
-		log.Errorf(err, "verify request token failed, %s %s", req.Method, req.RequestURI)
 		return err
 	}
 
-	m, ok := claims.(map[string]interface{})
-	if !ok {
-		log.Error("claims convert failed", rbacmodel.ErrConvertErr)
-		return rbacmodel.ErrConvertErr
-	}
-	account, err := rbacmodel.GetAccount(m)
+	// if account not exist should return auth failure
+	err = accountExist(req.Context(), account.Name)
 	if err != nil {
-		log.Error("get account from token failed", err)
 		return err
 	}
-	util.SetRequestContext(req, rbacsvc.CtxRequestClaims, m)
+
 	// user can change self password
-	if isChangeSelfPassword(pattern, account, req) {
+	if isChangeSelfPassword(pattern, account.Name, req) {
 		return nil
 	}
 
+	matchedLabels, err := checkPerm(account.Roles, req)
+	if err != nil {
+		return err
+	}
+
+	util.SetRequestContext(req, authHandler.CtxResourceLabels, matchedLabels)
+	return nil
+}
+
+func (ba *TokenAuthenticator) readAccount(req *http.Request) (*rbacmodel.Account, error) {
+	claims, err := ba.VerifyToken(req)

Review comment:
       不能在名字为readxx的函数签名内干验证加读的工作,把函数签名改为VerifyAndRead




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r676258457



##########
File path: server/service/rbac/resource.go
##########
@@ -112,19 +112,27 @@ func initAuthResources() {
 	scopes := strings.Split(config.GetString("rbac.scope", "*"), ",")

Review comment:
       role account两个资源必须不可以配置,而是代码写死决定的,这两个资源必须受到校验和保护。否则可以通过不配置这两个资源,而导致出现安全漏洞。也就是说用户对系统缺乏理解而导致的。原则上,我们尽可能进行一些防呆设计,减少用户自己引发安全事故,或者自行分析安全保护




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
little-cui commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r676010021



##########
File path: server/service/rbac/authr_plugin.go
##########
@@ -102,19 +99,6 @@ func (a *EmbeddedAuthenticator) Authenticate(ctx context.Context, tokenStr strin
 		}
 		return nil, err
 	}
-	accountNameI := claims[rbac.ClaimsUser]
-	n, ok := accountNameI.(string)
-	if !ok {
-		return nil, rbac.ErrConvert
-	}
-	exist, err := datasource.GetAccountManager().AccountExist(ctx, n)

Review comment:
       并没有删除,只是这个函数是解析jwt的claims信息,我觉得把账号存在性耦合不合适,单独抽离到server/plugin/auth/buildin/buildin.go:73,这也是为了完成root不校验的关键修改点




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#issuecomment-886309934


   错误的用户名或密码,server端必须返回401,而更具体的错误,可以用字符串和错误码对客户端响应,不该返回404改变约定俗成的http状态码语义


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
little-cui commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r676010021



##########
File path: server/service/rbac/authr_plugin.go
##########
@@ -102,19 +99,6 @@ func (a *EmbeddedAuthenticator) Authenticate(ctx context.Context, tokenStr strin
 		}
 		return nil, err
 	}
-	accountNameI := claims[rbac.ClaimsUser]
-	n, ok := accountNameI.(string)
-	if !ok {
-		return nil, rbac.ErrConvert
-	}
-	exist, err := datasource.GetAccountManager().AccountExist(ctx, n)

Review comment:
       并没有删除,只是这个函数是解析jwt的claims信息,我觉得把账号存在性耦合不合适,单独抽离到server/plugin/auth/buildin/buildin.go:73




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
little-cui commented on pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#issuecomment-886371088


   > 错误的用户名或密码,server端必须返回401,而更具体的错误,可以用字符串和错误码对客户端响应,不该返回404改变约定俗成的http状态码语义
   
   Resolve


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r675328082



##########
File path: server/service/rbac/authr_plugin.go
##########
@@ -102,19 +99,6 @@ func (a *EmbeddedAuthenticator) Authenticate(ctx context.Context, tokenStr strin
 		}
 		return nil, err
 	}
-	accountNameI := claims[rbac.ClaimsUser]
-	n, ok := accountNameI.(string)
-	if !ok {
-		return nil, rbac.ErrConvert
-	}
-	exist, err := datasource.GetAccountManager().AccountExist(ctx, n)

Review comment:
       为何删掉这段逻辑,这是考虑账号被删除的场景




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang merged pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang merged pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r676258457



##########
File path: server/service/rbac/resource.go
##########
@@ -112,19 +112,27 @@ func initAuthResources() {
 	scopes := strings.Split(config.GetString("rbac.scope", "*"), ",")

Review comment:
       role account两个资源必须不可以配置,而是代码写死决定的,这两个资源必须受到校验和保护。否则可以通过不配置这两个资源,而导致出现安全漏洞




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #1104: Change: DON'T check root exist if pass root token

Posted by GitBox <gi...@apache.org>.
tianxiaoliang commented on a change in pull request #1104:
URL: https://github.com/apache/servicecomb-service-center/pull/1104#discussion_r675327312



##########
File path: server/plugin/auth/buildin/buildin.go
##########
@@ -60,51 +64,76 @@ func (ba *TokenAuthenticator) Identify(req *http.Request) error {
 		return nil
 	}
 
-	claims, err := ba.VerifyToken(req)
+	account, err := ba.readAccount(req)
 	if err != nil {
-		log.Errorf(err, "verify request token failed, %s %s", req.Method, req.RequestURI)
 		return err
 	}
 
-	m, ok := claims.(map[string]interface{})
-	if !ok {
-		log.Error("claims convert failed", rbacmodel.ErrConvertErr)
-		return rbacmodel.ErrConvertErr
-	}
-	account, err := rbacmodel.GetAccount(m)
+	// if account not exist should return auth failure
+	err = accountExist(req.Context(), account.Name)
 	if err != nil {
-		log.Error("get account from token failed", err)
 		return err
 	}
-	util.SetRequestContext(req, rbacsvc.CtxRequestClaims, m)
+
 	// user can change self password
-	if isChangeSelfPassword(pattern, account, req) {
+	if isChangeSelfPassword(pattern, account.Name, req) {
 		return nil
 	}
 
+	matchedLabels, err := checkPerm(account.Roles, req)
+	if err != nil {
+		return err
+	}
+
+	util.SetRequestContext(req, authHandler.CtxResourceLabels, matchedLabels)
+	return nil
+}
+
+func (ba *TokenAuthenticator) readAccount(req *http.Request) (*rbacmodel.Account, error) {
+	claims, err := ba.VerifyToken(req)

Review comment:
       不能在名字为readxx的函数签名内干验证加读的工作,把函数签名改为Verify




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org