Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/incus: add AppArmor rules #386060

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions nixos/modules/virtualisation/incus.nix
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,39 @@ in
"lxc-containers".profile = ''
include ${cfg.lxcPackage}/etc/apparmor.d/lxc-containers
'';
"incusd".profile = ''
# This profile allows everything and only exists to give the
# application a name instead of having the label "unconfined"

abi <abi/4.0>,
include <tunables/global>

profile incusd ${lib.getExe' config.virtualisation.incus.package "incusd"} flags=(unconfined) {
userns,
include </var/lib/incus/security/apparmor/cache>
include </var/lib/incus/security/apparmor/profiles>

# Site-specific additions and overrides. See local/README for details.
include if exists <local/incusd>
}
'';
};
includes."abstractions/base" = ''
# Allow incusd's various AA profiles to load dynamic libraries from Nix store
# https://discuss.linuxcontainers.org/t/creating-new-containers-vms-blocked-by-apparmor-on-nixos/21908/6
mr /nix/store/*/lib/*.so*,
r ${pkgs.stdenv.cc.libc}/lib/gconv/gconv-modules,
r ${pkgs.stdenv.cc.libc}/lib/gconv/gconv-modules.d/,
r ${pkgs.stdenv.cc.libc}/lib/gconv/gconv-modules.d/gconv-modules-extra.conf,

# Support use of VM instance
mrix ${pkgs.qemu_kvm}/bin/*,
k ${OVMF2MB.fd}/FV/*.fd,
k ${pkgs.OVMFFull.fd}/FV/*.fd,
''
+ lib.optionalString pkgs.stdenv.hostPlatform.isx86_64 ''
k ${pkgs.seabios-qemu}/share/seabios/bios.bin,
'';
};

systemd.services.incus = {
Expand Down
9 changes: 8 additions & 1 deletion nixos/tests/incus/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ in

zfs = incusTest {
inherit lts pkgs system;
storageLvm = true;
storageZfs = true;
};

appArmor = incusTest {
inherit lts pkgs system;
appArmor = true;
initLegacy = false;
instanceContainer = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reduce the scope a bit more and disable legacy init for now. initLegacy = false; will also make the tests quicker by reducing the number of nixos instances.

};
}
4 changes: 4 additions & 0 deletions nixos/tests/incus/incus-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ../make-test-python.nix (

allTests ? false,

appArmor ? false,
featureUser ? allTests,
initLegacy ? true,
initSystemd ? true,
Expand Down Expand Up @@ -139,6 +140,9 @@ import ../make-test-python.nix (
networking.hostId = "01234567";
networking.firewall.trustedInterfaces = [ "incusbr0" ];

security.apparmor.enable = appArmor;
services.dbus.apparmor = (if appArmor then "enabled" else "disabled");

services.lvm = {
boot.thin.enable = storageLvm;
dmeventd.enable = storageLvm;
Expand Down
Loading