Repository navigation
Share /tmp between instances of the same app - #4093
Conversation
|
v2 (ec77505): documented the new fields in flatpak-metadata(5). |
|
v3 (e0fb9ce): rewrite to share these directories between all instances, not just a main app and subsandboxes. |
|
Latest version also resolves #4120, but probably needs some more thought. |
|
Looks like this went far beyond pressure-vessel support and now is going to fix a bunch of long-lasting issues. That's really cool. |
|
So is this is still opt-in? |
Yes, because opt-in is more code than not opt-in. If I test and submit a PR where it's opt-in, but maintainers want it to be applied to all apps, then I can delete the feature flag quickly and the PR will be ready. If I test and submit a PR where it's applied to all apps, but maintainers want it to be opt-in, it would take me longer to add the feature flag back in. I do not have any particular opinion on whether it should be opt-in or not, I'm going by what @alexlarsson told me to do. |
Do you think it's sufficient fixing stuff like #4120 only per opt-in basis? Main argument against opt-in is that it doesn't really fix anything without additional effort to change every app separately while that effort may be easily avoided without a downside. Do you disagree with this? As Filippe wrote above this work is more about fixing long standing bugs/issues rather than introducing new feature. |
|
@Erick555 I guess opt-in is still much better than nothing. And indeed this can be reconsidered and made default in future. |
That one is actually not opt-in as currently implemented, just At the moment I'm fairly sure I'm creating the per-app-ID XDG_RUNTIME_DIR in a more complicated way than I needed to in this version of the branch, but I ran out of time on Friday - I'll come back to it next week. |
|
Fine, when you find some time please update description from first post to show current state of this work, thx. |
If we want to provide a per-app-ID XDG_RUNTIME_DIR (flatpak#4120) or a per-app-ID /tmp or /dev/shm (flatpak#4093) then we'll need somewhere to put them. Unlike $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this should be somewhere that is *not* accessible to the app, so that we can trust its contents. Signed-off-by: Simon McVittie <[email protected]>
Fixed, and moved to #4126. |
|
With some more testing: this seems to work as intended. I need to do more on the pressure-vessel side to make it compatible with Steam, but I think this part is solved, so this change is ready to be reviewed. |
|
Other than the out value this looks good to me. |
Previously, this only had to consider two situations: either an instance is still running (alive), or it is not (dead). When we start sharing directories between all instances of a particular app-ID (flatpak#4120, flatpak#4093), we'll also need to consider whether instances share an app-ID, expanding the test to three situations: either an instance is still running (alive), or it has exited but shares its app-ID with a different instance that is still running (the app is alive but the instance is dead, abbreviated here as alive_dead), or it has exited and does not share its app-ID with any running instances (dead). Signed-off-by: Simon McVittie <[email protected]>
If we want to provide a per-app-ID XDG_RUNTIME_DIR (flatpak#4120) or a per-app-ID /tmp or /dev/shm (flatpak#4093) then we'll need somewhere to put them. Unlike $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this should be somewhere that is *not* accessible to the app, so that we can trust its contents. Signed-off-by: Simon McVittie <[email protected]>
Signed-off-by: Simon McVittie <[email protected]>
Signed-off-by: Simon McVittie <[email protected]>
Previously, this only had to consider two situations: either an instance is still running (alive), or it is not (dead). When we start sharing directories between all instances of a particular app-ID (flatpak#4120, flatpak#4093), we'll also need to consider whether instances share an app-ID, expanding the test to three situations: either an instance is still running (alive), or it has exited but shares its app-ID with a different instance that is still running (the app is alive but the instance is dead, abbreviated here as alive_dead), or it has exited and does not share its app-ID with any running instances (dead). Signed-off-by: Simon McVittie <[email protected]>
If we want to provide a per-app-ID XDG_RUNTIME_DIR (flatpak#4120) or a per-app-ID /tmp or /dev/shm (flatpak#4093) then we'll need somewhere to put them. Unlike $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this should be somewhere that is *not* accessible to the app, so that we can trust its contents. Signed-off-by: Simon McVittie <[email protected]>
If we want to provide a per-app-ID XDG_RUNTIME_DIR (flatpak#4120) or a per-app-ID /tmp or /dev/shm (flatpak#4093) then we'll need somewhere to put them. Unlike $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this should be somewhere that is *not* accessible to the app, so that we can trust its contents. Signed-off-by: Simon McVittie <[email protected]>
This combines the functionality of flatpak_context_get_exports() and its open-coded version in flatpak_context_append_bwrap_filesystem(). Signed-off-by: Simon McVittie <[email protected]>
flatpak_context_get_exports_full() previously copied the interface of flatpak_context_export(), which appended entries to a caller-supplied GString, but it's a more GLib-style API if we use an "out" argument. Signed-off-by: Simon McVittie <[email protected]>
A subsequent commit will need to look at the FlatpakExports before we are ready to append their arguments to the FlatpakBwrap. Signed-off-by: Simon McVittie <[email protected]>
This allows apps that use /tmp as an IPC rendezvous point, such as those that embed Chromium-derived browsers, to communicate between instances; this would not previously have worked without --filesystem=/tmp, which is a significant weakening of the sandbox. It also allows /tmp to be shared with subsandboxes (if they are not sandboxed more strictly). The temporary directory is actually created in XDG_RUNTIME_DIR, to avoid it becoming visible to unrelated apps that happen to have --filesystem=/tmp. Signed-off-by: Simon McVittie <[email protected]>
|
Ready for re-review. If you're happy with the first three commits "utils: Add flatpak_str_is_integer()", "run: Mark some preconditions around the app ID" and "test-instance: Provide app-IDs for our mock apps" but work is still needed on subsequent commits, please let me know and I can get those first three merged. |
Previously, this only had to consider two situations: either an instance is still running (alive), or it is not (dead). When we start sharing directories between all instances of a particular app-ID (#4120, #4093), we'll also need to consider whether instances share an app-ID, expanding the test to three situations: either an instance is still running (alive), or it has exited but shares its app-ID with a different instance that is still running (the app is alive but the instance is dead, abbreviated here as alive_dead), or it has exited and does not share its app-ID with any running instances (dead). Signed-off-by: Simon McVittie <[email protected]>
If we want to provide a per-app-ID XDG_RUNTIME_DIR (#4120) or a per-app-ID /tmp or /dev/shm (#4093) then we'll need somewhere to put them. Unlike $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this should be somewhere that is *not* accessible to the app, so that we can trust its contents. Signed-off-by: Simon McVittie <[email protected]>
If we call this after flatpak_run_add_app_info_args(), then the garbage-collection code will have a chance to run, cleaning up after a previous instance of the same app. In a previous implementation of flatpak#4093 that also implemented flatpak#4120, we had to allocate the per-app directory this early to avoid shadowing the XDG_RUNTIME_DIR allocated in flatpak_run_add_app_info_args(), but I'm taking a different approach to that now. Signed-off-by: Simon McVittie <[email protected]>
If we call this after flatpak_run_add_app_info_args(), then the garbage-collection code will have a chance to run, cleaning up after a previous instance of the same app. In a previous implementation of #4093 that also implemented #4120, we had to allocate the per-app directory this early to avoid shadowing the XDG_RUNTIME_DIR allocated in flatpak_run_add_app_info_args(), but I'm taking a different approach to that now. Signed-off-by: Simon McVittie <[email protected]>
Part of #4091.
Design
This no longer depends on #4126, and instead contains the parts of #4126 that it needs, so that we can try to land this feature without being blocked by the concerns about symlink attacks in the
XDG_RUNTIME_DIR.The
g_get_user_runtime_dir()on the host now looks like this:The shared
/tmpis only used forflatpak run, not forflatpak build(which reinvents a lot offlatpak_run_app()), and also not forapply_extra.Whenever we garbage-collect the numbered per-instance directories, we check their app info. If an instance is disappearing, we attempt to garbage-collect the corresponding
tmpif no apps are still using them.The shared
/tmpis backed by a directory ing_get_user_runtime_dir(), so that unrelated Flatpak apps that happen to have--filesystem=/tmpdon't see it.g_get_user_runtime_dir()will usually be atmpfs(except on systems using e.g.sysvinitto boot).The per-app-ID directory and the
.reffile are never garbage-collected, to avoid defeating the locking scheme:$XDG_RUNTIME_DIR/.flatpak/will contain one subdirectory for each app that the user has run during the current session, each containing an empty.reffile. These will normally get cleaned up when the user fully logs out (at the transition from 1 to 0 concurrent login sessions).Commits
Best reviewed commit-by-commit, I think.
utils: Add flatpak_str_is_integer() (previously part of Create a shared XDG_RUNTIME_DIR for each app-ID #4126)
run: Mark some preconditions around the app ID
test-instance: Provide app-IDs for our mock apps
Previously, this only had to consider two situations: either an instance
is still running (alive), or it is not (dead).
When we start sharing directories between all instances of a particular
app-ID (Multiple instances of the same app don't share XDG_RUNTIME_DIR #4120, Share /tmp between instances of the same app #4093), we'll also need to consider whether instances
share an app-ID, expanding the test to three situations: either an
instance is still running (alive), or it has exited but shares its
app-ID with a different instance that is still running (the app is
alive but the instance is dead, abbreviated here as alive_dead),
or it has exited and does not share its app-ID with any running
instances (dead).
instance: Create and destroy per-app-ID subdirs of XRD/.flatpak
If we want to provide a per-app-ID XDG_RUNTIME_DIR (Multiple instances of the same app don't share XDG_RUNTIME_DIR #4120) or a
per-app-ID /tmp or /dev/shm (Share /tmp between instances of the same app #4093) then we'll need somewhere to put
them. Unlike $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this should be somewhere
that is not accessible to the app, so that we can trust its contents.
context: Factor out flatpak_context_get_exports_full()
This combines the functionality of flatpak_context_get_exports() and its
open-coded version in flatpak_context_append_bwrap_filesystem().
context: Build xdg_dirs_conf as an "out" argument
flatpak_context_get_exports_full() previously copied the interface of
flatpak_context_export(), which appended entries to a caller-supplied
GString, but it's a more GLib-style API if we use an "out" argument.
common: Separate creation of FlatpakExports from append_bwrap_filesystem
A subsequent commit will need to look at the FlatpakExports before
we are ready to append their arguments to the FlatpakBwrap.
run: Share /tmp between all instances of an app-ID
This allows apps that use /tmp as an IPC rendezvous point, such as those
that embed Chromium-derived browsers, to communicate between instances;
this would not previously have worked without --filesystem=/tmp, which
is a significant weakening of the sandbox.
It also allows /tmp to be shared with subsandboxes (if they are not
sandboxed more strictly).
The temporary directory is actually created in XDG_RUNTIME_DIR,
to avoid it becoming visible to unrelated apps that happen to have
--filesystem=/tmp.