Skip to content

Commit

Permalink
Hide the password info when failing to authorize (milvus-io#28428)
Browse files Browse the repository at this point in the history
/kind improvement

Signed-off-by: SimFG <[email protected]>
  • Loading branch information
SimFG authored Nov 15, 2023
1 parent 836f300 commit 899a5a3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/proxy/authentication_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func AuthenticationInterceptor(ctx context.Context) (context.Context, error) {

if len(authStrArr) < 1 {
log.Warn("key not found in header")
return nil, merr.WrapErrParameterInvalidMsg("missing authorization in header")
return nil, status.Error(codes.Unauthenticated, "missing authorization in header")
}

// token format: base64<username:password>
Expand All @@ -71,14 +71,14 @@ func AuthenticationInterceptor(ctx context.Context) (context.Context, error) {
rawToken, err := crypto.Base64Decode(token)
if err != nil {
log.Warn("fail to decode the token", zap.Error(err))
return nil, merr.WrapErrParameterInvalidMsg("invalid token format")
return nil, status.Error(codes.Unauthenticated, "invalid token format")
}

if !strings.Contains(rawToken, util.CredentialSeperator) {
user, err := VerifyAPIKey(rawToken)
if err != nil {
log.Warn("fail to verify apikey", zap.Error(err))
return nil, err
return nil, status.Error(codes.Unauthenticated, "auth check failure, please check api key is correct")
}
metrics.UserRPCCounter.WithLabelValues(user).Inc()
userToken := fmt.Sprintf("%s%s%s", user, util.CredentialSeperator, "___")
Expand All @@ -88,8 +88,9 @@ func AuthenticationInterceptor(ctx context.Context) (context.Context, error) {
// username+password authentication
username, password := parseMD(rawToken)
if !passwordVerify(ctx, username, password, globalMetaCache) {
log.Warn("fail to verify password", zap.String("username", username))
// NOTE: don't use the merr, because it will cause the wrong retry behavior in the sdk
return nil, status.Errorf(codes.Unauthenticated, "auth check failure, please check username [%s] and password [%s] are correct", username, password)
return nil, status.Error(codes.Unauthenticated, "auth check failure, please check username and password are correct")
}
metrics.UserRPCCounter.WithLabelValues(username).Inc()
}
Expand Down

0 comments on commit 899a5a3

Please sign in to comment.