Skip to content

Commit

Permalink
refactor(meta): aesthethic changes
Browse files Browse the repository at this point in the history
Signed-off-by: Laurentiu Niculae <[email protected]>
  • Loading branch information
laurentiuNiculae committed Oct 17, 2023
1 parent 292ac05 commit 7f28bee
Show file tree
Hide file tree
Showing 44 changed files with 2,580 additions and 3,175 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SWAGGER_VERSION := v1.8.12
STACKER := $(TOOLSDIR)/bin/stacker
BATS := $(TOOLSDIR)/bin/bats
PROTOC_VERSION := 3.15.8
GO_PROTOC_VERSION := 1.31.0
PROTOC := $(TOOLSDIR)/bin/protoc
TESTDATA := $(TOP_LEVEL)/test/data
OS ?= $(shell go env GOOS)
Expand Down Expand Up @@ -237,9 +238,9 @@ $(CRICTL):
$(PROTOC):
mkdir -p $(TOOLSDIR)/bin
curl -Lo protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip
unzip -d $(TOOLSDIR) protoc.zip bin/protoc
unzip -o -d $(TOOLSDIR) protoc.zip bin/protoc
chmod +x $(PROTOC)
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(GO_PROTOC_VERSION)

$(ACTION_VALIDATOR):
mkdir -p $(TOOLSDIR)/bin
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ignore:
- "./pkg/test/mocks/*.go"
- "./swagger/*.go"
- "./pkg/test/test_http_server.go"
- "./pkg/meta/proto_go/*.go"
2 changes: 1 addition & 1 deletion errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var (
ErrManifestConflict = errors.New("manifest: multiple manifests found")
ErrManifestMetaNotFound = errors.New("metadb: image metadata not found for given manifest reference")
ErrManifestDataNotFound = errors.New("metadb: image data not found for given manifest digest")
ErrImageDataNotFound = errors.New("metadb: image data not found for")
ErrImageDataNotFound = errors.New("metadb: image data not found")
ErrWrongMediaType = errors.New("metadb: got unexpected media type")
ErrIndexDataNotFount = errors.New("metadb: index data not found for given digest")
ErrRepoMetaNotFound = errors.New("metadb: repo metadata not found for given repo name")
Expand Down
2 changes: 0 additions & 2 deletions pkg/api/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func TestCreateMetaDBDriver(t *testing.T) {
"repometatablename": "RepoMetadataTable",
"imagedatatablename": "ZotImageDataTable",
"repoblobsinfotablename": "ZotRepoBlobsInfoTable",
"indexdatatablename": "IndexDataTable",
"userdatatablename": "ZotUserDataTable",
"apikeytablename": "APIKeyTable",
"versiontablename": "1",
Expand Down Expand Up @@ -437,7 +436,6 @@ func TestObjectStorageController(t *testing.T) {
"repometatablename": "RepoMetadataTable",
"imagedatatablename": "ZotImageDataTable",
"repoblobsinfotablename": "ZotRepoBlobsInfoTable",
"indexdatatablename": "IndexDataTable",
"userdatatablename": "ZotUserDataTable",
"apikeytablename": "APIKeyTable1",
"versiontablename": "Version",
Expand Down
6 changes: 6 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const (
ArtifactTypeNotation = "application/vnd.cncf.notary.signature"
)

var cosignTagRule = regexp.MustCompile(`sha256\-.+\.sig`)

func IsCosignTag(tag string) bool {
return cosignTagRule.MatchString(tag)
}

func Contains[T comparable](elems []T, v T) bool {
for _, s := range elems {
if v == s {
Expand Down
4 changes: 2 additions & 2 deletions pkg/extensions/imagetrust/image_trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func GetSecretsManagerRetrieval(region, endpoint string) *secretcache.Cache {
return cache
}

func (imgTrustStore *ImageTrustStore) ProtoVerifySignature(
func (imgTrustStore *ImageTrustStore) VerifySignature(
signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageData mTypes.ImageData,
repo string,
) (string, time.Time, bool, error) {
Expand All @@ -166,7 +166,7 @@ func (imgTrustStore *ImageTrustStore) ProtoVerifySignature(
}
}

func (imgTrustStore *ImageTrustStore) VerifySignature(
func (imgTrustStore *ImageTrustStore) DepVerifySignature(
signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, blob []byte,
repo string,
) (string, time.Time, bool, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/extensions/imagetrust/image_trust_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func NewAWSImageTrustStore(region, endpoint string) (*imageTrustDisabled, error)

type imageTrustDisabled struct{}

func (imgTrustStore *imageTrustDisabled) VerifySignature(
func (imgTrustStore *imageTrustDisabled) DepVerifySignature(
signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, manifestContent []byte,
repo string,
) (string, time.Time, bool, error) {
return "", time.Time{}, false, nil
}

func (imgTrustStore *imageTrustDisabled) ProtoVerifySignature(
func (imgTrustStore *imageTrustDisabled) VerifySignature(
signatureType string, rawSignature []byte, sigKey string, manifestDigest godigest.Digest, imageData mTypes.ImageData,
repo string,
) (string, time.Time, bool, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/extensions/imagetrust/image_trust_disabled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestImageTrust(t *testing.T) {
localImgTrustStore, err := imagetrust.NewLocalImageTrustStore(rootDir)
So(err, ShouldBeNil)

author, expTime, ok, err := localImgTrustStore.VerifySignature("cosign",
author, expTime, ok, err := localImgTrustStore.DepVerifySignature("cosign",
[]byte(""), "", manifestDigest, manifestContent, repo,
)
So(author, ShouldBeEmpty)
Expand All @@ -53,7 +53,7 @@ func TestImageTrust(t *testing.T) {
)
So(err, ShouldBeNil)

author, expTime, ok, err = cloudImgTrustStore.VerifySignature("cosign",
author, expTime, ok, err = cloudImgTrustStore.DepVerifySignature("cosign",
[]byte(""), "", manifestDigest, manifestContent, repo,
)
So(author, ShouldBeEmpty)
Expand Down
43 changes: 25 additions & 18 deletions pkg/extensions/imagetrust/image_trust_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,20 @@ func TestInitCosignAndNotationDirs(t *testing.T) {
})
}

func SkipTest(t *testing.T) {
t.Helper()
t.SkipNow()
}

func TestVerifySignatures(t *testing.T) {
SkipTest(t)

Convey("empty manifest digest", t, func() {
image := CreateRandomImage()
manifestContent := image.ManifestDescriptor.Data

imgTrustStore := &imagetrust.ImageTrustStore{}
_, _, _, err := imgTrustStore.VerifySignature("", []byte(""), "", "", manifestContent, "repo")
_, _, _, err := imgTrustStore.DepVerifySignature("", []byte(""), "", "", manifestContent, "repo")
So(err, ShouldNotBeNil)
So(err, ShouldEqual, zerr.ErrBadManifestDigest)
})
Expand All @@ -163,7 +170,7 @@ func TestVerifySignatures(t *testing.T) {
manifestDigest := image.ManifestDescriptor.Digest

imgTrustStore := &imagetrust.ImageTrustStore{}
_, _, _, err := imgTrustStore.VerifySignature("wrongType", []byte(""), "", manifestDigest, manifestContent, "repo")
_, _, _, err := imgTrustStore.DepVerifySignature("wrongType", []byte(""), "", manifestDigest, manifestContent, "repo")
So(err, ShouldNotBeNil)
So(err, ShouldEqual, zerr.ErrInvalidSignatureType)
})
Expand All @@ -181,7 +188,7 @@ func TestVerifySignatures(t *testing.T) {
CosignStorage: &imagetrust.PublicKeyLocalStorage{},
}

_, _, _, err := imgTrustStore.VerifySignature("cosign", []byte(""), "", manifestDigest, manifestContent, repo)
_, _, _, err := imgTrustStore.DepVerifySignature("cosign", []byte(""), "", manifestDigest, manifestContent, repo)
So(err, ShouldNotBeNil)
So(err, ShouldEqual, zerr.ErrSignConfigDirNotSet)
})
Expand All @@ -201,7 +208,7 @@ func TestVerifySignatures(t *testing.T) {
CosignStorage: pubKeyStorage,
}

_, _, _, err = imgTrustStore.VerifySignature("cosign", []byte(""), "", manifestDigest, manifestContent, repo)
_, _, _, err = imgTrustStore.DepVerifySignature("cosign", []byte(""), "", manifestDigest, manifestContent, repo)
So(err, ShouldNotBeNil)
})

Expand All @@ -221,7 +228,7 @@ func TestVerifySignatures(t *testing.T) {
CosignStorage: pubKeyStorage,
}

_, _, isTrusted, err := imgTrustStore.VerifySignature("cosign", []byte(""), "", manifestDigest,
_, _, isTrusted, err := imgTrustStore.DepVerifySignature("cosign", []byte(""), "", manifestDigest,
manifestContent, repo)
So(err, ShouldBeNil)
So(isTrusted, ShouldBeFalse)
Expand Down Expand Up @@ -309,7 +316,7 @@ func TestVerifySignatures(t *testing.T) {
}

// signature is trusted
author, _, isTrusted, err := imgTrustStore.VerifySignature("cosign", rawSignature, sigKey, manifestDigest,
author, _, isTrusted, err := imgTrustStore.DepVerifySignature("cosign", rawSignature, sigKey, manifestDigest,
manifestContent, repo)
So(err, ShouldBeNil)
So(isTrusted, ShouldBeTrue)
Expand All @@ -329,7 +336,7 @@ func TestVerifySignatures(t *testing.T) {
NotationStorage: &imagetrust.CertificateLocalStorage{},
}

_, _, _, err := imgTrustStore.VerifySignature("notation", []byte("signature"), "", manifestDigest,
_, _, _, err := imgTrustStore.DepVerifySignature("notation", []byte("signature"), "", manifestDigest,
manifestContent, repo)
So(err, ShouldNotBeNil)
So(err, ShouldEqual, zerr.ErrSignConfigDirNotSet)
Expand All @@ -345,7 +352,7 @@ func TestVerifySignatures(t *testing.T) {
NotationStorage: certStorage,
}

_, _, isTrusted, err := imgTrustStore.VerifySignature("notation", []byte(""), "", manifestDigest,
_, _, isTrusted, err := imgTrustStore.DepVerifySignature("notation", []byte(""), "", manifestDigest,
manifestContent, repo)
So(err, ShouldNotBeNil)
So(isTrusted, ShouldBeFalse)
Expand All @@ -366,7 +373,7 @@ func TestVerifySignatures(t *testing.T) {
NotationStorage: certStorage,
}

_, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", manifestDigest,
_, _, _, err = imgTrustStore.DepVerifySignature("notation", []byte("signature"), "", manifestDigest,
manifestContent, repo)
So(err, ShouldNotBeNil)
})
Expand All @@ -388,7 +395,7 @@ func TestVerifySignatures(t *testing.T) {
NotationStorage: certStorage,
}

_, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", manifestDigest, manifestContent,
_, _, _, err = imgTrustStore.DepVerifySignature("notation", []byte("signature"), "", manifestDigest, manifestContent,
repo)
So(err, ShouldNotBeNil)
})
Expand Down Expand Up @@ -491,7 +498,7 @@ func TestVerifySignatures(t *testing.T) {
}

// signature is trusted
author, _, isTrusted, err := imgTrustStore.VerifySignature("notation", rawSignature, sigKey, manifestDigest,
author, _, isTrusted, err := imgTrustStore.DepVerifySignature("notation", rawSignature, sigKey, manifestDigest,
manifestContent, repo)
So(err, ShouldBeNil)
So(isTrusted, ShouldBeTrue)
Expand All @@ -501,7 +508,7 @@ func TestVerifySignatures(t *testing.T) {
So(err, ShouldBeNil)

// signature is not trusted
author, _, isTrusted, err = imgTrustStore.VerifySignature("notation", rawSignature, sigKey, manifestDigest,
author, _, isTrusted, err = imgTrustStore.DepVerifySignature("notation", rawSignature, sigKey, manifestDigest,
manifestContent, repo)
So(err, ShouldNotBeNil)
So(isTrusted, ShouldBeFalse)
Expand Down Expand Up @@ -923,7 +930,7 @@ func TestAWSTrustStore(t *testing.T) {
NotationStorage: notationStorage,
}

_, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", manifestDigest,
_, _, _, err = imgTrustStore.DepVerifySignature("notation", []byte("signature"), "", manifestDigest,
manifestContent, repo)
So(err, ShouldNotBeNil)
})
Expand Down Expand Up @@ -956,7 +963,7 @@ func TestAWSTrustStore(t *testing.T) {
NotationStorage: notationStorage,
}

_, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", manifestDigest,
_, _, _, err = imgTrustStore.DepVerifySignature("notation", []byte("signature"), "", manifestDigest,
manifestContent, repo)
So(err, ShouldNotBeNil)

Expand All @@ -973,7 +980,7 @@ func TestAWSTrustStore(t *testing.T) {
NotationStorage: notationStorage,
}

_, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", manifestDigest,
_, _, _, err = imgTrustStore.DepVerifySignature("notation", []byte("signature"), "", manifestDigest,
manifestContent, repo)
So(err, ShouldNotBeNil)

Expand All @@ -990,7 +997,7 @@ func TestAWSTrustStore(t *testing.T) {
NotationStorage: notationStorage,
}

_, _, _, err = imgTrustStore.VerifySignature("notation", []byte("signature"), "", manifestDigest,
_, _, _, err = imgTrustStore.DepVerifySignature("notation", []byte("signature"), "", manifestDigest,
manifestContent, repo)
So(err, ShouldNotBeNil)
})
Expand Down Expand Up @@ -1230,7 +1237,7 @@ func RunVerificationTests(t *testing.T, dbDriverParams map[string]interface{}) {
imageTrustStore := ctlr.MetaDB.ImageTrustStore()

// signature is trusted
author, _, isTrusted, err := imageTrustStore.VerifySignature("cosign", rawSignature, sigKey, manifestDigest,
author, _, isTrusted, err := imageTrustStore.DepVerifySignature("cosign", rawSignature, sigKey, manifestDigest,
manifestContent, repo)
So(err, ShouldBeNil)
So(isTrusted, ShouldBeTrue)
Expand Down Expand Up @@ -1322,7 +1329,7 @@ func RunVerificationTests(t *testing.T, dbDriverParams map[string]interface{}) {
imageTrustStore := ctlr.MetaDB.ImageTrustStore()

// signature is trusted
author, _, isTrusted, err := imageTrustStore.VerifySignature("notation", rawSignature, sigKey, manifestDigest,
author, _, isTrusted, err := imageTrustStore.DepVerifySignature("notation", rawSignature, sigKey, manifestDigest,
manifestContent, repo)
So(err, ShouldBeNil)
So(isTrusted, ShouldBeTrue)
Expand Down
6 changes: 3 additions & 3 deletions pkg/extensions/search/convert/convert_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestCVEConvert(t *testing.T) {
So(imageSummary, ShouldBeNil)
So(graphql.GetErrors(ctx), ShouldBeNil)

imageSummary, _, err = ProtoImageManifest2ImageSummary(ctx, "repo1", "0.1.0", repoMetaList[0],
imageSummary, _, err = ImageManifest2ImageSummary(ctx, "repo1", "0.1.0", repoMetaList[0],
imageData[image.DigestStr()])
So(err, ShouldBeNil)

Expand Down Expand Up @@ -162,7 +162,7 @@ func TestCVEConvert(t *testing.T) {
So(repoSummary, ShouldBeNil)
So(graphql.GetErrors(ctx), ShouldBeNil)

imageSummary, _, err := ProtoImageManifest2ImageSummary(ctx, "repo1", "0.1.0", repoMetaList[0],
imageSummary, _, err := ImageManifest2ImageSummary(ctx, "repo1", "0.1.0", repoMetaList[0],
imageData[image.DigestStr()])
So(err, ShouldBeNil)

Expand Down Expand Up @@ -220,7 +220,7 @@ func TestCVEConvert(t *testing.T) {
So(manifestSummary, ShouldBeNil)
So(graphql.GetErrors(ctx), ShouldBeNil)

imageSummary, _, err := ProtoImageManifest2ImageSummary(ctx, "repo1", "0.1.0", repoMetaList[0],
imageSummary, _, err := ImageManifest2ImageSummary(ctx, "repo1", "0.1.0", repoMetaList[0],
imageData[image.DigestStr()])
So(err, ShouldBeNil)
manifestSummary = imageSummary.Manifests[0]
Expand Down
Loading

0 comments on commit 7f28bee

Please sign in to comment.