Skip to content

Commit

Permalink
Skip admin and change oidc user not found message more readable
Browse files Browse the repository at this point in the history
  fixes goharbor#21041

Signed-off-by: stonezdj <[email protected]>
  • Loading branch information
stonezdj committed Oct 18, 2024
1 parent ab3d350 commit 4ba168e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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
4 changes: 4 additions & 0 deletions src/server/middleware/security/oidc_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (o *oidcCli) Generate(req *http.Request) security.Context {
return nil
}

if username == "admin" {
return nil
}

info, err := oidc.VerifySecret(ctx, username, secret)
if err != nil {
logger.Errorf("failed to verify secret, username: %s, error: %v", username, err)
Expand Down

0 comments on commit 4ba168e

Please sign in to comment.