Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CWS] allow the sec profile manager to communicate to the ADM to stop persisting unused dumps #29426

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 9 additions & 0 deletions pkg/security/security_profile/dump/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,12 @@ func (adm *ActivityDumpManager) StopDumpsWithSelector(selector cgroupModel.Workl
ad.Unlock()
}
}

// PushIgnoreLocalPersistImage adds an image to the list of images to ignore for local persist
func (adm *ActivityDumpManager) PushIgnoreLocalPersistImage(image string) {
if adm.storage == nil {
return
}

adm.storage.PushIgnoreLocalPersistImage(image)
}
24 changes: 24 additions & 0 deletions pkg/security/security_profile/dump/storage_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package dump
import (
"bytes"
"fmt"
"sync"

"github.com/DataDog/datadog-go/v5/statsd"

Expand All @@ -33,6 +34,9 @@ type ActivityDumpStorage interface {
type ActivityDumpStorageManager struct {
statsdClient statsd.ClientInterface
storages map[config.StorageType]ActivityDumpStorage

ilpiLock sync.Mutex
ignoreLocalPersistImages map[string]struct{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about pre-filling this list at startup with already present profile ?

}

// NewAgentStorageManager returns a new instance of ActivityDumpStorageManager
Expand Down Expand Up @@ -127,6 +131,10 @@ func (manager *ActivityDumpStorageManager) PersistRaw(requests []config.StorageR
continue
}

if request.Type == config.LocalStorage && !manager.shouldPersistADLocally(ad) {
continue
}

if err := storage.Persist(request, ad, raw); err != nil {
seclog.Errorf("couldn't persist [%s] in [%s] storage: %v", ad.GetSelectorStr(), request.Type, err)
continue
Expand Down Expand Up @@ -155,3 +163,19 @@ func (manager *ActivityDumpStorageManager) SendTelemetry() {
storage.SendTelemetry(manager.statsdClient)
}
}

// PushIgnoreLocalPersistImage adds an image to the list of images to ignore for local persist
func (manager *ActivityDumpStorageManager) PushIgnoreLocalPersistImage(image string) {
manager.ilpiLock.Lock()
defer manager.ilpiLock.Unlock()
manager.ignoreLocalPersistImages[image] = struct{}{}
}

func (manager *ActivityDumpStorageManager) shouldPersistADLocally(ad *ActivityDump) bool {
ws := ad.GetWorkloadSelector()
manager.ilpiLock.Lock()
defer manager.ilpiLock.Unlock()

_, ok := manager.ignoreLocalPersistImages[ws.Image]
return !ok
}
5 changes: 5 additions & 0 deletions pkg/security/security_profile/profile/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type eventFilteringEntry struct {
// ActivityDumpManager is a generic interface to reach the Activity Dump manager
type ActivityDumpManager interface {
StopDumpsWithSelector(selector cgroupModel.WorkloadSelector)
PushIgnoreLocalPersistImage(image string)
}

// SecurityProfileManager is used to manage Security Profiles
Expand Down Expand Up @@ -443,6 +444,10 @@ func (m *SecurityProfileManager) ShouldDeleteProfile(profile *SecurityProfile) {
if err := m.persistProfile(profile); err != nil {
seclog.Errorf("couldn't persist profile: %v", err)
}

if profile.selector.Tag == "*" {
m.activityDumpManager.PushIgnoreLocalPersistImage(profile.selector.Image)
}
}
}

Expand Down
Loading