aboutsummaryrefslogtreecommitdiffhomepage
path: root/README.md
blob: 5d62b0f7aada90203f4a35c4462293cca0d5dfa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
Fortify
=======

[![Go Reference](https://pkg.go.dev/badge/git.ophivana.moe/security/fortify.svg)](https://pkg.go.dev/git.ophivana.moe/security/fortify)
[![Go Report Card](https://goreportcard.com/badge/git.ophivana.moe/security/fortify)](https://goreportcard.com/report/git.ophivana.moe/security/fortify)

Lets you run graphical applications as another user in a confined environment with a nice NixOS
module to configure target users and provide launchers and desktop files for your privileged user.

Why would you want this?

- It protects the desktop environment from applications.

- It protects applications from each other.

- It provides UID isolation on top of the standard application sandbox.

There are a few different things to set up for this to work:

- A set of users, each for a group of applications that should be allowed access to each other

- A tool to switch users, currently sudo and machinectl are supported.

- If you are running NixOS, the module in this repository can take care of launchers and desktop files in the privileged
  user's environment, as well as packages and extra home-manager configuration for target users.

If you have a flakes-enabled nix environment, you can try out the tool by running:

```shell
nix run git+https://git.ophivana.moe/security/fortify -- -h
```

## Module usage

The NixOS module currently requires home-manager and impermanence to function correctly.

To use the module, import it into your configuration with

```nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";

    fortify = {
      url = "git+https://git.ophivana.moe/security/fortify";

      # Optional but recommended to limit the size of your system closure.
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, fortify, ... }:
  {
    nixosConfigurations.fortify = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        fortify.nixosModules.fortify
      ];
    };
  };
}
```

This adds the `environment.fortify` option:

```nix
{ pkgs, ... }:

{
  environment.fortify = {
    enable = true;
    user = "nixos";
    stateDir = "/var/lib/persist/module";
    target = {
      chronos = {
        launchers = {
          weechat.method = "sudo";
          claws-mail.capability.pulse = false;

          discord = {
            id = "dev.vencord.Vesktop";
            command = "vesktop --ozone-platform-hint=wayland";
            userns = true;
            useRealUid = true;
            dbus = {
              session =
                f:
                f {
                  talk = [ "org.kde.StatusNotifierWatcher" ];
                  own = [ ];
                  call = { };
                  broadcast = { };
                };
              system.filter = true;
            };
            share = pkgs.vesktop;
          };

          chromium = {
            id = "org.chromium.Chromium";
            userns = true;
            useRealUid = true;
            dbus = {
              system = {
                filter = true;
                talk = [
                  "org.bluez"
                  "org.freedesktop.Avahi"
                  "org.freedesktop.UPower"
                ];
              };
              session = f: f {
                talk = [
                  "org.freedesktop.DBus"
                  "org.freedesktop.FileManager1"
                  "org.freedesktop.Notifications"
                  "org.freedesktop.ScreenSaver"
                  "org.freedesktop.secrets"
                  "org.kde.kwalletd5"    
                  "org.kde.kwalletd6"
                ];   
                own = [
                  "org.chromium.Chromium.*"
                  "org.mpris.MediaPlayer2.org.chromium.Chromium.*"
                  "org.mpris.MediaPlayer2.chromium.*"
                ];
                call = { };
                broadcast = { };
              };
            };
          };
        };
        packages = with pkgs; [
          weechat
          claws-mail
          vesktop
          chromium
        ];
        persistence.directories = [
          ".config/weechat"
          ".claws-mail"
          ".config/vesktop"
        ];
        extraConfig = {
          programs.looking-glass-client.enable = true;
        };
      };
    };
  };
}
```

* `enable` determines whether the module should be enabled or not. Useful when sharing configurations between graphical
  and headless systems. Defaults to `false`.

* `user` specifies the privileged user with access to fortified applications.

* `stateDir` is the path to your persistent storage location. It is directly passed through to the impermanence module.

* `target` is an attribute set of submodules, where the attribute name is the username of the unprivileged target user.

  The available options are:

    * `packages`, the list of packages to make available in the target user's environment.

    * `persistence`, user persistence attribute set passed to impermanence.

    * `extraConfig`, extra home-manager configuration for the target user.

    * `launchers`, attribute set where the attribute name is the name of the launcher.

      The available options are:

        * `id`, the freedesktop application ID, primarily used by dbus, null to disable.

        * `script`, application launch script.

        * `command`, the command to run as the target user. Defaults to launcher name. Has no effect when script is set.

        * `dbus.session`, D-Bus session proxy custom configuration.

        * `dbus.configSystem`, D-Bus system proxy custom configuration, null to disable.

        * `env`, attrset of environment variables to set for the initial process in the sandbox.

        * `nix`, whether to allow nix daemon connections from within the sandbox.

        * `userns`, whether to allow userns within the sandbox.

        * `useRealUid`, whether to map to the real UID within the sandbox.

        * `net`, whether to allow network access within the sandbox.

        * `gpu`, target process GPU and driver access, null to follow Wayland or X capability.

        * `dev`, whether to allow full device access within the sandbox.

        * `extraPaths`, a list of extra paths to make available inside the sandbox.

        * `capability.wayland`, whether to share the Wayland socket.

        * `capability.x11`, whether to share the X11 socket and allow connection.

        * `capability.dbus`, whether to proxy D-Bus.

        * `capability.pulse`, whether to share the PulseAudio socket and cookie.

        * `share`, package containing desktop/icon files. Defaults to launcher name.

        * `method`, the launch method for the sandboxed program, can be `"sudo"`, `"systemd"`, `"simple"`.