forked from tiiuae/ghaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve BT functionality and hardening
- change 'mutableUsers' to false (system-wide) - add bluetooth system user/group (requires immutability) - enable hardened systemd configs in audiovm - add hardened systemd config + dbus policy - add persistence to save bt device configs - add uinput kernel module + udev rules - change control socket in launcher Signed-off-by: Manuel Bluhm <[email protected]>
- Loading branch information
1 parent
6ce095f
commit 67edf00
Showing
8 changed files
with
164 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,76 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ config, lib, ... }: | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
cfg = config.ghaf.services.bluetooth; | ||
inherit (lib) mkIf mkEnableOption; | ||
bluetoothUser = "bluetooth"; | ||
in | ||
{ | ||
options.ghaf.services.bluetooth = { | ||
enable = mkEnableOption "Bluetooth configurations"; | ||
}; | ||
config = mkIf cfg.enable { | ||
|
||
# Enable bluetooth | ||
hardware.bluetooth = { | ||
enable = true; | ||
}; | ||
|
||
# Polkit rules for blueman | ||
ghaf.systemd.withPolkit = true; | ||
security.polkit = { | ||
enable = true; | ||
extraConfig = '' | ||
polkit.addRule(function(action, subject) { | ||
if ((action.id == "org.blueman.network.setup" || | ||
action.id == "org.blueman.dhcp.client" || | ||
action.id == "org.blueman.rfkill.setstate" || | ||
action.id == "org.blueman.pppd.pppconnect") && | ||
subject.user == "ghaf") { | ||
return polkit.Result.YES; | ||
} | ||
}); | ||
''; | ||
# Setup bluetooth user and group | ||
users = { | ||
users."${bluetoothUser}" = { | ||
isSystemUser = true; | ||
group = "${bluetoothUser}"; | ||
}; | ||
groups."${bluetoothUser}" = { }; | ||
}; | ||
|
||
systemd.tmpfiles.rules = [ "f /var/lib/systemd/linger/${config.ghaf.users.accounts.user}" ]; | ||
# Uinput kernel module | ||
boot.kernelModules = [ "uinput" ]; | ||
|
||
# Rfkill udev rule | ||
services.udev.extraRules = '' | ||
KERNEL=="rfkill", SUBSYSTEM=="misc", GROUP="${bluetoothUser}" | ||
KERNEL=="uinput", SUBSYSTEM=="misc", GROUP="${bluetoothUser}" | ||
''; | ||
|
||
# Dbus policy updates | ||
services.dbus.packages = [ | ||
(pkgs.writeTextFile { | ||
name = "bluez-dbus-policy"; | ||
text = '' | ||
<!DOCTYPE busconfig PUBLIC | ||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" | ||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> | ||
<busconfig> | ||
<policy user="${bluetoothUser}"> | ||
<allow own="org.bluez"/> | ||
<allow send_destination="org.bluez.*"/> | ||
<allow send_interface="org.bluez.*"/> | ||
<allow send_type="method_call"/> | ||
<allow send_interface="org.freedesktop.DBus.Introspectable"/> | ||
<allow send_interface="org.freedesktop.DBus.Properties"/> | ||
<allow send_interface="org.freedesktop.DBus.ObjectManager"/> | ||
</policy> | ||
<policy user="pipewire"> | ||
<allow send_destination="org.bluez"/> | ||
</policy> | ||
</busconfig> | ||
''; | ||
destination = "/share/dbus-1/system.d/bluez.conf"; | ||
}) | ||
]; | ||
|
||
# Configure bluetooth service | ||
systemd.services.bluetooth.serviceConfig = { | ||
User = "${bluetoothUser}"; | ||
Group = "${bluetoothUser}"; | ||
}; | ||
}; | ||
} |
80 changes: 80 additions & 0 deletions
80
modules/common/systemd/hardened-configs/common/bluetooth.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ | ||
ProtectProc = "noaccess"; | ||
ProcSubset = "pid"; | ||
ProtectHome = true; | ||
ProtectSystem = "full"; | ||
PrivateTmp = true; | ||
PrivateMounts = true; | ||
UMask = 77; | ||
ProtectKernelTunables = true; | ||
ProtectKernelModules = true; | ||
ProtectKernelLogs = true; | ||
KeyringMode = "private"; | ||
ProtectHostname = true; | ||
ProtectClock = true; | ||
ProtectControlGroups = true; | ||
RestrictRealtime = true; | ||
RemoveIPC = true; | ||
NotifyAccess = "all"; | ||
NoNewPrivileges = true; | ||
RestrictSUIDSGID = true; | ||
LockPersonality = true; | ||
MemoryDenyWriteExecute = true; | ||
IPAddressDeny = "any"; | ||
RestrictAddressFamilies = [ | ||
"AF_BLUETOOTH" | ||
"AF_ALG" | ||
"AF_UNIX" | ||
]; | ||
ReadWritePaths = [ "/var/lib/bluetooth" ]; | ||
DeviceAllow = [ | ||
"/dev/rfkill" | ||
"/dev/uinput" | ||
]; | ||
RestrictNamespaces = [ | ||
"~user" | ||
"~pid" | ||
"~net" | ||
"~uts" | ||
"~mnt" | ||
"~cgroup" | ||
"~ipc" | ||
]; | ||
AmbientCapabilities = [ | ||
"CAP_NET_BIND_SERVICE" | ||
"CAP_NET_ADMIN" | ||
"CAP_NET_RAW" | ||
"CAP_SYS_RESOURCE" | ||
"CAP_AUDIT_WRITE" | ||
]; | ||
CapabilityBoundingSet = [ | ||
"CAP_NET_BIND_SERVICE" | ||
"CAP_NET_ADMIN" | ||
"CAP_NET_RAW" | ||
"CAP_SYS_RESOURCE" | ||
"CAP_AUDIT_WRITE" | ||
]; | ||
SystemCallArchitectures = "native"; | ||
SystemCallFilter = [ | ||
"~@swap" | ||
"~@timer" | ||
"~@pkey" | ||
"~@debug" | ||
"~@cpu_emulation" | ||
"~@mount" | ||
"~@ipc" | ||
"~@resources" | ||
"~@memlock" | ||
"~@keyring" | ||
"~@raw_io" | ||
"~@clock" | ||
"~@aio" | ||
"~@setuid" | ||
"~@module" | ||
"~@reboot" | ||
"~@sandbox" | ||
"~@chown" | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
overlays/custom-packages/pulseaudio/pulseaudio-remove-dont-move.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters