From 74efee569ea17dcee613bc682f8cc2831809b480 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Mon, 1 Apr 2019 19:15:07 +0800 Subject: [PATCH] Update the registry client to support pulling public images from docker hub without login Only add the authentication info when the username is provided to support pulling public images from docker hub without login Signed-off-by: Wenkai Yin --- src/common/utils/registry/auth/credential.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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