Skip to content

fix: fall back to binary presence when netfilter capability checks both fails - #1281

Open
thomasferrandiz wants to merge 1 commit into
containernetworking:mainfrom
thomasferrandiz:portmap-autodetect
Open

fix: fall back to binary presence when netfilter capability checks both fails#1281
thomasferrandiz wants to merge 1 commit into
containernetworking:mainfrom
thomasferrandiz:portmap-autodetect

Conversation

@thomasferrandiz

Copy link
Copy Markdown

Summary

  • Add IPTablesBinaryAvailable() and NFTablesBinaryAvailable() to pkg/utils — lightweight PATH checks that require no kernel access
  • Update ensureBackend() (portmap) and SetupIPMasqForNetworks() (ipmasq) to use these as a fallback detection tier when the full capability checks fail

Problem

Closes #1280

Auto-detection of the nftables backend fails on systems where iptables is not installed, even when nftables is fully available.

SupportsNFTables() calls knftables.New(), which runs nft --check via exec. That requires CAP_NET_ADMIN to connect to the kernel nftables subsystem via netlink — even for a dry run. When the process lacks that capability at detection time, SupportsNFTables() returns false.

The detection logic was:

if !utils.SupportsIPTables() && utils.SupportsNFTables() {
    use nftables
} else {
    use iptables  // unconditional fallback
}

…th fail

SupportsNFTables() runs `nft --check` via exec, which requires
CAP_NET_ADMIN even for a dry run. On systems where iptables is absent
but that capability is unavailable at detection time, both
SupportsIPTables() and SupportsNFTables() return false, causing
ensureBackend() and SetupIPMasqForNetworks() to unconditionally default
to iptables — which then also fails.

Add IPTablesBinaryAvailable() and NFTablesBinaryAvailable() (LookPath
only, no kernel access required) as a second detection tier. When both
full checks fail, binary presence breaks the tie: if the iptables binary
is absent but nft is present, select the nftables backend.

Signed-off-by: Thomas Ferrandiz <thomas.ferrandiz@suse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

portmap: nftables auto-detection fails when iptables binary is absent

1 participant