From aa212773804561eaee04c3b4a7d9399dfbb9cad1 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Wed, 3 May 2023 18:44:26 +0200 Subject: [PATCH] fix: fallback to unauthenticated pull (#1774) * fix: fallback to unauthenticated pull * move logger def * fixup * add import * . --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/container/docker_pull.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/container/docker_pull.go b/pkg/container/docker_pull.go index 75bfed1..6fb2961 100644 --- a/pkg/container/docker_pull.go +++ b/pkg/container/docker_pull.go @@ -7,6 +7,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "strings" "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" @@ -59,6 +60,13 @@ func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor { _ = logDockerResponse(logger, reader, err != nil) if err != nil { + if imagePullOptions.RegistryAuth != "" && strings.Contains(err.Error(), "unauthorized") { + logger.Errorf("pulling image '%v' (%s) failed with credentials %s retrying without them, please check for stale docker config files", imageRef, input.Platform, err.Error()) + imagePullOptions.RegistryAuth = "" + reader, err = cli.ImagePull(ctx, imageRef, imagePullOptions) + + _ = logDockerResponse(logger, reader, err != nil) + } return err } return nil @@ -69,9 +77,9 @@ func getImagePullOptions(ctx context.Context, input NewDockerPullExecutorInput) imagePullOptions := types.ImagePullOptions{ Platform: input.Platform, } + logger := common.Logger(ctx) if input.Username != "" && input.Password != "" { - logger := common.Logger(ctx) logger.Debugf("using authentication for docker pull") authConfig := types.AuthConfig{ @@ -93,6 +101,7 @@ func getImagePullOptions(ctx context.Context, input NewDockerPullExecutorInput) if authConfig.Username == "" && authConfig.Password == "" { return imagePullOptions, nil } + logger.Info("using DockerAuthConfig authentication for docker pull") encodedJSON, err := json.Marshal(authConfig) if err != nil {