-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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-1120] Merge activity dump and security profile managers #33877
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
func diffActivityDump(_ log.Component, _ config.Component, _ secrets.Component, args *activityDumpCliParams) error { | ||
ad := dump.NewEmptyActivityDump(nil) | ||
if err := ad.Decode(args.file); err != nil { | ||
p := profile.New(cgroupModel.WorkloadSelector{}, nil, false, 0, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could have an helper like NewEmpty
here (and on the other similar places), instead of having to call a func with a lot of variables (for code clarity). WDYT ?
for _, existingTagName := range existingTagNames { | ||
if existingTagName == tagName { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
p.tags = append(p.tags, tag) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use slices.Contains() instead ?
p.m.Lock() | ||
defer p.m.Unlock() | ||
|
||
imageTag := utils.GetTagValue("image_tag", p.tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not use the tag of the profile here IMHO
// getSelectorStr internal, thread-unsafe version of GetSelectorStr | ||
func (p *Profile) getSelectorStr() string { | ||
tags := make([]string, 0, len(p.tags)+2) | ||
if len(p.Metadata.ContainerID) > 0 { | ||
tags = append(tags, fmt.Sprintf("container_id:%s", p.Metadata.ContainerID)) | ||
} | ||
sp := &SecurityProfile{ | ||
selector: selector, | ||
eventTypes: eventTypes, | ||
versionContexts: make(map[string]*VersionContext), | ||
timeResolver: tr, | ||
pathsReducer: pathsReducer, | ||
if len(p.Metadata.CGroupContext.CGroupID) > 0 { | ||
tags = append(tags, fmt.Sprintf("cgroup_id:%s", p.Metadata.CGroupContext.CGroupID)) | ||
} | ||
if selector.Tag != "" && selector.Tag != "*" { | ||
sp.versionContexts[selector.Tag] = &VersionContext{ | ||
eventTypeState: make(map[model.EventType]*EventTypeState), | ||
if len(p.tags) > 0 { | ||
for _, tag := range p.tags { | ||
if !strings.HasPrefix(tag, "container_id") && !strings.HasPrefix(tag, "cgroup_id") { | ||
tags = append(tags, tag) | ||
} | ||
} | ||
} | ||
return sp | ||
if len(tags) == 0 { | ||
return "empty_selector" | ||
} | ||
return strings.Join(p.tags, ",") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use the p.selector.String() instead? To avoid having to compute the selector every time
if opts.DifferentiateArgs && input.Metadata.DifferentiateArgs { | ||
p.ActivityTree.DifferentiateArgs() | ||
} | ||
imageTag := utils.GetTagValue("image_tag", p.tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use the imagetag of the event if any, not the profile's one
for _, workload := range p.Instances { | ||
if entry.ContainerID == workload.ContainerID { | ||
return true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly linked to your PR, but this looks insufficient for the new cgroup selectors
profileFiles := make(map[string]*profileFile) | ||
for _, file := range files { | ||
if !fileHasProfileExtension(file.Name()) { | ||
continue | ||
} | ||
|
||
fileInfo, err := file.Info() | ||
if err != nil { | ||
seclog.Warnf("failed to retrieve file [%s] information: %s", file.Name(), err) | ||
continue | ||
} | ||
|
||
if !fileInfo.Mode().IsRegular() { | ||
continue | ||
} | ||
|
||
path := filepath.Join(directoryPath, file.Name()) | ||
_, ok := profileFiles[path] | ||
if !ok { | ||
profileFiles[path] = &profileFile{ | ||
path: path, | ||
mTime: fileInfo.ModTime(), | ||
} | ||
} | ||
} | ||
|
||
fileSlice := make([]*profileFile, 0, len(profileFiles)) | ||
for _, file := range profileFiles { | ||
fileSlice = append(fileSlice, file) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not creating directly a slice instead of a map (to then copy it to a slice) ?
// selectorToName allows finding a security profile from a given selector | ||
// selector to names is a 1-to-N mapping (because multiple profiles can be created for the same selector) | ||
selectorToNames map[cgroupModel.WorkloadSelector][]string | ||
// namesToFiles allows finding the files associated from a given security profile name | ||
// name to files is a 1-to-N mapping (because a same profile can be stored with multiple file formats) | ||
nameToEntry *simplelru.LRU[string, *profileEntry] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO we should really try to simplify this representation. Having a cgroup selector as key for the first map, and as value on the second is super error prone.
We need to spend some time discussing together, but a first idea to simplify it would be:
- Don't bother having selector with versions. At the end, what we want is only image_name as selector (and '*' as tag/version), right?
- I would also suggest to keep only the last version of a profile when persisting a new one. I don't see the point of keeping old versions of a profile (except for debug purposes?)
- Ideally, if we can only keep the first map (selector to files) IMHO it would be great and would simplify by a lot the code complexity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It starts to be such a huge file! Could we find a way to split it on multiple files? If it make sense to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like load_controller / snapshot / stats / grpc funcs etc (I think we should try to keep dump/profile logic funcs in the same place)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a big file, I guess it's mostly copied funcs from original dump/profile managers + some plumbing. Should I look specifically on some parts for the review?
if !ad.Profile.IsEmpty() && ad.Profile.GetWorkloadSelector() != nil { | ||
if err := m.persist(ad.Profile, m.configuredStorageRequests); err != nil { | ||
seclog.Errorf("couldn't persist dump [%s]: %v", ad.GetSelectorStr(), err) | ||
} else if m.config.RuntimeSecurity.SecurityProfileEnabled { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we remove the else
here?
if !ad.Profile.IsEmpty() && ad.Profile.GetWorkloadSelector() != nil { | ||
if err := m.persist(ad.Profile, m.configuredStorageRequests); err != nil { | ||
seclog.Errorf("couldn't persist dump [%s]: %v", ad.GetSelectorStr(), err) | ||
} else if m.config.RuntimeSecurity.SecurityProfileEnabled { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, should we remove the else
?
// AddProfile adds a profile to the manager | ||
func (m *Manager) AddProfile(profile *profile.Profile) { | ||
m.newProfiles <- profile | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a comment to tell it's only used for test purposes?
// a profile loaded from file can be of two forms: | ||
// 1. a profile coming from the activity dump manager, providing an activity tree corresponding to | ||
// the selector image_name + image_tag. | ||
// 2. a profile coming from the security profile manager, providing an activity tree corresponding to | ||
// the selector image_name, containing multiple image tag versions. Not yet the case, but it will be. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the comments are still aligned with the code. here we only have a the case of a dump right?
09defad
to
2d49296
Compare
Go Package Import DifferencesBaseline: e3dc9b4
|
Uncompressed package size comparisonComparison with ancestor Diff per package
Decision✅ Passed |
Regression DetectorRegression Detector ResultsMetrics dashboard Baseline: e3dc9b4 Optimization Goals: ✅ No significant changes detected
|
perf | experiment | goal | Δ mean % | Δ mean % CI | trials | links |
---|---|---|---|---|---|---|
➖ | quality_gate_logs | % cpu utilization | +3.04 | [+0.04, +6.04] | 1 | Logs |
➖ | tcp_syslog_to_blackhole | ingress throughput | +0.75 | [+0.70, +0.81] | 1 | Logs |
➖ | uds_dogstatsd_to_api_cpu | % cpu utilization | +0.74 | [-0.14, +1.62] | 1 | Logs |
➖ | file_to_blackhole_500ms_latency | egress throughput | +0.30 | [-0.47, +1.08] | 1 | Logs |
➖ | quality_gate_idle | memory utilization | +0.14 | [+0.11, +0.18] | 1 | Logs bounds checks dashboard |
➖ | quality_gate_idle_all_features | memory utilization | +0.04 | [-0.01, +0.10] | 1 | Logs bounds checks dashboard |
➖ | file_to_blackhole_0ms_latency | egress throughput | +0.02 | [-0.85, +0.88] | 1 | Logs |
➖ | file_to_blackhole_0ms_latency_http1 | egress throughput | +0.01 | [-0.82, +0.83] | 1 | Logs |
➖ | file_to_blackhole_300ms_latency | egress throughput | +0.00 | [-0.62, +0.63] | 1 | Logs |
➖ | tcp_dd_logs_filter_exclude | ingress throughput | -0.00 | [-0.02, +0.02] | 1 | Logs |
➖ | uds_dogstatsd_to_api | ingress throughput | -0.01 | [-0.29, +0.28] | 1 | Logs |
➖ | file_to_blackhole_100ms_latency | egress throughput | -0.02 | [-0.64, +0.60] | 1 | Logs |
➖ | file_to_blackhole_0ms_latency_http2 | egress throughput | -0.04 | [-0.84, +0.77] | 1 | Logs |
➖ | file_to_blackhole_1000ms_latency | egress throughput | -0.04 | [-0.82, +0.74] | 1 | Logs |
➖ | file_to_blackhole_1000ms_latency_linear_load | egress throughput | -0.11 | [-0.57, +0.35] | 1 | Logs |
➖ | file_tree | memory utilization | -0.28 | [-0.34, -0.22] | 1 | Logs |
Bounds Checks: ✅ Passed
perf | experiment | bounds_check_name | replicates_passed | links |
---|---|---|---|---|
✅ | file_to_blackhole_0ms_latency | lost_bytes | 10/10 | |
✅ | file_to_blackhole_0ms_latency | memory_usage | 10/10 | |
✅ | file_to_blackhole_0ms_latency_http1 | lost_bytes | 10/10 | |
✅ | file_to_blackhole_0ms_latency_http1 | memory_usage | 10/10 | |
✅ | file_to_blackhole_0ms_latency_http2 | lost_bytes | 10/10 | |
✅ | file_to_blackhole_0ms_latency_http2 | memory_usage | 10/10 | |
✅ | file_to_blackhole_1000ms_latency | memory_usage | 10/10 | |
✅ | file_to_blackhole_1000ms_latency_linear_load | memory_usage | 10/10 | |
✅ | file_to_blackhole_100ms_latency | lost_bytes | 10/10 | |
✅ | file_to_blackhole_100ms_latency | memory_usage | 10/10 | |
✅ | file_to_blackhole_300ms_latency | lost_bytes | 10/10 | |
✅ | file_to_blackhole_300ms_latency | memory_usage | 10/10 | |
✅ | file_to_blackhole_500ms_latency | lost_bytes | 10/10 | |
✅ | file_to_blackhole_500ms_latency | memory_usage | 10/10 | |
✅ | quality_gate_idle | intake_connections | 10/10 | bounds checks dashboard |
✅ | quality_gate_idle | memory_usage | 10/10 | bounds checks dashboard |
✅ | quality_gate_idle_all_features | intake_connections | 10/10 | bounds checks dashboard |
✅ | quality_gate_idle_all_features | memory_usage | 10/10 | bounds checks dashboard |
✅ | quality_gate_logs | intake_connections | 10/10 | |
✅ | quality_gate_logs | lost_bytes | 10/10 | |
✅ | quality_gate_logs | memory_usage | 10/10 |
Explanation
Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%
Performance changes are noted in the perf column of each table:
- ✅ = significantly better comparison variant performance
- ❌ = significantly worse comparison variant performance
- ➖ = no significant change in performance
A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".
For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:
-
Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.
-
Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.
-
Its configuration does not mark it "erratic".
CI Pass/Fail Decision
✅ Passed. All Quality Gates passed.
- quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
What does this PR do?
Profile
type that includes fields used for both activity collection (dump) and profile lookups.Motivation
Describe how you validated your changes
Possible Drawbacks / Trade-offs
Additional Notes