summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2020-05-27 14:23:03 +0100
committerAlexander Larsson <alexander.larsson@gmail.com>2020-07-24 10:28:30 +0200
commit7872935e129db8e2bab72dbadf24368d17ba1102 (patch)
tree7b9cf2e4cde1495bd04a1018255677b05287809e
parent1bf5f2ed9e95e060517db82b7b7b4153a8bb805c (diff)
downloadflatpak-7872935e129db8e2bab72dbadf24368d17ba1102.tar.gz
run: implement sandbox host os-release interface
If available, always read-only bind-mount /etc/os-release as /run/host/os-release (or /usr/lib/os-release as fallback) as suggested by the os-release specification: https://www.freedesktop.org/software/systemd/man/os-release.html
-rw-r--r--common/flatpak-exports.c8
-rw-r--r--doc/flatpak-run.xml7
-rw-r--r--tests/test-run.sh24
3 files changed, 38 insertions, 1 deletions
diff --git a/common/flatpak-exports.c b/common/flatpak-exports.c
index 37a93e13..912c5755 100644
--- a/common/flatpak-exports.c
+++ b/common/flatpak-exports.c
@@ -395,6 +395,14 @@ flatpak_exports_append_bwrap_args (FlatpakExports *exports,
flatpak_bwrap_add_args (bwrap,
etc_bind_mode, "/etc", "/run/host/etc", NULL);
}
+
+ /* As per the os-release specification https://www.freedesktop.org/software/systemd/man/os-release.html
+ * always read-only bind-mount /etc/os-release if it exists, or /usr/lib/os-release as a fallback from
+ * the host into the application's /run/host */
+ if (g_file_test ("/etc/os-release", G_FILE_TEST_EXISTS))
+ flatpak_bwrap_add_args (bwrap, "--ro-bind", "/etc/os-release", "/run/host/os-release", NULL);
+ else if (g_file_test ("/usr/lib/os-release", G_FILE_TEST_EXISTS))
+ flatpak_bwrap_add_args (bwrap, "--ro-bind", "/usr/lib/os-release", "/run/host/os-release", NULL);
}
/* Returns 0 if not visible */
diff --git a/doc/flatpak-run.xml b/doc/flatpak-run.xml
index 82582d42..c28f2fa1 100644
--- a/doc/flatpak-run.xml
+++ b/doc/flatpak-run.xml
@@ -113,6 +113,13 @@
ID of the running app.
</para>
<para>
+ Flatpak also bind-mounts as read-only the host's <filename>/etc/os-release</filename>
+ (if available, or <filename>/usr/lib/os-release</filename> as a fallback) to
+ <filename>/run/host/os-release</filename> in accordance with the
+ <ulink url="https://www.freedesktop.org/software/systemd/man/os-release.html">
+ os-release specification</ulink>.
+ </para>
+ <para>
If parental controls support is enabled, flatpak will check the
current user’s parental controls settings, and will refuse to
run an app if it is blocklisted for the current user.
diff --git a/tests/test-run.sh b/tests/test-run.sh
index fe6e9add..57740a3b 100644
--- a/tests/test-run.sh
+++ b/tests/test-run.sh
@@ -24,7 +24,7 @@ set -euo pipefail
skip_without_bwrap
skip_revokefs_without_fuse
-echo "1..16"
+echo "1..17"
# Use stable rather than master as the branch so we can test that the run
# command automatically finds the branch correctly
@@ -80,6 +80,28 @@ assert_file_has_content runtime-fpi "^runtime=runtime/org\.test\.Platform/$ARCH/
ok "run a runtime"
+if [ -f /etc/os-release ]; then
+ run_sh org.test.Platform cat /run/host/os-release >os-release
+ (cd /etc; md5sum os-release) | md5sum -c
+
+ ARGS="--filesystem=host-etc" run_sh org.test.Platform cat /run/host/os-release >os-release
+ (cd /etc; md5sum os-release) | md5sum -c
+
+ if run_sh org.test.Platform "echo test >> /run/host/os-release"; then exit 1; fi
+ if run_sh org.test.Platform "echo test >> /run/host/os-release"; then exit 1; fi
+elif [ -f /usr/lib/os-release ]; then
+ run_sh org.test.Platform cat /run/host/os-release >os-release
+ (cd /usr/lib; md5sum os-release) | md5sum -c
+
+ ARGS="--filesystem=host-os" run_sh org.test.Platform cat /run/host/os-release >os-release
+ (cd /usr/lib; md5sum os-release) | md5sum -c
+
+ if run_sh org.test.Platform "echo test >> /run/host/os-release"; then exit 1; fi
+ if run_sh org.test.Platform "echo test >> /run/host/os-release"; then exit 1; fi
+fi
+
+ok "host os-release"
+
if run org.test.Nonexistent 2> run-error-log; then
assert_not_reached "Unexpectedly able to run non-existent runtime"
fi