Skip to content

Commit 49d5339

Browse files
Update settings for SELinux and Apparmor (#662)
* Update settings for SELinux and Apparmor * Update AppArmor and SELinux docs per review comments - Target only the libvirt AppArmor profiles with aa-enforce - Remove the disable links left by previous CloudStack versions - Explain AppArmor enforcement vs security_driver="none" - Add Debian and SUSE (zypper) instructions for AppArmor - Update intro and stale notes that said the mechanisms must be disabled * Add note on issues when security_driver is not set to none * Add release notice on SELinux and AppArmor no longer being configured * Add commands to check SELinux and AppArmor settings on KVM hosts * Mention that VM migration may be denied if security_driver differs between hosts
1 parent 3f54e7b commit 49d5339

5 files changed

Lines changed: 124 additions & 73 deletions

File tree

‎source/developersguide/ansible.rst‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,6 @@ For the management server role we create a main.yml task like this:
272272
  template: src=cloudstack.repo.j2 dest=/etc/yum.repos.d/cloudstack.repo
273273

274274

275-
- name: Ensure selinux is in permissive mode
276-
277-
  command: setenforce permissive
278-
279-
280-
- name: Ensure selinux is set permanently
281-
282-
  selinux: policy=targeted state=permissive
283-
284-
285275
-name: Ensure CloudStack packages are installed
286276

287277
yum: name=cloud-client state=present

‎source/installguide/hypervisor/kvm.rst‎

Lines changed: 101 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,17 @@ cloudstack-agent and should already be installed.
587587
$ systemctl restart libvirtd
588588
589589
590+
.. _kvm-security-policies:
591+
590592
Configure the Security Policies
591593
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
592594

593595
CloudStack 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

674746
Configuring the Networking

‎source/installguide/management-server/_database.rst‎

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ MySQL. See :ref:`install-database-on-separate-node`.
122122
mysql_secure_installation
123123
124124
#. CloudStack can be blocked by security mechanisms, such as SELinux.
125-
Disable SELinux to ensure + that the Agent has all the required
126-
permissions.
125+
SELinux can stay enabled, as long as the necessary SELinux policies allow
126+
the services to run.
127127

128128
Configure SELinux (RHEL and CentOS):
129129

@@ -138,37 +138,15 @@ MySQL. See :ref:`install-database-on-separate-node`.
138138
rpm -qa | grep selinux
139139
140140
#. Set the SELINUX variable in ``/etc/selinux/config`` to
141-
"permissive". This ensures that the permissive setting will be
141+
"enforcing" or "permissive". This ensures that the setting will be
142142
maintained after a system reboot.
143143

144-
In RHEL or CentOS:
145-
146-
.. parsed-literal::
147-
148-
vi /etc/selinux/config
149-
150-
Change the following line
151-
152-
.. parsed-literal::
153-
154-
SELINUX=enforcing
155-
156-
to this:
157-
158-
.. parsed-literal::
159-
160-
SELINUX=permissive
161-
162-
#. Set SELinux to permissive starting immediately, without requiring
144+
#. Set SELinux to enforcing or permissive starting immediately, without requiring
163145
a system reboot.
164146

165147
.. parsed-literal::
166148
167-
setenforce permissive
168-
169-
.. note:: In a production environment, selinux should be set to enforcing
170-
and the necessary selinux policies are created to allow the
171-
services to run.
149+
setenforce enforcing
172150
173151
#. Set up the database.
174152

‎source/quickinstallationguide/qig.rst‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,17 @@ SELinux
192192
^^^^^^^
193193

194194
In an ideal environment, selinux should be set to enforcing and the necessary
195-
selinux policies are created to allow the services to run. For this guide,
196-
we will set selinux to permissive mode. This will allow us to install and
197-
configure the services without having to worry about selinux policies.
195+
selinux policies are created to allow the services to run.
198196

199-
To configure SELinux to be permissive in the running system we need to run the
197+
To configure SELinux to be enforcing in the running system we need to run the
200198
following command:
201199

202200
.. parsed-literal::
203201
204-
# setenforce 0
202+
# setenforce 1
205203
206204
To ensure that it remains in that state we need to configure the file
207-
/etc/selinux/config to reflect the permissive state, as shown in this example:
205+
/etc/selinux/config to reflect the enforcing state, as shown in this example:
208206

209207
.. parsed-literal::
210208
@@ -213,7 +211,7 @@ To ensure that it remains in that state we need to configure the file
213211
# enforcing - SELinux security policy is enforced.
214212
# permissive - SELinux prints warnings instead of enforcing.
215213
# disabled - No SELinux policy is loaded.
216-
SELINUX=permissive
214+
SELINUX=enforcing
217215
# SELINUXTYPE= can take one of these two values:
218216
# targeted - Targeted processes are protected,
219217
# mls - Multi Level Security protection.

‎source/releasenotes/about.rst‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,18 @@ Known Issues
5555
primary storage, due to a regression in the restore-and-attach command handling. See
5656
https://github.com/apache/cloudstack/pull/14007 for details and status.
5757

58+
SELinux and AppArmor on KVM Hosts
59+
---------------------------------
60+
61+
In older versions, CloudStack set SELinux to permissive mode and disabled the
62+
libvirt AppArmor profiles when configuring a KVM host. Since 24.0.0,
63+
CloudStack no longer changes these settings. If you face issues on a KVM host,
64+
for example Instances failing to start or storage operations failing with
65+
permission errors, please check the SELinux and AppArmor settings of the host
66+
and the ``security_driver`` setting in ``/etc/libvirt/qemu.conf``. Please
67+
note that if the hosts of a cluster have different ``security_driver`` settings,
68+
the migration of Instances between them may be denied by libvirt. See
69+
:ref:`kvm-security-policies` for the recommended configuration.
70+
5871
The full list of new features can be found in the project release notes at
5972
https://docs.cloudstack.apache.org/en/4.23.0.0/releasenotes/changes.html

0 commit comments

Comments
 (0)