| 1 |
Sandboxing of NetworkManager Daemon |
| 2 |
=================================== |
| 3 |
|
| 4 |
NetworkManager runs as root user, although it might also be possible to run |
| 5 |
as a separate user ([#843](https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/843)). |
| 6 |
|
| 7 |
The daemon requires certain permissions to perform its tasks, but it also |
| 8 |
runs network facing code (like the DHCP library). We should better sandbox |
| 9 |
the process to mitigate exploitable bugs. |
| 10 |
|
| 11 |
We want to drop unrequired Capabilities and confine the daemon with SELinux. |
| 12 |
The SELinux policy is maintained on downstream distributions. |
| 13 |
|
| 14 |
For dropping capabilities, we use Systemd's `CapabilityBoundingSet`. |
| 15 |
|
| 16 |
Another idea would be to run network facing code (DHCP) as a separate sandboxed process |
| 17 |
or to rewrite in a safe(er) language. Both is high effort and not clear to be worth |
| 18 |
it. Possibly that effort would be better spent in fuzzing and improved unit testing |
| 19 |
of the code. |
| 20 |
|
| 21 |
See also [#71](https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/71). |
| 22 |
|
| 23 |
|
| 24 |
Certificate Files |
| 25 |
----------------- |
| 26 |
|
| 27 |
For 802-1x and VPN plugins, the connection profile can contain files. |
| 28 |
Files are highly problematic because they might be owned by a different |
| 29 |
user or not have the right SELinx context (`~/.cert/`). Also, they make the |
| 30 |
profile not self-contained and are hard to cleanup when deleting the file. |
| 31 |
|
| 32 |
NetworkManager itself does not much with certificate files, mostly they are just |
| 33 |
passed on to wpa_supplicant or the VPN plugin. Wpa_supplicant in turn is not yet |
| 34 |
sandboxed (that is a problem?!), and can usually read the files (by having `CAP_DAC_OVERRIDE`). |
| 35 |
|
| 36 |
One aim is to drop `CAP_DAC_OVERRIDE` capability. So let's focus on that. |
| 37 |
But there are similar other problems with files. |
| 38 |
|
| 39 |
Possible Solutions: |
| 40 |
|
| 41 |
- NetworkManager mostly read the certificate files to determine whether a secret |
| 42 |
is needed. We could just pass them on to supplicant, and supplicant needs a way |
| 43 |
to call back and request more secrets. That is how VPN plugins work. |
| 44 |
|
| 45 |
- move away from files and use PKCS#11 URIs and have a certificate store. |
| 46 |
|
| 47 |
- for simple questions like is-file-valid-certificate or is-passwd-valid |
| 48 |
we could ask nm-priv-helper via D-Bus. The problem is that such requests |
| 49 |
would be asynchronous and currently the code expects an answer right away. |
| 50 |
But even a higher privileged service like nm-priv-helper might be confined |
| 51 |
by SELinux or the file might be on a fuse filesystem. Files just don't |
| 52 |
work well. |
| 53 |
|
| 54 |
- drop `CAP_DAC_OVERRIDE` and expect users either to not use 802-1x with certificates, |
| 55 |
to have the certificates with suitable permissions, or to grant `CAP_DAC_OVERRIDE` |
| 56 |
to NetworkManager.service. We do the same already w.r.t. the SELinux context. |
| 57 |
|
| 58 |
- document that users can drop `CAP_DAC_OVERRIDE` themselves (insecure by default), |
| 59 |
if they either don't use 802-1x certificates or make sure that the file permissions |
| 60 |
are suitable. |
| 61 |
|
| 62 |
See [@8021x_tls](https://gitlab.freedesktop.org/NetworkManager/NetworkManager-ci/-/merge_requests/998) |
| 63 |
test for reproducing a problem. |
| 64 |
|
| 65 |
|
| 66 |
VPN Plugins |
| 67 |
----------- |
| 68 |
|
| 69 |
The NetworkManager process spawns the VPN plugins, that means the plugins |
| 70 |
inherit all sandboxing from the daemon. That is a problem, because we don't |
| 71 |
necessarily know what capabilities the VPN plugin will require and we tend |
| 72 |
to just have capabilities because a VPN plugin might use it. |
| 73 |
|
| 74 |
The solution is to let somebody else (with elevated privileges) spawn the |
| 75 |
plugins. |
| 76 |
|
| 77 |
This could be done by running the VPN plugins a separate systemd service. That would |
| 78 |
be great, but has two severe downsides: it would only work with systemd and break |
| 79 |
non-systemd use cases. More importantly, all existing plugins need to be update |
| 80 |
for this new way of running. That could be done, however, there will be a transitioning |
| 81 |
period during which we would need both ways to run the plugin. This means there |
| 82 |
is a need to implement a systemd-less approach, and once we implement that, the |
| 83 |
incentive for using systemd decreased. It still could be done maybe in the future. |
| 84 |
|
| 85 |
The better way is to have our own VPN plugin runner. That could be `nm-priv-helper.service`. |
| 86 |
It already runs as a separate service with distinct environment and sandboxing. |
| 87 |
Note that spawning the VPN plugin process is already an async operation. So replacing |
| 88 |
that with an async call to nm-priv-helper will be relatively straight forward. |
| 89 |
|
| 90 |
|
| 91 |
Can we Drop a Capability? |
| 92 |
------------------------- |
| 93 |
|
| 94 |
### `CAP_DAC_OVERRIDE`: |
| 95 |
|
| 96 |
1) Used for [VPN Plugins](#vpn-plugins). |
| 97 |
See there for how to solve that. |
| 98 |
|
| 99 |
2) Used for 802-1x [certificate files](#certificate-files). |
| 100 |
See there for how to solve that. |
| 101 |
|
| 102 |
|
| 103 |
Other systemd Sandboxing Options |
| 104 |
-------------------------------- |
| 105 |
|
| 106 |
Enable sandboxing options possible. Again, the main problem are certificate files in802-1x |
| 107 |
and VPN plugins. |
| 108 |
|
| 109 |
Enable them one at a time, and open issues/merge-request for discussion. |