@@ -52,7 +52,7 @@ type Repo struct {
52
52
Auth func () docker.Authorizer
53
53
}
54
54
55
- func rewriteURL (u * url.URL , fromRepo , toRepo , host , tag string ) {
55
+ func ( proxy * Proxy ) rewriteURL (u * url.URL , fromRepo , toRepo , host , tag string ) {
56
56
var (
57
57
from = "/v2/" + strings .Trim (fromRepo , "/" ) + "/"
58
58
to = "/v2/" + strings .Trim (toRepo , "/" ) + "/"
@@ -76,6 +76,13 @@ func rewriteURL(u *url.URL, fromRepo, toRepo, host, tag string) {
76
76
}
77
77
}
78
78
79
+ if u .RawQuery != "" {
80
+ // As per OCI distribution spec this (from=) should be the only possible reference to a cross repo
81
+ // https://github.com/opencontainers/distribution-spec/blob/main/spec.md#push
82
+ for k , v := range proxy .Aliases {
83
+ u .RawQuery = strings .Replace (u .RawQuery , "from=" + k , "from=" + v .Repo , 1 )
84
+ }
85
+ }
79
86
u .Host = host
80
87
}
81
88
@@ -99,7 +106,7 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
99
106
return
100
107
}
101
108
102
- rewriteURL (r .URL , alias , repo .Repo , repo .Host , repo .Tag )
109
+ proxy . rewriteURL (r .URL , alias , repo .Repo , repo .Host , repo .Tag )
103
110
r .Host = r .URL .Host
104
111
105
112
auth := repo .Auth ()
@@ -192,7 +199,7 @@ func (proxy *Proxy) reverse(alias string) *httputil.ReverseProxy {
192
199
return err
193
200
}
194
201
195
- rewriteURL (lurl , repo .Repo , alias , proxy .Host .Host , "" )
202
+ proxy . rewriteURL (lurl , repo .Repo , alias , proxy .Host .Host , "" )
196
203
lurl .Host = proxy .Host .Host
197
204
// force scheme to http assuming this proxy never runs as https
198
205
lurl .Scheme = proxy .Host .Scheme
0 commit comments