diff --git a/pkg/sensors/load.go b/pkg/sensors/load.go index 5d06674988e..d464ba88cab 100644 --- a/pkg/sensors/load.go +++ b/pkg/sensors/load.go @@ -71,6 +71,7 @@ func (s *Sensor) policyDir() string { } func (s *Sensor) createDirs(bpfDir string) { + policyDir := fmt.Sprintf("%s:%s", s.Namespace, sanitize(s.Policy)) for _, p := range s.Progs { // setup sensor based program pin path p.PinPath = filepath.Join(s.policyDir(), s.Name, p.PinName) diff --git a/pkg/sensors/tracing/generickprobe.go b/pkg/sensors/tracing/generickprobe.go index 6a07009f101..870dec5bf9e 100644 --- a/pkg/sensors/tracing/generickprobe.go +++ b/pkg/sensors/tracing/generickprobe.go @@ -580,6 +580,7 @@ func createGenericKprobeSensor( name string, policyID policyfilter.PolicyID, policyName string, + namespace string, customHandler eventhandler.Handler, ) (*sensors.Sensor, error) { var progs []*program.Program @@ -648,10 +649,11 @@ func createGenericKprobeSensor( } return &sensors.Sensor{ - Name: name, - Progs: progs, - Maps: maps, - Policy: policyName, + Name: name, + Progs: progs, + Maps: maps, + Policy: policyName, + Namespace: namespace, DestroyHook: func() error { var errs error for _, id := range ids { diff --git a/pkg/sensors/tracing/generickprobe_test.go b/pkg/sensors/tracing/generickprobe_test.go index f65a302186b..01af82cb4a6 100644 --- a/pkg/sensors/tracing/generickprobe_test.go +++ b/pkg/sensors/tracing/generickprobe_test.go @@ -81,7 +81,7 @@ func Test_SensorDestroyHook(t *testing.T) { // insertion in the table in AddKprobe, but this is done by the caller to // have just DestroyHook that regroups all the potential multiple kprobes // contained in one sensor. - sensor, err := createGenericKprobeSensor(spec, "test_sensor", 0, "test_policy", nil) + sensor, err := createGenericKprobeSensor(spec, "test_sensor", 0, "test_policy", "", nil) if err != nil { t.Errorf("createGenericKprobeSensor err expected: nil, got: %s", err) } diff --git a/pkg/sensors/tracing/genericlsm.go b/pkg/sensors/tracing/genericlsm.go index 78ede697b53..7f5a059c748 100644 --- a/pkg/sensors/tracing/genericlsm.go +++ b/pkg/sensors/tracing/genericlsm.go @@ -322,6 +322,7 @@ func createGenericLsmSensor( name string, policyID policyfilter.PolicyID, policyName string, + namespace string, ) (*sensors.Sensor, error) { var progs []*program.Program var maps []*program.Map @@ -377,7 +378,8 @@ func createGenericLsmSensor( } return errs }, - Policy: policyName, + Policy: policyName, + Namespace: namespace, }, nil } diff --git a/pkg/sensors/tracing/generictracepoint.go b/pkg/sensors/tracing/generictracepoint.go index 667c0149c26..358176d1a85 100644 --- a/pkg/sensors/tracing/generictracepoint.go +++ b/pkg/sensors/tracing/generictracepoint.go @@ -362,6 +362,7 @@ func createGenericTracepointSensor( name string, policyID policyfilter.PolicyID, policyName string, + namespace string, customHandler eventhandler.Handler, ) (*sensors.Sensor, error) { confs := spec.Tracepoints @@ -506,10 +507,11 @@ func createGenericTracepointSensor( } return &sensors.Sensor{ - Name: name, - Progs: progs, - Maps: maps, - Policy: policyName, + Name: name, + Progs: progs, + Maps: maps, + Policy: policyName, + Namespace: namespace, }, nil } diff --git a/pkg/sensors/tracing/genericuprobe.go b/pkg/sensors/tracing/genericuprobe.go index eceb67b5051..47bf50f87c9 100644 --- a/pkg/sensors/tracing/genericuprobe.go +++ b/pkg/sensors/tracing/genericuprobe.go @@ -245,6 +245,7 @@ func createGenericUprobeSensor( spec *v1alpha1.TracingPolicySpec, name string, policyName string, + namespace string, ) (*sensors.Sensor, error) { var progs []*program.Program var maps []*program.Map @@ -284,10 +285,11 @@ func createGenericUprobeSensor( } return &sensors.Sensor{ - Name: name, - Progs: progs, - Maps: maps, - Policy: policyName, + Name: name, + Progs: progs, + Maps: maps, + Policy: policyName, + Namespace: namespace, }, nil } diff --git a/pkg/sensors/tracing/policyhandler.go b/pkg/sensors/tracing/policyhandler.go index 136d11f1c0f..6cc10db9810 100644 --- a/pkg/sensors/tracing/policyhandler.go +++ b/pkg/sensors/tracing/policyhandler.go @@ -27,6 +27,11 @@ func (h policyHandler) PolicyHandler( policyName := policy.TpName() spec := policy.TpSpec() + namespace := "" + if tpn, ok := policy.(tracingpolicy.TracingPolicyNamespaced); ok { + namespace = tpn.TpNamespace() + } + sections := 0 if len(spec.KProbes) > 0 { sections++ @@ -48,16 +53,16 @@ func (h policyHandler) PolicyHandler( if err != nil { return nil, fmt.Errorf("validation failed: %w", err) } - return createGenericKprobeSensor(spec, name, policyID, policyName, handler) + return createGenericKprobeSensor(spec, name, policyID, policyName, namespace, handler) } if len(spec.Tracepoints) > 0 { - return createGenericTracepointSensor(spec, "generic_tracepoint", policyID, policyName, handler) + return createGenericTracepointSensor(spec, "generic_tracepoint", policyID, policyName, namespace, handler) } if len(spec.LsmHooks) > 0 { - return createGenericLsmSensor(spec, "generic_lsm", policyID, policyName) + return createGenericLsmSensor(spec, "generic_lsm", policyID, policyName, namespace) } if len(spec.UProbes) > 0 { - return createGenericUprobeSensor(spec, "generic_lsm", policyName) + return createGenericUprobeSensor(spec, "generic_lsm", policyName, namespace) } return nil, nil } diff --git a/pkg/sensors/tracing/tracepoint_test.go b/pkg/sensors/tracing/tracepoint_test.go index bdb78f6de26..d674e7774e2 100644 --- a/pkg/sensors/tracing/tracepoint_test.go +++ b/pkg/sensors/tracing/tracepoint_test.go @@ -83,7 +83,7 @@ func TestGenericTracepointSimple(t *testing.T) { sm := tus.GetTestSensorManager(ctx, t) // create and add sensor - sensor, err := createGenericTracepointSensor(&spec, "GtpLseekTest", policyfilter.NoFilterID, "policyName", nil) + sensor, err := createGenericTracepointSensor(&spec, "GtpLseekTest", policyfilter.NoFilterID, "policyName", "", nil) if err != nil { t.Fatalf("failed to create generic tracepoint sensor: %s", err) } @@ -147,7 +147,7 @@ func doTestGenericTracepointPidFilter(t *testing.T, conf v1alpha1.TracepointSpec sm := tus.GetTestSensorManager(ctx, t) // create and add sensor - sensor, err := createGenericTracepointSensor(&spec, "GtpLseekTest", policyfilter.NoFilterID, "policyName", nil) + sensor, err := createGenericTracepointSensor(&spec, "GtpLseekTest", policyfilter.NoFilterID, "policyName", "", nil) if err != nil { t.Fatalf("failed to create generic tracepoint sensor: %s", err) } @@ -543,7 +543,7 @@ func TestTracepointCloneThreads(t *testing.T) { sm := tus.GetTestSensorManager(ctx, t) // create and add sensor - sensor, err := createGenericTracepointSensor(&spec, "GtpLseekTest", policyfilter.NoFilterID, "policyName", nil) + sensor, err := createGenericTracepointSensor(&spec, "GtpLseekTest", policyfilter.NoFilterID, "policyName", "", nil) if err != nil { t.Fatalf("failed to create generic tracepoint sensor: %s", err) }