Closed zenofile closed 2 months ago
Enabling many of the hardening features makes sense (for example there's no need for network access). However I wouldn't want to break any functionality. Like you listed:
/etc/modprobe.d
+ call to the initramfs generator It's also worth noting that the hardening isn't as necessary for the lact daemon as it is for something like a web server. The API is only accessible to a whitelisted admin via unix socket permissions (this admin would already most likely have access to everything that's being limited here), and the functionality exposed has a pretty limited surface compared to some general purpose internet-facing service... but I understand the concern since the service runs as root.
I agree that the example settings are a bit restrictive. They can certainly be relaxed and still provide some form of protection without altering the codebase to support them.
Allow read-only access to /home/*
(/usr
is already readable) for access to vulkan layer files. I suppose they could be anywhere because of VK_LAYER_PATH
environment variable?, but I'm not entirely sure how that works:
ProtectHome=read-only
TemporaryFileSystem=/root/.cache
No namespaced /tmp
to allow easily accessible debug info dumps:
PrivateTmp=no
ReadWritePaths=/etc/lact /tmp
D-Bus access should still be possible, but I did not test that.
This does not fix the initramfs generation though.
For that ProtectSystem
, SystemCallFilter
, DeviceAllow
and CapabilityBoundingSet
need to be relaxed or dropped completely in order to allow access to /boot
, /efi
as well as mknod
, ioctl (ffreeze)
, chroot
system calls etc. – at that point there is no real benefit in trying to restrict access since most settings can be undone by the privileged process I suppose.
But I think disabling networking with something like this might still be worth it without losing any functionality lact has right now:
[Service]
MemoryDenyWriteExecute=yes
PrivateNetwork=yes
RestrictAddressFamilies=AF_UNIX AF_LOCAL AF_NETLINK
SystemCallArchitectures=native
SystemCallFilter=~@debug
CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_RAW CAP_BPF CAP_SYS_PTRACE
Since LACT runs the daemon as root, it would be desirable to restrict the processes permissions utilizing systemd's sandboxing capabilities to only permit access to necessary system components.
Currently, I run the daemon with these overrides and didn't experience any problems so far:
This results in a
systemd-analyze
score of2.3 OK
as opposed to9.6 UNSAFE
.There are however two issues I see with this restrictive configuration:
1) Accessing a generated debug snapshots is now more complicated due to
PrivateTmp=yes
; however it can still be accessed by joining the mount namespace:2) Enabling overclocking support won't be possible using the GUI:
/etc/modprobe.d/99-amdgpu-overdrive.conf
could be added toReadWritePaths
, but regenerating the initrd would not be possible due to child processes inheriting the parent's restrictions. For exampledracut
would have insufficient permissions for writing to/boot
.Not using
PrivateTmp
is of course an option, but allowing proper execution ofdracut
et al. would result in dropping quite a few restrictions.Maybe there could be an alternative service file bundled that launches the daemon in hardened mode, since I assume you probably do not want to separate the initrd– and debug info generation into a separate binary or cli subcommand for the user to execute.
This is of course just a suggestion, I personally am fine with overriding the settings.