mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
feat(cve): implemented trivy image scan for multiarch images (#1510)
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
+16
-6
@@ -29,6 +29,7 @@ import (
|
||||
zotErrors "zotregistry.io/zot/errors"
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
zcommon "zotregistry.io/zot/pkg/common"
|
||||
extconf "zotregistry.io/zot/pkg/extensions/config"
|
||||
"zotregistry.io/zot/pkg/extensions/monitoring"
|
||||
cveinfo "zotregistry.io/zot/pkg/extensions/search/cve"
|
||||
@@ -1035,7 +1036,7 @@ func TestServerCVEResponse(t *testing.T) {
|
||||
space := regexp.MustCompile(`\s+`)
|
||||
str := space.ReplaceAllString(buff.String(), " ")
|
||||
So(err, ShouldBeNil)
|
||||
So(strings.TrimSpace(str), ShouldEqual,
|
||||
So(strings.TrimSpace(str), ShouldResemble,
|
||||
"IMAGE NAME TAG OS/ARCH DIGEST SIGNED SIZE zot-cve-test 0.0.1 linux/amd64 40d1f749 false 605B")
|
||||
})
|
||||
|
||||
@@ -1172,7 +1173,8 @@ func getMockCveInfo(repoDB repodb.RepoDB, log log.Logger) cveinfo.CveInfo {
|
||||
// Setup test CVE data in mock scanner
|
||||
scanner := mocks.CveScannerMock{
|
||||
ScanImageFn: func(image string) (map[string]cvemodel.CVE, error) {
|
||||
if image == "zot-cve-test:0.0.1" {
|
||||
if image == "zot-cve-test@sha256:40d1f74918aefed733c590f798d7eafde8fc0a7ec63bb8bc52eaae133cf92495" ||
|
||||
image == "zot-cve-test:0.0.1" {
|
||||
return map[string]cvemodel.CVE{
|
||||
"CVE-1": {
|
||||
ID: "CVE-1",
|
||||
@@ -1223,12 +1225,20 @@ func getMockCveInfo(repoDB repodb.RepoDB, log log.Logger) cveinfo.CveInfo {
|
||||
return false, err
|
||||
}
|
||||
|
||||
manifestDigestStr, ok := repoMeta.Tags[inputTag]
|
||||
if !ok {
|
||||
return false, zotErrors.ErrTagMetaNotFound
|
||||
manifestDigestStr := reference
|
||||
|
||||
if zcommon.IsTag(reference) {
|
||||
var ok bool
|
||||
|
||||
descriptor, ok := repoMeta.Tags[inputTag]
|
||||
if !ok {
|
||||
return false, zotErrors.ErrTagMetaNotFound
|
||||
}
|
||||
|
||||
manifestDigestStr = descriptor.Digest
|
||||
}
|
||||
|
||||
manifestDigest, err := godigest.Parse(manifestDigestStr.Digest)
|
||||
manifestDigest, err := godigest.Parse(manifestDigestStr)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -1891,8 +1891,8 @@ func (service mockService) getTagsForCVEGQL(ctx context.Context, config searchCo
|
||||
|
||||
func (service mockService) getFixedTagsForCVEGQL(ctx context.Context, config searchConfig, username, password,
|
||||
imageName, cveID string,
|
||||
) (*common.FixedTags, error) {
|
||||
fixedTags := &common.FixedTags{
|
||||
) (*common.ImageListWithCVEFixedResponse, error) {
|
||||
fixedTags := &common.ImageListWithCVEFixedResponse{
|
||||
Errors: nil,
|
||||
ImageListWithCVEFixed: struct {
|
||||
common.PaginatedImagesResult `json:"ImageListWithCVEFixed"` //nolint:tagliatelle // graphQL schema
|
||||
|
||||
+4
-4
@@ -43,7 +43,7 @@ type SearchService interface { //nolint:interfacebloat
|
||||
getTagsForCVEGQL(ctx context.Context, config searchConfig, username, password, imageName,
|
||||
cveID string) (*common.ImagesForCve, error)
|
||||
getFixedTagsForCVEGQL(ctx context.Context, config searchConfig, username, password, imageName,
|
||||
cveID string) (*common.FixedTags, error)
|
||||
cveID string) (*common.ImageListWithCVEFixedResponse, error)
|
||||
getDerivedImageListGQL(ctx context.Context, config searchConfig, username, password string,
|
||||
derivedImage string) (*common.DerivedImageListResponse, error)
|
||||
getBaseImageListGQL(ctx context.Context, config searchConfig, username, password string,
|
||||
@@ -377,7 +377,7 @@ func (service searchService) getTagsForCVEGQL(ctx context.Context, config search
|
||||
|
||||
func (service searchService) getFixedTagsForCVEGQL(ctx context.Context, config searchConfig,
|
||||
username, password, imageName, cveID string,
|
||||
) (*common.FixedTags, error) {
|
||||
) (*common.ImageListWithCVEFixedResponse, error) {
|
||||
query := fmt.Sprintf(`
|
||||
{
|
||||
ImageListWithCVEFixed(id: "%s", image: "%s") {
|
||||
@@ -398,7 +398,7 @@ func (service searchService) getFixedTagsForCVEGQL(ctx context.Context, config s
|
||||
}`,
|
||||
cveID, imageName)
|
||||
|
||||
result := &common.FixedTags{}
|
||||
result := &common.ImageListWithCVEFixedResponse{}
|
||||
|
||||
err := service.makeGraphQLQuery(ctx, config, username, password, query, result)
|
||||
|
||||
@@ -847,7 +847,7 @@ func (service searchService) getFixedTagsForCVE(ctx context.Context, config sear
|
||||
}
|
||||
}`, cvid, imageName)
|
||||
|
||||
result := &common.FixedTags{}
|
||||
result := &common.ImageListWithCVEFixedResponse{}
|
||||
|
||||
err := service.makeGraphQLQuery(ctx, config, username, password, query, result)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user