Skip to content

Commit 5cafc77

Browse files
author
Prince Rachit Sinha
committed
replace reference to aliases with actual repo
1 parent 95f9c2d commit 5cafc77

File tree

1 file changed

+10
-3
lines changed
  • components/image-builder-bob/pkg/proxy

1 file changed

+10
-3
lines changed

components/image-builder-bob/pkg/proxy/proxy.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type Repo struct {
5252
Auth func() docker.Authorizer
5353
}
5454

55-
func rewriteURL(u *url.URL, fromRepo, toRepo, host, tag string) {
55+
func (proxy *Proxy) rewriteURL(u *url.URL, fromRepo, toRepo, host, tag string) {
5656
var (
5757
from = "/v2/" + strings.Trim(fromRepo, "/") + "/"
5858
to = "/v2/" + strings.Trim(toRepo, "/") + "/"
@@ -76,6 +76,13 @@ func rewriteURL(u *url.URL, fromRepo, toRepo, host, tag string) {
7676
}
7777
}
7878

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+
}
7986
u.Host = host
8087
}
8188

@@ -99,7 +106,7 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
99106
return
100107
}
101108

102-
rewriteURL(r.URL, alias, repo.Repo, repo.Host, repo.Tag)
109+
proxy.rewriteURL(r.URL, alias, repo.Repo, repo.Host, repo.Tag)
103110
r.Host = r.URL.Host
104111

105112
auth := repo.Auth()
@@ -192,7 +199,7 @@ func (proxy *Proxy) reverse(alias string) *httputil.ReverseProxy {
192199
return err
193200
}
194201

195-
rewriteURL(lurl, repo.Repo, alias, proxy.Host.Host, "")
202+
proxy.rewriteURL(lurl, repo.Repo, alias, proxy.Host.Host, "")
196203
lurl.Host = proxy.Host.Host
197204
// force scheme to http assuming this proxy never runs as https
198205
lurl.Scheme = proxy.Host.Scheme

0 commit comments

Comments
 (0)