Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ func (r *FlowCollector) validateAgent(_ context.Context, fc *FlowCollector) (adm
}
var errs []error
if fc.Spec.Agent.EBPF.FlowFilter != nil && fc.Spec.Agent.EBPF.FlowFilter.Enable != nil && *fc.Spec.Agent.EBPF.FlowFilter.Enable {
m := make(map[string]bool)
for i := range fc.Spec.Agent.EBPF.FlowFilter.FlowFilterRules {
errs = append(errs, validateFilter(&fc.Spec.Agent.EBPF.FlowFilter.FlowFilterRules[i])...)
rule := fc.Spec.Agent.EBPF.FlowFilter.FlowFilterRules[i]
if found := m[rule.CIDR]; found {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks for an exact match. Do you need to check for overlapping IPs such as:

10.0.0.0/24
10.0.0.1/32

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no overlapping can be intentional we discussed that and we agreed to leave this to the user cc'd @jotak

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, a typical example would be to set a global ALLOW on 0.0.0.0/0 and then add exceptions

errs = append(errs, fmt.Errorf("flow filter rule CIDR %s already exists", rule.CIDR))
break
}
m[rule.CIDR] = true
errs = append(errs, validateFilter(&rule)...)
}
errs = append(errs, validateFilter(fc.Spec.Agent.EBPF.FlowFilter)...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestValidateAgent(t *testing.T) {
Action: "Accept",
CIDR: "0.0.0.0/0",
Direction: "Egress",
Protocol: "TCP",
},
},
},
Expand All @@ -57,6 +58,42 @@ func TestValidateAgent(t *testing.T) {
},
},
},
{
name: "Invalid filter with duplicate CIDR",
fc: &FlowCollector{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster",
},
Spec: FlowCollectorSpec{
Agent: FlowCollectorAgent{
Type: AgentEBPF,
EBPF: FlowCollectorEBPF{
Features: []AgentFeature{DNSTracking, FlowRTT, PacketDrop},
Privileged: true,
Sampling: ptr.To(int32(100)),
FlowFilter: &EBPFFlowFilter{
Enable: ptr.To(true),
FlowFilterRules: []EBPFFlowFilterRule{
{
Action: "Accept",
CIDR: "0.0.0.0/0",
Direction: "Egress",
Protocol: "TCP",
},
{
Action: "Accept",
CIDR: "0.0.0.0/0",
Direction: "Egress",
Protocol: "UDP",
},
},
},
},
},
},
},
expectedError: "flow filter rule CIDR 0.0.0.0/0 already exists",
},
{
name: "PacketDrop without privilege triggers warning",
fc: &FlowCollector{
Expand Down
Loading