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:
stonezdj 2024-10-18 14:06:56 +08:00 committed by stonezdj(Daojun Zhang)
parent 66c98c81f1
commit 58b968097b
2 changed files with 9 additions and 0 deletions

View File

@ -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)
}

View File

@ -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
}