Skip to content

Commit

Permalink
filters: implement container_id filter
Browse files Browse the repository at this point in the history
Implement a container_id filter, primarily to support its use in docker-based unit
testing.

Signed-off-by: William Findlay <[email protected]>
  • Loading branch information
will-isovalent committed Dec 10, 2024
1 parent 05e9fed commit 0364efd
Show file tree
Hide file tree
Showing 10 changed files with 576 additions and 486 deletions.
1 change: 1 addition & 0 deletions api/v1/README.md

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

336 changes: 174 additions & 162 deletions api/v1/tetragon/events.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions api/v1/tetragon/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ message Filter {
// Filter by process.parent.arguments field using RE2 regular expression syntax:
// https://github.com/google/re2/wiki/Syntax
repeated string parent_arguments_regex = 14;
// Filter by the container ID in the process.docker field. Matches a string
// prefix to emulate the behaviour of docker CLI.
repeated string container_id = 15;
}

// Filter over a set of Linux process capabilities. See `message Capabilities`
Expand Down

Large diffs are not rendered by default.

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

1 change: 1 addition & 0 deletions docs/content/en/docs/reference/grpc-api.md

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

42 changes: 42 additions & 0 deletions pkg/filters/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium

package filters

import (
"context"
"strings"

v1 "github.com/cilium/cilium/pkg/hubble/api/v1"
hubbleFilters "github.com/cilium/cilium/pkg/hubble/filters"
"github.com/cilium/tetragon/api/v1/tetragon"
)

func filterByContainerID(ids []string) (hubbleFilters.FilterFunc, error) {
return func(ev *v1.Event) bool {
process := GetProcess(ev)
if process == nil {
return false
}
for _, id := range ids {
if strings.HasPrefix(process.Docker, id) {
return true
}
}
return false
}, nil
}

type ContainerIDFilter struct{}

func (f *ContainerIDFilter) OnBuildFilter(_ context.Context, ff *tetragon.Filter) ([]hubbleFilters.FilterFunc, error) {
var fs []hubbleFilters.FilterFunc
if ff.ContainerId != nil {
filters, err := filterByContainerID(ff.ContainerId)
if err != nil {
return nil, err
}
fs = append(fs, filters)
}
return fs, nil
}
1 change: 1 addition & 0 deletions pkg/filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var Filters = []OnBuildFilter{
&PodRegexFilter{},
&PolicyNamesFilter{},
&CapsFilter{},
&ContainerIDFilter{},
}

func GetProcess(event *v1.Event) *tetragon.Process {
Expand Down
336 changes: 174 additions & 162 deletions vendor/github.com/cilium/tetragon/api/v1/tetragon/events.pb.go

Large diffs are not rendered by default.

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

0 comments on commit 0364efd

Please sign in to comment.