mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
da780e4d27
Currently bind mounts of filesystems with nodev, nosuid, noexec, noatime, relatime, strictatime, nodiratime options set fail in rootless mode if the same options are not set for the bind mount. For ro filesystems this was resolved by #2570 by remounting again with ro set. Follow the same approach for nodev, nosuid, noexec, noatime, relatime, strictatime, nodiratime but allow to revert back to the old behaviour via the new `--no-mount-fallback` command line option. Add a testcase to verify that bind mounts of filesystems with nodev, nosuid, noexec, noatime options set work in rootless mode. Add a testcase that mounts a nodev, nosuid, noexec, noatime filesystem with a ro flag. Add two further testcases that ensure that the above testcases would fail if the `--no-mount-fallback` command line option is set. * contrib/completions/bash/runc: Add `--no-mount-fallback` command line option for bash completion. * create.go: Add `--no-mount-fallback` command line option. * restore.go: Add `--no-mount-fallback` command line option. * run.go: Add `--no-mount-fallback` command line option. * libcontainer/configs/config.go: Add `NoMountFallback` field to the `Config` struct to store the command line option value. * libcontainer/specconv/spec_linux.go: Add `NoMountFallback` field to the `CreateOpts` struct to store the command line option value and store it in the libcontainer config. * utils_linux.go: Store the command line option value in the `CreateOpts` struct. * libcontainer/rootfs_linux.go: In case that `--no-mount-fallback` is not set try to remount the bind filesystem again with the options nodev, nosuid, noexec, noatime, relatime, strictatime or nodiratime if they are set on the source filesystem. * tests/integration/mounts_sshfs.bats: Add testcases and rework sshfs setup to allow specifying different mount options depending on the test case. Signed-off-by: Ruediger Pluem <ruediger.pluem@vodafone.com>
111 lines
3.5 KiB
Bash
111 lines
3.5 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load helpers
|
|
|
|
function setup() {
|
|
setup_busybox
|
|
update_config '.process.args = ["/bin/echo", "Hello World"]'
|
|
}
|
|
|
|
function teardown() {
|
|
# Some distros do not have fusermount installed
|
|
# as a dependency of fuse-sshfs, and good ol' umount works.
|
|
fusermount -u "$DIR" || umount "$DIR"
|
|
|
|
teardown_bundle
|
|
}
|
|
|
|
function setup_sshfs() {
|
|
# Create a fuse-sshfs mount; skip the test if it's not working.
|
|
local sshfs="sshfs
|
|
-o UserKnownHostsFile=/dev/null
|
|
-o StrictHostKeyChecking=no
|
|
-o PasswordAuthentication=no"
|
|
|
|
DIR="$BATS_RUN_TMPDIR/fuse-sshfs"
|
|
mkdir -p "$DIR"
|
|
|
|
if ! $sshfs -o "$1" rootless@localhost: "$DIR"; then
|
|
skip "test requires working sshfs mounts"
|
|
fi
|
|
}
|
|
|
|
@test "runc run [rw bind mount of a ro fuse sshfs mount]" {
|
|
setup_sshfs "ro"
|
|
update_config ' .mounts += [{
|
|
type: "bind",
|
|
source: "'"$DIR"'",
|
|
destination: "/mnt",
|
|
options: ["rw", "rprivate", "nosuid", "nodev", "rbind"]
|
|
}]'
|
|
|
|
runc run --no-mount-fallback test_busybox
|
|
[ "$status" -eq 0 ]
|
|
}
|
|
|
|
@test "runc run [dev,exec,suid,atime bind mount of a nodev,nosuid,noexec,noatime fuse sshfs mount]" {
|
|
setup_sshfs "nodev,nosuid,noexec,noatime"
|
|
# The "sync" option is used to trigger a remount with the below options.
|
|
# It serves no further purpose. Otherwise only a bind mount without
|
|
# applying the below options will be done.
|
|
update_config ' .mounts += [{
|
|
type: "bind",
|
|
source: "'"$DIR"'",
|
|
destination: "/mnt",
|
|
options: ["dev", "suid", "exec", "atime", "rprivate", "rbind", "sync"]
|
|
}]'
|
|
|
|
runc run test_busybox
|
|
[ "$status" -eq 0 ]
|
|
}
|
|
|
|
@test "runc run [ro bind mount of a nodev,nosuid,noexec,noatime fuse sshfs mount]" {
|
|
setup_sshfs "nodev,nosuid,noexec,noatime"
|
|
update_config ' .mounts += [{
|
|
type: "bind",
|
|
source: "'"$DIR"'",
|
|
destination: "/mnt",
|
|
options: ["rbind", "ro"]
|
|
}]'
|
|
|
|
runc run test_busybox
|
|
[ "$status" -eq 0 ]
|
|
}
|
|
|
|
@test "runc run [dev,exec,suid,atime bind mount of a nodev,nosuid,noexec,noatime fuse sshfs mount without fallback]" {
|
|
setup_sshfs "nodev,nosuid,noexec,noatime"
|
|
# The "sync" option is used to trigger a remount with the below options.
|
|
# It serves no further purpose. Otherwise only a bind mount without
|
|
# applying the below options will be done.
|
|
update_config ' .mounts += [{
|
|
type: "bind",
|
|
source: "'"$DIR"'",
|
|
destination: "/mnt",
|
|
options: ["dev", "suid", "exec", "atime", "rprivate", "rbind", "sync"]
|
|
}]'
|
|
|
|
runc run --no-mount-fallback test_busybox
|
|
# The above will fail as we added --no-mount-fallback which causes us not to
|
|
# try to remount a bind mount again after the first attempt failed on source
|
|
# filesystems that have nodev, noexec, nosuid, noatime set.
|
|
[ "$status" -ne 0 ]
|
|
[[ "$output" == *"runc run failed: unable to start container process: error during container init: error mounting"*"operation not permitted"* ]]
|
|
}
|
|
|
|
@test "runc run [ro bind mount of a nodev,nosuid,noexec,noatime fuse sshfs mount without fallback]" {
|
|
setup_sshfs "nodev,nosuid,noexec,noatime"
|
|
update_config ' .mounts += [{
|
|
type: "bind",
|
|
source: "'"$DIR"'",
|
|
destination: "/mnt",
|
|
options: ["rbind", "ro"]
|
|
}]'
|
|
|
|
runc run --no-mount-fallback test_busybox
|
|
# The above will fail as we added --no-mount-fallback which causes us not to
|
|
# try to remount a bind mount again after the first attempt failed on source
|
|
# filesystems that have nodev, noexec, nosuid, noatime set.
|
|
[ "$status" -ne 0 ]
|
|
[[ "$output" == *"runc run failed: unable to start container process: error during container init: error mounting"*"operation not permitted"* ]]
|
|
}
|