mirror of https://github.com/containers/podman.git
Set default rule at the head of device configuration
The default rule should be set at the head of device configuration. Otherwise, rules for user devices are overridden by the default rule so that any access to the user devices are denied. Signed-off-by: Hironori Shiina <shiina.hironori@jp.fujitsu.com>
This commit is contained in:
parent
4a242b1327
commit
d2f77c2568
|
@ -332,6 +332,11 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
|
||||||
}
|
}
|
||||||
// Devices
|
// Devices
|
||||||
|
|
||||||
|
// set the default rule at the beginning of device configuration
|
||||||
|
if !inUserNS && !s.Privileged {
|
||||||
|
g.AddLinuxResourcesDevice(false, "", nil, nil, "rwm")
|
||||||
|
}
|
||||||
|
|
||||||
var userDevices []spec.LinuxDevice
|
var userDevices []spec.LinuxDevice
|
||||||
if s.Privileged {
|
if s.Privileged {
|
||||||
// If privileged, we need to add all the host devices to the
|
// If privileged, we need to add all the host devices to the
|
||||||
|
@ -363,7 +368,6 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
|
||||||
|
|
||||||
// set the devices cgroup when not running in a user namespace
|
// set the devices cgroup when not running in a user namespace
|
||||||
if !inUserNS && !s.Privileged {
|
if !inUserNS && !s.Privileged {
|
||||||
g.AddLinuxResourcesDevice(false, "", nil, nil, "rwm")
|
|
||||||
for _, dev := range s.DeviceCgroupRule {
|
for _, dev := range s.DeviceCgroupRule {
|
||||||
g.AddLinuxResourcesDevice(true, dev.Type, dev.Major, dev.Minor, dev.Access)
|
g.AddLinuxResourcesDevice(true, dev.Type, dev.Major, dev.Minor, dev.Access)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,11 @@ var _ = Describe("Podman run device", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg", ALPINE, "test", "-c", "/dev/kmsg"})
|
session := podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg", ALPINE, "test", "-c", "/dev/kmsg"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
|
if !isRootless() {
|
||||||
|
session = podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg", "--cap-add", "SYS_ADMIN", ALPINE, "head", "-n", "1", "/dev/kmsg"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman run device rename test", func() {
|
It("podman run device rename test", func() {
|
||||||
|
|
Loading…
Reference in New Issue