Unverified Commit 66c3fa9e authored by Daniel Jiang's avatar Daniel Jiang Committed by GitHub
Browse files

Return basic auth challenge for /v2/_catalog (#12956)



Fixes #12192
Signed-off-by: default avatarDaniel Jiang <jiangd@vmware.com>
parent f4938ca9
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment