README
¶
azure-iptables-monitor
azure-iptables-monitor is a utility for monitoring iptables rules on Kubernetes nodes and labeling a ciliumnode resource based on whether the corresponding node contains user-defined iptables rules.
Description
The goal of this program is to periodically scan iptables rules across all tables (nat, mangle, filter, raw, security) and determine if any rules exist that don't match expected patterns. When unexpected rules are found, the ciliumnode resource is labeled to indicate the presence of user-defined iptables rules.
Usage
Follow the steps below to build and run the program:
-
Build the binary using
make:make azure-iptables-monitoror make an image:
make azure-iptables-monitor-image -
Deploy or copy the binary to your node(s).
-
Prepare your allowed pattern files in the input directory. Each file should be named after an iptables table (
nat,mangle,filter,raw,security) orglobaland contain regex patterns that match expected iptables rules. You may want to mount a configmap for this purpose. -
Start the program with:
./azure-iptables-monitor -input=/etc/config/ -interval=300- The
-inputflag specifies the directory containing allowed regex pattern files. Default:/etc/config/ - The
-input6flag specifies the directory containing allowed regex pattern files for IPv6 ip6tables. Default:/etc/config6/ - The
-intervalflag specifies how often to check iptables rules and the bpf map in seconds. Default:300 - The
-eventsflag enables Kubernetes event creation for rule violations. Default:false - The
-ipv6flag enables IPv6 ip6tables monitoring using the IPv6 allowlists. Default:false - The
-checkMapflag enables checking the pinned bpf map specified in mapPath for increases. Default:false - The
-mapPathflag specifies the pinned bpf map path to check. Default:/azure-block-iptables-bpf-map/iptables_block_event_counter - The
-terminateOnSuccessflag, when set, will exit the program once there are no longer user iptables rules detected. Default:false - The program must be in a k8s environment and
NODE_NAMEmust be a set environment variable with the current node.
- The
-
The program will set the
kubernetes.azure.com/user-iptables-ruleslabel totrueon the specified ciliumnode resource if unexpected rules are found, orfalseif all rules match expected patterns. Proper RBAC is required for patching (patch for ciliumnodes, create for events, get for nodes). -
The program will also send out an event if the bpf map value specified increases between checks
Pattern File Format
Each pattern file should contain one regex pattern per line:
^-A INPUT -i lo -j ACCEPT$
^-A FORWARD -j DOCKER.*
^-A POSTROUTING -s 10\.0\.0\.0/8 -j MASQUERADE$
global: Patterns that can match rules in any iptables tablenat,mangle,filter,raw,security: Patterns specific to each iptables table- Empty lines are ignored
- Each line should be a valid Go regex pattern
- The ipv6 config directory uses files with same names, but will match against ipv6 iptables rules
Debugging
Logs are output to standard error. Increase verbosity with the -v flag:
./azure-iptables-monitor -v 3
Development
To run tests at the repository level:
make test-azure-iptables-monitor
Documentation
¶
There is no documentation for this package.