Skip to content

Commit

Permalink
Don't try cross-origin mounting against dockerhub (#1743)
Browse files Browse the repository at this point in the history
* Don't try cross-origin mounting against dockerhub

* Don't try to mount at all if we hit an error
  • Loading branch information
jonjohnsonjr authored Jun 22, 2023
1 parent 2472cbb commit fe268b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pkg/v1/remote/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (w *writer) initiateUpload(ctx context.Context, from, mount, origin string)
req.Header.Set("Content-Type", "application/json")
resp, err := w.client.Do(req.WithContext(ctx))
if err != nil {
if origin != "" && origin != w.repo.RegistryStr() {
if from != "" {
// https://github.com/google/go-containerregistry/issues/1679
logs.Warn.Printf("retrying without mount: %v", err)
return w.initiateUpload(ctx, "", "", "")
Expand All @@ -220,7 +220,7 @@ func (w *writer) initiateUpload(ctx context.Context, from, mount, origin string)
defer resp.Body.Close()

if err := transport.CheckError(resp, http.StatusCreated, http.StatusAccepted); err != nil {
if origin != "" && origin != w.repo.RegistryStr() {
if from != "" {
// https://github.com/google/go-containerregistry/issues/1404
logs.Warn.Printf("retrying without mount: %v", err)
return w.initiateUpload(ctx, "", "", "")
Expand Down Expand Up @@ -360,8 +360,16 @@ func (w *writer) uploadOne(ctx context.Context, l v1.Layer) error {
if err := w.maybeUpdateScopes(ctx, ml); err != nil {
return err
}

from = ml.Reference.Context().RepositoryStr()
origin = ml.Reference.Context().RegistryStr()

// This keeps breaking with DockerHub.
// https://github.com/google/go-containerregistry/issues/1741
if w.repo.RegistryStr() == name.DefaultRegistry && origin != w.repo.RegistryStr() {
from = ""
origin = ""
}
}

location, mounted, err := w.initiateUpload(ctx, from, mount, origin)
Expand Down
14 changes: 12 additions & 2 deletions pkg/v1/remote/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,26 @@ func TestInitiateUploadNoMountsBadStatus(t *testing.T) {
"from": []string{"baz/bar"},
}.Encode()

first := true

w, closer, err := setupWriter(expectedRepo, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
t.Errorf("Method; got %v, want %v", r.Method, http.MethodPost)
}
if r.URL.Path != expectedPath {
t.Errorf("URL; got %v, want %v", r.URL.Path, expectedPath)
}
if r.URL.RawQuery != expectedQuery {
t.Errorf("RawQuery; got %v, want %v", r.URL.RawQuery, expectedQuery)
if first {
if r.URL.RawQuery != expectedQuery {
t.Errorf("RawQuery; got %v, want %v", r.URL.RawQuery, expectedQuery)
}
first = false
} else {
if r.URL.RawQuery != "" {
t.Errorf("RawQuery; got %v, want %v", r.URL.RawQuery, "")
}
}

http.Error(w, "Unknown", http.StatusNoContent)
}))
if err != nil {
Expand Down

0 comments on commit fe268b7

Please sign in to comment.