Skip to content

Commit 2f33458

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. In addition, the test case serves as a demo how to limit the container device access to a subset of default AllowedDevices. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent a756459 commit 2f33458

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/integration/dev.bats

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

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

0 commit comments

Comments
 (0)