Skip to content

Commit 7ac5702

Browse files
akerouantontianon
andauthored
Switch over to xtables-legacy when nf_tables module isn't available (#465)
* Switch over to xtables-legacy when nf_tables module isn't available PR 461 updated Alpine to 3.19 and made a change to load the nf_tables kernel module if needed. However, as demonstrated by 463 and 464 this might break when the host system doesn't have the nf_tables module available. In that case, we should still try to load the ip_tables module and symlink /sbin/iptables to xtables-legacy-multi. Signed-off-by: Albin Kerouanton <[email protected]> * Adjust iptables-legacy fallback implementation to use an image-provided symlink farm instead of symlinking over package-provided files in /sbin/ at runtime --------- Signed-off-by: Albin Kerouanton <[email protected]> Co-authored-by: Tianon Gravi <[email protected]>
1 parent 0411c8f commit 7ac5702

6 files changed

Lines changed: 93 additions & 6 deletions

File tree

‎24/dind/Dockerfile‎

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎24/dind/dockerd-entrypoint.sh‎

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎25-rc/dind/Dockerfile‎

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎25-rc/dind/dockerd-entrypoint.sh‎

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Dockerfile-dind.template‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ RUN set -eux; \
2525

2626
# TODO aufs-tools
2727

28+
# dind might be used on systems where the nf_tables kernel module isn't available. In that case,
29+
# we need to switch over to xtables-legacy. See https://github.com/docker-library/docker/issues/463
30+
RUN set -eux; \
31+
apk add --no-cache iptables-legacy; \
32+
# set up a symlink farm we can use PATH to switch to legacy with
33+
mkdir -p /usr/local/sbin/.iptables-legacy; \
34+
# https://git.alpinelinux.org/aports/tree/main/iptables/APKBUILD?id=b215d54de159eacafecb13c68dfadce6eefd9ec9#n73
35+
for f in \
36+
iptables \
37+
iptables-save \
38+
iptables-restore \
39+
ip6tables \
40+
ip6tables-save \
41+
ip6tables-restore \
42+
; do \
43+
# "iptables-save" -> "iptables-legacy-save", "ip6tables" -> "ip6tables-legacy", etc.
44+
# https://pkgs.alpinelinux.org/contents?branch=v3.19&name=iptables-legacy&arch=x86_64
45+
b="/sbin/${f/tables/tables-legacy}"; \
46+
"$b" --version; \
47+
ln -svT "$b" "/usr/local/sbin/.iptables-legacy/$f"; \
48+
done; \
49+
# verify it works (and gets us legacy)
50+
export PATH="/usr/local/sbin/.iptables-legacy:$PATH"; \
51+
iptables --version | grep legacy
52+
2853
# set up subuid/subgid so that "--userns-remap=default" works out-of-the-box
2954
RUN set -eux; \
3055
addgroup -S dockremap; \

‎dockerd-entrypoint.sh‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,15 @@ if [ "$1" = 'dockerd' ]; then
144144
set -- docker-init -- "$@"
145145

146146
if ! iptables -nL > /dev/null 2>&1; then
147-
# if iptables fails to run, chances are high the necessary kernel modules aren't loaded (perhaps the host is using nftables with the translating "iptables" wrappers, for example)
147+
# if iptables fails to run, chances are high the necessary kernel modules aren't loaded (perhaps the host is using xtables, for example)
148148
# https://github.com/docker-library/docker/issues/350
149149
# https://github.com/moby/moby/issues/26824
150150
# https://github.com/docker-library/docker/pull/437#issuecomment-1854900620
151-
modprobe nf_tables || :
151+
if ! modprobe nf_tables; then
152+
modprobe ip_tables || :
153+
# see https://github.com/docker-library/docker/issues/463 (and the dind Dockerfile where this directory is set up)
154+
export PATH="/usr/local/sbin/.iptables-legacy:$PATH"
155+
fi
152156
fi
153157

154158
uid="$(id -u)"

0 commit comments

Comments
 (0)