Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libct/configs/validate: allow / in sysctl names #3254

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libcontainer/configs/validate/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (v *ConfigValidator) sysctl(config *configs.Config) error {
)

for s := range config.Sysctl {
s := strings.Replace(s, "/", ".", -1)
Copy link

@mengjiao-liu mengjiao-liu Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a problem with your conversion:
If the ssyctl value is net/pv4/conf/eno2.100/rp_filter
The correct conversion result should be net.ipv4.conf.eno2/100.rp_filter

see kubernetes/kubernetes#102393 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mengjiao-liu Could you open a github issue?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will open a issue.

if validSysctlMap[s] || strings.HasPrefix(s, "fs.mqueue.") {
if config.Namespaces.Contains(configs.NEWIPC) {
continue
Expand Down
6 changes: 6 additions & 0 deletions libcontainer/configs/validate/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ func TestValidateUsernamespaceWithoutUserNS(t *testing.T) {
func TestValidateSysctl(t *testing.T) {
sysctl := map[string]string{
"fs.mqueue.ctl": "ctl",
"fs/mqueue/ctl": "ctl",
"net.ctl": "ctl",
"net/ctl": "ctl",
"kernel.ctl": "ctl",
"kernel/ctl": "ctl",
Comment on lines +191 to +195

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the unit test, the sysctl value with existing dots and slashes is also added.

}

for k, v := range sysctl {
Expand All @@ -209,8 +212,11 @@ func TestValidateSysctl(t *testing.T) {
func TestValidateValidSysctl(t *testing.T) {
sysctl := map[string]string{
"fs.mqueue.ctl": "ctl",
"fs/mqueue/ctl": "ctl",
"net.ctl": "ctl",
"net/ctl": "ctl",
"kernel.msgmax": "ctl",
"kernel/msgmax": "ctl",
}

for k, v := range sysctl {
Expand Down
15 changes: 10 additions & 5 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,16 +897,21 @@ func TestSysctl(t *testing.T) {
config := newTemplateConfig(t, nil)
config.Sysctl = map[string]string{
"kernel.shmmni": "8192",
"kernel/shmmax": "4194304",
}
const (
cmd = "cat shmmni shmmax"
exp = "8192\n4194304\n"
)

container, err := newContainer(t, config)
ok(t, err)
defer destroyContainer(container)

var stdout bytes.Buffer
pconfig := libcontainer.Process{
Cwd: "/",
Args: []string{"sh", "-c", "cat /proc/sys/kernel/shmmni"},
Cwd: "/proc/sys/kernel",
Args: []string{"sh", "-c", cmd},
Env: standardEnvironment,
Stdin: nil,
Stdout: &stdout,
Expand All @@ -918,9 +923,9 @@ func TestSysctl(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

shmmniOutput := strings.TrimSpace(stdout.String())
if shmmniOutput != "8192" {
t.Fatalf("kernel.shmmni property expected to be 8192, but is %s", shmmniOutput)
out := stdout.String()
if out != exp {
t.Fatalf("expected %s, got %s", exp, out)
}
}

Expand Down