Skip to content

Commit b14eef6

Browse files
committed
libcontainer: improve "kernel.{domainname,hostname}" sysctl handling
These sysctls are namespaced by CLONE_NEWUTS, and we need to use "kernel.domainname" if we want users to be able to set an NIS domainname on Linux. However we disallow "kernel.hostname" because it would conflict with the "hostname" field and cause confusion (but we include a helpful message to make it clearer to the user). Signed-off-by: Aleksa Sarai <[email protected]>
1 parent f405929 commit b14eef6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libcontainer/configs/validate/validator.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ func (v *ConfigValidator) sysctl(config *configs.Config) error {
151151
return fmt.Errorf("sysctl %q is not allowed in the hosts network namespace", s)
152152
}
153153
}
154+
if config.Namespaces.Contains(configs.NEWUTS) {
155+
switch s {
156+
case "kernel.domainname":
157+
// This is namespaced and there's no explicit OCI field for it.
158+
continue
159+
case "kernel.hostname":
160+
// This is namespaced but there's a conflicting (dedicated) OCI field for it.
161+
return fmt.Errorf("sysctl %q is not allowed as it conflicts with the OCI %q field", s, "hostname")
162+
}
163+
}
154164
return fmt.Errorf("sysctl %q is not in a separate kernel namespace", s)
155165
}
156166

0 commit comments

Comments
 (0)