Skip to content

Commit 3ccc755

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#55945 from x13n/master-startup
Automatic merge from submit-queue (batch tested with PRs 55841, 55948, 55945). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Set -w flag on all iptables calls during master startup Lack of this flag sometimes causes iptables to return error code 4 (if other process holds xtables lock). As a result, because of `set -o errexit`, whole startup script fails, leaving master in an incorrect state. This is another occurence of (already closed) kubernetes#7370 **What this PR does / why we need it**: **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: **Special notes for your reviewer**: **Release note**: ```release-note Bugfix: master startup script on GCP no longer fails randomly due to concurrent iptables invocations. ```
2 parents a83f78e + ea64edd commit 3ccc755

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

cluster/gce/gci/configure-helper.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,38 @@ function config-ip-firewall {
4141

4242
# The GCI image has host firewall which drop most inbound/forwarded packets.
4343
# We need to add rules to accept all TCP/UDP/ICMP packets.
44-
if iptables -L INPUT | grep "Chain INPUT (policy DROP)" > /dev/null; then
44+
if iptables -w -L INPUT | grep "Chain INPUT (policy DROP)" > /dev/null; then
4545
echo "Add rules to accept all inbound TCP/UDP/ICMP packets"
4646
iptables -A INPUT -w -p TCP -j ACCEPT
4747
iptables -A INPUT -w -p UDP -j ACCEPT
4848
iptables -A INPUT -w -p ICMP -j ACCEPT
4949
fi
50-
if iptables -L FORWARD | grep "Chain FORWARD (policy DROP)" > /dev/null; then
50+
if iptables -w -L FORWARD | grep "Chain FORWARD (policy DROP)" > /dev/null; then
5151
echo "Add rules to accept all forwarded TCP/UDP/ICMP packets"
5252
iptables -A FORWARD -w -p TCP -j ACCEPT
5353
iptables -A FORWARD -w -p UDP -j ACCEPT
5454
iptables -A FORWARD -w -p ICMP -j ACCEPT
5555
fi
5656

57-
iptables -N KUBE-METADATA-SERVER
58-
iptables -I FORWARD -p tcp -d 169.254.169.254 --dport 80 -j KUBE-METADATA-SERVER
57+
iptables -w -N KUBE-METADATA-SERVER
58+
iptables -w -I FORWARD -p tcp -d 169.254.169.254 --dport 80 -j KUBE-METADATA-SERVER
5959

6060
if [[ "${ENABLE_METADATA_CONCEALMENT:-}" == "true" ]]; then
61-
iptables -A KUBE-METADATA-SERVER -j DROP
61+
iptables -w -A KUBE-METADATA-SERVER -j DROP
6262
fi
6363

6464
# Flush iptables nat table
65-
iptables -t nat -F || true
65+
iptables -w -t nat -F || true
6666

6767
echo "Add rules for ip masquerade"
6868
if [[ "${NON_MASQUERADE_CIDR:-}" == "0.0.0.0/0" ]]; then
69-
iptables -t nat -N IP-MASQ
70-
iptables -t nat -A POSTROUTING -m comment --comment "ip-masq: ensure nat POSTROUTING directs all non-LOCAL destination traffic to our custom IP-MASQ chain" -m addrtype ! --dst-type LOCAL -j IP-MASQ
71-
iptables -t nat -A IP-MASQ -d 169.254.0.0/16 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN
72-
iptables -t nat -A IP-MASQ -d 10.0.0.0/8 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN
73-
iptables -t nat -A IP-MASQ -d 172.16.0.0/12 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN
74-
iptables -t nat -A IP-MASQ -d 192.168.0.0/16 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN
75-
iptables -t nat -A IP-MASQ -m comment --comment "ip-masq: outbound traffic is subject to MASQUERADE (must be last in chain)" -j MASQUERADE
69+
iptables -w -t nat -N IP-MASQ
70+
iptables -w -t nat -A POSTROUTING -m comment --comment "ip-masq: ensure nat POSTROUTING directs all non-LOCAL destination traffic to our custom IP-MASQ chain" -m addrtype ! --dst-type LOCAL -j IP-MASQ
71+
iptables -w -t nat -A IP-MASQ -d 169.254.0.0/16 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN
72+
iptables -w -t nat -A IP-MASQ -d 10.0.0.0/8 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN
73+
iptables -w -t nat -A IP-MASQ -d 172.16.0.0/12 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN
74+
iptables -w -t nat -A IP-MASQ -d 192.168.0.0/16 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN
75+
iptables -w -t nat -A IP-MASQ -m comment --comment "ip-masq: outbound traffic is subject to MASQUERADE (must be last in chain)" -j MASQUERADE
7676
fi
7777
}
7878

0 commit comments

Comments
 (0)