c8d/pull: Don't wrap no basic auth error

Don't wrap the `no basic auth credentials` error from containerd and
return it as-is.

The error will look like:
```
failed to resolve reference "docker.io/library/aodkoakds:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
```

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2023-10-17 09:57:22 +02:00
parent 1f096174d6
commit df34db1158
No known key found for this signature in database
GPG key ID: B85EFCFE26DEF92A

View file

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"strings"
"github.com/containerd/containerd"
cerrdefs "github.com/containerd/containerd/errdefs"
@ -124,6 +125,11 @@ func (i *ImageService) PullImage(ctx context.Context, ref reference.Named, platf
img, err := i.client.Pull(ctx, ref.String(), opts...)
if err != nil {
if errors.Is(err, docker.ErrInvalidAuthorization) {
// Match error returned by containerd.
// https://github.com/containerd/containerd/blob/v1.7.8/remotes/docker/authorizer.go#L189-L191
if strings.Contains(err.Error(), "no basic auth credentials") {
return err
}
return errdefs.NotFound(fmt.Errorf("pull access denied for %s, repository does not exist or may require 'docker login'", reference.FamiliarName(ref)))
}
return err