Browse code

oci: include the domainname in "kernel.domainname"

The OCI doesn't have a specific field for an NIS domainname[1] (mainly
because FreeBSD and Solaris appear to have a similar concept but it is
configured entirely differently).

However, on Linux, the NIS domainname can be configured through both the
setdomainname(2) syscall but also through the "kernel.domainname"
sysctl. Since the OCI has a way of injecting sysctls this means we don't
need to have any OCI changes to support NIS domainnames (and we can
always switch if the OCI picks up such support in the future).

It should be noted that because we have to generate this each spec
creation we also have to make sure that it's not clobbered by the
HostConfig. I'm pretty sure making this change generic (so that
HostConfig will not clobber any pre-set sysctls) will not cause other
issues to crop up.

[1]: https://github.com/opencontainers/runtime-spec/issues/592

Signed-off-by: Aleksa Sarai <asarai@suse.de>

Aleksa Sarai authored on 2018/06/17 16:05:54
Showing 1 changed files
... ...
@@ -678,7 +678,15 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
678 678
 	s.Process.Cwd = cwd
679 679
 	s.Process.Env = c.CreateDaemonEnvironment(c.Config.Tty, linkedEnv)
680 680
 	s.Process.Terminal = c.Config.Tty
681
-	s.Hostname = c.FullHostname()
681
+
682
+	s.Hostname = c.Config.Hostname
683
+	// There isn't a field in the OCI for the NIS domainname, but luckily there
684
+	// is a sysctl which has an identical effect to setdomainname(2) so there's
685
+	// no explicit need for runtime support.
686
+	s.Linux.Sysctl = make(map[string]string)
687
+	if c.Config.Domainname != "" {
688
+		s.Linux.Sysctl["kernel.domainname"] = c.Config.Domainname
689
+	}
682 690
 
683 691
 	return nil
684 692
 }
... ...
@@ -714,7 +722,11 @@ func (daemon *Daemon) createSpec(c *container.Container) (retSpec *specs.Spec, e
714 714
 	if err := setResources(&s, c.HostConfig.Resources); err != nil {
715 715
 		return nil, fmt.Errorf("linux runtime spec resources: %v", err)
716 716
 	}
717
-	s.Linux.Sysctl = c.HostConfig.Sysctls
717
+	// We merge the sysctls injected above with the HostConfig (latter takes
718
+	// precedence for backwards-compatibility reasons).
719
+	for k, v := range c.HostConfig.Sysctls {
720
+		s.Linux.Sysctl[k] = v
721
+	}
718 722
 
719 723
 	p := s.Linux.CgroupsPath
720 724
 	if useSystemd {