mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-19 15:17:43 +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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/goharbor/harbor/src/lib"
|
||||||
lib_http "github.com/goharbor/harbor/src/lib/http"
|
lib_http "github.com/goharbor/harbor/src/lib/http"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -84,8 +85,9 @@ func (rc *reqChecker) projectID(name string) (int64, error) {
|
|||||||
func getChallenge(req *http.Request, accessList []access) string {
|
func getChallenge(req *http.Request, accessList []access) string {
|
||||||
logger := log.G(req.Context())
|
logger := log.G(req.Context())
|
||||||
auth := req.Header.Get(authHeader)
|
auth := req.Header.Get(authHeader)
|
||||||
if len(auth) > 0 {
|
if len(auth) > 0 ||
|
||||||
// Return basic auth challenge by default
|
len(lib.V2CatalogURLRe.FindStringSubmatch(req.URL.Path)) == 1 {
|
||||||
|
// Return basic auth challenge by default, incl. request to '/v2/_catalog'
|
||||||
return `Basic realm="harbor"`
|
return `Basic realm="harbor"`
|
||||||
}
|
}
|
||||||
// No auth header, treat it as CLI and redirect to token service
|
// No auth header, treat it as CLI and redirect to token service
|
||||||
|
@ -262,7 +262,7 @@ func TestGetChallenge(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
request: req2,
|
request: req2,
|
||||||
challenge: `Bearer realm="https://harbor.test/service/token",service="harbor-registry"`,
|
challenge: `Basic realm="harbor"`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
request: req2x,
|
request: req2x,
|
||||||
|
Loading…
Reference in New Issue
Block a user