Skip to content

feat: update iptables monitor with ipv6 and bpf map reading capabilities #3948

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

QxBytes
Copy link
Contributor

@QxBytes QxBytes commented Aug 19, 2025

Reason for Change:

Adds two new capabilities to azure-iptables-monitor:

  • Reads ipv6 iptables rules if present on the node. To accomodate ipv6, will now read config files from a new directory for allowed ipv6 iptables rules-- these config files are separate from the ipv4 iptables allowlist. The ipv6 directory has the same structure as the ipv4 one (ex: an allowlist pattern file for each ipv6 table). If there are either ipv4 or ipv6 rules that are unexpected, we send an event and set the ciliumnode label as before.
  • Can read a pinned bpf map at a configurable location. The bpf map records how times on the node an iptables rule add request was blocked by a separate iptables block binary. If the number of blocks increases between intervals, we create a new event.

Issue Fixed:

See above

Requirements:

Notes:
Tested on a cilium dualstack cluster

  • If ipv6 rules not in allowlist are found, confirmed user iptables rules true
  • If ipv4 and ipv6 rules are all allowed, confirmed user iptables rules false
  • If bpf map increases between intervals, confirmed event emitted
  • Confirmed ipv6 uses an ipv6 client and shows ipv6 rules

@QxBytes QxBytes self-assigned this Aug 19, 2025
@QxBytes QxBytes added the cilium Related to Cilium. label Aug 19, 2025
@QxBytes QxBytes requested a review from Copilot August 19, 2025 19:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the azure-iptables-monitor with IPv6 support and BPF map monitoring capabilities. The monitor can now detect unexpected iptables rules in both IPv4 and IPv6 tables, and can track blocked iptables rule attempts via a pinned BPF map.

Key changes:

  • Adds IPv6 iptables monitoring with separate allowlist configuration directory
  • Implements BPF map reading to track blocked iptables rule attempts and generate events when blocks increase
  • Updates the Kubernetes label name to follow Azure conventions

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
iptables_monitor.go Core implementation adding IPv6 support, BPF map monitoring, and label name update
iptables_monitor_test.go Updates test to match new function signature with config path parameter
go.mod Adds cilium/ebpf dependency for BPF map functionality
README.md Documents new command-line flags and updated label name

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@QxBytes
Copy link
Contributor Author

QxBytes commented Aug 19, 2025

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@QxBytes QxBytes marked this pull request as ready for review August 19, 2025 21:27
Copy link
Contributor

@santhoshmprabhu santhoshmprabhu left a comment

Choose a reason for hiding this comment

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

In the event description, let's add an explanation indicating that eBPF host routing is enabled. The user may not immediately have context on why iptables rules are being blocked. We could also link aka.ms/acnsperformance

- The `-events` flag enables Kubernetes event creation for rule violations. Default: `false`
- The `-ipv6` flag enables IPv6 ip6tables monitoring using the IPv6 allowlists. Default: `false`
- The `-checkMap` flag enables checking the pinned bpf map specified in mapPath for increases. Default: `false`
- The `-mapPath` flag species the pinned bpf map path to check. Default: `/block-iptables/iptables_block_event_counter`
Copy link
Member

Choose a reason for hiding this comment

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

can it be /azure-block-iptables/iptables_block_event_counter

Copy link
Contributor Author

@QxBytes QxBytes Aug 20, 2025

Choose a reason for hiding this comment

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

The default uses the path specified here: https://github.com/Azure/azure-container-networking/blob/master/bpf-prog/azure-block-iptables/pkg/bpfprogram/program.go#L20 . In any case, the bpf map is on the vm and needs to be mounted to the container, and that mount can be at any location on the container. The mount location is specific to the container with the iptables monitor image. The mapPath is configurable as well if we need to change it later.

5. The program will set the `user-iptables-rules` label to `true` on the specified ciliumnode resource if unexpected rules are found, or `false` if all rules match expected patterns. Proper RBAC is required for patching (patch for ciliumnodes, create for events, get for nodes).
5. The program will set the `kubernetes.azure.com/user-iptables-rules` label to `true` on the specified ciliumnode resource if unexpected rules are found, or `false` if all rules match expected patterns. Proper RBAC is required for patching (patch for ciliumnodes, create for events, get for nodes).

6. The program will also send out an event if the bpf map value specified increases between checks
Copy link
Member

Choose a reason for hiding this comment

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

can we also specify how often the program check for increases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The increases are checked based on -interval, unless you mean you would like a second configurable interval option for checking the map?

- The `-events` flag enables Kubernetes event creation for rule violations. Default: `false`
- The `-ipv6` flag enables IPv6 ip6tables monitoring using the IPv6 allowlists. Default: `false`
- The `-checkMap` flag enables checking the pinned bpf map specified in mapPath for increases. Default: `false`
- The `-mapPath` flag species the pinned bpf map path to check. Default: `/block-iptables/iptables_block_event_counter`
- The program must be in a k8s environment and `NODE_NAME` must be a set environment variable with the current node.
Copy link
Member

Choose a reason for hiding this comment

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

why NODE_NAME is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to create events for the current node the program is running on-- the field needs to be passed in for the program to know about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cilium Related to Cilium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants