refactor the directives system, so that dbus can be entirely implemented without...
[bubblebox.git] / profiles.py
1 from bubblebox import *
2
3 # Various default sandbox settings
4 DEFAULT = group(
5   # namespace unsharing
6   # cannot unshare IPC as that breaks some wine applications
7   bwrap_flags("--unshare-user", "--unshare-pid", "--unshare-cgroup"),
8   # A different hostname is useful to be able to see when we are inside the sandbox.
9   # However, some applications will not like this unless the hostname also exists in `/etc/hosts`!
10   bwrap_flags("--unshare-uts", "--hostname", "bubblebox"),
11   # Make sure the sandbox cannot inject commands into the host terminal.
12   bwrap_flags("--new-session"),
13   # basic directories
14   bwrap_flags("--proc", "/proc", "--dev", "/dev", "--dir", "/tmp", "--dir", "/var", "--dir", "/run", "--symlink", "../run", "/var/run"),
15   # an empty XDG_RUNTIME_DIR
16   bwrap_flags("--perms", "0700", "--dir", XDG_RUNTIME_DIR),
17   # merged-usr symlinks
18   bwrap_flags("--symlink", "usr/lib", "/lib", "--symlink", "usr/lib64", "/lib64", "--symlink", "usr/bin", "/bin", "--symlink", "usr/sbin", "/sbin"),
19   # folders we always need access to
20   host_access({ ("/usr", "/sys", "/etc"): Access.Read }),
21   # make a basic shell work
22   home_access({
23     (".bashrc", ".bash_aliases", ".profile"): Access.Read,
24     "bin": Access.Read,
25   }),
26 )
27
28 # https://github.com/igo95862/bubblejail is a good source of paths that need allowing.
29 # We do not give access to pipewire, that needs a portal (https://docs.pipewire.org/page_portal.html).
30 def DESKTOP(name):
31   return group(
32     DEFAULT,
33     # Share XDG_RUNTIME_DIR among all instances of this sandbox
34     shared_runtime_dir(name),
35     # Access to screen and audio
36     host_access({
37       "dev": {
38         ("dri", "snd"): Access.Device,
39       },
40       "/tmp/.X11-unix/": Access.Read,
41       os.environ["XAUTHORITY"]: Access.Read,
42       XDG_RUNTIME_DIR: {
43         ("wayland*", "pulse"): Access.Read,
44       },
45     }),
46     # Access to some key user configuration
47     home_access({
48       (".config/fontconfig", ".XCompose", ".local/share/applications"): Access.Read,
49     }),
50     # Access to basic d-bus services (that are hopefully safe to expose...)
51     dbus_proxy_flags("--talk=org.kde.StatusNotifierWatcher.*", "--talk=org.freedesktop.Notifications.*", "--talk=org.freedesktop.ScreenSaver.*", "--talk=org.freedesktop.portal.*"),
52     # Make it possible to open websites in Firefox
53     home_access({ ".mozilla/firefox/profiles.ini": Access.Read }),
54     dbus_proxy_flags("--talk=org.mozilla.firefox.*"),
55   )