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

Skip admin and change oidc user not found message more readable #21061

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/pkg/oidc/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"

"github.com/goharbor/harbor/src/common/utils"
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions src/server/middleware/security/oidc_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading