Skip to content

Commit

Permalink
Assume sha256 if digest algo is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjohnsonjr committed Aug 23, 2018
1 parent 3165313 commit 79c8fa3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/v1/remote/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ func (r *remoteImage) RawManifest() ([]byte, error) {
}
} else if checksum := resp.Header.Get("Docker-Content-Digest"); checksum != "" && checksum != digest.String() {
err := fmt.Errorf("manifest digest: %q does not match Docker-Content-Digest: %q for %q", digest, checksum, r.ref)

// Wall of registry shame:
if r.ref.Context().RegistryStr() == name.DefaultRegistry {
// TODO(docker/distribution#2395): Remove this check.
} else if "sha256:"+checksum == digest.String() {
// Assume sha256 if algo is missing, see GoogleContainerTools/kaniko#298.
} else {
// When pulling by tag, we can only validate that the digest matches what the registry told us it should be.
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions pkg/v1/remote/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"

"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -107,6 +108,12 @@ func TestRawManifestDigests(t *testing.T) {
responseBody: mustRawManifest(t, img),
contentDigest: mustDigest(t, img).String(),
wantErr: false,
}, {
name: "normal pull, by tag, missing algo in digest",
ref: "latest",
responseBody: mustRawManifest(t, img),
contentDigest: strings.Split(mustDigest(t, img).String(), ":")[1],
wantErr: false,
}, {
name: "normal pull, by digest",
ref: mustDigest(t, img).String(),
Expand Down

0 comments on commit 79c8fa3

Please sign in to comment.