Repository navigation
Description
This is a query about what enhancements would be considered if they came in as PRs from me or my colleagues, rather than a request for Flatpak maintainers to write new code. We intend to prepare Flatpak PRs for what we need, but obviously I don't want to waste your time on reviewing things that can't work or aren't considered a valid change.
Recent versions of Steam can optionally put each game in its own container, using a Flatpak-derived tool named pressure-vessel. This is currently exposed to users as "Steam Linux Runtime". The hope is to be able to use this for newer games as a way to build the game itself in a more modern runtime environment (possibly Debian 10-based for Steam Runtime 2, but if this works well there'll be more versions in future), which it will get instead of the Ubuntu-12.04-derived "scout" runtime currently used for both "Steam Linux Runtime" containers and traditional non-containerized games.
We cannot just use the same runtime that Steam itself is running under, because old games need to continue to run in their old runtimes, while new games run in new runtimes. Because we take some libraries from the host system to support their matching graphics drivers, these runtimes also need to be set up on-demand (in a directory owned by the Steam client) instead of being static.
At the moment, this doesn't and can't work under Flatpak, because Flatpak apps aren't allowed to create nested containers. I'd like to make this work, so that the Flathub app for Steam can remain almost as featureful as installing onto the host system even when games start relying on the newer runtimes. A natural way to make this happen would be to put a container alongside Steam's instead. We're currently trying to prototype this by disabling the Flathub Steam app's sandbox restrictions and using flatpak-spawn --host, but obviously that's a massive hole in the sandbox, so when we get past the proof-of-concept stage, we'd prefer to use the sub-sandboxing that was added for things like WebKit.
One reason why this is needed is that when games start relying on the newer, container-only runtimes, if the Flathub Steam app can't launch those games, it becomes decreasingly useful. The other major advantage of this for the Flathub Steam app is that it reduces the support burden for games not working in the current sandbox/runtime environment: for future games that have been flagged to use the container runtime, the way the game runs in "native Steam" and the way the game runs in the Flathub Steam app will be as similar as possible, so if it works during the developer's or Valve's QA, it'll probably also work in the Flathub Steam app's sub-sandbox. There might also be a mechanism to flag older games as preferring the container runtime after successful testing, similar to the way specific Windows games can be flagged to play under a suitable version of Proton by either their developers or community feedback, without requiring end-user intervention.
Before we go beyond the flatpak-spawn --host prototype, I'd like to explore how much new functionality in Flatpak this would need, how much of this is even implementable, and whether there's any of it that is technically implementable but would not be accepted.
The things I can think of right now are:
-
The Steam client's subprocesses need to be able to build the runtime's /usr (and associated directories: /bin, /sbin, /lib, /libQUAL) in either its own namespace or a directory that it shares with the host, and tell the Flatpak portal "instead of a runtime from ostree, use this". If it's forced to be a merged /usr like the real Flatpak runtimes, we can live with that, but the ability to use an unmerged-/usr would be straightforward to implement and nicer for debugging, because for historical reasons we have to ship an unmerged-/usr SDK.
-
For symmetry, and because the Flathub Steam app's
/appis designed to work on a fd.o runtime that isn't the same as the game's runtime, it would probably be best if we can also tell the Flatpak portal "instead of/appfrom ostree, use this" (in practice probably an empty directory). -
To set the runtime up, the Flathub version of the Steam client will need to gain at least
--filesystem=host-os:ro, and possibly--filesystem=host-etc:ro(or if not that, then expanding the definition ofhost-osto encompass a few extra files, especially on exotic Linux distros like Exherbo). I hope that wouldn't be controversial? -
One possible alternative to the host graphics stack would be to take the graphics stack from the Steam client's sandbox (which we know is good enough in practice for "most" games, even if it isn't quite as shiny as the host's). I don't know how workable that is. If we went that route, we would have to mount the Steam client's complete i386 and x86_64 library stacks, including GL extensions if any, into the sub-sandbox in a way that is analogous to
host-os- perhaps the same structure ashost-os, but in/run/parent-app/{app,usr}instead of/run/host/usr. -
The sub-sandbox will need access to the Steam client's
$HOME(which is really~/.var/app/com.valvesoftware.Steam), and all other--filesystemthat the Steam client can see. I think sub-sandboxes already do this, but I'm mentioning it for completeness. -
Some IPC unfortunately assumes that process IDs are suitable for the Steam client and games to refer to each other, so it would be best if the Steam client and the game were in the same pid namespace. Am I right in thinking that this currently only works on systems where bubblewrap does not need to be setuid?
-
Some IPC unfortunately assumes that /tmp is shared between the Steam client and the game (similar to the way X11, XIM, ICE, tmux use /tmp as a rendezvous point). So we'd likely need one of these:
- sharing
/tmpbetween the host, Steam and the subsandbox (--filesystem=/tmp); - sharing
/tmpbetween Steam and the subsandbox (another new mechanism)
- sharing
Behind-the-scenes mechanisms we'll likely need for those:
-
We need a way for the original sandbox (Steam) to give the Flatpak portal a secure reference to part of its filesystem namespace, so that the Flatpak portal can turn that into a fully-qualified host path and inject it into the container. I've had some thoughts about how to set this up with fd-passing; it's complicated by the fact that
mount(2)is path- rather than fd-based, but I'm hoping some tricks withopenat(),O_PATHandO_NOFOLLOWcan make it unforgeable. -
We might end up passing enough fds that the number of fds in the message becomes a robustness concern with my D-Bus-maintainer hat on (the current limit is 64 per message, but that might need to reduce if it turns out to be a denial-of-service problem), so we might need a way to submit fds to the portal a few at a time, and then say "see these previously-sent fds for details..." in the message that actually creates the sandbox.
Does any of that seem problematic?
I have contacts who can ask for changes in the proprietary part of Steam if there are things that particularly block us, but there's no guarantee that those changes will happen, particularly if they're intrusive or numerous, so we need to pick our battles.
Activity
smcv commentedon Aug 13, 2020
Something we might try to do as a follow-up for this would be using a per-game home directory distinct from the one used for the Steam client, with selected directories from the Steam client's
--persistdirectory mounted over the top - the current non-Flatpak-compatible prototype of this uses Flatpak-style directories like~/.var/app/com.steampowered.App12345, as though each Steam game was a separate app. That would require the Flatpak portal to let us specify what to mount as$HOME, and which paths below$HOMEto bind-mount from the Steam client's namespace. However, that's a lower priority, and very experimental even in the absence of Flatpak.smcv commentedon Aug 13, 2020
I forget whether I've linked this before, but here are some of the things we're hoping to achieve in this area: https://github.com/ValveSoftware/steam-runtime/blob/master/doc/goals.md
nanonyme commentedon Aug 13, 2020
smcv commentedon Aug 13, 2020
Absolutely - of the three entities involved (host, Steam client app and game subsandbox), it's only the Steam client app and the game subsandbox that need to share stuff, with some targeted exceptions for places where the Steam client and/or the games communicate with non-Steam things (like reading ~/Music).
smcv commentedon Aug 13, 2020
The intention is that the default for the long tail of games of unknown status is always the current arrangement, and it's only games that are known to be particularly well-behaved (like Team Fortress 2) that might get flagged to run in a scout container.
smcv commentedon Aug 13, 2020
I'm aware. By default, pressure-vessel shares the whole home directory as-is, so that anything that works with no container will also work with the container.
In the "one home directory per game" mode, which I'll repeat is considered very experimental, it makes sure to reset XDG_FOO_HOME to their default values from the basedir spec (
~/.configand so on), inspired by the solution you settled on for the Flathub app, so that it doesn't matter whether the game has implemented the basedir spec correctly or just hard-coded~/.config.Steam Cloud doesn't currently work with this mode anyway, because it doesn't yet have any knowledge of the private home directories - that's something that would have to be changed in the proprietary Steam client before that experimental mode could ever become non-experimental.
nanonyme commentedon Aug 13, 2020
Hm, you mean pressure-vessel allows full home write access to all of the games? Or sandboxed home? From security perspective currently real home is only exposed in very limited fashion and even there only as read-only.
smcv commentedon Aug 13, 2020
When run without Flatpak, pressure-vessel isn't currently intended to be a security boundary: any restrictions it puts on reads or writes are about making games behave more predictably, not about distrusting malicious/compromised games. If it later gets a mode where it is a security boundary, that'll definitely break some games, so it'll have to be opt-in.
When run with Flatpak, currently it doesn't work at all, which is what we're trying to fix.
The proof-of-concept with
flatpak-spawn --hostis only a proof of concept, and is totally insecure. It isn't meant to ship or be used with non-disposable Steam accounts, only to demonstrate that it can work in some form.For an actually useful version of Flatpak + pressure-vessel, what we would want to share with the games is the same "view" of the home directory that is seen by the Steam client, whatever that means (so mostly the
--persist=.directory, with some very limited ro or rw mounts from the real home). The security properties should be identical to the game running directly in the Steam client's main sandbox, like they do now.alexlarsson commentedon Aug 17, 2020
The whole steam-in-flatpak setup in general, and the integration with pressure-vessel in particular is quite complicated, and I can't really speak with any sort of high certainty about these things without spending a lot of time on it. However, in general I thing these are good things to have, because being able to support steam (as well as webkit/chrome) well in a flatpak is very important to us.
As a general point we try to avoid having the sandbox restructure the filesystem hierarchy as much as possible (as opposed to just subsetting it), because I feel that doing so makes for a poor user experience (when paths in the UI mean different things) and because that could potentially be used to trick some other code in an attack. Obviously we do rearrange some things, such as what
/usrand/app, but those are in fixed places. So, allowing the parent to set up what is /usr and /app of a child seems ok to me, but I'd rather we do so in a limited way than completely free-form bind-mount setups, which means that we might need to limit setups to be merged-usr./run/parent-appisn't immediately problematic, although the naming doesn't allow multi-level containers (although that is maybe a good thing).And yes, sharing pid namespace happens by attaching to the old one rather than spawning as a child namespace of the old one, so that will only work in the non-setuid case.
As for
/tmpsharing, it seems better to have a way to share tmp between app and child rather than sharing the host one, but its possibly hard in practice, as that tmpfs is not typically visible on the host side. Would need some research.smcv commentedon Aug 17, 2020
Thanks, those sound like constraints we can work with! Expect some PRs to implement parts of this puzzle when we have figured out how.
Technically it is visible on the host side, but only via
/proc/$pid/root, which will be tricky to deal with because that's a "magic symlink" -readlink()says it points to/, but opening it as a directory gives you the other process's root directory instead of your own, and I'm not sure how to turn that into something you canmount(2).alexlarsson commentedon Aug 18, 2020
/proc/$pid/rootis sometimes tricky when you're using a setuid bwrap, but I think it works with the latest flatpak.run: Allow caller to supply a /usr to use instead of the runtime
portal: Allow specifying a replacement for /usr
run: Allow caller to supply a /usr to use instead of the runtime
portal: Allow specifying a replacement for /usr, and sharing pidns
22 remaining items
gasinvein commentedon Apr 16, 2021
This became pretty tricky after 495449d. I had to revert this commit to be able to run matching
flatpakandflatpak-portalbinaries without installation. I guess installing to some/usr/localis the only option otherwise.smcv commentedon Apr 19, 2021
Yeah, I noticed that. I might add an option for an override.
TiZ-HugLife commentedon Apr 27, 2021
After getting the Flatpak 1.11.1 update via the PPA for Xubuntu 20.04, I switched the client, SLR, and SLR Soldier to beta, and was able to run SoulCalibur VI with the standard distribution of Proton 6.3. Controller input, MangoHud, and even NVIDIA render offload all work just fine! 🎉 I also tested Power Rangers: Battle for the Grid, and CrossCode (gotta use Proton because NW.js broke controllers on Linux) and they work fine too. 😀
I noticed in the terminal that it was complaining about /dev/shm not being shared and thus the Steam Overlay wouldn't work. And indeed, it didn't. It was also complaining that it couldn't tell whether or not /tmp was shared and thus the overlay browser might not work. But after
flatpak --user override --allow=per-app-dev-shm com.valvesoftware.Steam, both messages went away and the overlay started working, including the overlay browser. 🎉This is looking very promising! So much so that I will use the standard distribution of Proton 6.3 as my default Steam Play tool. I really appreciate all the amazing work everyone has put in and hope my test provided good information. ❤
nanonyme commentedon Apr 27, 2021
Please don't forget the override on, we want to test enabling this through manifest soon.
TiZ-HugLife commentedon Apr 27, 2021
Once this is in the manifest, I'll take my override out to make sure it works. How will older versions of flatpak respond to manifests requesting the per-app-dev-shm feature when it doesn't exist for them?
nanonyme commentedon Apr 27, 2021
As per my understanding older flatpak will ignore it. That is also something we must test. At least this will bump the build requirement of flatpak (which is more fine than runtime requirement).
nanonyme commentedon Apr 27, 2021
Update with feature enabled should be available in a couple of hours.
TiZ-HugLife commentedon Apr 28, 2021
Okay, I did some testing of the new manifest. I removed the manual override for per-app-dev-shm and it mentioned the feature in the upgrade, and the overlay still worked on my Proton 6.3 games. I ran that test on my laptop. So things are all good on that front. 🎉
I know we also wanted to see what older versions would do. So on my work computer, which did not have Steam installed until today, I used ppa-purge to revert to Xubuntu 20.04's distro Flatpak, which is all the way back on 1.6.5. When I installed Steam, it did mention the per-app-dev-shm feature, but it didn't stop me from installing it. I verified it was indeed 1.6.5 by trying to run Spelunky in Proton 6.3. Even with all the required beta components installed, it failed to start, which is as expected for Flatpak < 1.11.1.
I'm not sure the per-app-dev-shm feature even comes into play unless subsandboxing happens, which you can't do in any Flatpak prior to 1.11.1 anyways. But it didn't stop me from installing and running Steam, so I think that's the desired result? Is there some other test I should do before I remove Steam and re-update Flatpak? I need to have Chromium around, and it requires a newer Flatpak than what's in 20.04's repo.
nanonyme commentedon Apr 28, 2021
Yes, it's working as expected. It's mentioned but doesn't do anything (including fail) on older flatpak.
nanonyme commentedon Apr 28, 2021
https://github.com/flathub/org.flatpak.Builder is now updated and the next release is going to have new enough flatpak to build Steam.
TiZ-HugLife commentedon May 3, 2021
One thing I think I should mention is that about 5% to 10% of the time, a game will immediately fail to start when launched this way. There doesn't seem to be any sort of rhyme or reason to when it fails. Maybe some sort of race condition? I'll set up some logging in order to be able to provide more info next time it happens.
smcv commentedon May 3, 2021
Please report this (and any other issues) to https://github.com/ValveSoftware/steam-runtime/issues, and be as specific as possible. If you were running Steam with its stderr sent to a terminal, a log file or the systemd journal, there might be a clue there (check whether your desktop environment sends Steam's stderr to the systemd journal - GNOME does), but it's a lot more likely we'll be able to solve problems if we can see a log with at least
STEAM_LINUX_RUNTIME_LOG=1. It's also useful if issues can be reproduced with a relatively small free-to-play game (we often use Floating Point or Life is Strange episode 1) so that everyone can easily test the same thing. See https://github.com/ValveSoftware/steam-runtime/blob/master/doc/reporting-steamlinuxruntime-bugs.md for more bug reporting guidelines.smcv commentedon May 21, 2021
This might be caused by #4286.
smcv commentedon May 21, 2021
This feature request is basically solved by Flatpak 1.11.1, although #4286 would be a good follow-up fix.