Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Add support for mount profiles #51
Merged
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6948741
add setup_bind_mounts()
mvo5 73c901a
add reading of mount profiles
mvo5 b3404eb
use getmntent()
mvo5 7bd1376
add spread tests
mvo5 e45ede2
address review comments
mvo5 2e031c5
more review feedback
mvo5 42e3520
improve basic/task.yaml
mvo5 ba27784
remove extra \n (thanks @zyga)
mvo5 519269c
use must_snprintf()
mvo5 ce0df54
use bind,ro,nodev,nosuid by default as mount flags
mvo5 db1848f
Merge remote-tracking branch 'origin/master' into feature/bind
zyga 9b5e267
Add and use sc_cleanup_file
zyga e4b57e6
Fix typo
zyga 5258029
Add sc_cleanup_endmntent
zyga 329a583
Use setmntent/endmntent to read mount profiles
zyga e1bd4ed
Fix copy-pasted error message
zyga a292800
Synchronize mount profile directory with snapd
zyga 3d6bd50
Rename setup_bind_mounts to sc_setup_mount_profiles
zyga 4e2018b
Document sc_setup_mount_profiles
zyga 8fa2512
Drop trailing slash from bind_profile_dir
zyga 8bd65ba
Rename bind_profile_dir to mount_profile_dir
zyga 5da87fe
Improve debug output for mount profiles
zyga 2756150
Add a spread smoke test for bind mounts
zyga 9da50ae
Remove installed snap in the restore section
zyga 05aee1f
Add a negative test for mount profile
zyga 8db5fed
Tweak and expand mount profile tests
zyga 462ecf8
Add cleanup that removes .fstab files
zyga e88b823
Tweak mount tests
zyga c2d228f
Add more mount tests
zyga 9a2ba98
Move sc_setup_mount_profiles call to after critical confinement.
zyga
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,13 @@ | ||
| +summary: Check that basic install works | ||
| +# This is blacklisted on debian because we first have to get the dpkg-vendor patches | ||
| +systems: [-debian-8] | ||
| +restore: | | ||
| + snap remove hello-world | ||
| +execute: | | ||
| + cd / | ||
| + echo Run some hello-world stuff | ||
| + snap install hello-world | ||
| + hello-world.echo | grep Hello | ||
| + hello-world.env | grep SNAP_NAME=hello-world | ||
| + echo Ensure that we get an error if hello-world.evil does not return an error | ||
| + if hello-world.evil; then exit 1; fi |
| @@ -0,0 +1,21 @@ | ||
| +summary: Check that missing destination directory aborts mount processing | ||
| +# This is blacklisted on debian because we first have to get the dpkg-vendor patches | ||
| +systems: [-debian-8] | ||
| +restore: | | ||
| + snap remove snapd-hacker-toolbelt | ||
| + rm -rf /var/snap/snapd-hacker-toolbelt | ||
| + rm -f /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| +execute: | | ||
| + echo "Having installed the snapd-hacker-toolbelt snap" | ||
| + snap list | grep -q snapd-hacker-toolbelt || snap install snapd-hacker-toolbelt | ||
| + | ||
| + echo "We can change its mount profile externally to create a read-only bind-mount" | ||
| + echo "/var/snap/snapd-hacker-toolbelt/common/src -> /var/snap/snapd-hacker-toolbelt/common/dst" | ||
| + mkdir -p /var/lib/snapd/mount | ||
| + echo "/var/snap/snapd-hacker-toolbelt/common/src /var/snap/snapd-hacker-toolbelt/common/dst none bind,ro 0 0" > /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| + | ||
| + echo "We can now create the source directory, missing the destination directory" | ||
| + mkdir -p /var/snap/snapd-hacker-toolbelt/common/src | ||
| + | ||
| + echo "We can now run busybox.true and expect it to fail" | ||
| + ( cd / && ! /snap/bin/snapd-hacker-toolbelt.busybox true ) |
| @@ -0,0 +1,21 @@ | ||
| +summary: Check that missing source directory aborts mount processing | ||
| +# This is blacklisted on debian because we first have to get the dpkg-vendor patches | ||
| +systems: [-debian-8] | ||
| +restore: | | ||
| + snap remove snapd-hacker-toolbelt | ||
| + rm -rf /var/snap/snapd-hacker-toolbelt | ||
| + rm -f /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| +execute: | | ||
| + echo "Having installed the snapd-hacker-toolbelt snap" | ||
| + snap list | grep -q snapd-hacker-toolbelt || snap install snapd-hacker-toolbelt | ||
| + | ||
| + echo "We can change its mount profile externally to create a read-only bind-mount" | ||
| + echo "/var/snap/snapd-hacker-toolbelt/common/src -> /var/snap/snapd-hacker-toolbelt/common/dst" | ||
| + mkdir -p /var/lib/snapd/mount | ||
| + echo "/var/snap/snapd-hacker-toolbelt/common/src /var/snap/snapd-hacker-toolbelt/common/dst none bind,ro 0 0" > /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| + | ||
| + echo "We can now create the destination directory, missing the source directory" | ||
| + mkdir -p /var/snap/snapd-hacker-toolbelt/common/dst | ||
| + | ||
| + echo "We can now run busybox.true and expect it to fail" | ||
| + ( cd / && ! /snap/bin/snapd-hacker-toolbelt.busybox true ) |
| @@ -0,0 +1,20 @@ | ||
| +summary: Check that mount profiles cannot be used to mount tmpfs | ||
| +# This is blacklisted on debian because we first have to get the dpkg-vendor patches | ||
| +systems: [-debian-8] | ||
| +restore: | | ||
| + snap remove snapd-hacker-toolbelt | ||
| + rm -rf /var/snap/snapd-hacker-toolbelt | ||
| + rm -f /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| +execute: | | ||
| + echo "Having installed the snapd-hacker-toolbelt snap" | ||
| + snap list | grep -q snapd-hacker-toolbelt || snap install snapd-hacker-toolbelt | ||
| + | ||
| + echo "We can change its mount profile externally to mount tmpfs at /var/snap/snapd-hacker-toolbelt/mnt" | ||
| + mkdir -p /var/lib/snapd/mount | ||
| + echo "none /var/snap/snapd-hacker-toolbelt/common/mnt tmpfs rw 0 0" > /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| + | ||
| + echo "We can now create the test mount directory" | ||
| + mkdir -p /var/snap/snapd-hacker-toolbelt/common/mnt | ||
| + | ||
| + echo "We can now run busybox.true and expect it to fail" | ||
| + ( cd / && ! /snap/bin/snapd-hacker-toolbelt.busybox true ) |
| @@ -0,0 +1,26 @@ | ||
| +summary: Check that read-only bind mounts can be created | ||
| +# This is blacklisted on debian because we first have to get the dpkg-vendor patches | ||
| +systems: [-debian-8] | ||
| +restore: | | ||
| + snap remove snapd-hacker-toolbelt | ||
| + rm -rf /var/snap/snapd-hacker-toolbelt | ||
| + rm -f /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| +execute: | | ||
| + echo "Having installed the snapd-hacker-toolbelt snap" | ||
| + snap list | grep -q snapd-hacker-toolbelt || snap install snapd-hacker-toolbelt | ||
| + | ||
| + echo "We can change its mount profile externally to create a read-only bind-mount" | ||
| + echo "/var/snap/snapd-hacker-toolbelt/common/src -> /var/snap/snapd-hacker-toolbelt/common/dst" | ||
| + mkdir -p /var/lib/snapd/mount | ||
| + echo "/var/snap/snapd-hacker-toolbelt/common/src /var/snap/snapd-hacker-toolbelt/common/dst none bind,ro 0 0" > /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| + | ||
| + echo "We can now create both test directories" | ||
| + mkdir -p /var/snap/snapd-hacker-toolbelt/common/src | ||
| + mkdir -p /var/snap/snapd-hacker-toolbelt/common/dst | ||
| + | ||
| + echo "And put a canary file with a random value inside" | ||
| + value="canary-$(dd if=/dev/urandom bs=4 count=1 2>/dev/null | od -A none -t x4 | cut -f 2 -d ' ')" | ||
| + echo "$value" > /var/snap/snapd-hacker-toolbelt/common/src/canary | ||
| + | ||
| + echo "We can now run busybox.cat from the destination directory and expect the random value to match" | ||
| + [ "$(cd / && /snap/bin/snapd-hacker-toolbelt.busybox cat /var/snap/snapd-hacker-toolbelt/common/dst/canary)" = "$value" ] |
| @@ -0,0 +1,28 @@ | ||
| +summary: Check that write-only bind mounts can be created | ||
| +# This is blacklisted on debian because we first have to get the dpkg-vendor patches | ||
| +systems: [-debian-8] | ||
| +restore: | | ||
| + snap remove snapd-hacker-toolbelt | ||
| + rm -rf /var/snap/snapd-hacker-toolbelt | ||
| + rm -f /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| +execute: | | ||
| + echo "Having installed the snapd-hacker-toolbelt snap" | ||
| + snap list | grep -q snapd-hacker-toolbelt || snap install snapd-hacker-toolbelt | ||
| + | ||
| + echo "We can change its mount profile externally to create a writable bind-mount" | ||
| + echo "/var/snap/snapd-hacker-toolbelt/common/src -> /var/snap/snapd-hacker-toolbelt/common/dst" | ||
| + mkdir -p /var/lib/snapd/mount | ||
| + echo "/var/snap/snapd-hacker-toolbelt/common/src /var/snap/snapd-hacker-toolbelt/common/dst none bind,rw 0 0" > /var/lib/snapd/mount/snap.snapd-hacker-toolbelt.busybox.fstab | ||
| + | ||
| + echo "We can now create both test directories" | ||
| + mkdir -p /var/snap/snapd-hacker-toolbelt/common/src | ||
| + mkdir -p /var/snap/snapd-hacker-toolbelt/common/dst | ||
| + chmod 0777 /var/snap/snapd-hacker-toolbelt/common/dst | ||
| + | ||
| + value="canary-$(dd if=/dev/urandom bs=4 count=1 2>/dev/null | od -A none -t x4 | cut -f 2 -d ' ')" | ||
| + | ||
| + echo "We can now run busybox.tee to write to the file in the destination directory" | ||
| + ( cd / && echo "$value" | /snap/bin/snapd-hacker-toolbelt.busybox tee /var/snap/snapd-hacker-toolbelt/common/dst/canary ) | ||
| + | ||
| + echo "And we should see the written value from the source directory" | ||
| + [ "$(cat /var/snap/snapd-hacker-toolbelt/common/src/canary)" = "$value" ] |
| @@ -1,4 +1,6 @@ | ||
| summary: Check that ubuntu-core-launcher executes correctly | ||
| +# This is blacklisted on debian because we first have to get the dpkg-vendor patches | ||
| +systems: [-debian-8] | ||
| execute: | | ||
| echo "ubuntu-core-launcher is installed and responds to --help" | ||
| ubuntu-core-launcher --help 2>&1 | grep -F -q 'Usage: ubuntu-core-launcher <security-tag> <binary>' |
I'd suggest defining an easy-to-type macro for "attribute ((cleanup(sc_cleanup_endmntent)))". I think "autofclose" is descriptive.