Skip to content

Commit 7a2942f

Browse files
committed
tests/int: demo default device access rule removal
Since commit 0709202 ("Remove runc default devices that overlap with spec devices.") runc removes the default cgroup device access rule from the default set in case a device with the same path is also listed in container spec. Judging by the commit description, this was not the intention, and yet this is what we have. As the behavior is now part of runc (since v1.0-rc93), it makes sense to at least test it, to ensure it won't be broken in the future. Note that the above behavior is only for rootful runc (rootless does not use cgroup device access rules and bind-mounts host devices instead). In addition, the test case serves as a demo how to limit the container device access to a subset of default AllowedDevices, which we thought was not possible before. Turns out it is possible, in a way (and for rootful runc only). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 8487a06 commit 7a2942f

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/integration/dev.bats

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@ function teardown() {
1010
teardown_bundle
1111
}
1212

13+
@test "runc run [redundant default /dev/full]" {
14+
requires root # Rootless devices behave differently.
15+
16+
# 1. This is how a device from the default AllowedDevices should work as is.
17+
# It's /dev/full so it should return "no space left on device" error.
18+
update_config ' .process.args |= ["sh", "-c", "stat /dev/full; echo foo >/dev/full"]'
19+
runc run test_dev
20+
[ "$status" -eq 1 ]
21+
[[ "$output" == *"Device type: 1,7"* ]]
22+
[[ "$output" == *": No space left on device"* ]]
23+
24+
# 2. Add the device to linux.devices only (but not to linux.resources.devices).
25+
# This way it will be excluded from the cgroup allow rules.
26+
update_config ' .linux.devices += [{"path": "/dev/full", "type": "c", "major": 1, "minor": 7}]'
27+
runc run test_dev
28+
[ "$status" -eq 1 ]
29+
[[ "$output" == *"Device type: 1,7"* ]]
30+
[[ "$output" == *": Operation not permitted"* ]]
31+
32+
# 3. Also add it to cgroups list. Now it should work like the default one (see 1 above).
33+
update_config ' .linux.resources.devices = [
34+
{"allow": false, "access": "rwm"},
35+
{"allow": true, "type": "c", "major": 1, "minor": 7, "access": "rw"}
36+
]'
37+
runc run test_dev
38+
[ "$status" -eq 1 ]
39+
[[ "$output" == *"Device type: 1,7"* ]]
40+
[[ "$output" == *": No space left on device"* ]]
41+
}
42+
1343
@test "runc run [redundant default /dev/tty]" {
1444
update_config ' .linux.devices += [{"path": "/dev/tty", "type": "c", "major": 5, "minor": 0}]
1545
| .process.args |= ["ls", "-lLn", "/dev/tty"]'

0 commit comments

Comments
 (0)