Skip to content
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

NETOBSERV-2047: extend flow filter apis to introduce peerCIDR #989

Merged
merged 2 commits into from
Jan 22, 2025
Merged
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
4 changes: 4 additions & 0 deletions apis/flowcollector/v1beta1/flowcollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ type EBPFFlowFilterRule struct {
// +optional
PeerIP string `json:"peerIP,omitempty"`

// `peerCIDR` defines the Peer IP CIDR to filter flows by.
// Examples: `10.10.10.0/24` or `100:100:100:100::/64`
PeerCIDR string `json:"peerCIDR,omitempty"`

// `icmpCode`, for Internet Control Message Protocol (ICMP) traffic, optionally defines the ICMP code to filter flows by.
// +optional
ICMPCode *int `json:"icmpCode,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions apis/flowcollector/v1beta1/zz_generated.conversion.go

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

4 changes: 4 additions & 0 deletions apis/flowcollector/v1beta2/flowcollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ type EBPFFlowFilterRule struct {
// +optional
PeerIP string `json:"peerIP,omitempty"`

// `peerCIDR` defines the Peer IP CIDR to filter flows by.
// Examples: `10.10.10.0/24` or `100:100:100:100::/64`
PeerCIDR string `json:"peerCIDR,omitempty"`

// `icmpCode`, for Internet Control Message Protocol (ICMP) traffic, optionally defines the ICMP code to filter flows by.
// +optional
ICMPCode *int `json:"icmpCode,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ func (r *FlowCollector) validateAgent(_ context.Context, fc *FlowCollectorSpec)
m := make(map[string]bool)
for i := range fc.Agent.EBPF.FlowFilter.FlowFilterRules {
rule := fc.Agent.EBPF.FlowFilter.FlowFilterRules[i]
if found := m[rule.CIDR]; found {
errs = append(errs, fmt.Errorf("flow filter rule CIDR %s already exists", rule.CIDR))
key := rule.CIDR + "-" + rule.PeerCIDR
if found := m[key]; found {
errs = append(errs, fmt.Errorf("flow filter rule CIDR and PeerCIDR %s already exists",
key))
break
}
m[rule.CIDR] = true
m[key] = true
errs = append(errs, validateFilter(&rule)...)
}
errs = append(errs, validateFilter(fc.Agent.EBPF.FlowFilter)...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ func TestValidateAgent(t *testing.T) {
{
Action: "Accept",
CIDR: "0.0.0.0/0",
PeerCIDR: "1.1.1.1/24",
Direction: "Egress",
Protocol: "TCP",
},
{
Action: "Accept",
CIDR: "0.0.0.0/0",
PeerCIDR: "1.1.1.1/24",
Direction: "Egress",
Protocol: "UDP",
},
Expand All @@ -92,7 +94,7 @@ func TestValidateAgent(t *testing.T) {
},
},
},
expectedError: "flow filter rule CIDR 0.0.0.0/0 already exists",
expectedError: "flow filter rule CIDR and PeerCIDR 0.0.0.0/0-1.1.1.1/24 already exists",
},
{
name: "PacketDrop without privilege triggers warning",
Expand Down
20 changes: 20 additions & 0 deletions bundle/manifests/flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ spec:
description: '`icmpType`, for ICMP traffic, optionally
defines the ICMP type to filter flows by.'
type: integer
peerCIDR:
description: |-
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`
type: string
peerIP:
description: |-
`peerIP` optionally defines the remote IP address to filter flows by.
Expand Down Expand Up @@ -285,6 +290,11 @@ spec:
description: '`icmpType`, for ICMP traffic, optionally
defines the ICMP type to filter flows by.'
type: integer
peerCIDR:
description: |-
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`
type: string
peerIP:
description: |-
`peerIP` optionally defines the remote IP address to filter flows by.
Expand Down Expand Up @@ -4024,6 +4034,11 @@ spec:
description: '`icmpType`, for ICMP traffic, optionally
defines the ICMP type to filter flows by.'
type: integer
peerCIDR:
description: |-
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`
type: string
peerIP:
description: |-
`peerIP` optionally defines the remote IP address to filter flows by.
Expand Down Expand Up @@ -4103,6 +4118,11 @@ spec:
description: '`icmpType`, for ICMP traffic, optionally
defines the ICMP type to filter flows by.'
type: integer
peerCIDR:
description: |-
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`
type: string
peerIP:
description: |-
`peerIP` optionally defines the remote IP address to filter flows by.
Expand Down
20 changes: 20 additions & 0 deletions config/crd/bases/flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ spec:
icmpType:
description: '`icmpType`, for ICMP traffic, optionally defines the ICMP type to filter flows by.'
type: integer
peerCIDR:
description: |-
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`
type: string
peerIP:
description: |-
`peerIP` optionally defines the remote IP address to filter flows by.
Expand Down Expand Up @@ -247,6 +252,11 @@ spec:
icmpType:
description: '`icmpType`, for ICMP traffic, optionally defines the ICMP type to filter flows by.'
type: integer
peerCIDR:
description: |-
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`
type: string
peerIP:
description: |-
`peerIP` optionally defines the remote IP address to filter flows by.
Expand Down Expand Up @@ -3697,6 +3707,11 @@ spec:
icmpType:
description: '`icmpType`, for ICMP traffic, optionally defines the ICMP type to filter flows by.'
type: integer
peerCIDR:
description: |-
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`
type: string
peerIP:
description: |-
`peerIP` optionally defines the remote IP address to filter flows by.
Expand Down Expand Up @@ -3762,6 +3777,11 @@ spec:
icmpType:
description: '`icmpType`, for ICMP traffic, optionally defines the ICMP type to filter flows by.'
type: integer
peerCIDR:
description: |-
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`
type: string
peerIP:
description: |-
`peerIP` optionally defines the remote IP address to filter flows by.
Expand Down
1 change: 1 addition & 0 deletions config/samples/flows_v1beta2_flowcollector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ spec:
# cidr: 0.0.0.0/0
# - action: Accept
# cidr: 10.128.0.1/24
# peerCIDR: 0.0.0.0/0
# ports: 6443
# protocol: TCP
# sampling: 10
Expand Down
6 changes: 6 additions & 0 deletions controllers/ebpf/agent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ func mapFlowFilterRuleToFilter(rule *flowslatest.EBPFFlowFilterRule) ebpfconfig.
if rule.PeerIP != "" {
f.FilterPeerIP = rule.PeerIP
}
if rule.PeerCIDR != "" {
f.FilterPeerCIDR = rule.PeerCIDR
}
if rule.TCPFlags != "" {
f.FilterTCPFlags = rule.TCPFlags
}
Expand Down Expand Up @@ -575,6 +578,9 @@ func mapFlowFilterToFilter(filter *flowslatest.EBPFFlowFilter) ebpfconfig.FlowFi
if filter.PeerIP != "" {
f.FilterPeerIP = filter.PeerIP
}
if filter.PeerCIDR != "" {
f.FilterPeerCIDR = filter.PeerCIDR
}
if filter.TCPFlags != "" {
f.FilterTCPFlags = filter.TCPFlags
}
Expand Down
32 changes: 32 additions & 0 deletions docs/FlowCollector.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,14 @@ To filter two ports, use a "port1,port2" in string format. For example, `ports:
`icmpType`, for ICMP traffic, optionally defines the ICMP type to filter flows by.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>peerCIDR</b></td>
<td>string</td>
<td>
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>peerIP</b></td>
<td>string</td>
Expand Down Expand Up @@ -631,6 +639,14 @@ To filter two ports, use a "port1,port2" in string format. For example, `ports:
`icmpType`, for ICMP traffic, optionally defines the ICMP type to filter flows by.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>peerCIDR</b></td>
<td>string</td>
<td>
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>peerIP</b></td>
<td>string</td>
Expand Down Expand Up @@ -8221,6 +8237,14 @@ To filter two ports, use a "port1,port2" in string format. For example, `ports:
`icmpType`, for ICMP traffic, optionally defines the ICMP type to filter flows by.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>peerCIDR</b></td>
<td>string</td>
<td>
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>peerIP</b></td>
<td>string</td>
Expand Down Expand Up @@ -8361,6 +8385,14 @@ To filter two ports, use a "port1,port2" in string format. For example, `ports:
`icmpType`, for ICMP traffic, optionally defines the ICMP type to filter flows by.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>peerCIDR</b></td>
<td>string</td>
<td>
`peerCIDR` defines the Peer IP CIDR to filter flows by.
Examples: `10.10.10.0/24` or `100:100:100:100::/64`<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>peerIP</b></td>
<td>string</td>
Expand Down
30 changes: 14 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/coreos/go-semver v0.3.1
github.com/go-logr/logr v1.4.2
github.com/google/go-cmp v0.6.0
github.com/netobserv/flowlogs-pipeline v1.7.0-community.0.20241126155124-18e017f67001
github.com/netobserv/netobserv-ebpf-agent v1.6.1-crc2.0.20241008130234-a20397fb8f88
github.com/netobserv/flowlogs-pipeline v1.7.0-community.0.20241217113023-fa0540a1658e
github.com/netobserv/netobserv-ebpf-agent v1.7.0-community.0.20250122180127-fa88f3515234
github.com/onsi/ginkgo/v2 v2.22.2
github.com/onsi/gomega v1.36.2
github.com/openshift/api v0.0.0-20240722135205-ae4f370f361f
Expand Down Expand Up @@ -79,20 +79,20 @@ require (
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gopacket/gopacket v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ip2location/ip2location-go/v9 v9.7.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/libp2p/go-reuseport v0.3.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.77 // indirect
github.com/minio/minio-go/v7 v7.0.82 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -102,7 +102,7 @@ require (
github.com/netobserv/loki-client-go v0.0.0-20220927092034-f37122a54500 // indirect
github.com/netsampler/goflow2 v1.3.7 // indirect
github.com/ovn-org/libovsdb v0.7.1-0.20240820095311-ce1951614a20 // indirect
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20241126140656-c95491e46334 // indirect
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20250116185920-20e7a0e40c93 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pion/dtls/v2 v2.2.4 // indirect
github.com/pion/logging v0.2.2 // indirect
Expand Down Expand Up @@ -132,16 +132,16 @@ require (
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand All @@ -156,8 +156,8 @@ require (
golang.org/x/time v0.7.0 // indirect
golang.org/x/tools v0.28.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
Expand All @@ -177,5 +177,3 @@ require (
)

replace github.com/prometheus/common v0.55.0 => github.com/netobserv/prometheus-common v0.55.0-netobserv

replace github.com/netobserv/netobserv-ebpf-agent => github.com/msherif1234/netobserv-ebpf-agent v0.0.0-20241213142900-5c07db3a6c0b
Loading
Loading