grimm-nixos-laptop/common/tooling/apparmor/default.nix

199 lines
5.7 KiB
Nix
Raw Normal View History

2024-10-12 18:19:18 +02:00
{
pkgs,
config,
lib,
...
}:
let
inherit (config.grimmShared) enable tooling;
2024-10-13 13:44:16 +02:00
inherit (lib) mkIf optionalString getExe' getExe;
2024-10-12 18:19:18 +02:00
in
{
imports = [ ./apparmor-d-module.nix ];
2024-10-12 18:19:18 +02:00
config = mkIf (enable && tooling.enable) {
services.dbus.apparmor = "enabled";
security.auditd.enable = true;
security.apparmor.enable = true;
2024-10-16 15:20:09 +02:00
# security.apparmor.enableCache = true;
security.apparmor_d = {
enable = true;
2024-10-16 15:20:09 +02:00
profiles = {
vesktop = "enforce";
speech-dispatcher = "enforce";
thunderbird-glxtest = "enforce";
"firefox.apparmor.d" = "enforce";
pass = "enforce";
spotify = "enforce";
"thunderbird.apparmor.d" = "enforce";
xdg-open = "enforce";
child-open-any = "enforce";
child-open = "enforce";
firefox-glxtest = "enforce";
gamemoded = "disable";
pkexec = "disable";
xdg-mime = "complain";
mimetype = "complain";
};
};
2024-10-13 13:44:16 +02:00
2024-10-12 18:19:18 +02:00
security.apparmor.includes = {
2024-10-13 13:44:16 +02:00
"abstractions/base" = ''
2024-10-12 21:01:10 +02:00
/nix/store/*/bin/** mr,
/nix/store/*/lib/** mr,
/nix/store/** r,
2024-10-14 14:49:17 +02:00
${getExe' pkgs.coreutils "coreutils"} rix,
${getExe' pkgs.coreutils-full "coreutils"} rix,
2024-10-12 21:01:10 +02:00
'';
2024-10-13 13:44:16 +02:00
"local/speech-dispatcher" = ''
${pkgs.speechd}/libexec/speech-dispatcher-modules/* rix,
@{PROC}/@{pid}/stat r,
@{bin}/mbrola rix,
'';
2024-10-13 14:28:46 +02:00
"local/pass" = ''
${getExe' pkgs.pass ".pass-wrapped"} rix,
2024-10-14 14:49:17 +02:00
'';
"local/pass_gpg" = ''
@{PROC}/@{pid}/fd/ r,
/nix/store/*/libexec/keyboxd ix,
owner /run/user/*/gnupg/S.keyboxd wr,
'';
"abstractions/app/udevadm.d/udevadm_is_exec" = ''
@{bin}/udevadm mrix,
2024-10-13 14:28:46 +02:00
'';
"local/firefox" = ''
2024-10-16 11:28:00 +02:00
${pkgs.passff-host}/share/passff-host/passff.py rPx -> passff,
2024-10-14 14:49:17 +02:00
@{HOME}/.mozilla/firefox/** mr,
2024-10-13 14:28:46 +02:00
'';
2024-10-13 13:44:16 +02:00
"local/thunderbird" = ''
${getExe' pkgs.thunderbird ".thunderbird-wrapped_"} rix,
/dev/urandom w,
'';
2024-10-16 11:28:00 +02:00
"abstractions/common/electron.d/libexec" = ''
2024-10-13 13:44:16 +02:00
/nix/store/*/libexec/electron/** rix,
2024-10-16 11:28:00 +02:00
'';
2024-10-12 18:19:18 +02:00
};
2024-10-12 21:01:10 +02:00
security.apparmor.policies = {
2024-10-13 14:28:46 +02:00
passff = {
enable = true;
enforce = true;
profile = ''
abi <abi/4.0>,
include <tunables/global>
profile passff ${pkgs.passff-host}/share/passff-host/passff.py {
include <abstractions/base> # read access to /nix/store, basic presets for most apps
include <abstractions/python>
2024-10-16 11:28:00 +02:00
@{bin}/pass Px -> pass,
2024-10-13 14:28:46 +02:00
}
'';
};
2024-10-13 13:44:16 +02:00
swaymux = {
enable = true;
enforce = true;
profile = ''
abi <abi/4.0>,
include <tunables/global>
profile swaymux ${getExe pkgs.swaymux} {
include <abstractions/base> # read access to /nix/store, basic presets for most apps
${pkgs.swaymux}/bin/* rix, # wrapping
2024-10-16 11:28:00 +02:00
/dev/tty r,
2024-10-13 13:44:16 +02:00
owner @{user_config_dirs}/Kvantum/** r, # themeing
}
'';
};
2024-10-14 14:49:17 +02:00
osu-lazer = {
enable = true;
enforce = true;
profile = ''
abi <abi/4.0>,
include <tunables/global>
profile osu-lazer @{bin}/osu\! flags=(attach_disconnected) {
include <abstractions/base> # read access to /nix/store, basic presets for most apps
include <abstractions/common/bwrap>
include <abstractions/devices-usb>
include <abstractions/nameservice-strict>
include <abstractions/app/udevadm>
include <abstractions/app/bus>
include <abstractions/common/game>
network inet dgram,
network inet6 dgram,
network inet stream,
network inet6 stream,
network netlink raw,
owner @{PROC}/@{pid}/net/dev r,
owner @{PROC}/@{pid}/net/if_inet6 r,
owner @{PROC}/@{pid}/net/ipv6_route r,
owner @{PROC}/@{pid}/net/route r,
capability mknod,
/dev/tty{@{d},} rw,
${pkgs.osu-lazer-bin}/bin/osu? ix,
${getExe pkgs.bubblewrap} rix,
/nix/store/*-osu-lazer-bin-*-bwrap ix,
/nix/store/*-osu-lazer-bin-*-init ix,
2024-10-16 15:20:09 +02:00
/nix/store/*-container-init ix,
2024-10-14 14:49:17 +02:00
/nix/store/*-osu-lazer-bin-*-extracted/** rk,
/nix/store/*-osu-lazer-bin-*-extracted/AppRun ix,
/nix/store/*-osu-lazer-bin-*-extracted/usr/bin/** ix,
@{bin}/ldconfig ix,
@{bin}/appimage-exec.sh ix,
@{bin}/rev ix,
@{bin}/bash ix,
@{bin}/grep ix,
@{bin}/lsblk ix,
@{bin}/awk ix,
@{bin}/gawk ix,
@{bin}/xdg-mime Px,
${getExe' pkgs.gamemode "gamemoderun"} ix,
owner @{HOME}/@{XDG_DATA_DIR}/osu/** rwkm,
owner @{HOME}/.dotnet/** rwkm,
owner @{HOME}/@{XDG_DATA_DIR}/Sentry/** rwk,
owner @{HOME}/@{XDG_CONFIG_DIR}/mimeapps* rwk,
owner @{HOME}/@{XDG_DATA_DIR}/applications/discord-*.desktop rwk,
/nix/store/*-etc-os-release rk,
/nix/store/*/share/zoneinfo/** rk,
owner /tmp/** rwk,
/usr/lib/ r,
2024-10-14 16:54:09 +02:00
owner /var/cache/ldconfig/ rw,
2024-10-14 14:49:17 +02:00
owner /etc/ld.so* rw,
2024-10-14 16:54:09 +02:00
owner @{PROC}/@{pid}/{maps,stat} rk,
@{PROC}/sys/kernel/os{type,release} rk,
2024-10-14 14:49:17 +02:00
/dev/snd/** rw,
/dev/udmabuf wr,
/.host-etc/alsa/conf.d/{,**} r,
/.host-etc/ssl/certs/{,**} r,
/.host-etc/resolv.conf rk,
}
'';
};
2024-10-12 21:01:10 +02:00
};
2024-10-12 18:19:18 +02:00
};
}