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 bind profiles #43
Closed
Commits
Show all changes
10 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
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,10 @@ | ||
| +summary: Check that basic install works | ||
| +restore: | | ||
| + snap remove hello-world | ||
| +execute: | | ||
| + 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 |
38
spread.yaml
| @@ -0,0 +1,38 @@ | ||
| +project: snap-confine | ||
|
|
||
| + | ||
| +environment: | ||
| + REUSE_PROJECT: $(echo $REUSE_PROJECT) | ||
| + PATH: /snap/bin:$PATH | ||
| + | ||
| +backends: | ||
| + linode: | ||
| + key: $(echo $SPREAD_LINODE_KEY) | ||
| + systems: | ||
| + - ubuntu-16.04-64-grub | ||
| + - ubuntu-16.04-32-grub | ||
| + | ||
| +path: /spread/snap-confine | ||
| + | ||
| +exclude: | ||
| + - .git | ||
| + | ||
| +prepare: | | ||
| + [ "$REUSE_PROJECT" != 1 ] || exit 0 | ||
| + | ||
mvo5
Contributor
|
||
| + apt purge -y snap-confine || true | ||
| + apt update | ||
| + apt install -y snapd fakeroot | ||
| + apt build-dep -y ./ | ||
| + | ||
| + test -d /home/test || adduser --quiet --disabled-password --gecos '' test | ||
| + chown test.test -R /home/test /spread/ | ||
| + sudo -i -u test /bin/sh -c "cd $PWD && DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -tc -b -Zgzip" | ||
| + apt install -y ../ubuntu-core-launcher_*.deb ../snap-confine_*.deb | ||
| + rm -f ../snap-confine_*.deb | ||
| + | ||
| +suites: | ||
| + spread-tests/: | ||
| + summary: Full-system tests for snap-confinue | ||
| + prepare: | | ||
| + echo Ensure ubuntu-core is installed | ||
| + sudo snap install ubuntu-core | ||
| @@ -30,6 +30,7 @@ | ||
| #include <errno.h> | ||
| #include <sched.h> | ||
| #include <string.h> | ||
| +#include <mntent.h> | ||
| #include "utils.h" | ||
| #include "snap.h" | ||
| @@ -293,3 +294,50 @@ void setup_slave_mount_namespace() | ||
| die("can not make make / rslave"); | ||
| } | ||
| } | ||
| + | ||
| +void setup_bind_mounts(const char *appname) | ||
| +{ | ||
| + debug("%s: %s", __FUNCTION__, appname); | ||
| + | ||
| + FILE *f = NULL; | ||
| + const char *bind_profile_dir = "/var/lib/snapd/bind/profiles/"; | ||
|
|
||
| + | ||
| + char profile_path[PATH_MAX]; | ||
| + must_snprintf(profile_path, sizeof(profile_path), "%s/%s.bind", | ||
|
|
||
| + bind_profile_dir, appname); | ||
| + | ||
| + f = fopen(profile_path, "r"); | ||
zyga
Collaborator
|
||
| + // it is ok for the file to not exist | ||
| + if (f == NULL && errno == ENOENT) | ||
| + return; | ||
| + // however any other error is a real error | ||
| + if (f == NULL) { | ||
| + die("cannot open %s", profile_path); | ||
| + } | ||
| + | ||
| + struct mntent *m = NULL; | ||
| + while ((m = getmntent(f)) != NULL) { | ||
| + int flags = MS_BIND | MS_RDONLY | MS_NODEV | MS_NOSUID; | ||
| + | ||
| + if (strcmp(m->mnt_type, "none") != 0) { | ||
| + die("only 'none' filesystemtype is supported"); | ||
| + } | ||
| + if (hasmntopt(m, "bind") == NULL) { | ||
| + die("need bind mount flag"); | ||
| + } | ||
| + if (hasmntopt(m, "rw") != NULL) { | ||
| + flags &= ~MS_RDONLY; | ||
| + } | ||
| + | ||
| + if (mount(m->mnt_fsname, m->mnt_dir, NULL, flags, NULL) != 0) { | ||
| + die("unable to bind private /tmp"); | ||
| + } | ||
| + } | ||
| + | ||
mvo5
Contributor
|
||
| + if (f != NULL) { | ||
| + if (fclose(f) != 0) | ||
| + die("could not close bind mount file"); | ||
| + } | ||
| + | ||
| + return; | ||
| +} | ||
| @@ -23,4 +23,6 @@ void setup_private_pts(); | ||
| void setup_snappy_os_mounts(); | ||
| void setup_slave_mount_namespace(); | ||
| +void setup_bind_mounts(const char *appname); | ||
zyga
Collaborator
|
||
| + | ||
| #endif | ||
The
profiles/component was removed from the snapd side. Please update this here.