mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 02:05:41 +01:00
Skip admin and change oidc user not found message more readable
fixes #21041 Signed-off-by: stonezdj <stone.zhang@broadcom.com>
This commit is contained in:
parent
66c98c81f1
commit
58b968097b
@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/goharbor/harbor/src/common/utils"
|
||||
@ -86,6 +87,9 @@ var m SecretManager = &defaultManager{
|
||||
func (dm *defaultManager) VerifySecret(ctx context.Context, username string, secret string) (*UserInfo, error) {
|
||||
log.Debugf("Verifying the secret for user: %s", username)
|
||||
oidcUser, err := dm.metaDao.GetByUsername(ctx, username)
|
||||
if strings.Contains(err.Error(), "no row found") {
|
||||
return nil, fmt.Errorf("oidc user: %v not found", username)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get oidc user info, error: %v", err)
|
||||
}
|
||||
|
@ -65,6 +65,11 @@ func (o *oidcCli) Generate(req *http.Request) security.Context {
|
||||
|
||||
info, err := oidc.VerifySecret(ctx, username, secret)
|
||||
if err != nil {
|
||||
user, err2 := uctl.GetByName(ctx, username)
|
||||
// skip to log the error if the user is the admin user
|
||||
if err2 == nil && user != nil && user.UserID == 1 {
|
||||
return nil
|
||||
}
|
||||
logger.Errorf("failed to verify secret, username: %s, error: %v", username, err)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user