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
1 change: 1 addition & 0 deletions docs/content/en/docs/reference/helm-chart.md

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

3 changes: 3 additions & 0 deletions docs/data/tetragon_flags.yaml

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

1 change: 1 addition & 0 deletions install/kubernetes/tetragon/README.md

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
Expand Up @@ -67,6 +67,9 @@ data:
{{- if .Values.tetragon.enablePolicyFilterDebug }}
enable-policy-filter-debug: "true"
{{- end }}
{{- if .Values.tetragon.enablePolicyFilterNoPrealloc }}
enable-policy-filter-no-prealloc: "true"
{{- end }}
{{- if .Values.tetragon.enableMsgHandlingLatency }}
enable-msg-handling-latency: "true"
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions install/kubernetes/tetragon/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ tetragon:
enablePolicyFilterCgroupMap: false
# -- Enable policy filter debug messages.
enablePolicyFilterDebug: false
# -- Enable BPF_F_NO_PREALLOC flag for policy filter inner maps.
enablePolicyFilterNoPrealloc: false
# -- Enable latency monitoring in message handling
enableMsgHandlingLatency: false
healthGrpc:
Expand Down
7 changes: 4 additions & 3 deletions pkg/option/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ type config struct {

ReleasePinned bool

EnablePolicyFilter bool
EnablePolicyFilterCgroupMap bool
EnablePolicyFilterDebug bool
EnablePolicyFilter bool
EnablePolicyFilterCgroupMap bool
EnablePolicyFilterDebug bool
EnablePolicyFilterNoPrealloc bool

EnablePidSetFilter bool

Expand Down
9 changes: 6 additions & 3 deletions pkg/option/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ const (

KeyReleasePinnedBPF = "release-pinned-bpf"

KeyEnablePolicyFilter = "enable-policy-filter"
KeyEnablePolicyFilterCgroupMap = "enable-policy-filter-cgroup-map"
KeyEnablePolicyFilterDebug = "enable-policy-filter-debug"
KeyEnablePolicyFilter = "enable-policy-filter"
KeyEnablePolicyFilterCgroupMap = "enable-policy-filter-cgroup-map"
KeyEnablePolicyFilterDebug = "enable-policy-filter-debug"
KeyEnablePolicyFilterNoPrealloc = "enable-policy-filter-no-prealloc"

KeyEnablePidSetFilter = "enable-pid-set-filter"

Expand Down Expand Up @@ -237,6 +238,7 @@ func ReadAndSetFlags() error {
Config.EnablePolicyFilter = viper.GetBool(KeyEnablePolicyFilter)
Config.EnablePolicyFilterCgroupMap = viper.GetBool(KeyEnablePolicyFilterCgroupMap)
Config.EnablePolicyFilterDebug = viper.GetBool(KeyEnablePolicyFilterDebug)
Config.EnablePolicyFilterNoPrealloc = viper.GetBool(KeyEnablePolicyFilterNoPrealloc)
Config.EnableMsgHandlingLatency = viper.GetBool(KeyEnableMsgHandlingLatency)

Config.EnablePidSetFilter = viper.GetBool(KeyEnablePidSetFilter)
Expand Down Expand Up @@ -441,6 +443,7 @@ func AddFlags(flags *pflag.FlagSet) {
flags.Bool(KeyEnablePolicyFilter, false, "Enable policy filter code")
flags.Bool(KeyEnablePolicyFilterCgroupMap, false, "Enable cgroup mappings for policy filter maps")
flags.Bool(KeyEnablePolicyFilterDebug, false, "Enable policy filter debug messages")
flags.Bool(KeyEnablePolicyFilterNoPrealloc, false, "Enable BPF_F_NO_PREALLOC flag for policy filter inner maps")

// Provide option to enable the pidSet export filters.
flags.Bool(KeyEnablePidSetFilter, false, "Enable pidSet export filters. Not recommended for production use")
Expand Down
10 changes: 10 additions & 0 deletions pkg/policyfilter/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/cilium/tetragon/pkg/bpf"
"github.com/cilium/tetragon/pkg/config"
"github.com/cilium/tetragon/pkg/option"
)

const (
Expand All @@ -39,6 +40,11 @@ func openMap(spec *ebpf.CollectionSpec, mapName string, innerMaxEntries uint32)
// inserting a different size of inner-map, but for older kernels, we
// fix the spec here.
policyMapSpec.InnerMap.MaxEntries = innerMaxEntries
if option.Config.EnablePolicyFilterNoPrealloc {
policyMapSpec.InnerMap.Flags |= bpf.BPF_F_NO_PREALLOC
} else {
policyMapSpec.InnerMap.Flags &^= bpf.BPF_F_NO_PREALLOC
}

ret, err := ebpf.NewMap(policyMapSpec)
if err != nil {
Expand Down Expand Up @@ -185,6 +191,10 @@ func (m PfMap) newPolicyMap(polID PolicyID, cgIDs []CgroupID) (polMap, error) {
MaxEntries: uint32(polMapSize),
}

if option.Config.EnablePolicyFilterNoPrealloc {
innerSpec.Flags = bpf.BPF_F_NO_PREALLOC
}

inner, err := ebpf.NewMap(innerSpec)
if err != nil {
return polMap{}, fmt.Errorf("failed to create policy (id=%d) map: %w", polID, err)
Expand Down
Loading