From fe471a3c352fa4f9c8dbf008ca6ba62e6b1b4c40 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Wed, 18 Mar 2020 15:42:06 -0700 Subject: [PATCH] gc: fix test cases since umoci GC is more strict umoci GC enforces a valid index.json and current tests were a little lax. --- go.mod | 2 +- go.sum | 3 +++ pkg/compliance/v1_0_0/check.go | 45 +++++++++++++++++++++++++++++++--- pkg/storage/storage.go | 7 +++++- pkg/storage/storage_test.go | 16 +++++++++++- 5 files changed, 67 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 1b5f83b5..b4c144fb 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/mitchellh/mapstructure v1.1.2 github.com/nmcclain/asn1-ber v0.0.0-20170104154839-2661553a0484 // indirect github.com/nmcclain/ldap v0.0.0-20191021200707-3b3b69a7e9e3 - github.com/openSUSE/umoci v0.4.5 + github.com/openSUSE/umoci v0.4.6-0.20200320140503-9aa268eeb258 github.com/opencontainers/distribution-spec v1.0.0-rc0 github.com/opencontainers/go-digest v1.0.0-rc1 github.com/opencontainers/image-spec v1.0.1 diff --git a/go.sum b/go.sum index 5753ed7f..7b7c2fb4 100644 --- a/go.sum +++ b/go.sum @@ -128,6 +128,7 @@ github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo github.com/klauspost/pgzip v1.2.1 h1:oIPZROsWuPHpOdMVWLuJZXwgjhrW8r1yEX8UqMyeNHM= github.com/klauspost/pgzip v1.2.1/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -172,6 +173,8 @@ github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/openSUSE/umoci v0.4.5 h1:MZgFLy5Jl3VKe5uEOU9c25FoySbx3vUXeXLw4Jf6aRs= github.com/openSUSE/umoci v0.4.5/go.mod h1:3p4KA5nwyY65lVmQZxv7tm0YEylJ+t1fY91ORsVXv58= +github.com/openSUSE/umoci v0.4.6-0.20200320140503-9aa268eeb258 h1:/8Yu54FufyHHQgIZ/wLy+BLQyzk0gbOG24xf5suWOOI= +github.com/openSUSE/umoci v0.4.6-0.20200320140503-9aa268eeb258/go.mod h1:3p4KA5nwyY65lVmQZxv7tm0YEylJ+t1fY91ORsVXv58= github.com/opencontainers/distribution-spec v1.0.0-rc0 h1:xMzwhweo1gjvEo74mQjGTLau0TD3ACyTEC1310NbuSQ= github.com/opencontainers/distribution-spec v1.0.0-rc0/go.mod h1:copR2flp+jTEvQIFMb6MIx45OkrxzqyjszPDT3hx/5Q= github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= diff --git a/pkg/compliance/v1_0_0/check.go b/pkg/compliance/v1_0_0/check.go index 71a49b1f..4f0af291 100644 --- a/pkg/compliance/v1_0_0/check.go +++ b/pkg/compliance/v1_0_0/check.go @@ -481,7 +481,20 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.StatusCode(), ShouldEqual, 404) // create a manifest - m := ispec.Manifest{Layers: []ispec.Descriptor{{Digest: digest}}} + m := ispec.Manifest{ + Config: ispec.Descriptor{ + Digest: digest, + Size: int64(len(content)), + }, + Layers: []ispec.Descriptor{ + { + MediaType: "application/vnd.oci.image.layer.v1.tar", + Digest: digest, + Size: int64(len(content)), + }, + }, + } + m.SchemaVersion = 2 content, err = json.Marshal(m) So(err, ShouldBeNil) digest = godigest.FromBytes(content) @@ -498,7 +511,20 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { digest = godigest.FromBytes(content) So(digest, ShouldNotBeNil) // create a manifest with same blob but a different tag - m = ispec.Manifest{Layers: []ispec.Descriptor{{Digest: digest}}} + m = ispec.Manifest{ + Config: ispec.Descriptor{ + Digest: digest, + Size: int64(len(content)), + }, + Layers: []ispec.Descriptor{ + { + MediaType: "application/vnd.oci.image.layer.v1.tar", + Digest: digest, + Size: int64(len(content)), + }, + }, + } + m.SchemaVersion = 2 content, err = json.Marshal(m) So(err, ShouldBeNil) digest = godigest.FromBytes(content) @@ -599,7 +625,20 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) { So(resp.Header().Get(api.DistContentDigestKey), ShouldNotBeEmpty) // create a manifest - m := ispec.Manifest{Layers: []ispec.Descriptor{{Digest: digest}}} + m := ispec.Manifest{ + Config: ispec.Descriptor{ + Digest: digest, + Size: int64(len(content)), + }, + Layers: []ispec.Descriptor{ + { + MediaType: "application/vnd.oci.image.layer.v1.tar", + Digest: digest, + Size: int64(len(content)), + }, + }, + } + m.SchemaVersion = 2 content, err = json.Marshal(m) So(err, ShouldBeNil) digest = godigest.FromBytes(content) diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index eaf9637a..44547317 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -15,9 +15,9 @@ import ( "github.com/anuvu/zot/errors" zlog "github.com/anuvu/zot/pkg/log" guuid "github.com/gofrs/uuid" + "github.com/openSUSE/umoci" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/openSUSE/umoci" "github.com/rs/zerolog" ) @@ -335,6 +335,11 @@ func (is *ImageStore) PutImageManifest(repo string, reference string, mediaType return "", errors.ErrBadManifest } + if m.SchemaVersion != 2 { + is.log.Error().Int("SchemaVersion", m.SchemaVersion).Msg("invalid manifest") + return "", errors.ErrBadManifest + } + for _, l := range m.Layers { digest := l.Digest blobPath := is.BlobPath(repo, digest) diff --git a/pkg/storage/storage_test.go b/pkg/storage/storage_test.go index 0419104f..f194af89 100644 --- a/pkg/storage/storage_test.go +++ b/pkg/storage/storage_test.go @@ -105,6 +105,7 @@ func TestAPIs(t *testing.T) { So(err, ShouldBeNil) m := ispec.Manifest{} + m.SchemaVersion = 2 mb, _ := json.Marshal(m) Convey("Bad image manifest", func() { @@ -116,7 +117,20 @@ func TestAPIs(t *testing.T) { }) Convey("Good image manifest", func() { - m := ispec.Manifest{Layers: []ispec.Descriptor{{Digest: d}}} + m := ispec.Manifest{ + Config: ispec.Descriptor{ + Digest: d, + Size: int64(l), + }, + Layers: []ispec.Descriptor{ + { + MediaType: "application/vnd.oci.image.layer.v1.tar", + Digest: d, + Size: int64(l), + }, + }, + } + m.SchemaVersion = 2 mb, _ = json.Marshal(m) d := godigest.FromBytes(mb) _, err = il.PutImageManifest("test", d.String(), ispec.MediaTypeImageManifest, mb)