From 66137ae42914c647e793a1f7ac566bf92649ccf2 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 1 Jun 2023 13:33:16 +0200 Subject: [PATCH] containerd: set user-agent when pushing/pulling images Before this, the client would report itself as containerd, and the containerd version from the containerd go module: time="2023-06-01T09:43:21.907359755Z" level=info msg="listening on [::]:5000" go.version=go1.19.9 instance.id=67b89d83-eac0-4f85-b36b-b1b18e80bde1 service=registry version=2.8.2 ... 172.18.0.1 - - [01/Jun/2023:09:43:33 +0000] "HEAD /v2/multifoo/blobs/sha256:cb269d7c0c1ca22fb5a70342c3ed2196c57a825f94b3f0e5ce3aa8c55baee829 HTTP/1.1" 404 157 "" "containerd/1.6.21+unknown" With this patch, the user-agent has the docker daemon information; time="2023-06-01T11:27:07.959822887Z" level=info msg="listening on [::]:5000" go.version=go1.19.9 instance.id=53590f34-096a-4fd1-9c58-d3b8eb7e5092 service=registry version=2.8.2 ... 172.18.0.1 - - [01/Jun/2023:11:27:20 +0000] "HEAD /v2/multifoo/blobs/sha256:c7ec7661263e5e597156f2281d97b160b91af56fa1fd2cc045061c7adac4babd HTTP/1.1" 404 157 "" "docker/dev go/go1.20.4 git-commit/8d67d0c1a8 kernel/5.15.49-linuxkit-pr os/linux arch/arm64 UpstreamClient(Docker-Client/24.0.2 \\(linux\\))" Signed-off-by: Sebastiaan van Stijn --- daemon/containerd/image_pull.go | 2 +- daemon/containerd/image_push.go | 2 +- daemon/containerd/resolver.go | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/daemon/containerd/image_pull.go b/daemon/containerd/image_pull.go index 3e2f623319..8d2c873143 100644 --- a/daemon/containerd/image_pull.go +++ b/daemon/containerd/image_pull.go @@ -45,7 +45,7 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string, } } - resolver, _ := i.newResolverFromAuthConfig(authConfig) + resolver, _ := i.newResolverFromAuthConfig(ctx, authConfig) opts = append(opts, containerd.WithResolver(resolver)) jobs := newJobs() diff --git a/daemon/containerd/image_push.go b/daemon/containerd/image_push.go index ae3814761d..f0a38ef63b 100644 --- a/daemon/containerd/image_push.go +++ b/daemon/containerd/image_push.go @@ -62,7 +62,7 @@ func (i *ImageService) PushImage(ctx context.Context, targetRef reference.Named, target := img.Target store := i.client.ContentStore() - resolver, tracker := i.newResolverFromAuthConfig(authConfig) + resolver, tracker := i.newResolverFromAuthConfig(ctx, authConfig) progress := pushProgress{Tracker: tracker} jobsQueue := newJobs() finishProgress := jobsQueue.showProgress(ctx, out, combinedProgress([]progressUpdater{ diff --git a/daemon/containerd/resolver.go b/daemon/containerd/resolver.go index 5edd83181b..97bc9780df 100644 --- a/daemon/containerd/resolver.go +++ b/daemon/containerd/resolver.go @@ -1,6 +1,7 @@ package containerd import ( + "context" "crypto/tls" "errors" "net/http" @@ -8,19 +9,23 @@ import ( "github.com/containerd/containerd/remotes" "github.com/containerd/containerd/remotes/docker" registrytypes "github.com/docker/docker/api/types/registry" + "github.com/docker/docker/dockerversion" "github.com/docker/docker/registry" "github.com/sirupsen/logrus" ) -func (i *ImageService) newResolverFromAuthConfig(authConfig *registrytypes.AuthConfig) (remotes.Resolver, docker.StatusTracker) { +func (i *ImageService) newResolverFromAuthConfig(ctx context.Context, authConfig *registrytypes.AuthConfig) (remotes.Resolver, docker.StatusTracker) { tracker := docker.NewInMemoryTracker() hostsFn := i.registryHosts.RegistryHosts() hosts := hostsWrapper(hostsFn, authConfig, i.registryService) + headers := http.Header{} + headers.Set("User-Agent", dockerversion.DockerUserAgent(ctx)) return docker.NewResolver(docker.ResolverOptions{ Hosts: hosts, Tracker: tracker, + Headers: headers, }), tracker }