Skip to content
Draft
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
22 changes: 20 additions & 2 deletions pkg/nftables/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nftables

import (
"fmt"
"net/netip"
"strings"

networkingv1 "k8s.io/api/networking/v1"
Expand Down Expand Up @@ -73,6 +74,11 @@ func clusterwideNetworkPolicyEgressDNSCacheRules(cache FQDNCache, logAcceptedCon
}, nil
}

var (
ipv4any = netip.MustParsePrefix("0.0.0.0/0")
ipv6any = netip.MustParsePrefix("::/0")
)

func clusterwideNetworkPolicyEgressRules(
cache FQDNCache,
np firewallv1.ClusterwideNetworkPolicy,
Expand All @@ -88,8 +94,20 @@ func clusterwideNetworkPolicyEgressRules(
rb = append(rb, fmt.Sprintf("ip daddr != { %s }", strings.Join(except, ", ")))
}
if len(allow) > 0 {
if allow[0] != "0.0.0.0/0" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is only the first allow entry considered ??

rb = append(rb, fmt.Sprintf("ip daddr { %s }", strings.Join(allow, ", ")))
destination, err := netip.ParsePrefix(allow[0])
if err != nil {
// TODO error handling
continue
}
if destination.Addr().Is4() {
if destination != ipv4any {
rb = append(rb, fmt.Sprintf("ip daddr { %s }", strings.Join(allow, ", ")))
}
}
if destination.Addr().Is6() {
if destination != ipv6any {
rb = append(rb, fmt.Sprintf("ip daddr { %s }", strings.Join(allow, ", ")))
}
}
}
ruleBases = append(ruleBases, ruleBase{base: rb})
Expand Down
Loading