Skip to content

Rootless setup: check for module nf_tables#49727

Merged
thaJeztah merged 1 commit intomoby:masterfrom
robmry:rootlesskit_iptables_check
Apr 3, 2025
Merged

Rootless setup: check for module nf_tables#49727
thaJeztah merged 1 commit intomoby:masterfrom
robmry:rootlesskit_iptables_check

Conversation

@robmry
Copy link
Contributor

@robmry robmry commented Apr 1, 2025

- What I did

CentOS 10 uses iptables-nft by default, and doesn't have kernel module ip_tables - so dockerd-rootless-setuptool.sh reports that the module is missing. It suggests installing it (which isn't needed), or using --skip-iptables (which disables iptables in daemon config).

- How I did it

Unless the iptables --version command reports legacy, check for kernel module nf_tables instead of ip_tables.

- How to verify it

Ran the install script on a CentOS Stream 10 VM, it worked normally with these changes.

(Not tested on RHEL10 as I don't have a license.)

On a Debian host, where I could switch between iptables-nft and iptables-legacy - with kernel module ip_tables unloaded ("rlk_setup.sh" was my modified version of the script) ...

robm@debian:~$ /usr/sbin/iptables --version
iptables v1.8.9 (legacy)
robm@debian:~$ ./rlk_setup.sh install
[ERROR] Missing system requirements. Run the following commands to
[ERROR] install the requirements and run this tool again.
[ERROR] Alternatively iptables checks can be disabled with --skip-iptables .

########## BEGIN ##########
sudo sh -eux <<EOF
# Load ip_tables module
modprobe ip_tables
EOF
########## END ##########

Switched to iptables-nft, with ip_tables still not loaded, then ...

robm@debian:~$ /usr/sbin/iptables --version
iptables v1.8.9 (nf_tables)
robm@debian:~$ ./rlk_setup.sh install
[INFO] Creating /home/robm/.config/systemd/user/docker.service
[INFO] starting systemd service docker.service
...

- Human readable description for the release notes

- Fix an issue preventing rootless Docker setup on a host with no `ip_tables` kernel module.

@robmry robmry added this to the 28.1.0 milestone Apr 1, 2025
@robmry robmry self-assigned this Apr 1, 2025
@robmry robmry changed the title Rootlesskit: check for module nf_tables Rootless setup: check for module nf_tables Apr 1, 2025
@robmry robmry force-pushed the rootlesskit_iptables_check branch 2 times, most recently from 08e52ac to 153c124 Compare April 2, 2025 09:02
@robmry robmry marked this pull request as ready for review April 2, 2025 10:01
@robmry robmry requested review from AkihiroSuda and tianon April 2, 2025 10:01
Comment on lines 187 to 190
iptables_module="nf_tables"
if [ -n "$(echo $iptables_version | grep "legacy" 2> /dev/null)" ]; then
iptables_module="ip_tables"
fi
Copy link
Member

Choose a reason for hiding this comment

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

Probably don't need to grep here if we use a switch;

Suggested change
iptables_module="nf_tables"
if [ -n "$(echo $iptables_version | grep "legacy" 2> /dev/null)" ]; then
iptables_module="ip_tables"
fi
case $iptables_version in
*legacy*) iptables_module="ip_tables" ;;
*) iptables_module="nf_tables" ;;
esac

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Un-done - now it's option 2!

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! Yes, I wrote one, then wrote the other comment, it was possibly a bit confusing; we got there in the end ❤️

Comment on lines 146 to 151
iptables_command=$(PATH=$PATH:/sbin:/usr/sbin command -v iptables 2> /dev/null) || :
iptables_version=""
if [ -n "$iptables_command" ]; then
iptables_version=$($iptables_command --version 2> /dev/null) || :
Copy link
Member

Choose a reason for hiding this comment

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

Actually; so iptables_version is only used to set iptables_module, correct? In that case, we could just put all here? Or won't that work?

Suggested change
iptables_command=$(PATH=$PATH:/sbin:/usr/sbin command -v iptables 2> /dev/null) || :
iptables_version=""
if [ -n "$iptables_command" ]; then
iptables_version=$($iptables_command --version 2> /dev/null) || :
# Many OSs now use iptables-nft by default so, check for module nf_tables by default. But,
# if "iptables --version" worked and reported "legacy", check for module ip_tables instead.
iptables_module="nf_tables"
iptables_command=$(PATH=$PATH:/sbin:/usr/sbin command -v iptables 2> /dev/null) || :
if [ -n "$iptables_command" ]; then
iptables_version=$($iptables_command --version 2> /dev/null) || :
case $iptables_version in
*legacy*) iptables_module="ip_tables" ;;
esac

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 first block (instruction: iptables dependency check) is working out whether there's an iptables command, and the second block (instruction: ip_tables module dependency check) works out whether the kernel module is loaded.

So, I thought it was best for the second block to use the command the first block found - rather than finding the command again, but maybe a bit differently.

If that makes sense (?) ... I'll swap the grep for case, as you suggest above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've taken option 1 ... can update again if needed!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry - misread, this is the first block ... done now.

@robmry robmry force-pushed the rootlesskit_iptables_check branch from 153c124 to ad177b4 Compare April 3, 2025 18:27
@robmry robmry requested a review from thaJeztah April 3, 2025 18:28
CentOS 10 uses iptables-nft by default, and doesn't have
kernel module ip_tables - so dockerd-rootless-setuptool.sh
reports that the module is missing. It suggests installing
it (which isn't needed), or using --skip-iptables (which
disables iptables in daemon config).

So, unless "iptables --version" command reports "legacy",
check for kernel module "nf_tables" instead of "ip_tables".

Signed-off-by: Rob Murray <[email protected]>
@robmry robmry force-pushed the rootlesskit_iptables_check branch from ad177b4 to f80feba Compare April 3, 2025 19:25
Copy link
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

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

Seems fine to me 👍

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@thaJeztah thaJeztah merged commit 4ad6854 into moby:master Apr 3, 2025
154 checks passed
Comment on lines +148 to 155
iptables_module="nf_tables"
iptables_command=$(PATH=$PATH:/sbin:/usr/sbin command -v iptables 2> /dev/null) || :
if [ -n "$iptables_command" ]; then
iptables_version=$($iptables_command --version 2> /dev/null) || :
case $iptables_version in
*legacy*) iptables_module="ip_tables" ;;
esac
faced_iptables_error=1
Copy link
Contributor

Choose a reason for hiding this comment

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

This sets faced_iptables_error=1 even when iptables are available

Copy link
Contributor

Choose a reason for hiding this comment

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

$ iptables --version
iptables v1.8.10 (nf_tables)
$ curl https://get.docker.com/rootless | sh -
[ERROR] Missing system requirements. Run the following commands to
[ERROR] install the requirements and run this tool again.
[ERROR] Alternatively iptables checks can be disabled with --skip-iptables .

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @robmry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RHEL/CentOS Stream 10 does not include the iptables kernel module

5 participants