From 0dbb2b65d059c3ef1662382716083e718e9a3baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domas=20Tama=C5=A1auskas?= Date: Mon, 1 Jul 2024 13:38:56 +0300 Subject: [PATCH] When authenticating to docker registry use either token or username with password --- cmd/imagescan/collector/collector.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/imagescan/collector/collector.go b/cmd/imagescan/collector/collector.go index 03f0e0a8..77d8829a 100644 --- a/cmd/imagescan/collector/collector.go +++ b/cmd/imagescan/collector/collector.go @@ -166,11 +166,16 @@ func (c *Collector) getImage(ctx context.Context) (image.ImageWithIndex, func(), if authKey, auth, ok := findRegistryAuth(cfg, imgRef); ok { c.log.Infof("using registry auth, key=%s", authKey) - opts.RegistryOptions.Credentials = append(opts.RegistryOptions.Credentials, types.Credential{ - Username: auth.Username, - Password: auth.Password, - }) - opts.RegistryOptions.RegistryToken = auth.Token + if auth.Username == "" || auth.Password == "" { + if auth.Token != "" { + opts.RegistryOptions.RegistryToken = auth.Token + } + } else { + opts.RegistryOptions.Credentials = append(opts.RegistryOptions.Credentials, types.Credential{ + Username: auth.Username, + Password: auth.Password, + }) + } } else { c.log.Infof("image pull secret %q cannot be used to pull %q", c.cfg.ImagePullSecret, imgRef.String()) }