Skip to content

Conversation

@santhoshmprabhu
Copy link
Contributor

@santhoshmprabhu santhoshmprabhu commented Jul 29, 2025

Reason for Change:

This PR introduces a binary that will block iptable rule installation in the host network namespace. We are doing this as a sub-feature for eBPF host routing in Cilium. This is relevant because any iptables rules in the host network namespace are skipped when Cilium eBPF host routing is enabled. Further, we allow certain processes, such as cilium-agent and ip-masq-agent to install rules, even if those rules may get bypassed. We account for this difference in behavior in our design.

The block covers both iptables netlink and iptables legacy. iptables netlink block targets the netlink_send LSM BPF hook, which gets invoked when a netlink message is sent (such as when installing iptables rules). If the message is an iptables rule installation, and the network namespace is host network namespace, and the parent of the calling process is not one of the allow-listed processes, we block that installation. The switch to parent is needed because cilium-agent, ip-masq-agent etc invoke the iptables binary as a child to do rule installation. In the legacy case, we block the setsockopt call with the IPT_SO_SET_REPLACE option, which is used for iptables rule installation.

Whenever we block a rule installation, we increment a counter in a map that is pinned at /sys/fs/bpf/block-iptables/event_counter. We can read the count from a CNS sidecar container and generate kube events, so that the customer has visibility into failing iptables rule installations.

The binary is meant for packaging into a systemd service. The service will be always running, but will only block rule installation depending on the contents of a config file. If the config file is missing, or is present and has contents, the service will not block iptables rules. If the config file is present but empty, the service will block. The idea is that any process/component that needs to stop the iptables block can append a unique value to the file, and remove it once it is done with the need for the service to stop.

The Makefile changes build the binary, we will separately make the changes needed for inclusion of the binary in the github release artifacts.

Validation steps completed

  • Packaged this binary manually into a systemd service and applied on AKS nodes, validated that iptables rule installations are blocked when the config file is present and empty, and not blocked otherwise. On real AKS clusters, AgentBaker will be responsible to set up this systemd service.
  • When the systemd service is running, validated that Cilium is able to install iptables rules.
  • Verified that block counts increase when rule installation attempts are blocked.
  • Verified that iptables rules can be installed from pods that are not running in hostNetwork mode.

Issue Fixed:

Requirements:

Notes:

Copilot AI review requested due to automatic review settings July 29, 2025 23:04
@santhoshmprabhu santhoshmprabhu requested review from a team and camrynl as code owners July 29, 2025 23:05
Copy link
Contributor

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 introduces a new eBPF-based binary called block-iptables that prevents iptables rule installation in the host network namespace, supporting Cilium's eBPF host routing feature. The binary monitors for iptables operations via both netlink and legacy interfaces, blocking installations except for allowed processes like cilium-agent and ip-masq-agent.

  • Implements eBPF LSM hooks for both iptables netlink (netlink_send) and legacy (socket_setsockopt) interfaces
  • Adds file-based configuration monitoring to dynamically enable/disable blocking based on allow-list presence
  • Integrates build system support for the new binary with version management and archiving

Reviewed Changes

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

File Description
bpf-prog/block-iptables/pkg/blockservice/gen.go Go generate directive for eBPF code compilation
bpf-prog/block-iptables/cmd/block-iptables/main.go Main application logic with file watching and BPF program lifecycle management
bpf-prog/block-iptables/bpf/src/block_iptables.bpf.c eBPF program implementing LSM hooks for blocking iptables operations
Makefile Build system integration for the new block-iptables binary
Comments suppressed due to low confidence (1)

bpf-prog/block-iptables/cmd/block-iptables/main.go:130

  • The target name 'ip-masq-merger' should be 'azure-ip-masq-merger' to match the pattern used elsewhere in the Makefile and the actual binary name.
} 
santhoshmprabhu and others added 4 commits July 29, 2025 16:07
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Santhosh Prabhu <6684582+santhoshmprabhu@users.noreply.github.com>
@santhoshmprabhu santhoshmprabhu requested review from a team as code owners July 29, 2025 23:34
@santhoshmprabhu santhoshmprabhu requested a review from a team as a code owner July 31, 2025 05:31
@santhoshmprabhu
Copy link
Contributor Author

/azp run Azure Container Networking PR

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).
@santhoshmprabhu
Copy link
Contributor Author

/azp run Azure Container Networking PR

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).
tamilmani1989
tamilmani1989 previously approved these changes Aug 6, 2025
tamilmani1989
tamilmani1989 previously approved these changes Aug 6, 2025
@santhoshmprabhu
Copy link
Contributor Author

/azp run Azure Container Networking PR

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).
@santhoshmprabhu santhoshmprabhu added this pull request to the merge queue Aug 8, 2025
Merged via the queue into master with commit 3e68e58 Aug 8, 2025
20 checks passed
@santhoshmprabhu santhoshmprabhu deleted the sanprabhu/iptables-block-binary branch August 8, 2025 22:56
NihaNallappagari pushed a commit to NihaNallappagari/azure-container-networking that referenced this pull request Sep 4, 2025
* feat: iptables block using LSM BPF * feat: makefile changes * chore: cleanup * Update bpf-prog/block-iptables/bpf/src/block_iptables.bpf.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Santhosh Prabhu <6684582+santhoshmprabhu@users.noreply.github.com> * chore: fix const * fix: dockerfiles, bug * test: add test for bpf attach/detach * feat: add event tracking * feat: add event counting * chore: dockerfiles * fix: nolint for generated code * fix: nolint for generated code * fix: golangci skip * fix:skip directory with generated code * chore:skip block iptales generated code * chore: fix * fix: run go generate first * fix: use installed go * fix: install bpf libraries * fix: remove file * fix: roll back linter changes * fix: add code generation to tests * chore: switch to dual license * fix: run generate before lint * fix: install libs * fix: fix linting, address some comments * fix: address comments, fix lint * fix: missed change * fix: compile only on linux * fix: compile only on linux * fix: address comments * fix: address comments * chore: dockerfiles * fix: address comments * chore:dockerfiles * fix: address comments * chore: dockerfiles * fix: address comments --------- Signed-off-by: Santhosh Prabhu <6684582+santhoshmprabhu@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
sivakami-projects pushed a commit that referenced this pull request Oct 23, 2025
* feat: iptables block using LSM BPF * feat: makefile changes * chore: cleanup * Update bpf-prog/block-iptables/bpf/src/block_iptables.bpf.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Santhosh Prabhu <6684582+santhoshmprabhu@users.noreply.github.com> * chore: fix const * fix: dockerfiles, bug * test: add test for bpf attach/detach * feat: add event tracking * feat: add event counting * chore: dockerfiles * fix: nolint for generated code * fix: nolint for generated code * fix: golangci skip * fix:skip directory with generated code * chore:skip block iptales generated code * chore: fix * fix: run go generate first * fix: use installed go * fix: install bpf libraries * fix: remove file * fix: roll back linter changes * fix: add code generation to tests * chore: switch to dual license * fix: run generate before lint * fix: install libs * fix: fix linting, address some comments * fix: address comments, fix lint * fix: missed change * fix: compile only on linux * fix: compile only on linux * fix: address comments * fix: address comments * chore: dockerfiles * fix: address comments * chore:dockerfiles * fix: address comments * chore: dockerfiles * fix: address comments --------- Signed-off-by: Santhosh Prabhu <6684582+santhoshmprabhu@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

8 participants