mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
[GH-ISSUE #1824] Is there way to start few applications in single x11 sandbox? #1240
Labels
No labels
LTS merge
LTS merge
bug
bug
converted-to-discussion
doc-todo
documentation
duplicate
enhancement
file-transfer
firecfg
firejail-in-firejail
firetools
graphics
help wanted
information_old
installation
invalid
modif
moved
needinfo
networking
notabug
notourbug
old-version
overlayfs
packaging
profile-request
pull-request
question
question_old
removal
runtime-permissions
sandbox-ipc
security
stale
wiki
wiki
wontfix
wordpress
workaround
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/firejail#1240
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @punksta on GitHub (Mar 22, 2018).
Original GitHub issue: https://github.com/netblue30/firejail/issues/1824
I'd like to run time-tracking app with ide and browser in single x11 sandbox. Is it possible?
@Fincer commented on GitHub (Mar 24, 2018):
I have used systemd-nspawn to run Pale Moon web browser in a container with graphical interface (X11) + Pulseaudio enabled. Pulseaudio is needed for any web media content that have audio in it (such as Youtube videos).
I have read it is possible to run graphical applications with docker, too.
Please take also a look on x11docker project which claims to focus on X11 security issues and should provide a somewhat easy set-up for X11 + docker container environment.
For loose reference:
Running Firefox in a systemd-nspawn container
You can very likely use firejail inside systemd-nspawn container so that the end-user environment is kind of having two containers stacked. I have planned to use firejail in my systemd-nspawn containers after issue private-lib doesn't work with Palemoon & Firefox is fixed.
Security & X11
Problem of sharing X11 environment with the host is the shared memory which, in some cases, can be a security issue. This is likely an issue with Pulseaudio, too.
Setting up systemd-nspawn container + X11 application (my personal setup)
I have done this on Arch Linux, so some parts are specific for that distribution. The following stuff assumes you have your main system's current user in sudo group and you have working internet connection available in the system.
You can choose whatever path you want to. ~/my-container is just an example here.
In container environment, login as root when login credentials are asked.
In this step, we request public keys of Arch Linux package maintainers and run database updates.
In container environment, run:
The last two commands (touch & chmod) must be run as 'default' user.
where 'my_command' is the name of your program's executable file in container environment. If you don't use Pulseaudio in container environment, remove PULSE_SERVER=unix:/run/user/host/pulse/native part.
Note: any environment variables you describe in the command above depends on your set-up. If you use ALSA, for example, write a correct string for that.
Exit the container environment by pressing CTRL + % key combination (or CTRL + ] with en_US keyboard) rapidly three times sequentially.
Execute your program in container by running the following command in your main system:
The above command does as follows:
Share main system X11 environment
Initialize systemd-nspawn container
bind your main system's current user .Xauthority file to the container's default user home directory (read-only).
bind your main system's X11 sockets to the container environment (read-only)
bind your main system's Pulseaudio to the container environment (read-only)
specify container path (-D ~/my-container)
in container environment, execute home/default/launch.sh (in which we have set up that our command is executed as user 'default')
Additional Pale Moon parameters
NOTE: bind parameters you might want to use vary, depending on the requirements for the program. For example, I have additional parameters for my 'Pale Moon' web browser environment:
Note that I have binded my main system's $HOME/Downloads folder as writable.
Some of these bindings are irrelevant if I have set up a working GTK2 environment or installed fonts/icons into the container. As I haven't installed fonts/icons in the container, I bind the ones I have in my main system. And, for example, without GTK2/icon bindings the program (Pale Moon) works but looks awful.
Which systemd-nspawn bindings to use?
How do you know which bindings you want to use? Check your program requirements.
Does your containerized program use Qt5, GTK2 or GTK3? Does it require ALSA or Pulseaudio? Does it require some fonts installed? Does it require some icons installed? Just find out (can be tricky) and by your findings, set up your --bind-ro parameters correctly to the command in step 11.
Firefox/Palemoon + systemd-nspawn X11 workaround
For Firefox and Pale Moon, there seems to be a bug of some sort which prevents these web browsers to start (ABORT: X_ShmPutImage).
If you encounter this issue, you may try the following as a workaround: set up a short while loop for the launch command (in /home/default/launch.sh) which executes it twice unless the program has already been started successfully. So, in my case with Pale Moon, I replace the contents of /home/default/launch.sh with the following:
NOTE: Executable name varies depending on your program of choice. In my case, it is palemoon, as seen in the above command.
NOTE: I don't guarantee this workaround works for you but I can say "It works for me".
In the above command, I need procps-ng package to be installed in my Arch Linux container. To do that, I simply execute the following in the main system:
Now I should be able to launch the program correctly with the command introduced in step 11, with additional Pale Moon parameters (see 'Additional Pale Moon parameters' section above).
Setting up a shortcut for the container
Other contents of your desktop file vary depending on your program of choice.
Controlling systemd-nspawn container resources
Please check this, this and this link for some details.
I hope this helps you a little bit in your issue. Remember to fit my instructions depending on your running system environment (do you run Ubuntu/Debian/Fedora...etc.) and program requirements.
-Fincer
@punksta commented on GitHub (Mar 24, 2018):
@Fincer Thank you for such detailed answer! it's was unexpected. I'll try to follow this in free time.
For quick solution I've just set up qemu-kvm image for work environment with not trusted applications (upwork, zoom, slack, teamviewer). I can combine firejail and vm os now :). Maybe having second os on another encrypted partition is best option for that case.
@Fincer commented on GitHub (Mar 24, 2018):
You are welcome. 👍 Actually, I just had similar problem earlier in this week so the timing for your question was a fun coincidence for me.
Take your time, feel free to comment the solution as well!
Not many answers given for this issue in the internet satisfied me. Personally, either I couldn't find a proper answer which could perfectly satisfy my needs.
Therefore, as...
...I investigated the issue + found satisfying answer by myself and...
...because I see there are people who fight with the exact same issues...
...I decided to write my personal documented answer here. It's not foolproof, may have security or other issues depending on system environment but, at least, it's a good starting point and can be fine tuned afterwards.
Personally, I haven't checked the docker solution I described above, but I think it's totally worth closer look.
My starting point for the little "Create a container for Pale Moon web browser" project was my basic requirement to get rid of bulky x86_64 virtual machine environments (Oracle VirtualBox) I have set up on my main system, and to reduce RAM usage as a result.
I have also set up an encrypted Vault container (KDE) for my Pale Moon browser profile. The solution I currently use is not a good one and should be improved. I have ideas for this but just haven't tried them yet.
@netblue30 commented on GitHub (Mar 24, 2018):
It is quite easy, you start the first application and find out on what display is running:
Then, you start all the other sandboxes using DISPLAY environment variable:
If you want to verify, run "firemon --x11":
So, you'll have a sandbox for each app, and another one for xephyr/xpra