Skip to content

Commit 6e97f3a

Browse files
committed
tests: mask: use test paths rather than /sys
In certain circumstances (such as the rootless containers patchset), it is not possible to test things using /sys/firmware. In addition, we should be testing our own functionality rather than testing protection against /sys attacks (for which the system might already have extra protections). Instead, just make some fake paths in the rootfs that we then mask. Oddly I noticed that one of the errors changed when doing this (because before we tested removing a file from /sys/firmware which is -EPERM). So the old test was broken. Fixes: 5317955 ("MaskPaths: support directory") Fixes: #1068 Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 88b4c48 commit 6e97f3a

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

tests/integration/mask.bats

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,61 @@
33
load helpers
44

55
function setup() {
6-
teardown_busybox
7-
setup_busybox
6+
teardown_busybox
7+
setup_busybox
8+
9+
# Create fake rootfs.
10+
mkdir rootfs/testdir
11+
echo "Forbidden information!" > rootfs/testfile
12+
13+
# add extra masked paths
14+
sed -i 's;"maskedPaths": \[;"maskedPaths": \["/testdir","/testfile",;g' config.json
815
}
916

1017
function teardown() {
11-
teardown_busybox
18+
teardown_busybox
1219
}
1320

14-
@test "MaskPaths(file)" {
15-
# run busybox detached
16-
runc run -d --console /dev/pts/ptmx test_busybox
17-
[ "$status" -eq 0 ]
21+
@test "mask paths [file]" {
22+
# run busybox detached
23+
runc run -d --console /dev/pts/ptmx test_busybox
24+
[ "$status" -eq 0 ]
1825

19-
wait_for_container 15 1 test_busybox
26+
wait_for_container 15 1 test_busybox
2027

21-
runc exec test_busybox cat /proc/kcore
22-
[ "$status" -eq 0 ]
23-
[[ "${output}" == "" ]]
28+
runc exec test_busybox cat /testfile
29+
[ "$status" -eq 0 ]
30+
[[ "${output}" == "" ]]
2431

25-
runc exec test_busybox rm -f /proc/kcore
26-
[ "$status" -eq 1 ]
27-
[[ "${output}" == *"Permission denied"* ]]
32+
runc exec test_busybox rm -f /testfile
33+
[ "$status" -eq 1 ]
34+
[[ "${output}" == *"Read-only file system"* ]]
2835

29-
runc exec test_busybox umount /proc/kcore
30-
[ "$status" -eq 1 ]
31-
[[ "${output}" == *"Operation not permitted"* ]]
36+
runc exec test_busybox umount /testfile
37+
[ "$status" -eq 1 ]
38+
[[ "${output}" == *"Operation not permitted"* ]]
3239
}
3340

34-
@test "MaskPaths(directory)" {
35-
# run busybox detached
36-
runc run -d --console /dev/pts/ptmx test_busybox
37-
[ "$status" -eq 0 ]
41+
@test "mask paths [directory]" {
42+
# run busybox detached
43+
runc run -d --console /dev/pts/ptmx test_busybox
44+
[ "$status" -eq 0 ]
3845

39-
wait_for_container 15 1 test_busybox
46+
wait_for_container 15 1 test_busybox
4047

41-
runc exec test_busybox ls /sys/firmware
42-
[ "$status" -eq 0 ]
43-
[[ "${output}" == "" ]]
48+
runc exec test_busybox ls /testdir
49+
[ "$status" -eq 0 ]
50+
[[ "${output}" == "" ]]
4451

45-
runc exec test_busybox touch /sys/firmware/foo
46-
[ "$status" -eq 1 ]
47-
[[ "${output}" == *"Read-only file system"* ]]
52+
runc exec test_busybox touch /testdir/foo
53+
[ "$status" -eq 1 ]
54+
[[ "${output}" == *"Read-only file system"* ]]
4855

49-
runc exec test_busybox rm -rf /sys/firmware
50-
[ "$status" -eq 1 ]
51-
[[ "${output}" == *"Read-only file system"* ]]
56+
runc exec test_busybox rm -rf /testdir
57+
[ "$status" -eq 1 ]
58+
[[ "${output}" == *"Read-only file system"* ]]
5259

53-
runc exec test_busybox umount /sys/firmware
54-
[ "$status" -eq 1 ]
55-
[[ "${output}" == *"Operation not permitted"* ]]
60+
runc exec test_busybox umount /testdir
61+
[ "$status" -eq 1 ]
62+
[[ "${output}" == *"Operation not permitted"* ]]
5663
}

0 commit comments

Comments
 (0)