Skip to content

Commit 62d611a

Browse files
nixos/incus: add AppArmor rules (NixOS#386060)
2 parents bd85f31 + f6128c6 commit 62d611a

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

nixos/modules/virtualisation/incus.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,40 @@ in
338338
"lxc-containers".profile = ''
339339
include ${cfg.lxcPackage}/etc/apparmor.d/lxc-containers
340340
'';
341+
"incusd".profile = ''
342+
# This profile allows everything and only exists to give the
343+
# application a name instead of having the label "unconfined"
344+
345+
abi <abi/4.0>,
346+
include <tunables/global>
347+
348+
profile incusd ${lib.getExe' config.virtualisation.incus.package "incusd"} flags=(unconfined) {
349+
userns,
350+
</var/lib/incus/security/apparmor/cache>
351+
</var/lib/incus/security/apparmor/profiles>
352+
353+
# Site-specific additions and overrides. See local/README for details.
354+
include if exists <local/incusd>
355+
}
356+
'';
341357
};
358+
includes."abstractions/base" =
359+
''
360+
# Allow incusd's various AA profiles to load dynamic libraries from Nix store
361+
# https://discuss.linuxcontainers.org/t/creating-new-containers-vms-blocked-by-apparmor-on-nixos/21908/6
362+
mr /nix/store/*/lib/*.so*,
363+
r ${pkgs.stdenv.cc.libc}/lib/gconv/gconv-modules,
364+
r ${pkgs.stdenv.cc.libc}/lib/gconv/gconv-modules.d/,
365+
r ${pkgs.stdenv.cc.libc}/lib/gconv/gconv-modules.d/gconv-modules-extra.conf,
366+
367+
# Support use of VM instance
368+
mrix ${pkgs.qemu_kvm}/bin/*,
369+
k ${OVMF2MB.fd}/FV/*.fd,
370+
k ${pkgs.OVMFFull.fd}/FV/*.fd,
371+
''
372+
+ lib.optionalString pkgs.stdenv.hostPlatform.isx86_64 ''
373+
k ${pkgs.seabios-qemu}/share/seabios/bios.bin,
374+
'';
342375
};
343376

344377
systemd.services.incus = {

nixos/tests/incus/default.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ in
4444

4545
zfs = incusTest {
4646
inherit lts pkgs system;
47-
storageLvm = true;
47+
storageZfs = true;
48+
};
49+
50+
appArmor = incusTest {
51+
inherit lts pkgs system;
52+
appArmor = true;
53+
allTests = true;
4854
};
4955
}

nixos/tests/incus/incus-tests.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ../make-test-python.nix (
77

88
allTests ? false,
99

10+
appArmor ? false,
1011
featureUser ? allTests,
1112
initLegacy ? true,
1213
initSystemd ? true,
@@ -139,6 +140,9 @@ import ../make-test-python.nix (
139140
networking.hostId = "01234567";
140141
networking.firewall.trustedInterfaces = [ "incusbr0" ];
141142

143+
security.apparmor.enable = appArmor;
144+
services.dbus.apparmor = (if appArmor then "enabled" else "disabled");
145+
142146
services.lvm = {
143147
boot.thin.enable = storageLvm;
144148
dmeventd.enable = storageLvm;

0 commit comments

Comments
 (0)