diff --git a/src/common/utils/registry/auth/credential.go b/src/common/utils/registry/auth/credential.go index b93077101..fcac4c350 100644 --- a/src/common/utils/registry/auth/credential.go +++ b/src/common/utils/registry/auth/credential.go @@ -38,7 +38,12 @@ func NewBasicAuthCredential(username, password string) Credential { } func (b *basicAuthCredential) AddAuthorization(req *http.Request) { - req.SetBasicAuth(b.username, b.password) + // only add the authentication info when the username isn't empty + // the logic is needed for requesting resources from docker hub's + // public repositories + if len(b.username) > 0 { + req.SetBasicAuth(b.username, b.password) + } } // implement github.com/goharbor/harbor/src/common/http/modifier.Modifier