From 50ad4b96c4acfde425e1fc6e7411b52658d7af92 Mon Sep 17 00:00:00 2001 From: Ethan Chen Date: Wed, 26 May 2021 09:45:54 +0800 Subject: [PATCH] Fix incorrect UA used for registry authentication Previously, containerd uses Go's default UA "Go-http-client/1.1" while authenticating with registry. This commit changes it to the pattern like "containerd/v1.5.2" which is used for all other requests. Signed-off-by: Ethan Chen --- remotes/docker/auth/fetch.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/remotes/docker/auth/fetch.go b/remotes/docker/auth/fetch.go index 0d01c81ac..8b0a87e75 100644 --- a/remotes/docker/auth/fetch.go +++ b/remotes/docker/auth/fetch.go @@ -26,6 +26,7 @@ import ( "github.com/containerd/containerd/log" remoteserrors "github.com/containerd/containerd/remotes/errors" + "github.com/containerd/containerd/version" "github.com/pkg/errors" "golang.org/x/net/context/ctxhttp" ) @@ -109,6 +110,9 @@ func FetchTokenWithOAuth(ctx context.Context, client *http.Client, headers http. for k, v := range headers { req.Header[k] = append(req.Header[k], v...) } + if len(req.Header.Get("User-Agent")) == 0 { + req.Header.Set("User-Agent", "containerd/"+version.Version) + } resp, err := ctxhttp.Do(ctx, client, req) if err != nil { @@ -153,6 +157,9 @@ func FetchToken(ctx context.Context, client *http.Client, headers http.Header, t for k, v := range headers { req.Header[k] = append(req.Header[k], v...) } + if len(req.Header.Get("User-Agent")) == 0 { + req.Header.Set("User-Agent", "containerd/"+version.Version) + } reqParams := req.URL.Query()