From afa72eb3bb2e8fc03366c87f4a51b6894ea65b2e Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Fri, 8 Dec 2023 05:13:21 +0000 Subject: [PATCH] Add ns query parameter when using a mirror endpoint This is required by some registries that are capable of serving multiple upstreams Signed-off-by: Brad Davidson --- pkg/registries/endpoint.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/registries/endpoint.go b/pkg/registries/endpoint.go index 62d7118..c74b62c 100644 --- a/pkg/registries/endpoint.go +++ b/pkg/registries/endpoint.go @@ -13,6 +13,11 @@ import ( var _ authn.Keychain = &endpoint{} var _ http.RoundTripper = &endpoint{} +const ( + defaultRegistry = "docker.io" + defaultRegistryHost = "index.docker.io" +) + type endpoint struct { auth authn.Authenticator keychain authn.Keychain @@ -69,10 +74,17 @@ func (e endpoint) RoundTrip(req *http.Request) (*http.Response, error) { } } - // override request host and scheme + // override request host and scheme; set ns from original host + q := req.URL.Query() + if req.Host == defaultRegistryHost { + q.Set("ns", defaultRegistry) + } else { + q.Set("ns", req.Host) + } req.Host = endpointURL.Host req.URL.Host = endpointURL.Host req.URL.Scheme = endpointURL.Scheme + req.URL.RawQuery = q.Encode() } if newURL := req.URL.String(); originalURL != newURL {