Skip to content

Commit ca9c460

Browse files
authored
feat(linkerd-cni): add support for plain iptables commands (#449)
Currently the `iptables-mode` for linkerd-cni admits the values `legacy` and `nft`, which make the plugin use the `iptables-legacy[-save]` and `iptables-nft[-save]` commands respectively. This assumes those commands are available in the node environment, given that linkerd-cni is triggered by the kubelet. We have found that not to be the case for RHEL, where by default only `iptables[-save]` is available, which is equivalent to the `iptables-nft[-save]` command in other enviroments. To address this case, this change adds a new possible value `iptables-mode: plain` that makes the plugin use the `iptables[-save]` commands. This has been tested successfully using RKE2 deployed in RHEL 8.10.
1 parent 1ebd08d commit ca9c460

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

proxy-init/cmd/root.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const (
1818
IPTablesModeLegacy = "legacy"
1919
// IPTablesModeNFT signals the usage of the iptables-nft commands
2020
IPTablesModeNFT = "nft"
21+
// IPTablesModePlain signals the usage of the iptables commands, which
22+
// can be either legacy or nft
23+
IPTablesModePlain = "plain"
2124

2225
cmdLegacy = "iptables-legacy"
2326
cmdLegacySave = "iptables-legacy-save"
@@ -27,6 +30,10 @@ const (
2730
cmdNFTSave = "iptables-nft-save"
2831
cmdNFTIPv6 = "ip6tables-nft"
2932
cmdNFTIPv6Save = "ip6tables-nft-save"
33+
cmdPlain = "iptables"
34+
cmdPlainSave = "iptables-save"
35+
cmdPlainIPv6 = "ip6tables"
36+
cmdPlainIPv6Save = "ip6tables-save"
3037
)
3138

3239
// RootOptions provides the information that will be used to build a firewall configuration.
@@ -147,7 +154,7 @@ func NewRootCmd() *cobra.Command {
147154
cmd.PersistentFlags().IntVar(&options.TimeoutCloseWaitSecs, "timeout-close-wait-secs", options.TimeoutCloseWaitSecs, "Sets nf_conntrack_tcp_timeout_close_wait")
148155
cmd.PersistentFlags().StringVar(&options.LogFormat, "log-format", options.LogFormat, "Configure log format ('plain' or 'json')")
149156
cmd.PersistentFlags().StringVar(&options.LogLevel, "log-level", options.LogLevel, "Configure log level")
150-
cmd.PersistentFlags().StringVar(&options.IPTablesMode, "iptables-mode", options.IPTablesMode, "Variant of iptables command to use (\"legacy\" or \"nft\"); overrides --firewall-bin-path and --firewall-save-bin-path")
157+
cmd.PersistentFlags().StringVar(&options.IPTablesMode, "iptables-mode", options.IPTablesMode, "Variant of iptables command to use (\"legacy\", \"nft\" or \"plain\"); overrides --firewall-bin-path and --firewall-save-bin-path")
151158
cmd.PersistentFlags().BoolVar(&options.IPv6, "ipv6", options.IPv6, "Set rules both via iptables and ip6tables to support dual-stack networking")
152159

153160
// these two flags are kept for backwards-compatibility, but --iptables-mode is preferred
@@ -158,8 +165,8 @@ func NewRootCmd() *cobra.Command {
158165

159166
// BuildFirewallConfiguration returns an iptables FirewallConfiguration suitable to use to configure iptables.
160167
func BuildFirewallConfiguration(options *RootOptions) (*iptables.FirewallConfiguration, error) {
161-
if options.IPTablesMode != "" && options.IPTablesMode != IPTablesModeLegacy && options.IPTablesMode != IPTablesModeNFT {
162-
return nil, fmt.Errorf("--iptables-mode valid values are only \"%s\" and \"%s\"", IPTablesModeLegacy, IPTablesModeNFT)
168+
if options.IPTablesMode != "" && options.IPTablesMode != IPTablesModeLegacy && options.IPTablesMode != IPTablesModeNFT && options.IPTablesMode != IPTablesModePlain {
169+
return nil, fmt.Errorf("--iptables-mode valid values are only \"%s\", \"%s\" and \"%s\"", IPTablesModeLegacy, IPTablesModeNFT, IPTablesModePlain)
163170
}
164171

165172
if options.IPTablesMode == "" {
@@ -168,8 +175,10 @@ func BuildFirewallConfiguration(options *RootOptions) (*iptables.FirewallConfigu
168175
options.IPTablesMode = IPTablesModeLegacy
169176
case cmdNFT:
170177
options.IPTablesMode = IPTablesModeNFT
178+
case cmdPlain:
179+
options.IPTablesMode = IPTablesModePlain
171180
default:
172-
return nil, fmt.Errorf("--firewall-bin-path valid values are only \"%s\" and \"%s\"", cmdLegacy, cmdNFT)
181+
return nil, fmt.Errorf("--firewall-bin-path valid values are only \"%s\", \"%s\" and \"%s\"", cmdLegacy, cmdNFT, cmdPlain)
173182
}
174183
}
175184

@@ -229,18 +238,23 @@ func getFormatter(format string) log.Formatter {
229238
}
230239

231240
func getCommands(options *RootOptions) (string, string) {
232-
if options.IPTablesMode == IPTablesModeLegacy {
241+
switch options.IPTablesMode {
242+
case IPTablesModeLegacy:
233243
if options.IPv6 {
234244
return cmdLegacyIPv6, cmdLegacyIPv6Save
235245
}
236246
return cmdLegacy, cmdLegacySave
247+
case IPTablesModeNFT:
248+
if options.IPv6 {
249+
return cmdNFTIPv6, cmdNFTIPv6Save
250+
}
251+
return cmdNFT, cmdNFTSave
252+
default:
253+
if options.IPv6 {
254+
return cmdPlainIPv6, cmdPlainIPv6Save
255+
}
256+
return cmdPlain, cmdPlainSave
237257
}
238-
239-
if options.IPv6 {
240-
return cmdNFTIPv6, cmdNFTIPv6Save
241-
}
242-
243-
return cmdNFT, cmdNFTSave
244258
}
245259

246260
func setLogLevel(logLevel string) error {

0 commit comments

Comments
 (0)