2019-04-29 21:41:18 +08:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
@test "overlay specific level" {
|
2019-11-23 03:52:25 +08:00
|
|
|
if test \! -e /usr/bin/fuse-overlayfs -a "$BUILDAH_ISOLATION" = "rootless"; then
|
2019-07-29 23:48:35 +08:00
|
|
|
skip "BUILDAH_ISOLATION = $BUILDAH_ISOLATION" and no /usr/bin/fuse-overlayfs present
|
2019-10-30 03:30:49 +08:00
|
|
|
elif test "$STORAGE_DRIVER" = "vfs"; then
|
|
|
|
skip "skipping overlay test because \$STORAGE_DRIVER = $STORAGE_DRIVER"
|
2019-04-29 21:41:18 +08:00
|
|
|
fi
|
|
|
|
image=alpine
|
2024-03-30 04:46:47 +08:00
|
|
|
_prefetch $image
|
2022-04-26 23:09:11 +08:00
|
|
|
mkdir ${TEST_SCRATCH_DIR}/lower
|
|
|
|
touch ${TEST_SCRATCH_DIR}/lower/foo
|
2019-04-29 21:41:18 +08:00
|
|
|
|
2022-04-26 23:09:11 +08:00
|
|
|
run_buildah from --quiet -v ${TEST_SCRATCH_DIR}/lower:/lower:O --quiet $WITH_POLICY_JSON $image
|
2019-12-12 03:11:08 +08:00
|
|
|
cid=$output
|
2019-04-29 21:41:18 +08:00
|
|
|
|
|
|
|
# This should succeed
|
2019-12-12 02:28:27 +08:00
|
|
|
run_buildah run $cid ls /lower/foo
|
2019-04-29 21:41:18 +08:00
|
|
|
|
2020-11-07 04:31:29 +08:00
|
|
|
# Create and remove content in the overlay directory, should succeed,
|
|
|
|
# resetting the contents between each run.
|
2019-12-12 02:28:27 +08:00
|
|
|
run_buildah run $cid touch /lower/bar
|
|
|
|
run_buildah run $cid rm /lower/foo
|
2019-04-29 21:41:18 +08:00
|
|
|
|
|
|
|
# This should fail, second runs of containers go back to original
|
2020-11-07 04:31:29 +08:00
|
|
|
run_buildah 1 run $cid ls /lower/bar
|
2019-04-29 21:41:18 +08:00
|
|
|
|
|
|
|
# This should fail
|
2022-04-26 23:09:11 +08:00
|
|
|
run ls ${TEST_SCRATCH_DIR}/lower/bar
|
2023-01-05 21:42:11 +08:00
|
|
|
assert "$status" -ne 0 "status of ls ${TEST_SCRATCH_DIR}/lower/bar"
|
2019-04-29 21:41:18 +08:00
|
|
|
}
|
2021-01-04 22:23:44 +08:00
|
|
|
|
2021-05-07 19:19:16 +08:00
|
|
|
@test "overlay source permissions and owners" {
|
2021-01-04 22:23:44 +08:00
|
|
|
if test \! -e /usr/bin/fuse-overlayfs -a "$BUILDAH_ISOLATION" = "rootless"; then
|
|
|
|
skip "BUILDAH_ISOLATION = $BUILDAH_ISOLATION" and no /usr/bin/fuse-overlayfs present
|
|
|
|
elif test "$STORAGE_DRIVER" = "vfs"; then
|
|
|
|
skip "skipping overlay test because \$STORAGE_DRIVER = $STORAGE_DRIVER"
|
|
|
|
fi
|
|
|
|
image=alpine
|
2024-03-30 04:46:47 +08:00
|
|
|
_prefetch $image
|
2022-04-26 23:09:11 +08:00
|
|
|
mkdir -m 770 ${TEST_SCRATCH_DIR}/lower
|
|
|
|
chown 1:1 ${TEST_SCRATCH_DIR}/lower
|
|
|
|
permission=$(stat -c "%a %u %g" ${TEST_SCRATCH_DIR}/lower)
|
|
|
|
run_buildah from --quiet -v ${TEST_SCRATCH_DIR}/lower:/tmp/test:O --quiet $WITH_POLICY_JSON $image
|
2021-01-04 22:23:44 +08:00
|
|
|
cid=$output
|
|
|
|
|
|
|
|
# This should succeed
|
2021-05-07 19:19:16 +08:00
|
|
|
run_buildah run $cid sh -c 'stat -c "%a %u %g" /tmp/test'
|
|
|
|
expect_output "$permission"
|
2021-01-04 22:23:44 +08:00
|
|
|
|
|
|
|
# Create and remove content in the overlay directory, should succeed
|
2022-04-26 23:09:11 +08:00
|
|
|
touch ${TEST_SCRATCH_DIR}/lower/foo
|
2021-03-06 04:51:14 +08:00
|
|
|
run_buildah run $cid touch /tmp/test/bar
|
|
|
|
run_buildah run $cid rm /tmp/test/foo
|
2021-01-04 22:23:44 +08:00
|
|
|
|
|
|
|
# This should fail, second runs of containers go back to original
|
2021-03-06 04:51:14 +08:00
|
|
|
run_buildah 1 run $cid ls /tmp/test/bar
|
2021-01-04 22:23:44 +08:00
|
|
|
|
2021-03-06 04:51:14 +08:00
|
|
|
# This should fail since /tmp/test was an overlay, not a bind mount
|
2022-04-26 23:09:11 +08:00
|
|
|
run ls ${TEST_SCRATCH_DIR}/lower/bar
|
2023-01-05 21:42:11 +08:00
|
|
|
assert "$status" -ne 0 "status of ls ${TEST_SCRATCH_DIR}/lower/bar"
|
2021-01-04 22:23:44 +08:00
|
|
|
}
|
2021-10-11 11:26:35 +08:00
|
|
|
|
|
|
|
@test "overlay path contains colon" {
|
|
|
|
if test \! -e /usr/bin/fuse-overlayfs -a "$BUILDAH_ISOLATION" = "rootless"; then
|
|
|
|
skip "BUILDAH_ISOLATION = $BUILDAH_ISOLATION" and no /usr/bin/fuse-overlayfs present
|
|
|
|
elif test "$STORAGE_DRIVER" = "vfs"; then
|
|
|
|
skip "skipping overlay test because \$STORAGE_DRIVER = $STORAGE_DRIVER"
|
|
|
|
fi
|
|
|
|
image=alpine
|
2024-03-30 04:46:47 +08:00
|
|
|
_prefetch $image
|
2022-04-26 23:09:11 +08:00
|
|
|
mkdir ${TEST_SCRATCH_DIR}/a:lower
|
|
|
|
touch ${TEST_SCRATCH_DIR}/a:lower/foo
|
2021-10-11 11:26:35 +08:00
|
|
|
|
|
|
|
# This should succeed.
|
|
|
|
# Add double backslash, because shell will escape.
|
2022-04-26 23:09:11 +08:00
|
|
|
run_buildah from --quiet -v ${TEST_SCRATCH_DIR}/a\\:lower:/a\\:lower:O --quiet $WITH_POLICY_JSON $image
|
2021-10-11 11:26:35 +08:00
|
|
|
cid=$output
|
|
|
|
|
|
|
|
# This should succeed
|
|
|
|
run_buildah run $cid ls /a:lower/foo
|
|
|
|
|
|
|
|
# Mount volume when run
|
2022-04-26 23:09:11 +08:00
|
|
|
run_buildah run -v ${TEST_SCRATCH_DIR}/a\\:lower:/b\\:lower:O $cid ls /b:lower/foo
|
2021-10-11 11:26:35 +08:00
|
|
|
|
|
|
|
# Create and remove content in the overlay directory, should succeed,
|
|
|
|
# resetting the contents between each run.
|
|
|
|
run_buildah run $cid touch /a:lower/bar
|
|
|
|
run_buildah run $cid rm /a:lower/foo
|
|
|
|
|
|
|
|
# This should fail, second runs of containers go back to original
|
|
|
|
run_buildah 1 run $cid ls /a:lower/bar
|
|
|
|
|
|
|
|
# This should fail
|
2022-04-26 23:09:11 +08:00
|
|
|
run ls ${TEST_SCRATCH_DIR}/a:lower/bar
|
2023-01-05 21:42:11 +08:00
|
|
|
assert "$status" -ne 0 "status of ls ${TEST_SCRATCH_DIR}/a:lower/bar"
|
|
|
|
}
|