@@ -587,14 +587,17 @@ cloudstack-agent and should already be installed.
587587 $ systemctl restart libvirtd
588588
589589
590+ .. _kvm-security-policies :
591+
590592Configure the Security Policies
591593~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
592594
593595CloudStack does various things which can be blocked by security
594- mechanisms like AppArmor and SELinux. These have to be disabled to
595- ensure the Agent has all the required permissions.
596+ mechanisms like AppArmor and SELinux. Both mechanisms can stay enabled on the
597+ host, but the libvirt per-Instance security driver must be turned off so that
598+ the Agent has all the required permissions for Instance and storage operations.
596599
597- #. Configure SELinux (RHEL, CentOS, SUSE )
600+ #. Configure SELinux (RHEL, CentOS)
598601
599602 #. Check to see whether SELinux is installed on your machine. If not,
600603 you can skip this section.
@@ -607,68 +610,137 @@ ensure the Agent has all the required permissions.
607610 $ rpm -qa | grep selinux
608611
609612 #. Set the SELINUX variable in ``/etc/selinux/config `` to
610- "permissive". This ensures that the permissive setting will be
613+ "enforcing" or " permissive". This ensures that the setting will be
611614 maintained after a system reboot.
612615
613- In RHEL or CentOS:
616+ #. Then set SELinux to enforcing or permissive starting immediately, without
617+ requiring a system reboot.
614618
615619 .. parsed-literal ::
616620
617- $ vi /etc/selinux/config
621+ $ setenforce enforcing
618622
619- Change the following line
623+ #. Set the security driver in `` /etc/libvirt/qemu.conf `` to "none".
620624
621625 .. parsed-literal ::
622626
623- SELINUX=enforcing
627+ security_driver="none"
624628
625- to this
629+ .. note :: In a production environment, SELinux should be set to enforcing
630+ and the necessary SELinux policies should be created to allow the
631+ services to run.
626632
627- .. parsed-literal ::
633+ #. Configure AppArmor (Ubuntu, Debian, SUSE)
628634
629- SELINUX=permissive
635+ AppArmor enforcement and ``security_driver="none" `` control different
636+ security layers. The AppArmor profiles of ``libvirtd `` and
637+ ``virt-aa-helper `` still protect the libvirt daemon itself, while
638+ ``security_driver="none" `` disables the dynamic per-Instance AppArmor (sVirt)
639+ confinement. This keeps the basic host protection while avoiding possible
640+ compatibility problems with CloudStack Instance and storage operations.
630641
631- #. Then set SELinux to permissive starting immediately, without
632- requiring a system reboot.
642+ #. Check to see whether AppArmor is installed on your machine. If
643+ not, you can skip this section.
644+
645+ In Ubuntu and Debian, AppArmor is installed and enabled by default. You
646+ can verify this with:
633647
634648 .. parsed-literal ::
635649
636- $ setenforce permissive
650+ $ dpkg --list 'apparmor'
637651
638- .. note :: In a production environment, selinux should be set to enforcing
639- and the necessary selinux policies are created to allow the
640- services to run.
652+ If the ``apparmor-utils `` package is not present, install it.
641653
642- #. Configure Apparmor ( Ubuntu)
654+ On Ubuntu and Debian:
643655
656+ .. parsed-literal ::
644657
645- #. Check to see whether AppArmor is installed on your machine. If
646- not, you can skip this section.
658+ $ apt install apparmor-utils
647659
648- In Ubuntu AppArmor is installed and enabled by default. You can
649- verify this with:
660+ On SUSE:
650661
651662 .. parsed-literal ::
652663
653- $ dpkg --list 'apparmor'
664+ $ zypper install apparmor-utils
665+
666+ #. Set the libvirt AppArmor profiles to enforcing mode. This step is mainly
667+ needed on existing hosts, because previous CloudStack versions disabled
668+ these profiles. On fresh hosts, the libvirt profiles are normally already
669+ enabled.
654670
655- #. Disable the AppArmor profiles for libvirt
671+ On existing hosts, first remove the links which were created by previous
672+ CloudStack versions to disable the profiles. Otherwise the profiles will
673+ be skipped again at the next boot.
656674
657675 .. parsed-literal ::
658676
659- $ ln -s /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable/
677+ $ rm -f /etc/apparmor.d/disable/usr.sbin.libvirtd
678+ $ rm -f /etc/apparmor.d/disable/usr.lib.libvirt.virt-aa-helper
679+
680+ Then enforce only the libvirt profiles:
660681
661682 .. parsed-literal ::
662683
663- $ ln -s /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper /etc/apparmor.d/disable/
684+ $ aa-enforce /usr/sbin/libvirtd
685+ $ aa-enforce /usr/lib/libvirt/virt-aa-helper
686+
687+ #. Set the security driver in ``/etc/libvirt/qemu.conf `` to "none".
688+ Existing hosts may already have this setting, while it must be
689+ configured manually on fresh hosts.
664690
665691 .. parsed-literal ::
666692
667- $ apparmor_parser -R /etc/apparmor.d/usr.sbin.libvirtd
693+ security_driver="none"
668694
669- .. parsed-literal ::
695+ .. note :: If ``security_driver`` is not set to "none", the per-Instance
696+ AppArmor profiles generated by libvirt may block some CloudStack
697+ Instance and storage operations, for example starting an Instance or
698+ accessing volumes and ISOs on primary and secondary storage.
699+
700+
701+ To check the current security settings of a KVM host, the following commands can be used:
702+
703+ - SELinux (RHEL, CentOS, Rocky Linux, Alma Linux, etc.):
704+
705+ .. parsed-literal ::
706+
707+ # Show the SELinux status, mode and loaded policy
708+ $ sestatus
709+ # Show the current mode (Enforcing, Permissive or Disabled)
710+ $ getenforce
711+ # List the SELinux booleans related to virtualization
712+ $ getsebool -a | grep -E 'virt|qemu'
713+ # Check whether libvirt/QEMU is allowed to use NFS storage
714+ $ getsebool virt_use_nfs
715+ # Show recent SELinux denials
716+ $ ausearch -m avc -ts recent
717+
718+ - AppArmor (Ubuntu, Debian, SUSE):
719+
720+ .. parsed-literal ::
721+
722+ # Show the loaded profiles and their modes
723+ $ aa-status
724+ # Show the libvirt profiles which are in enforce mode
725+ $ aa-status --filter.mode=enforce | grep libvirt
726+ # List the AppArmor profiles installed on the host
727+ $ ls /etc/apparmor.d/
728+ # List the profiles which are disabled (e.g. links created by previous CloudStack versions)
729+ $ ls /etc/apparmor.d/disable
730+ # Show recent AppArmor denials
731+ $ dmesg | grep -i 'apparmor.*denied'
732+
733+ - libvirt security driver:
734+
735+ .. parsed-literal ::
736+
737+ # Show the security driver configured for libvirt QEMU (should be "none")
738+ $ grep -E '^\s *security_driver' /etc/libvirt/qemu.conf
670739
671- $ apparmor_parser -R /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper
740+ .. warning :: Use the same ``security_driver`` setting on all KVM hosts of a
741+ cluster. If the hosts have different ``security_driver `` settings (for
742+ example "none" on one host and "apparmor" or "selinux" on another), the
743+ migration of Instances between them may be denied by libvirt.
672744
673745
674746Configuring the Networking
0 commit comments