Bladeren bron

Merge pull request #46564 from AkihiroSuda/fix-46563

Limit OOMScoreAdj when running in UserNS ("Rootful-in-Rootless")
Bjorn Neergaard 1 jaar geleden
bovenliggende
commit
bea1462f4f
2 gewijzigde bestanden met toevoegingen van 25 en 0 verwijderingen
  1. 11 0
      daemon/oci_linux.go
  2. 14 0
      pkg/rootless/specconv/specconv_linux.go

+ 11 - 0
daemon/oci_linux.go

@@ -110,6 +110,15 @@ func withRootless(daemon *Daemon, daemonCfg *dconfig.Config) coci.SpecOpts {
 	}
 	}
 }
 }
 
 
+// withRootfulInRootless is used for "rootful-in-rootless" dind;
+// the daemon is running in UserNS but has no access to RootlessKit API socket, host filesystem, etc.
+func withRootfulInRootless(daemon *Daemon, daemonCfg *dconfig.Config) coci.SpecOpts {
+	return func(_ context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
+		specconv.ToRootfulInRootless(s)
+		return nil
+	}
+}
+
 // WithOOMScore sets the oom score
 // WithOOMScore sets the oom score
 func WithOOMScore(score *int) coci.SpecOpts {
 func WithOOMScore(score *int) coci.SpecOpts {
 	return func(ctx context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
 	return func(ctx context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
@@ -1126,6 +1135,8 @@ func (daemon *Daemon) createSpec(ctx context.Context, daemonCfg *configStore, c
 	}
 	}
 	if daemonCfg.Rootless {
 	if daemonCfg.Rootless {
 		opts = append(opts, withRootless(daemon, &daemonCfg.Config))
 		opts = append(opts, withRootless(daemon, &daemonCfg.Config))
+	} else if userns.RunningInUserNS() {
+		opts = append(opts, withRootfulInRootless(daemon, &daemonCfg.Config))
 	}
 	}
 
 
 	var snapshotter, snapshotKey string
 	var snapshotter, snapshotKey string

+ 14 - 0
pkg/rootless/specconv/specconv_linux.go

@@ -13,6 +13,20 @@ import (
 	specs "github.com/opencontainers/runtime-spec/specs-go"
 	specs "github.com/opencontainers/runtime-spec/specs-go"
 )
 )
 
 
+// ToRootfulInRootless is used for "rootful-in-rootless" dind;
+// the daemon is running in UserNS but has no access to RootlessKit API socket, host filesystem, etc.
+//
+// This fuction does:
+// * Fix up OOMScoreAdj (needed since systemd v250: https://github.com/moby/moby/issues/46563)
+func ToRootfulInRootless(spec *specs.Spec) {
+	if spec.Process == nil || spec.Process.OOMScoreAdj == nil {
+		return
+	}
+	if currentOOMScoreAdj := getCurrentOOMScoreAdj(); *spec.Process.OOMScoreAdj < currentOOMScoreAdj {
+		*spec.Process.OOMScoreAdj = currentOOMScoreAdj
+	}
+}
+
 // ToRootless converts spec to be compatible with "rootless" runc.
 // ToRootless converts spec to be compatible with "rootless" runc.
 // * Remove non-supported cgroups
 // * Remove non-supported cgroups
 // * Fix up OOMScoreAdj
 // * Fix up OOMScoreAdj