-
Notifications
You must be signed in to change notification settings - Fork 499
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 |
|---|---|---|
|
|
@@ -139,6 +139,8 @@ const ( | |
| KeyExecveMapSize = "execve-map-size" | ||
|
|
||
| KeyRetprobesCacheSize = "retprobes-cache-size" | ||
|
|
||
| KeyPolicyFilterMapEntries = "policy-filter-map-entries" | ||
| ) | ||
|
|
||
| type UsernameMetadaCode int | ||
|
|
@@ -305,6 +307,8 @@ func ReadAndSetFlags() error { | |
| Config.ExecveMapSize = viper.GetString(KeyExecveMapSize) | ||
|
|
||
| Config.RetprobesCacheSize = viper.GetInt(KeyRetprobesCacheSize) | ||
|
|
||
| Config.PolicyFilterMapEntries = viper.GetInt(KeyPolicyFilterMapEntries) | ||
|
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. Given the discussion in 9dc9735#r2629371514, should we reject values that are larger than larger than POLICY_FILTER_MAX_POLICIES?
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 don’t think we should reject values larger than POLICY_FILTER_MAX_POLICIES. The goal of this PR is to allow users to configure the number of entries in the policy filter maps. The original limit of 128 is sometimes too small, and users may legitimately have more policies in their maps.
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. OK, but given that we have: Doesn't this mean that for a value larger than POLICY_FILTER_MAX_POLICIES, things will not work as expected when considering the |
||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -504,4 +508,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 maximum number of policies in policy_filter_maps. This map restricts tracing policies to specific pods/containers. Increase if you have many policies, decrease to save memory if you have few policies.") | ||
| } | ||
| 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" | ||
| ) | ||
|
|
||
|
|
@@ -961,6 +962,11 @@ func doLoadProgram( | |
| } | ||
| } | ||
|
|
||
| // TODO: remove this special case handling (see #4398) | ||
|
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.
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. Yeah, it was discussed here for info #4331 (comment)
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. oh right, I was waiting for this to land in first, just to avoid any potential conflict here. |
||
| if ms, ok := spec.Maps["policy_filter_maps"]; ok { | ||
| ms.MaxEntries = uint32(option.Config.PolicyFilterMapEntries) | ||
| } | ||
|
|
||
| // 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.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 Please feel free to add you comment. Thanks
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.
My reading is that that
policy_filter_cgroup_mapsusesPOLICY_FILTER_MAX_POLICIESsince it's the most pessimistic approach. This means, that there will be no capacity issues (i.e., a failure to insert) inpolicy_filter_cgroup_mapswithout hitting a capacity issue inpolicy_filter_maps.I think there are three options here:
policy_filter_cgroup_mapsis not enough and do something reasonable. This can be a follow-up PR.policy_filter_cgroup_mapsis not enough.Note that option (2.) can be done in a followup PR after (1.).
CCing @tpapagian who I believe introduced this change.
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.
My preference would be to leave it as-is for now, and keep
policy_filter_cgroup_mapssized usingPOLICY_FILTER_MAX_POLICIES.A few reasons for this:
POLICY_FILTER_MAX_POLICIESforpolicy_filter_cgroup_mapsis intentionally pessimistic and gives us a safety guarantee.I agree that we should eventually harden the error path around
policy_filter_cgroup_maps, but I think that can be done independently of changing sizing semantics, and safely as a follow-up.