Skip to content

Commit

Permalink
When authenticating to docker registry use either token or username w…
Browse files Browse the repository at this point in the history
…ith password
  • Loading branch information
domust committed Jul 1, 2024
1 parent 8fb1216 commit 0dbb2b6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cmd/imagescan/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down

0 comments on commit 0dbb2b6

Please sign in to comment.