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
265 changes: 182 additions & 83 deletions central/reprocessor/reprocessor.go

Large diffs are not rendered by default.

443 changes: 350 additions & 93 deletions central/reprocessor/reprocessor_unit_test.go

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions generated/internalapi/central/sensor_iservice.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions generated/internalapi/central/sensor_iservice_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions pkg/images/enricher/enricher.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,11 @@ const (
ScanTriggered
// ScanSucceeded denotes that the image was successfully scanned.
ScanSucceeded
// ScanReused denotes that an existing scan from the database was kept
// unchanged. No new scan data was produced; the image is not considered
// updated for downstream cache-invalidation purposes.
// ScanReused denotes that an existing scan from the database was reused unchanged.
ScanReused
)

// HasScanData returns true if the scan result indicates that usable scan data
// is available on the image, regardless of whether it was freshly produced or
// reused from the database.
// HasScanData reports whether usable scan data is present on the image.
func (s ScanResult) HasScanData() bool {
return s == ScanSucceeded || s == ScanReused
}
Expand Down
5 changes: 4 additions & 1 deletion proto/internalapi/central/sensor_iservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ message MsgFromSensor {
}
}

message ReprocessDeployments {}
message ReprocessDeployments {
// When true, Sensor uses targeted AC invalidation instead of a full flush.
bool skip_cache_flush = 1;
}

// next available tag: 31
message MsgToSensor {
Expand Down
35 changes: 25 additions & 10 deletions sensor/common/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/stackrox/rox/pkg/env"
"github.com/stackrox/rox/pkg/errorhelpers"
"github.com/stackrox/rox/pkg/errox"
imgUtils "github.com/stackrox/rox/pkg/images/utils"
"github.com/stackrox/rox/pkg/logging"
"github.com/stackrox/rox/pkg/networkgraph"
"github.com/stackrox/rox/pkg/networkgraph/networkbaseline"
Expand All @@ -27,6 +28,7 @@ import (
"github.com/stackrox/rox/pkg/sync"
"github.com/stackrox/rox/sensor/common"
"github.com/stackrox/rox/sensor/common/admissioncontroller"
"github.com/stackrox/rox/sensor/common/centralcaps"
"github.com/stackrox/rox/sensor/common/detector/baseline"
detectorMetrics "github.com/stackrox/rox/sensor/common/detector/metrics"
networkBaselineEval "github.com/stackrox/rox/sensor/common/detector/networkbaseline"
Expand Down Expand Up @@ -65,7 +67,7 @@ type Detector interface {
ProcessIndicator(ctx context.Context, indicator *storage.ProcessIndicator)
ProcessNetworkFlow(ctx context.Context, flow *storage.NetworkFlow)
ProcessPolicySync(ctx context.Context, sync *central.PolicySync) error
ProcessReprocessDeployments() error
ProcessReprocessDeployments(msg *central.ReprocessDeployments) error
ProcessUpdatedImage(image *storage.Image) error
ProcessFileAccess(ctx context.Context, access *storage.FileAccess)
}
Expand Down Expand Up @@ -181,7 +183,7 @@ type detectorImpl struct {
serializerStopper concurrency.Stopper
alertStopSig concurrency.Signal

admissionCacheNeedsFlush bool
updatedImageKeys []*central.ImageKey

networkPolicyStore store.NetworkPolicyStore

Expand Down Expand Up @@ -347,7 +349,8 @@ func (d *detectorImpl) processNetworkBaselineSync(sync *central.NetworkBaselineS
return nil
}

// ProcessUpdatedImage updates the imageCache with a new value
// ProcessUpdatedImage updates the imageCache with a new value and accumulates
// the image key for batched AC invalidation in ProcessReprocessDeployments.
func (d *detectorImpl) ProcessUpdatedImage(image *storage.Image) error {
key := cache.GetKey(image)
log.Debugf("Receiving update for image: %s from central. Updating cache", image.GetName().GetFullName())
Expand All @@ -357,18 +360,30 @@ func (d *detectorImpl) ProcessUpdatedImage(image *storage.Image) error {
regStore: d.enricher.regStore,
}
d.enricher.imageCache.Add(key, newValue)
d.admissionCacheNeedsFlush = true
imageKey := &central.ImageKey{
ImageId: image.GetId(),
ImageFullName: image.GetName().GetFullName(),
}
if centralcaps.Has(centralsensor.FlattenImageData) {
imageKey.ImageIdV2 = imgUtils.NewImageV2ID(image.GetName(), image.GetId())
}
d.updatedImageKeys = append(d.updatedImageKeys, imageKey)
return nil
}

// ProcessReprocessDeployments marks all deployments to be reprocessed
func (d *detectorImpl) ProcessReprocessDeployments() error {
// ProcessReprocessDeployments marks all deployments for reprocessing.
// When skip_cache_flush=true, sends batched targeted AC invalidation
// instead of a full purge.
func (d *detectorImpl) ProcessReprocessDeployments(msg *central.ReprocessDeployments) error {
log.Debug("Reprocess deployments triggered. Clearing cache and deduper")
if d.admissionCacheNeedsFlush && d.admCtrlSettingsMgr != nil {
// Would prefer to do a targeted flush
d.admCtrlSettingsMgr.FlushCache()
if d.admCtrlSettingsMgr != nil {
if !msg.GetSkipCacheFlush() {
d.admCtrlSettingsMgr.FlushCache()
} else if len(d.updatedImageKeys) > 0 {
d.admCtrlSettingsMgr.InvalidateImageCache(d.updatedImageKeys)
}
}
d.admissionCacheNeedsFlush = false
d.updatedImageKeys = nil
d.deduper.reset()
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions sensor/common/detector/mocks/detector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sensor/kubernetes/eventpipeline/pipeline_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (p *eventPipeline) ProcessMessage(_ context.Context, msg *central.MsgToSens
case msg.GetUpdatedImage() != nil:
return p.processUpdatedImage(msg.GetUpdatedImage())
case msg.GetReprocessDeployments() != nil:
return p.processReprocessDeployments()
return p.processReprocessDeployments(msg.GetReprocessDeployments())
case msg.GetReprocessDeployment() != nil:
return p.processReprocessDeployment(msg.GetReprocessDeployment())
case msg.GetInvalidateImageCache() != nil:
Expand Down Expand Up @@ -190,9 +190,9 @@ func (p *eventPipeline) processPolicySync(sync *central.PolicySync) error {
return nil
}

func (p *eventPipeline) processReprocessDeployments() error {
func (p *eventPipeline) processReprocessDeployments(reprocessMsg *central.ReprocessDeployments) error {
log.Debug("ReprocessDeployments message received from central")
if err := p.detector.ProcessReprocessDeployments(); err != nil {
if err := p.detector.ProcessReprocessDeployments(reprocessMsg); err != nil {
return errors.Wrap(err, "reprocessing deployments")
}
msg := component.NewEventWithTopicAndLane(pubsubDispatcher.FromCentralResolverEventTopic, pubsubDispatcher.FromCentralResolverEventLane)
Expand Down
2 changes: 1 addition & 1 deletion sensor/kubernetes/eventpipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (s *eventPipelineSuite) Test_ReprocessDeployments() {
ReprocessDeployments: &central.ReprocessDeployments{},
},
}
s.detector.EXPECT().ProcessReprocessDeployments().Times(1).Do(func() {
s.detector.EXPECT().ProcessReprocessDeployments(gomock.Any()).Times(1).Do(func(_ *central.ReprocessDeployments) {
defer messageReceived.Done()
})

Expand Down
Loading