Repository navigation
Allow caller to supply a /usr to use instead of the runtime - #4018
Conversation
|
Client-side: flatpak/flatpak-xdg-utils#39 |
| if (g_file_query_exists (runtime_child, NULL)) | ||
| flatpak_bwrap_add_args (bwrap, | ||
| "--symlink", "usr/etc", "/run/runtime/etc", | ||
| NULL); |
There was a problem hiding this comment.
This will be a bit different from the regular /etc that would be if this was used as a runtime in the regular way. Still, probably right to have it there if there are things like relative symlinks pointing to it.
There was a problem hiding this comment.
Right; in particular, if we want to look at the runtime's /etc/ld.so.cache, we can't, unless we provide /etc. It would be possible to do the full /etc setup for both /etc and /run/runtime/etc, but that seemed like extra code for no real gain.
There was a problem hiding this comment.
(This is unchanged except for moving it to /run/parent/etc; I think it's still correct?)
| /* For now we assume that if the caller wanted to update the | ||
| * ld.so.cache, it would already have done so; that's certainly | ||
| * true for pressure-vessel. */ | ||
| use_ld_so_cache = FALSE; |
There was a problem hiding this comment.
This will also remove the use of the ld.so cache for the app. But I guess its not really possible to run in some "mixed mode".
There was a problem hiding this comment.
Yeah, I need to think about this some more.
Disabling the ld.so cache regeneration and relying on LD_LIBRARY_PATH to find the imported graphics drivers is definitely the conservative, learn-to-walk-before-we-run option, and is how pressure-vessel works right now.
I'm trying to teach pressure-vessel to generate its own ld.so.cache in its specially-prepared /usr when it launches games outside Flatpak, and I had thought that I'd be able to do that in pressure-vessel in the Flatpak case too, and hand it over to Flatpak already prepared - but now that I think about it more, I might not be able to do that without entering a container. If I can't, and I want to use a ld.so.cache, I'll have to either teach Flatpak to do that (in a way that is appropriate for the /usr I'm giving it), or put ld.so.cache somewhere that is modifiable by the subsandbox (to which the one in /etc would be a symlink) and tell the launched command to regenerate it before running the actual game.
The code in pressure-vessel that generates its own ld.so.cache also doesn't work yet (graphics drivers don't load successfully, and I haven't been able to pin down why).
There was a problem hiding this comment.
I looked at enabling the ld.so cache generation, but the logic for cache invalidation assumes that the ld.so.cache is based on the app deployment, the app extensions, the runtime deployment and the runtime extensions. To be able to do the cache invalidation correctly, the caller would have to be able to pass in unique identifiers for its /app and /usr that would be hashed into the ld.so.cache checksum.
However, the Steam container runtime is dynamically set up based on not just a runtime, but also the graphics driver stack that it's borrowing, which might come from the Flatpak runtime, the host system or some third location - so there's no obvious unique ID to give it, and in practice I'd just be generating a UUID, which would result in the ld.so cache being invalidated and regenerated every time. The Steam runtime is also not stored in a content-addressed way, so we can't really rely on it not being modified locally.
Do we want to go to those lengths?
There was a problem hiding this comment.
The ld.so cache generation code also makes some assumptions about the ld.so.conf and ld.so.cache setup, such as "it's appropriate to enable all the extensions" and "we'll use /run/flatpak/ld.so.conf.d/runtime-*.conf" - although those are things I could work around in the runtime, if I need to.
| if (!flatpak_run_add_extension_args (bwrap, runtime_metakey, runtime_ref, use_ld_so_cache, &runtime_extensions, cancellable, error)) | ||
| if (!flatpak_run_add_extension_args (bwrap, runtime_metakey, runtime_ref, | ||
| use_ld_so_cache, | ||
| (runtime_files == original_runtime_files), |
There was a problem hiding this comment.
I understand why you would not want to update LD_LIBRARY_PATH based on extensions here if the runtime is not on /usr. However, this looses information that would be needed if you were to try to use the extensions from /run/runtime. Maybe we need to propagate this info somewhere else? RUNTIME_LD_LIBRARY_PATH?
There was a problem hiding this comment.
Maybe we could write it into /.flatpak-info? It probably doesn't need to be an environment variable.
My intention was that pressure-vessel will build a modified /usr containing exactly the files it needs, where each file is either a hard link to a pristine Steam Runtime file, a symlink into /run/host or a symlink into /run/runtime. It will need to know the layout of the extensions while building that modified /usr before launching the container, at which time they are Steam's and pressure-vessel's /usr, but the launched game will not need to know that.
There was a problem hiding this comment.
True, you will need it before the .flatpak-info (or RUNTIME_LD_LIBRARY_PATH) is filled anyway, so maybe exposing this is not so important.
There was a problem hiding this comment.
I haven't taken action for this so far.
|
|
||
| if (!flatpak_run_add_app_info_args (bwrap, | ||
| app_files, app_deploy_data, app_extensions, | ||
| runtime_files, runtime_deploy_data, runtime_extensions, |
There was a problem hiding this comment.
I think this is right, but we should perhaps add a new field to the flatpak-info file so you can tell what /usr is.
There was a problem hiding this comment.
Yes, I think that makes sense. I think the Steam-launched subsandbox should look like this:
- "official" runtime:
org.freedesktop.Platform/x86_64/20.08(or whatever version Steam is using by the time we land this) - replacement
/usr:/home/me/.var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps/common/SteamLinuxRuntime_soldier/var/tmp-abcdef/usr
instead of pretending the runtime is com.valvesoftware.SteamRuntime.Platform/x86_64/soldier - which it sort of is, but Flatpak has no good way to know it can trust a string supplied by pressure-vessel.
There was a problem hiding this comment.
In the next revision of this branch I'm going to make it look something like this:
[Application]
name=com.valvesoftware.Steam
runtime=runtime/org.freedesktop.Platform/x86_64/20.08
[Instance]
app-path=
original-app-path=/var/lib/flatpak/app/.../files
runtime-path=/home/me/.../SteamLinuxRuntime_soldier/var/tmp-abcdef/usr
original-runtime-path=/var/lib/flatpak/runtime/.../files
where app-path= denotes "an empty directory on a tmpfs".
Similarly, flatpak run --app-path=/tmp/app would come out as app-path=/tmp/app.
The other possibility would be to set app-path and runtime-path to the "official" app and runtime files, and have a new replacement-app-path and replacement-usr-path, like this:
[Application]
name=com.valvesoftware.Steam
runtime=runtime/org.freedesktop.Platform/x86_64/20.08
[Instance]
app-path=/var/lib/flatpak/app/.../files
replacement-app-path=
runtime-path=/var/lib/flatpak/runtime/.../files
replacement-usr-path=/home/me/.../SteamLinuxRuntime_soldier/var/tmp-abcdef/usr
but I think that has a worse compatibility story for existing versions of xdg-desktop-portal, which is the only user I can find of those fields.
|
Added some comments + this needs rebasing as the other PRs landed. But overall this looks good to me. There is some portal fallout though. In xdp_app_info_remap_path() in xdg-desktop-portal we rewrite paths on /usr. It would need to also rewrite stuff on the "new" /usr (and maybe /run/runtime too). |
|
I don't know yet whether I'm going to make pressure-vessel default to taking graphics drivers from Graphics drivers from Graphics drivers from |
|
Still WIP, and basically untested, but getting closer. I've added another feature that I'll need for Steam:
This adds |
|
Overall I think this looks good, although I'd like to add the replacement /usr in |
|
I'm taking a much-needed break from my Steam-related work until early January, at which point I will be resuming work on this change and the corresponding changes in pressure-vessel (unless it gets preempted by something higher-priority). From memory: This is likely to need some changes before it works well enough to support SteamLinuxRuntime. At the moment, the pressure-vessel side of this change relies on being able to set the I think we will also need to ignore the The other thing Steam is going to need, which I haven't attempted to resolve yet, is the ability to share a single |
This will be useful for Steam's pressure-vessel container tool. The IPC between Steam games and the Steam client relies on process IDs, and becomes confused if they don't match up. This weakens the security boundary between a subsandbox and the parent, but that's OK in some cases, particularly if the subsandbox is being used as a way to get a different runtime /usr (flatpak#4018) rather than as a security boundary. Signed-off-by: Simon McVittie <[email protected]>
As with flatpak run --parent-expose-pids, this will only work if we have a working, non-setuid bwrap. Systems where user namespace creation is restricted and bwrap needs to be setuid (Debian 10, RHEL/CentOS 7, Arch Linux linux-hardened kernel) will have degraded functionality. This option is similar to --expose-pids, except that instead of making the subsandbox use a nested pid namespace inside the parent's, it makes the subsandbox share the parent's pid namespace as-is, so that process IDs in the parent and the subsandbox are interchangeable. This will be useful if the parent and the subsandbox communicate via protocols that assume a global view of the process ID namespace, for example passing process IDs across an AF_UNIX socket or in shared memory. In particular, this will be useful for Steam's pressure-vessel container tool: the IPC between the Steam client and the "game overlay" loaded into Steam games uses process IDs, and becomes confused if they don't match up. This weakens the security boundary between a subsandbox and the parent, but that's OK in some cases, especially if the subsandbox is being used as a way to get a different runtime /usr (flatpak-spawn --latest-version or flatpak#4018) rather than as a security boundary. Signed-off-by: Simon McVittie <[email protected]>
731932e to
cd1cec0
Compare
|
I have now launched a real game with this for the first time! 🎉 Unfinished:
|
As with flatpak run --parent-expose-pids, this will only work if we have a working, non-setuid bwrap. Systems where user namespace creation is restricted and bwrap needs to be setuid (Debian 10, RHEL/CentOS 7, Arch Linux linux-hardened kernel) will have degraded functionality. This option is similar to --expose-pids, except that instead of making the subsandbox use a nested pid namespace inside the parent's, it makes the subsandbox share the parent's pid namespace as-is, so that process IDs in the parent and the subsandbox are interchangeable. This will be useful if the parent and the subsandbox communicate via protocols that assume a global view of the process ID namespace, for example passing process IDs across an AF_UNIX socket or in shared memory. In particular, this will be useful for Steam's pressure-vessel container tool: the IPC between the Steam client and the "game overlay" loaded into Steam games uses process IDs, and becomes confused if they don't match up. This weakens the security boundary between a subsandbox and the parent, but that's OK in some cases, especially if the subsandbox is being used as a way to get a different runtime /usr (flatpak-spawn --latest-version or #4018) rather than as a security boundary. Signed-off-by: Simon McVittie <[email protected]>
This was also resolved (possibly in e2c4ded?) as a follow-up to resolving CVE-2021-21261. Now the app (pressure-vessel) gets to choose all environment variables for the subsandbox, including PATH and LD_LIBRARY_PATH. |
We'll probably need the same for Steam already has |
In the next rev I'm going to rename |
|
Confirming this seems to work, tried several Proton games. Great job, @smcv! The only problem noticed is that Proton running in pressure-vessel refuses to use discrete GPU unless I specify |
Great! Thank you for not describing exactly how you did this - at the moment, I don't want people trying it unless they are sufficiently technical to be able to figure out how it works from the source code (the time taken to deal with confused bug reports from people following a recipe they don't understand would be detrimental to getting this feature landed).
I think this is a more general problem with pressure-vessel: we've had ongoing issues with multi-GPU systems, and we don't completely understand what is going on with those systems. Vulkan multi-GPU is complicated and I don't currently have access to a multi-GPU system that is sufficiently new for Vulkan to work, so I'm completely dependent on user reports, many of which are incomplete or confused. Future releases will hopefully improve on this. You might find that running with It might also be to do with one of NVIDIA's Vulkan layers apparently not being present (see flathub/org.freedesktop.Platform.GL.nvidia#35). When we have an actual release that you can test against, I'll ask you for some more targeted information. If you're able to run Steam unsandboxed (perhaps as a separate user account if you don't want it running unsandboxed under your main uid) then it would be useful to compare its behaviour as a Flatpak and unsandboxed. |
Well, it didn't work for me. These variables do work for native games, proton ≤ 5.0 and the "community" proton 5.13 build, but not for official proton 5.13 running in pressure-vessel. |
| "/run/parent"); | ||
|
|
||
| g_clear_object (&runtime_child); | ||
| runtime_child = g_file_get_child (runtime_files, "etc"); |
There was a problem hiding this comment.
Shouldn't this be original_runtime_files?
When we add a way to specify a different /usr for a subsandbox, we'll want to mount the "official" runtime elsewhere and avoid adding it to the LD_LIBRARY_PATH. Signed-off-by: Simon McVittie <[email protected]>
Signed-off-by: Simon McVittie <[email protected]>
The pressure-vessel container tool in Steam will want to use this, to replace /usr with a Steam Runtime container supplied by the Steam CDN, instead of using the same Flatpak runtime that is used to run the Steam client and non-containerized games. If a custom /usr is used, the "official" Flatpak runtime is still the one reflected in the metadata. It is also mounted at /run/parent, with all its extensions, so that pressure-vessel has the option of using its graphics drivers (by populating the custom /usr with symlinks into /run/parent and/or /run/host). When doing this, we need to put an empty directory on /app, because the real /app expects to be run on top of the real runtime. It would also be reasonable to substitute a custom replacement for /app, so I've included support for that too. Partially addresses flatpak#3797. Signed-off-by: Simon McVittie <[email protected]>
|
Testing this against Steam's containers, I confirm that it does work, with some limitations. Native Linux game in a container
Run Life is Strange. An You can use A log file for pressure-vessel (subsandbox) startup can be found in Known issue: pressing Shift+Tab to get the Steam overlay doesn't do anything. This is not expected to work until #4093 and #4214 land in Flatpak - I think it needs to see the same Comparison: if you disable the compatibility tool and run Life is Strange directly, as an ordinary native Linux game, it will run in the same Flatpak sandbox and the same systemd scope as Steam itself. Windows game with Proton, in a container
This time, the pressure-vessel log file appears in You can use By default, Proton's log file from Known issue: Shift+Tab for Steam overlay doesn't work, as above. Comparison: if you set the compatibility tool to Proton 5.0 or older, it will run in the same Flatpak sandbox and the same systemd scope as Steam itself. In this case the Steam overlay does work. |
The "setup commands" stage (installing Windows runtime libraries, setting registry keys, etc.) might well be failing as a result of the We used to be completely reliant on We are still going to need #4091 (as implemented in #4093 and #4214) for this to be anything like production-quality, because not having it breaks the Steam Overlay, and increasingly much Steam functionality relies on the overlay to be working. |
|
Thanks for explanation. Should we set up a shared directory under |
That's an interesting idea, but we need to get #4091 fixed anyway, which will mean we won't need that. Increasingly many Steam features need the Steam overlay, so if we enable this without a working overlay, we'll just be spending time dealing with issue reports like "game controller doesn't work" and "Remote Play doesn't work", which is time we can't spend on actually fixing things. |
Steam's pressure-vessel tool will use this to launch a parallel container with /usr supplied by the Steam Runtime, and an empty /app. This is a client-side for <flatpak/flatpak#4018>. Signed-off-by: Simon McVittie <[email protected]>
This is a client-side for <flatpak/flatpak#4018>. Steam's pressure-vessel tool does the equivalent of this to launch a parallel container with /usr supplied by the Steam Runtime, and an empty /app, although currently it has to use code derived from flatpak-spawn rather than using the runtime's copy of flatpak-spawn. Signed-off-by: Simon McVittie <[email protected]>
This is a client-side for <flatpak/flatpak#4018>. Steam's pressure-vessel tool does the equivalent of this to launch a parallel container with /usr supplied by the Steam Runtime, and an empty /app, although currently it has to use code derived from flatpak-spawn rather than using the runtime's copy of flatpak-spawn. Signed-off-by: Simon McVittie <[email protected]>
Part of #3797.
flatpak_run_add_extension_args: Give caller more control
When we add a way to specify a different /usr for a subsandbox, we'll
want to mount the "official" runtime elsewhere and avoid adding it
to the LD_LIBRARY_PATH.
flatpak_run_setup_usr_links: Add control over the mount point
run: Allow caller to replace /app and/or /usr
The pressure-vessel container tool in Steam will want to use this, to
replace /usr with a Steam Runtime container supplied by the Steam CDN,
instead of using the same Flatpak runtime that is used to run the Steam
client and non-containerized games.
If a custom /usr is used, the "official" Flatpak runtime is still the
one reflected in the metadata. It is also mounted at /run/parent,
with all its extensions, so that pressure-vessel has the option of using
its graphics drivers (by populating the custom /usr with symlinks into
/run/parent and/or /run/host).
When doing this, we need to put an empty directory on /app, because
the real /app expects to be run on top of the real runtime. It would
also be reasonable to substitute a custom replacement for /app, so
I've included support for that too.
Partially addresses Ability to subsandbox Steam games, with a different runtime #3797.