Skip to content

Commit

Permalink
Merge pull request moby#9 from vvoland/containerd-store-pull-auth
Browse files Browse the repository at this point in the history
containerd/pull: Use authorization
  • Loading branch information
rumpl committed Jul 8, 2022
2 parents b5fc758 + 063ee97 commit 7d9ebf8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions daemon/containerd/service.go
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/remotes"
"github.com/containerd/containerd/remotes/docker"
"github.com/containerd/containerd/snapshots"
"github.com/docker/distribution"
"github.com/docker/distribution/reference"
Expand Down Expand Up @@ -59,6 +61,9 @@ func (cs *containerdStore) PullImage(ctx context.Context, image, tag string, pla
}
}

resolver := newResolverFromAuthConfig(authConfig)
opts = append(opts, containerd.WithResolver(resolver))

_, err = cs.client.Pull(ctx, ref.String(), opts...)
return err
}
Expand Down Expand Up @@ -176,6 +181,24 @@ func (cs *containerdStore) setupFilters(ctx context.Context, opts types.ImageLis
return filters, nil
}

func newResolverFromAuthConfig(authConfig *types.AuthConfig) remotes.Resolver {
opts := []docker.RegistryOpt{}
if authConfig != nil {
authorizer := docker.NewDockerAuthorizer(docker.WithAuthCreds(func(_ string) (string, string, error) {
if authConfig.IdentityToken != "" {
return "", authConfig.IdentityToken, nil
}
return authConfig.Username, authConfig.Password, nil
}))

opts = append(opts, docker.WithAuthorizer(authorizer))
}

return docker.NewResolver(docker.ResolverOptions{
Hosts: docker.ConfigureDefaultRegistries(opts...),
})
}

func (cs *containerdStore) LogImageEvent(imageID, refName, action string) {
panic("not implemented")
}
Expand Down

0 comments on commit 7d9ebf8

Please sign in to comment.