Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions central/views/imagecve/db_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ type imageResponse struct {
ImageID string `db:"image_sha"`
}

type imageV2Response struct {
ImageID string `db:"id"`
}

type deploymentResponse struct {
DeploymentID string `db:"deployment_id"`
}
14 changes: 14 additions & 0 deletions central/views/imagecve/view_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
v1 "github.com/stackrox/rox/generated/api/v1"
"github.com/stackrox/rox/pkg/contextutil"
"github.com/stackrox/rox/pkg/env"
"github.com/stackrox/rox/pkg/features"
"github.com/stackrox/rox/pkg/postgres"
"github.com/stackrox/rox/pkg/postgres/walker"
"github.com/stackrox/rox/pkg/sac/resources"
Expand Down Expand Up @@ -191,6 +192,19 @@ func (v *imageCVECoreViewImpl) GetImageIDs(ctx context.Context, q *v1.Query) ([]
queryCtx, cancel := contextutil.ContextWithTimeoutIfNotExists(ctx, queryTimeout)
defer cancel()

if features.FlattenImageData.Enabled() {
var results []*imageV2Response
results, err = pgSearch.RunSelectRequestForSchema[imageV2Response](queryCtx, v.db, v.schema, q)
if err != nil || len(results) == 0 {
return nil, err
}

ret := make([]string, 0, len(results))
for _, r := range results {
ret = append(ret, r.ImageID)
}
return ret, nil
}
var results []*imageResponse
results, err = pgSearch.RunSelectRequestForSchema[imageResponse](queryCtx, v.db, v.schema, q)
if err != nil || len(results) == 0 {
Expand Down
9 changes: 8 additions & 1 deletion central/views/imagecveflat/view_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
v1 "github.com/stackrox/rox/generated/api/v1"
"github.com/stackrox/rox/pkg/contextutil"
"github.com/stackrox/rox/pkg/env"
"github.com/stackrox/rox/pkg/features"
"github.com/stackrox/rox/pkg/postgres"
"github.com/stackrox/rox/pkg/postgres/walker"
"github.com/stackrox/rox/pkg/sac/resources"
Expand Down Expand Up @@ -169,8 +170,14 @@ func withSelectCVEFlatResponseQuery(q *v1.Query, cveIDsToFilter []string, option
if !options.SkipGetTopCVSS {
cloned.Selects = append(cloned.Selects, search.NewQuerySelect(search.CVSS).AggrFunc(aggregatefunc.Max).Proto())
}
var searchField search.FieldLabel
if features.FlattenImageData.Enabled() {
searchField = search.ImageID
} else {
searchField = search.ImageSHA
}
if !options.SkipGetAffectedImages {
cloned.Selects = append(cloned.Selects, search.NewQuerySelect(search.ImageSHA).AggrFunc(aggregatefunc.Count).Distinct().Proto())
cloned.Selects = append(cloned.Selects, search.NewQuerySelect(searchField).AggrFunc(aggregatefunc.Count).Distinct().Proto())
}
if !options.SkipGetFirstDiscoveredInSystem {
cloned.Selects = append(cloned.Selects, search.NewQuerySelect(search.CVECreatedTime).AggrFunc(aggregatefunc.Min).Proto())
Expand Down
7 changes: 6 additions & 1 deletion central/views/images/db_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package images

import (
"github.com/stackrox/rox/central/views/common"
"github.com/stackrox/rox/pkg/features"
)

type imageResponse struct {
common.ResourceCountByImageCVESeverity
ImageID string `db:"image_sha"`
ImageID string `db:"image_sha"`
ImageV2ID string `db:"id"`
}

func (i *imageResponse) GetImageID() string {
if features.FlattenImageData.Enabled() {
return i.ImageV2ID
}
return i.ImageID
}

Expand Down
7 changes: 7 additions & 0 deletions central/views/images/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package images

import (
"github.com/stackrox/rox/central/globaldb"
"github.com/stackrox/rox/pkg/features"
"github.com/stackrox/rox/pkg/postgres"
"github.com/stackrox/rox/pkg/postgres/schema"
"github.com/stackrox/rox/pkg/sync"
Expand All @@ -16,6 +17,12 @@ var (
// NewImageView returns the interface ImageView
// that provides methods for searching images stored in the database.
func NewImageView(db postgres.DB) ImageView {
if features.FlattenImageData.Enabled() {
return &imageCoreViewImpl{
db: db,
schema: schema.ImagesV2Schema,
}
}
return &imageCoreViewImpl{
db: db,
schema: schema.ImagesSchema,
Expand Down
13 changes: 10 additions & 3 deletions central/views/images/view_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
v1 "github.com/stackrox/rox/generated/api/v1"
"github.com/stackrox/rox/pkg/contextutil"
"github.com/stackrox/rox/pkg/env"
"github.com/stackrox/rox/pkg/features"
"github.com/stackrox/rox/pkg/postgres"
"github.com/stackrox/rox/pkg/postgres/walker"
"github.com/stackrox/rox/pkg/sac/resources"
Expand Down Expand Up @@ -53,20 +54,26 @@ func (v *imageCoreViewImpl) Get(ctx context.Context, query *v1.Query) ([]ImageCo

func withSelectQuery(query *v1.Query) *v1.Query {
cloned := query.CloneVT()
var searchField search.FieldLabel
if features.FlattenImageData.Enabled() {
searchField = search.ImageID
} else {
searchField = search.ImageSHA
}
cloned.Selects = []*v1.QuerySelect{
search.NewQuerySelect(search.ImageSHA).Proto(),
search.NewQuerySelect(searchField).Proto(),
}

if common.IsSortBySeverityCounts(cloned) {
cloned.GroupBy = &v1.QueryGroupBy{
Fields: []string{search.ImageSHA.String()},
Fields: []string{searchField.String()},
}
cloned.Selects = append(cloned.Selects,
common.WithCountBySeverityAndFixabilityQuery(query, search.CVE).Selects...,
)
}
cloned.GroupBy = &v1.QueryGroupBy{
Fields: []string{search.ImageSHA.String()},
Fields: []string{searchField.String()},
}

// This is to minimize UI change and hide an implementation detail that the query groups images by their SHA.
Expand Down
Loading