-
Couldn't load subscription status.
- Fork 259
feat: iptables block using LSM BPF #3871
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
Conversation
There was a problem hiding this 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.
} Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Santhosh Prabhu <6684582+santhoshmprabhu@users.noreply.github.com>
| /azp run Azure Container Networking PR |
| Azure Pipelines successfully started running 1 pipeline(s). |
| /azp run Azure Container Networking PR |
| Azure Pipelines successfully started running 1 pipeline(s). |
| /azp run Azure Container Networking PR |
| Azure Pipelines successfully started running 1 pipeline(s). |
* 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>
* 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>
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
Issue Fixed:
Requirements:
Notes: