Repository navigation
Avoid exporting reserved directories more thoroughly / improve error reporting - #5213
Conversation
|
cc @RyuzakiKK |
|
Needs work: the warning "Unable to provide access to app-specific directory" is making some tests fail, because they're run with |
b97eab0 to
7566efa
Compare
7566efa to
2dfc2b3
Compare
b704302 to
f17bc58
Compare
|
This might have some minor conflicts with #5219 if that gets merged first, but is ready for review: |
f17bc58 to
8e93ddf
Compare
| }; | ||
|
|
||
| static void | ||
| cannot_export (FlatpakFilesystemMode mode, |
There was a problem hiding this comment.
Tiny bikeshed. I'd find this function more clear if it noted that its just a logging function.
print_cannot_export_error, log_cannot_export_error, etc
There was a problem hiding this comment.
Good thinking, I used log_cannot_export_error.
This will reduce conflicts when new entries are added. Helps: flatpak#5205 Signed-off-by: Simon McVittie <[email protected]>
These directories are reserved for Flatpak's own use. Helps: flatpak#5205 Signed-off-by: Simon McVittie <[email protected]>
Just for completeness, in practice the host system will not have this. Helps: flatpak#5205 Signed-off-by: Simon McVittie <[email protected]>
This is a step towards allowing its direct and indirect callers to decide how serious the failure is, and debug or warn accordingly. Helps: flatpak#5205 Signed-off-by: Simon McVittie <[email protected]>
8e93ddf to
4c7ad7e
Compare
This lets flatpak_context_export() or other callers decide how they want to handle failure to export each path. For now, the callers in FlatpakExports are still using g_debug() unconditionally, but we can now have somewhat better test coverage. Helps: flatpak#1357 Helps: flatpak#5035 Helps: flatpak#5205 Helps: flatpak#5207 Signed-off-by: Simon McVittie <[email protected]>
If the user gives us a override or command-line argument that we cannot obey, like --filesystem=/usr/share/whatever or --filesystem=/run/flatpak/whatever, then it's confusing that we silently ignore it. We should give them an opportunity to see that their override was ineffective. However, there are a few situations where we still want to keep quiet. If there is a --filesystem argument for something that simply doesn't exist, we don't diagnose the failure to share it: that avoids creating unnecessary noise for apps that opportunistically share locations that might or might not exist, like the way the Steam app on Flathub asks for access to $XDG_RUNTIME_DIR/app/com.discordapp.Discord. Similarly, if we have been asked for --filesystem=host, the root directory is very likely to contain symlinks into a reserved path, like /lib -> usr/lib. We don't need a user-visible warning for that. We actually use the equivalent of g_message() rather than g_warning(), to avoid this being fatal during unit testing (in particular when we do a `flatpak info` on an app that has never been run, which will be unable to share its `.var/app` subdirectory). `app/flatpak-main.c` currently displays them as equivalent to each other anyway. Signed-off-by: Simon McVittie <[email protected]>
If $HOME is below a reserved path (for example `/usr/home/thompson` for Unix traditionalists) or otherwise cannot be shared, or is a symbolic link to somewhere that cannot be shared, then we will end up running the app with $HOME not existing. This is unexpected, so we should make more noise about it. There are two situations here, both of which get a warning: if we have --filesystem=home or --filesystem=host then we are trying to share the real $HOME with the application, and if we do not, then we are trying to create a directory at the location of the real $HOME and replicate the chain of symlinks (if any) leading from $HOME to that location. Unlike the previous commit, this is not expected to happen during unit testing, so we do not use a g_warning() for this. Diagnoses: flatpak#5035 Signed-off-by: Simon McVittie <[email protected]>
Previously, --filesystem=/run would prevent apps from starting by breaking our ability to set up /run/flatpak and /run/host. Now it is ignored, with a diagnostic message, resolving flatpak#5205 and flatpak#5207. Similarly, --filesystem=/symlink-to-root (or --filesystem=host) would have prevented apps from starting if a symlink like `/symlink-to-root -> /` or `/symlink-to-root -> .` exists, and refusing to export the target of that symlink avoids that failure mode, resolving flatpak#1357. Resolves: flatpak#1357 Resolves: flatpak#5205 Resolves: flatpak#5207 Signed-off-by: Simon McVittie <[email protected]>
Reproduces: flatpak#5205 Reproduces: flatpak#5207 Signed-off-by: Simon McVittie <[email protected]>
Reproduces: flatpak#1357 Signed-off-by: Simon McVittie <[email protected]>
4c7ad7e to
fa005cd
Compare
|
I'll merge this when CI has finished. |
Signed-off-by: Simon McVittie <[email protected]>
Signed-off-by: Simon McVittie <[email protected]>
Signed-off-by: Simon McVittie <[email protected]>
If we try to share certain reserved directories with the sandbox, that can break our ability to set up sandbox-specific things: the app in
/app, the runtime in/usrand/etc, OS stuff in/devand/proc, and Flatpak-specific information in/.flatpak-info,/run/flatpakand/run/host.Previously, we would silently prevent descendants of most of these paths from being shared (#5035). We still prevent that, but now there is a warning so that users will be less mystified.
We did not previously prevent descendants of
/.flatpak-info,/run/flatpakand/run/hostfrom being shared, but now those three have joined the list.We also did not previously prevent ancestors of the reserved paths from being shared, which in practice manifested in two ways: a symlink like
/the-root -> /or/the-root -> .would prevent apps from being run successfully with--filesystem=hostor--filesystem=/the-root(#1357), and--filesystem=/runwould also fail. Now, both are prevented, with a warning in all cases except--filesystem=host:For
--filesystem=hostit seemed better for unsuitable top-level objects to be rejected silently (other than debug messages), so that there isn't a lot of noise for directories like/bin,/lib,/libx32or merged-/usr compat symlinks like/bin -> usr/bin,/lib -> usr/lib,/libx32 -> usr/libx32.exports, context: List unexported paths one per line in sorted order
This will reduce conflicts when new entries are added.
Helps: [Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start #5205
exports: Never try to export paths below /run/flatpak or /run/host
These directories are reserved for Flatpak's own use.
Helps: [Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start #5205
exports: Never try to export /.flatpak-info
Just for completeness, in practice the host system will not have this.
Helps: [Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start #5205
exports: Make _exports_path_expose produce a GError on failure
This is a step towards allowing its direct and indirect callers to decide
how serious the failure is, and debug or warn accordingly.
Helps: [Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start #5205
exports: Move error handling up into caller
This lets flatpak_context_export() or other callers decide how they want
to handle failure to export each path. For now, the callers in
FlatpakExports are still using g_debug() unconditionally, but we can now
have somewhat better test coverage.
Helps: bwrap: Can't mkdir parents for /run/host/usr: Permission denied #1357
Helps: Can't use with home directory in /usr: bwrap: Can't mkdir parents for /usr/people/home/$USER #5035
Helps: [Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start #5205
Helps: [Bug]: cannot share all of /run with a Flatpak app #5207
context: Show a warning when --filesystem exists but can't be shared
If the user gives us a override or command-line argument that we cannot
obey, like --filesystem=/usr/share/whatever or
--filesystem=/run/flatpak/whatever, then it's confusing that we silently
ignore it. We should give them an opportunity to see that their override
was ineffective.
However, there are a few situations where we still want to keep quiet.
If there is a --filesystem argument for something that simply doesn't
exist, we don't diagnose the failure to share it: that avoids creating
unnecessary noise for apps that opportunistically share locations that
might or might not exist, like the way the Steam app on Flathub asks
for access to $XDG_RUNTIME_DIR/app/com.discordapp.Discord.
Similarly, if we have been asked for --filesystem=host, the root
directory is very likely to contain symlinks into a reserved path, like
/lib -> usr/lib. We don't need a user-visible warning for that.
We actually use the equivalent of g_message() rather than g_warning(),
to avoid this being fatal during unit testing (in particular when we
do a
flatpak infoon an app that has never been run, which willbe unable to share its
.var/appsubdirectory).app/flatpak-main.ccurrently displays them as equivalent to each other anyway.
context: Show a warning if we cannot provide any $HOME
If $HOME is below a reserved path (for example
/usr/home/thompsonfor Unix traditionalists) or otherwise cannot be shared, or is a
symbolic link to somewhere that cannot be shared, then we will end
up running the app with $HOME not existing. This is unexpected, so
we should make more noise about it.
There are two situations here, both of which get a warning: if we have
--filesystem=home or --filesystem=host then we are trying to share the
real $HOME with the application, and if we do not, then we are trying
to create a directory at the location of the real $HOME and replicate
the chain of symlinks (if any) leading from $HOME to that location.
Unlike the previous commit, this is not expected to happen during unit
testing, so we do not use a g_warning() for this.
Diagnoses: Can't use with home directory in /usr: bwrap: Can't mkdir parents for /usr/people/home/$USER #5035
exports: Don't export parent or ancestor of reserved directories
Previously, --filesystem=/run would prevent apps from starting by
breaking our ability to set up /run/flatpak and /run/host. Now it is
ignored, with a diagnostic message, resolving [Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start #5205 and [Bug]: cannot share all of /run with a Flatpak app #5207.
Similarly, --filesystem=/symlink-to-root (or --filesystem=host) would
have prevented apps from starting if a symlink like
/symlink-to-root -> /or/symlink-to-root -> .exists, and refusingto export the target of that symlink avoids that failure mode,
resolving bwrap: Can't mkdir parents for /run/host/usr: Permission denied #1357.
Resolves: bwrap: Can't mkdir parents for /run/host/usr: Permission denied #1357
Resolves: [Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start #5205
Resolves: [Bug]: cannot share all of /run with a Flatpak app #5207
exports: Assert that recently-excluded paths are excluded
Reproduces: [Bug]: Some --filesystem options such as --filesystem=/run make Flatpak apps fail to start #5205
Reproduces: [Bug]: cannot share all of /run with a Flatpak app #5207
exports: Test that a symlink to the root directory is rejected
Reproduces: bwrap: Can't mkdir parents for /run/host/usr: Permission denied #1357