mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-18 14:47:38 +01:00
Return basic auth challenge for /v2/_catalog (#12956)
Fixes #12192 Signed-off-by: Daniel Jiang <jiangd@vmware.com>
This commit is contained in:
parent
f4938ca966
commit
66c3fa9eec
@ -16,6 +16,7 @@ package v2auth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/goharbor/harbor/src/lib"
|
||||
lib_http "github.com/goharbor/harbor/src/lib/http"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -84,8 +85,9 @@ func (rc *reqChecker) projectID(name string) (int64, error) {
|
||||
func getChallenge(req *http.Request, accessList []access) string {
|
||||
logger := log.G(req.Context())
|
||||
auth := req.Header.Get(authHeader)
|
||||
if len(auth) > 0 {
|
||||
// Return basic auth challenge by default
|
||||
if len(auth) > 0 ||
|
||||
len(lib.V2CatalogURLRe.FindStringSubmatch(req.URL.Path)) == 1 {
|
||||
// Return basic auth challenge by default, incl. request to '/v2/_catalog'
|
||||
return `Basic realm="harbor"`
|
||||
}
|
||||
// No auth header, treat it as CLI and redirect to token service
|
||||
|
@ -262,7 +262,7 @@ func TestGetChallenge(t *testing.T) {
|
||||
},
|
||||
{
|
||||
request: req2,
|
||||
challenge: `Bearer realm="https://harbor.test/service/token",service="harbor-registry"`,
|
||||
challenge: `Basic realm="harbor"`,
|
||||
},
|
||||
{
|
||||
request: req2x,
|
||||
|
Loading…
Reference in New Issue
Block a user