From e516689ec5f2246522ab7fcf5f76cfd23be6e07f Mon Sep 17 00:00:00 2001 From: anjmao Date: Tue, 30 Apr 2024 10:28:20 +0300 Subject: [PATCH] Fix username/password auth --- image/remote.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/image/remote.go b/image/remote.go index a7ee3f9..1705835 100644 --- a/image/remote.go +++ b/image/remote.go @@ -43,14 +43,23 @@ func NewFromRemote(ctx context.Context, imageName string, option types.ImageOpti } func tryRemote(ctx context.Context, imageName string, ref name.Reference, option types.ImageOptions) (ImageWithIndex, error) { - var remoteOpts []remote.Option + remoteOpts := []remote.Option{ + remote.WithContext(ctx), + } if option.RegistryOptions.Insecure { t := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec } remoteOpts = append(remoteOpts, remote.WithTransport(t)) } - remoteOpts = append(remoteOpts, remote.WithContext(ctx)) + + // Username/Password based auth. + for _, cred := range option.RegistryOptions.Credentials { + remoteOpts = append(remoteOpts, remote.WithAuth(&authn.Basic{ + Username: cred.Username, + Password: cred.Password, + })) + } domain := ref.Context().RegistryStr() auth := registry.GetToken(ctx, domain, option.RegistryOptions)