readme tweaks
[bubblebox.git] / README.md
1 # BubbleBox: Simple Application Sandboxing
2
3 ## Introduction
4
5 This is the documentation of [BubbleBox](https://www.ralfj.de/projects/bubblebox), a
6 tool to easily sandbox Linux applications.
7
8 The primary use-case for BubbleBox is running applications that you do not trust enough
9 to give them full access to hour home directory, and in particular the secret keys stored there.
10 In this regard it is similar to [firejail] and [bubblejail], but less powerful and in exchange hopefully easier to configure.
11 BubbleBox is based on [bubblewrap] and [xdg-dbus-proxy] which do all of the heavy lifting.
12
13 [firejail]: https://firejail.wordpress.com/
14 [bubblejail]: https://github.com/igo95862/bubblejail
15 [bubblewrap]: https://github.com/containers/bubblewrap
16 [xdg-dbus-proxy]: https://github.com/flatpak/xdg-dbus-proxy
17
18 ## Usage
19
20 The typical way to use BubbleBox is to create a new "jail" script in the BubbleBox source folder.
21 For instance, if you want a "gamejail" that you can use to run games, create a file `gamejail`
22 in a BubbleBox checkout with contents like this:
23
24 ```python
25 #!/bin/python3
26 from bubblebox import *
27
28 bubblebox(
29   profiles.DESKTOP("gamejail"),
30   dbus_proxy_flags("--own=com.steampowered.*"),
31
32   home_access({
33     ".steam": Access.Write,
34   }),
35 )
36 ```
37
38 Then add a symlink to this file somewhere to your PATH, and now you can use `gamejail <application>`
39 to run arbitrary games inside the BubbleBox.
40
41 ### Configuration directives
42
43 A BubbleBox sandbox is configured by passing a list of directives to the
44 `bubblebox` functions that declare things the sandbox has access to. Everything
45 else is blocked by default.
46
47 These directives are basically lists of bubblewrap and xdg-dbus-proxy flags,
48 but BubbleBox provides some convenience functions
49 to allow higher-level configuration and to share common patterns.
50
51 The `profiles.py` file contains some useful directives that are needed by most applications:
52 - `profiles.DEFAULT` adds the basic flags to isolate the sandbox from the environment
53   by unsharing all namespaces except for the network.
54   This profile gives access to `/usr`, `/sys`, and `/etc` and also creates a
55   stub file system inside the sandbox that is basically always required, such as
56   an empty folder to serve as XDG_RUNTIME_DIR. It assumes a merged-usr setup,
57   e.g. it will add `/bin` as a symlink to `/usr/bin`. It also gives read-only
58   access to some files in the home directory that are often needed to make a
59   basic shell work: `.bashrc`, `.bash_aliases`, `.profile` and the `bin`
60   directory.
61 - `profiles.DESKTOP("name")` is intended to make GUI applications work. It
62   extends `DEFAULT` by providing access to DRI, X11, ALSA, Wayland, and
63   PulseAudio. Furthermore, some GUI configuration files (`.XCompose`,
64   fontconfig, and default mime-type associations) are made available to the
65   sandbox. The `"name"` is used to create an XDG_RUNTIME_DIR that will be shared
66   among all instances of this sandbox. This also sets up the D-Bus proxy and
67   gives the application access to notifications, screen saver control, status
68   icons, and the flatpak portals (however, actually using these portals is
69   untested and would likely require further integration). Finally, it makes
70   clicking on links inside the sandbox work properly if your default browser is
71   Firefox.
72
73 I recommend looking at the sources in `default.py` to learn how to configure your
74 own sandboxes. Here are the key directives to use:
75 - `host_access` gives the sandbox read-only or read-write access to some part
76   of the host file system. This is declared via nested Python dicts and supports
77   glob expressions.
78 - `home_access` works the same as `host_access` except all paths are relative
79   to the home directory.
80 - `bwrap_flags` allows passing flags directly to `bwrap`. This is rarely needed.
81 - `dbus_proxy_flags` allows passing flags directly to `xdg-dbus-proxy`.
82   This is the typical way to provide access to additional D-Bus names.
83
84 ## Source, License
85
86 You can find the sources in the
87 [git repository](https://git.ralfj.de/bubblebox.git) (also available
88 [on GitHub](https://github.com/RalfJung/bubblebox)). They are provided under the
89 [GPLv2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) or (at your
90 option) any later version of the GPL.  See the file `LICENSE-GPL2` for more
91 details.
92
93 ## Contact
94
95 If you found a bug, or want to leave a comment, please
96 [send me a mail](mailto:post-AT-ralfj-DOT-de).  I'm also happy about pull
97 requests :)