2016-09-23 15:02:10 +08:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
function setup() {
|
2016-10-17 21:52:48 +08:00
|
|
|
teardown_busybox
|
|
|
|
setup_busybox
|
|
|
|
|
|
|
|
# Create fake rootfs.
|
|
|
|
mkdir rootfs/testdir
|
|
|
|
echo "Forbidden information!" > rootfs/testfile
|
|
|
|
|
|
|
|
# add extra masked paths
|
2020-05-25 08:54:13 +08:00
|
|
|
update_config '(.. | select(.maskedPaths? != null)) .maskedPaths += ["/testdir", "/testfile"]'
|
2016-09-23 15:02:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function teardown() {
|
2016-10-17 21:52:48 +08:00
|
|
|
teardown_busybox
|
2016-09-23 15:02:10 +08:00
|
|
|
}
|
|
|
|
|
2016-10-17 21:52:48 +08:00
|
|
|
@test "mask paths [file]" {
|
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-10-17 21:52:48 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-09-23 15:02:10 +08:00
|
|
|
|
2016-10-17 21:52:48 +08:00
|
|
|
runc exec test_busybox cat /testfile
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${output}" == "" ]]
|
2016-09-23 15:02:10 +08:00
|
|
|
|
2016-10-17 21:52:48 +08:00
|
|
|
runc exec test_busybox rm -f /testfile
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[[ "${output}" == *"Read-only file system"* ]]
|
2016-09-23 15:02:10 +08:00
|
|
|
|
2016-10-17 21:52:48 +08:00
|
|
|
runc exec test_busybox umount /testfile
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[[ "${output}" == *"Operation not permitted"* ]]
|
2016-09-23 15:02:10 +08:00
|
|
|
}
|
|
|
|
|
2016-10-17 21:52:48 +08:00
|
|
|
@test "mask paths [directory]" {
|
|
|
|
# run busybox detached
|
2016-09-06 20:40:01 +08:00
|
|
|
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
|
2016-10-17 21:52:48 +08:00
|
|
|
[ "$status" -eq 0 ]
|
2016-09-23 15:02:10 +08:00
|
|
|
|
2016-10-17 21:52:48 +08:00
|
|
|
runc exec test_busybox ls /testdir
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "${output}" == "" ]]
|
2016-09-23 15:02:10 +08:00
|
|
|
|
2016-10-17 21:52:48 +08:00
|
|
|
runc exec test_busybox touch /testdir/foo
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[[ "${output}" == *"Read-only file system"* ]]
|
2016-09-23 15:02:10 +08:00
|
|
|
|
2016-10-17 21:52:48 +08:00
|
|
|
runc exec test_busybox rm -rf /testdir
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[[ "${output}" == *"Read-only file system"* ]]
|
2016-09-23 15:02:10 +08:00
|
|
|
|
2016-10-17 21:52:48 +08:00
|
|
|
runc exec test_busybox umount /testdir
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[[ "${output}" == *"Operation not permitted"* ]]
|
2016-09-23 15:02:10 +08:00
|
|
|
}
|