Skip to content

Commit 50ad4b9

Browse files
committed
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 <[email protected]>
1 parent 531908c commit 50ad4b9

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

remotes/docker/auth/fetch.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/containerd/containerd/log"
2828
remoteserrors "github.com/containerd/containerd/remotes/errors"
29+
"github.com/containerd/containerd/version"
2930
"github.com/pkg/errors"
3031
"golang.org/x/net/context/ctxhttp"
3132
)
@@ -109,6 +110,9 @@ func FetchTokenWithOAuth(ctx context.Context, client *http.Client, headers http.
109110
for k, v := range headers {
110111
req.Header[k] = append(req.Header[k], v...)
111112
}
113+
if len(req.Header.Get("User-Agent")) == 0 {
114+
req.Header.Set("User-Agent", "containerd/"+version.Version)
115+
}
112116

113117
resp, err := ctxhttp.Do(ctx, client, req)
114118
if err != nil {
@@ -153,6 +157,9 @@ func FetchToken(ctx context.Context, client *http.Client, headers http.Header, t
153157
for k, v := range headers {
154158
req.Header[k] = append(req.Header[k], v...)
155159
}
160+
if len(req.Header.Get("User-Agent")) == 0 {
161+
req.Header.Set("User-Agent", "containerd/"+version.Version)
162+
}
156163

157164
reqParams := req.URL.Query()
158165

0 commit comments

Comments
 (0)