Skip to content

Commit 105aee6

Browse files
committed
iptables rule without an ip range applies to all interfaces
The current logic pretends it only applies to 127.0.0.1, which means the new `guestIPMustBeZero` rule does not detect it properly. This is a problem with nerdctl and containerd on Alpine. It works "by accident" on Ubuntu because the port was also bound to [::], which had an entry in /proc/net/tcp6. Signed-off-by: Jan Dubois <[email protected]>
1 parent 943c90b commit 105aee6

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

pkg/guestagent/iptables/iptables.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ func parsePortsFromRules(rules []string) ([]Entry, error) {
7575
istcp = true
7676
}
7777

78-
// if the IP is blank the port forwarding the portforwarding,
79-
// which gets information from this, will skip it. When no IP
80-
// is present localhost will work.
78+
// When no IP is present the rule applies to all interfaces.
8179
ip := found[1]
8280
if ip == "" {
83-
ip = "127.0.0.1"
81+
ip = "0.0.0.0"
8482
}
8583
ent := Entry{
8684
IP: net.ParseIP(ip),

pkg/guestagent/iptables/iptables_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ func TestParsePortsFromRules(t *testing.T) {
8484
t.Fatalf("expected 2 ports parsed from iptables but parsed %d", l)
8585
}
8686

87-
if res[0].IP.String() != "127.0.0.1" || res[0].Port != 8082 || res[0].TCP != true {
88-
t.Errorf("expected port 8082 on IP 127.0.0.1 with TCP true but go port %d on IP %s with TCP %t", res[0].Port, res[0].IP.String(), res[0].TCP)
87+
if res[0].IP.String() != "0.0.0.0" || res[0].Port != 8082 || res[0].TCP != true {
88+
t.Errorf("expected port 8082 on IP 0.0.0.0 with TCP true but got port %d on IP %s with TCP %t", res[0].Port, res[0].IP.String(), res[0].TCP)
8989
}
9090
if res[1].IP.String() != "127.0.0.1" || res[1].Port != 8081 || res[1].TCP != true {
9191
t.Errorf("expected port 8081 on IP 127.0.0.1 with TCP true but go port %d on IP %s with TCP %t", res[1].Port, res[1].IP.String(), res[1].TCP)

0 commit comments

Comments
 (0)