Merge pull request from giuseppe/bind-mount-sys-fs-cgroup-ro

linux: add /sys/fs/cgroup if /sys is a bind mount
This commit is contained in:
OpenShift Merge Robot
2023-01-09 16:31:03 -05:00
committed by GitHub
2 changed files with 14 additions and 1 deletions
pkg/specgen/generate
test/system

@ -107,11 +107,19 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
}
sysMnt := spec.Mount{
Destination: "/sys",
Type: "bind", // should we use a constant for this, like createconfig?
Type: "bind",
Source: "/sys",
Options: []string{"rprivate", "nosuid", "noexec", "nodev", r, "rbind"},
}
g.AddMount(sysMnt)
g.RemoveMount("/sys/fs/cgroup")
sysFsCgroupMnt := spec.Mount{
Destination: "/sys/fs/cgroup",
Type: "bind",
Source: "/sys/fs/cgroup",
Options: []string{"rprivate", "nosuid", "noexec", "nodev", r, "rbind"},
}
g.AddMount(sysFsCgroupMnt)
if !s.Privileged && isRootless {
g.AddLinuxMaskedPaths("/sys/kernel")
}

@ -974,4 +974,9 @@ EOF
run_podman 125 create --name "$randomname/" $IMAGE
}
@test "podman run --net=host --cgroupns=host with read only cgroupfs" {
# verify that the last /sys/fs/cgroup mount is read-only
run_podman run --net=host --cgroupns=host --rm $IMAGE sh -c "grep ' / /sys/fs/cgroup ' /proc/self/mountinfo | tail -n 1 | grep '/sys/fs/cgroup ro'"
}
# vim: filetype=sh