Skip to content

Commit 1af329c

Browse files
authored
nflog the packet that will be dropped by network policy enforcement (#889)
* nflog the packet that will be dropped by network policy enforcement that can be further by read by ulogd Fixes #505 * addressing review comments
1 parent f3ea1a6 commit 1af329c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

docs/Observability.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Observability
2+
3+
## Observing dropped traffic due to network policy enforcements
4+
5+
Traffic that gets rejected due to network policy enforcements gets logged by kube-route using iptables NFLOG target under the group 100. Simplest way to observe the dropped packets by kube-router is by running tcpdump on `nflog:100` interface for e.g. `tcpdump -i nflog:100 -n`. You can also configure ulogd to monitor dropped packets in desired output format. Please see https://kb.gtkc.net/iptables-with-ulogd-quick-howto/ for an example configuration to setup a stack to log packets.

pkg/controllers/netpol/network_policy_controller.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,14 @@ func (npc *NetworkPolicyController) syncPodFirewallChains(version string) (map[s
817817
}
818818
}
819819

820+
// add rule to log the packets that will be dropped due to network policy enforcement
821+
comment = "rule to log dropped traffic POD name:" + pod.name + " namespace: " + pod.namespace
822+
args = []string{"-m", "comment", "--comment", comment, "-j", "NFLOG", "--nflog-group", "100", "-m", "limit", "--limit", "10/minute", "--limit-burst", "10"}
823+
err = iptablesCmdHandler.AppendUnique("filter", podFwChainName, args...)
824+
if err != nil {
825+
return nil, fmt.Errorf("Failed to run iptables command: %s", err.Error())
826+
}
827+
820828
// add default DROP rule at the end of chain
821829
comment = "default rule to REJECT traffic destined for POD name:" + pod.name + " namespace: " + pod.namespace
822830
args = []string{"-m", "comment", "--comment", comment, "-j", "REJECT"}
@@ -933,6 +941,14 @@ func (npc *NetworkPolicyController) syncPodFirewallChains(version string) (map[s
933941
}
934942
}
935943

944+
// add rule to log the packets that will be dropped due to network policy enforcement
945+
comment = "rule to log dropped traffic POD name:" + pod.name + " namespace: " + pod.namespace
946+
args = []string{"-m", "comment", "--comment", comment, "-j", "NFLOG", "--nflog-group", "100", "-m", "limit", "--limit", "10/minute", "--limit-burst", "10"}
947+
err = iptablesCmdHandler.AppendUnique("filter", podFwChainName, args...)
948+
if err != nil {
949+
return nil, fmt.Errorf("Failed to run iptables command: %s", err.Error())
950+
}
951+
936952
// add default DROP rule at the end of chain
937953
comment = "default rule to REJECT traffic destined for POD name:" + pod.name + " namespace: " + pod.namespace
938954
args = []string{"-m", "comment", "--comment", comment, "-j", "REJECT"}

0 commit comments

Comments
 (0)