-
Notifications
You must be signed in to change notification settings - Fork 479
pkg/option: allow policy-filter-map-entries configurable via flag #4331
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,8 @@ const ( | |
| KeyExecveMapSize = "execve-map-size" | ||
|
|
||
| KeyRetprobesCacheSize = "retprobes-cache-size" | ||
|
|
||
| KeyPolicyFilterMapEntries = "policy-filter-map-entries" | ||
| ) | ||
|
|
||
| type UsernameMetadaCode int | ||
|
|
@@ -289,6 +291,8 @@ func ReadAndSetFlags() error { | |
| Config.ExecveMapSize = viper.GetString(KeyExecveMapSize) | ||
|
|
||
| Config.RetprobesCacheSize = viper.GetInt(KeyRetprobesCacheSize) | ||
|
|
||
| Config.PolicyFilterMapEntries = viper.GetInt(KeyPolicyFilterMapEntries) | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -483,4 +487,6 @@ func AddFlags(flags *pflag.FlagSet) { | |
| flags.String(KeyExecveMapSize, "", "Set size for execve_map table (allows K/M/G suffix)") | ||
|
|
||
| flags.Int(KeyRetprobesCacheSize, defaults.DefaultRetprobesCacheSize, "Set {k,u}retprobes events cache maximum size") | ||
|
|
||
| flags.Int(KeyPolicyFilterMapEntries, defaults.DefaultPolicyFilterMapEntries, "Set entries for policy_filter_map table (default 128)") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you be a little bit more explicit in the help what this map is for and why changing its size would matter (why you want to increase or decrease its size). Succinct is still better than extra verbose, but out of context on the map, it's not clear why this matters with this help (at least for me :)).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about this one?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep it's a nice suggestion! Don't need to repeat the default as cobra should display it in the help. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import ( | |
|
|
||
| "github.com/cilium/tetragon/pkg/bpf" | ||
| "github.com/cilium/tetragon/pkg/config" | ||
| "github.com/cilium/tetragon/pkg/option" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -72,6 +73,10 @@ func newPfMap(enableCgroupMap bool) (PfMap, error) { | |
| return PfMap{}, fmt.Errorf("loading spec for %s failed: %w", objPath, err) | ||
| } | ||
|
|
||
| if _, ok := spec.Maps["policy_filter_maps"]; ok { | ||
| spec.Maps["policy_filter_maps"].MaxEntries = uint32(option.Config.PolicyFilterMapEntries) | ||
| } | ||
|
Comment on lines
+76
to
+78
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see other comment about using |
||
|
|
||
| var ret PfMap | ||
| if ret.policyMap, err = openMap(spec, MapName, polMapSize); err != nil { | ||
| return PfMap{}, fmt.Errorf("opening map %s failed: %w", MapName, err) | ||
|
|
@@ -80,7 +85,7 @@ func newPfMap(enableCgroupMap bool) (PfMap, error) { | |
| if enableCgroupMap { | ||
| if ret.cgroupMap, err = openMap(spec, CgroupMapName, polMaxPolicies); err != nil { | ||
| releaseMap(ret.policyMap) | ||
| return PfMap{}, fmt.Errorf("opening cgroup map %s failed: %w", MapName, err) | ||
| return PfMap{}, fmt.Errorf("opening cgroup map %s failed: %w", CgroupMapName, err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this could be part of another commit fixing this typo?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll remove the typo fix from this commit.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same PR is fine :) |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import ( | |
| cachedbtf "github.com/cilium/tetragon/pkg/btf" | ||
| "github.com/cilium/tetragon/pkg/logger" | ||
| "github.com/cilium/tetragon/pkg/logger/logfields" | ||
| "github.com/cilium/tetragon/pkg/option" | ||
| "github.com/cilium/tetragon/pkg/sensors/unloader" | ||
| ) | ||
|
|
||
|
|
@@ -976,6 +977,12 @@ func doLoadProgram( | |
| } | ||
| } | ||
|
|
||
| // Set MaxEntries for policy_filter_maps if it exists in the spec. | ||
| // This ensures the spec matches the user-defined value. | ||
| if ms, ok := spec.Maps["policy_filter_maps"]; ok { | ||
| ms.MaxEntries = uint32(option.Config.PolicyFilterMapEntries) | ||
| } | ||
|
|
||
|
Comment on lines
+980
to
+985
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yes already have a facility to do that higher level in the loader (it's just above your new code btw), please use the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking to reuse
So your suggestion is to refactor
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's ask since we can before investing time in this :)! Hey @tpapagian and @kkourt, I see you are the one you touched this code, any reason why you didn't use program.Map in the first place?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not reason I remember. Is the idea be to make the map a part of the base/exec sensor?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, I think it makes sense to add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think @kkourt and @tpapagian?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if I jump in, but AFAIK
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see, even if we use the Sorry for the noise
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mtardy @kkourt I’ve been thinking more about the refactoring in the past week. IMO, it’s better to create a separate issue and PR for that work. The current issue and PR focus on adding a user-configurable knob for the size of |
||
| // Find all the maps referenced by the program, so we'll rewrite only | ||
| // the ones used. | ||
| var progSpec *ebpf.ProgramSpec | ||
|
|
||
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.
This is used by
policy_filter_cgroup_mapsjust nearby. Maybe we would need to update both and remove that const?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.
Sure, I think it makes sense to me. I'll update both of them and remove that const.
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.
@mtardy Given another think, the
POLICY_FILTER_MAX_POLICIESinpolicy_filter_cgroup_mapsrepresents how many policies can apply to a single cgroup (inner map size ofpolicy_filter_cgroup_maps).I’m fine to simplify and drive both
policy_filter_mapsandpolicy_filter_cgroup_mapsfrom the samepolicy-filter-map-entriessetting and remove that const. However, I just want you to aware that if we want to update both, it would be mixing a global capacity knob with a per-cgroup limit, which could waste memory if we config more policies globally.