forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
datapath: Create sysctl
rp_filter
overwrite config on agent init
SystemD versions greater than 245 will create sysctl config which sets the `rp_filter` value for all network interfaces to 1. This conflicts with cilium which requires `rp_filter` to be 0 on interfaces it uses. This commit adds a small utility/tool: `sysctlfix` which will insert a config file into the `/etc/sysctl.d` dir with the highest priority containing directives to disable `rp_filter` and perhaps to contain other sysctl config in future. This utility is called as an init container before the cilium agent starts. Because the sysctl config is in place before the agent starts, all interfaces created by the agent and matching the patten in the config file will have `rp_filter` disabled, even when SystemD >=245 is installed. Fixes: cilium#10645 Fixes: cilium#19909 Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
- Loading branch information
1 parent
6510b76
commit 6432558
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cilium-sysctlfix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright Authors of Cilium | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
include ../../Makefile.defs | ||
|
||
TARGET := cilium-sysctlfix | ||
|
||
.PHONY: all $(TARGET) $(SUBDIRS) clean install | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): | ||
@$(ECHO_GO) | ||
$(QUIET)$(GO_BUILD) -o $@ | ||
|
||
clean: | ||
@$(ECHO_CLEAN) | ||
-$(QUIET)rm -f $(TARGET) | ||
$(QUIET)$(GO_CLEAN) | ||
|
||
install: | ||
$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR) | ||
$(QUIET)$(INSTALL) -m 0755 $(TARGET) $(DESTDIR)$(BINDIR) | ||
|
||
install-binary: install | ||
|
||
install-bash-completion: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"strings" | ||
) | ||
|
||
// This tool attempts to write a sysctl config file to the sysctl config directory with the highest precedence so | ||
// we can overwrite any other config and ensure correct sysctl options for Cilium to function. | ||
|
||
const ( | ||
sysctlD = "/etc/sysctl.d/" | ||
// The 99-zzz prefix ensures our config file gets precedence over most if not all other files. | ||
ciliumOverwrites = "99-zzz-override_cilium.conf" | ||
) | ||
|
||
var sysctlConfig = strings.Join([]string{ | ||
"# Disable rp_filter on Cilium interfaces since it may cause mangled packets to be dropped", | ||
"net.ipv4.conf.lxc*.rp_filter = 0", | ||
"net.ipv4.conf.cilium_*.rp_filter = 0", | ||
"", | ||
}, "\n") | ||
|
||
// This program is executed by an init container so we purposely don't | ||
// exit with any error codes. In case of errors, the function will print warnings, | ||
// but we don't block cilium agent pod from running. | ||
func main() { | ||
info, err := os.Stat(sysctlD) | ||
if err != nil { | ||
fmt.Printf("can't stat sysctl.d dir '%s': %s", sysctlD, err) | ||
return | ||
} | ||
|
||
if !info.IsDir() { | ||
fmt.Printf("'%s' is not a directory", sysctlD) | ||
return | ||
} | ||
|
||
overwritesPath := path.Join(sysctlD, ciliumOverwrites) | ||
f, err := os.OpenFile(overwritesPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) | ||
if err != nil { | ||
fmt.Printf("unable to create cilium sysctl overwrites config: %s", err) | ||
return | ||
} | ||
defer f.Close() | ||
|
||
_, err = fmt.Fprint(f, sysctlConfig) | ||
if err != nil { | ||
fmt.Printf("error while writing to sysctl config: %s", err) | ||
return | ||
} | ||
|
||
fmt.Println("sysctl config written") | ||
} |