Repository: moby/moby (language: go)

Issue:
containerd-integration: `docker pull hello-world` fails with `pulling from host registry-1.docker.io failed with status code [manifests latest]: 401 Unauthorized.`
### Description

`docker pull hello-world` fails with containerd-integration mode

### Reproduce

1. Stop `dockerd` and `containerd`
2. `rm -rf /var/lib/{docker,containerd} /run/{docker,containerd}`
3. Create `/etc/docker/daemon.json`
```json
{"features":{"containerd-snapshotter":true}}
```
4. Start `dockerd`
5. `docker pull hello-world`
```console
# docker pull hello-world
Using default tag: latest
Error response from daemon: failed to resolve reference "docker.io/library/hello-world:latest": pulling from host registry-1.docker.io failed with status code [manifests latest]: 401 Unauthorized
```

### Expected behavior

`docker pull hello-world` should successfully pull the `hello-world` image

### docker version

```bash
Client: Docker Engine - Community
 Version:           24.0.0-rc.3
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        1d7dd91
 Built:             Thu May 11 19:25:21 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.0-rc.3
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       807e415
  Built:            Thu May 11 19:25:21 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
```


### docker info

```bash
Client: Docker Engine - Community
 Version:    24.0.0-rc.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.4
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.17.3
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 24.0.0-rc.3
 Storage Driver: overlayfs
  driver-type: io.containerd.snapshotter.v1
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3dce8eb055cbb6872793272b4f20ed16117344f8
 runc version: v1.1.7-0-g860f061
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.19.0-38-generic
 Operating System: Ubuntu 22.10
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.825GiB
 Name: lima-default
 ID: d28cb975-f75a-47e1-be32-22d1f7350521
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
```


### Additional Info

The image can be successfully pulled with `"containerd-snapshotter": false`


Discussion / hints:
🤨🤔🤔🤔 that's really odd. Wonder what happened here

@vvoland @rumpl @laurazard 
Discussed with @vvoland - probably regression point is https://github.com/moby/moby/pull/45517, as we need still need an authorizer in case of an empty authconfig

Fix patch:
diff --git a/daemon/containerd/resolver.go b/daemon/containerd/resolver.go
index 5b2d1dff4ccfa..5edd83181b19f 100644
--- a/daemon/containerd/resolver.go
+++ b/daemon/containerd/resolver.go
@@ -27,10 +27,7 @@ func (i *ImageService) newResolverFromAuthConfig(authConfig *registrytypes.AuthC
 func hostsWrapper(hostsFn docker.RegistryHosts, optAuthConfig *registrytypes.AuthConfig, regService RegistryConfigProvider) docker.RegistryHosts {
 	var authorizer docker.Authorizer
 	if optAuthConfig != nil {
-		auth := *optAuthConfig
-		if auth != (registrytypes.AuthConfig{}) {
-			authorizer = docker.NewDockerAuthorizer(authorizationCredsFromAuthConfig(auth))
-		}
+		authorizer = docker.NewDockerAuthorizer(authorizationCredsFromAuthConfig(*optAuthConfig))
 	}
 
 	return func(n string) ([]docker.RegistryHost, error) {


Test patch: