@@ -19,7 +19,6 @@ package remote
1919import (
2020 "fmt"
2121 "path/filepath"
22- "strings"
2322
2423 "k8s.io/klog/v2"
2524)
@@ -79,35 +78,21 @@ func setupCNI(host, workspace string) error {
7978
8079// configureFirewall configures iptable firewall rules.
8180func configureFirewall (host string ) error {
82- klog .V (2 ).Infof ("Configure iptables firewall rules on %q" , host )
83- // TODO: consider calling bootstrap script to configure host based on OS
84- output , err := SSH (host , "iptables" , "-L" , "INPUT" )
85- if err != nil {
86- return fmt .Errorf ("failed to get iptables INPUT on %q: %v output: %q" , host , err , output )
87- }
88- if strings .Contains (output , "Chain INPUT (policy DROP)" ) {
89- cmd := getSSHCommand ("&&" ,
90- "(iptables -C INPUT -w -p TCP -j ACCEPT || iptables -A INPUT -w -p TCP -j ACCEPT)" ,
91- "(iptables -C INPUT -w -p UDP -j ACCEPT || iptables -A INPUT -w -p UDP -j ACCEPT)" ,
92- "(iptables -C INPUT -w -p ICMP -j ACCEPT || iptables -A INPUT -w -p ICMP -j ACCEPT)" )
93- output , err := SSH (host , "sh" , "-c" , cmd )
94- if err != nil {
95- return fmt .Errorf ("failed to configured firewall on %q: %v output: %v" , host , err , output )
96- }
97- }
98- output , err = SSH (host , "iptables" , "-L" , "FORWARD" )
81+ klog .V (2 ).Infof ("Configure iptables HEYHO firewall rules on %q" , host )
82+
83+ // Since the goal is to enable connectivity without taking into account current rule,
84+ // we can just prepend the accept rules directly without any check
85+ cmd := getSSHCommand ("&&" ,
86+ "iptables -I INPUT 1 -w -p tcp -j ACCEPT" ,
87+ "iptables -I INPUT 1 -w -p udp -j ACCEPT" ,
88+ "iptables -I INPUT 1 -w -p icmp -j ACCEPT" ,
89+ "iptables -I FORWARD 1 -w -p tcp -j ACCEPT" ,
90+ "iptables -I FORWARD 1 -w -p udp -j ACCEPT" ,
91+ "iptables -I FORWARD 1 -w -p icmp -j ACCEPT" ,
92+ )
93+ output , err := SSH (host , "sh" , "-c" , cmd )
9994 if err != nil {
100- return fmt .Errorf ("failed to get iptables FORWARD on %q: %v output: %q" , host , err , output )
101- }
102- if strings .Contains (output , "Chain FORWARD (policy DROP)" ) {
103- cmd := getSSHCommand ("&&" ,
104- "(iptables -C FORWARD -w -p TCP -j ACCEPT || iptables -A FORWARD -w -p TCP -j ACCEPT)" ,
105- "(iptables -C FORWARD -w -p UDP -j ACCEPT || iptables -A FORWARD -w -p UDP -j ACCEPT)" ,
106- "(iptables -C FORWARD -w -p ICMP -j ACCEPT || iptables -A FORWARD -w -p ICMP -j ACCEPT)" )
107- output , err = SSH (host , "sh" , "-c" , cmd )
108- if err != nil {
109- return fmt .Errorf ("failed to configured firewall on %q: %v output: %v" , host , err , output )
110- }
95+ return fmt .Errorf ("failed to configured firewall on %q: %v output: %v" , host , err , output )
11196 }
11297 return nil
11398}
0 commit comments