Skip to content

Commit

Permalink
tetragon: Store namespace in generic sensors
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Oct 10, 2024
1 parent ac2b16f commit b1b658e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
1 change: 1 addition & 0 deletions pkg/sensors/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir)

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir)

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir)

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir)

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir)

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir)

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir)

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir)

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / golangci-lint

declared and not used: policyDir)

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / generated-files

declared and not used: policyDir

Check failure on line 74 in pkg/sensors/load.go

View workflow job for this annotation

GitHub Actions / analyze

declared and not used: policyDir
for _, p := range s.Progs {
// setup sensor based program pin path
p.PinPath = filepath.Join(s.policyDir(), s.Name, p.PinName)
Expand Down
10 changes: 6 additions & 4 deletions pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sensors/tracing/generickprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/sensors/tracing/genericlsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -377,7 +378,8 @@ func createGenericLsmSensor(
}
return errs
},
Policy: policyName,
Policy: policyName,
Namespace: namespace,
}, nil
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/sensors/tracing/generictracepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ func createGenericTracepointSensor(
name string,
policyID policyfilter.PolicyID,
policyName string,
namespace string,
customHandler eventhandler.Handler,
) (*sensors.Sensor, error) {
confs := spec.Tracepoints
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/sensors/tracing/genericuprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
13 changes: 9 additions & 4 deletions pkg/sensors/tracing/policyhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions pkg/sensors/tracing/tracepoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b1b658e

Please sign in to comment.