mirror of
https://github.com/containers/podman.git
synced 2025-06-25 20:26:51 +08:00
linux: add /sys/fs/cgroup if /sys is a bind mount
if /sys is bind mounted from the host then also add an explicit mount for /sys/fs/cgroup so that 'ro' is honored. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -107,11 +107,19 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
|
|||||||
}
|
}
|
||||||
sysMnt := spec.Mount{
|
sysMnt := spec.Mount{
|
||||||
Destination: "/sys",
|
Destination: "/sys",
|
||||||
Type: "bind", // should we use a constant for this, like createconfig?
|
Type: "bind",
|
||||||
Source: "/sys",
|
Source: "/sys",
|
||||||
Options: []string{"rprivate", "nosuid", "noexec", "nodev", r, "rbind"},
|
Options: []string{"rprivate", "nosuid", "noexec", "nodev", r, "rbind"},
|
||||||
}
|
}
|
||||||
g.AddMount(sysMnt)
|
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 {
|
if !s.Privileged && isRootless {
|
||||||
g.AddLinuxMaskedPaths("/sys/kernel")
|
g.AddLinuxMaskedPaths("/sys/kernel")
|
||||||
}
|
}
|
||||||
|
@ -974,4 +974,9 @@ EOF
|
|||||||
run_podman 125 create --name "$randomname/" $IMAGE
|
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
|
# vim: filetype=sh
|
||||||
|
Reference in New Issue
Block a user