{"id":3346,"date":"2023-02-06T07:00:00","date_gmt":"2023-02-06T06:00:00","guid":{"rendered":"https:\/\/www.my-it-brain.de\/wordpress\/?p=3346"},"modified":"2023-04-10T21:59:51","modified_gmt":"2023-04-10T19:59:51","slug":"rhel-system-roles-selinux","status":"publish","type":"post","link":"https:\/\/www.my-it-brain.de\/wordpress\/rhel-system-roles-selinux\/","title":{"rendered":"RHEL System Roles: selinux"},"content":{"rendered":"\n<p>Dies ist Teil 2 meiner kleinen Serie zu den RHEL System Roles. Ich beschreibe hierin, wie die Ansible-Rolle <em>selinux<\/em> genutzt werden kann, um Einstellungen f\u00fcr SELinux auf mehreren\/allen Hosts in der eigenen Infrastruktur zu konfigurieren.<\/p>\n\n\n\n<p>Die Anforderung dies zu tun, l\u00e4sst sich bspw. aus den IT-Grundschutzbausteinen SYS.1.3.A10, SYS.1.3.A16, SYS.2.3.A8 und SYS.2.3.A17 des BSI <a href=\"#quellen-links\">[2]<\/a> ableiten.<\/p>\n\n\n\n<p>Falls euch SELinux noch nichts sagt, schaut zuerst in meine <a href=\"https:\/\/www.my-it-brain.de\/wordpress\/einfuehrung-in-das-grundlegende-konzept-von-selinux\/\" data-type=\"post\" data-id=\"1647\">Einf\u00fchrung in das grundlegende Konzept von SELinux<\/a> <a href=\"#quellen-links\">[1]<\/a>.<\/p>\n\n\n\n<p>In dem folgenden und zugegeben sehr einfachen Beispiel nutze ich ein Playbook, welches sicherstellt, dass SELinux auf allen Ziel-Hosts im Modus <em>Enforcing<\/em> l\u00e4uft. Dieses Playbook kann ich dann bspw. durch cron(8) in regelm\u00e4\u00dfigen Abst\u00e4nden laufen lassen, um sicherzustellen, dass sich SELinux im gew\u00fcnschten Modus befindet bzw. in diesen zur\u00fcckversetzt wird.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Voraussetzungen<\/h2>\n\n\n\n<p>Auf dem Ansible-Controller m\u00fcssen die Pakete <code>ansible-core<\/code> und <code>rhel-system-roles<\/code> installiert sein.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Das Playbook<\/h2>\n\n\n\n<p>Die Dokumentation zu dieser Ansible-Rolle befindet sich in <code>\/usr\/share\/doc\/rhel-system-roles\/selinux\/README.md<\/code>. Darin enthalten ist auch ein Code-Beispiel, aus dem ich das folgende Playbook erstellt habe:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\n- name: Enforce SELinux Policy\n  hosts: all\n  vars:\n    selinux_policy: targeted\n    selinux_state: enforcing\n  roles:\n    - role: rhel-system-roles.selinux\n      become: true<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Testlauf in der Laborumgebung<\/h2>\n\n\n\n<p>Der erste Code-Block gibt die Ausgabe des Playbook-Laufs wieder. Der zweite Code-Block zeigt ein <a href=\"https:\/\/www.my-it-brain.de\/wordpress\/ansible-was-ich-am-ad-hoc-modus-schaetze\/\" data-type=\"post\" data-id=\"1701\">Ansible-Ad-Hoc-Kommando<\/a>, mit dem ich kontrolliere, ob Ansible auf allen Ziel-Hosts im Enforcing-Modus l\u00e4uft.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@ansible-ctrl ansible]# pwd\n\/root\/ansible\n&#91;root@ansible-ctrl ansible]# ansible-playbook enfoce_selinux.yml \n\nPLAY &#91;Enforce SELinux Policy] **************************************************************************\n\nTASK &#91;Gathering Facts] *********************************************************************************\nok: &#91;rhel7]\nok: &#91;rhel8]\nok: &#91;rhel9]\nok: &#91;ansible-pctrl]\n\nTASK &#91;rhel-system-roles.selinux : Set ansible_facts required by role and install packages] *************\nincluded: \/usr\/share\/ansible\/roles\/rhel-system-roles.selinux\/tasks\/set_facts_packages.yml for ansible-pctrl, rhel7, rhel8, rhel9\n\nTASK &#91;rhel-system-roles.selinux : Ensure ansible_facts used by role] ***********************************\nskipping: &#91;rhel7]\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel9]\nskipping: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.selinux : Install SELinux python2 tools] ***************************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\nok: &#91;rhel7]\n\nTASK &#91;rhel-system-roles.selinux : Install SELinux python3 tools] ***************************************\nskipping: &#91;rhel7]\nok: &#91;ansible-pctrl]\nok: &#91;rhel9]\nok: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.selinux : refresh facts] *******************************************************\nok: &#91;rhel7]\nok: &#91;rhel9]\nok: &#91;ansible-pctrl]\nok: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.selinux : Install SELinux tool semanage] ***************************************\nskipping: &#91;rhel7]\nok: &#91;rhel9]\nok: &#91;ansible-pctrl]\nok: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.selinux : Set permanent SELinux state if enabled] ******************************\nok: &#91;rhel7]\nok: &#91;rhel9]\nok: &#91;rhel8]\nok: &#91;ansible-pctrl]\n\nTASK &#91;rhel-system-roles.selinux : Set permanent SELinux state if disabled] *****************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\n\nTASK &#91;rhel-system-roles.selinux : Set selinux_reboot_required] *****************************************\nok: &#91;ansible-pctrl]\nok: &#91;rhel9]\nok: &#91;rhel7]\nok: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.selinux : Fail if reboot is required] ******************************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\n\nTASK &#91;rhel-system-roles.selinux : Warn if SELinux is disabled] *****************************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\n\nTASK &#91;rhel-system-roles.selinux : Drop all local modifications] ****************************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\n\nTASK &#91;rhel-system-roles.selinux : Purge all SELinux boolean local modifications] ***********************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\n\nTASK &#91;rhel-system-roles.selinux : Purge all SELinux file context local modifications] ******************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\n\nTASK &#91;rhel-system-roles.selinux : Purge all SELinux port local modifications] **************************\nskipping: &#91;rhel7]\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\n\nTASK &#91;rhel-system-roles.selinux : Purge all SELinux login local modifications] *************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\n\nTASK &#91;rhel-system-roles.selinux : Set SELinux booleans] ************************************************\n\nTASK &#91;rhel-system-roles.selinux : Set SELinux file contexts] *******************************************\n\nTASK &#91;rhel-system-roles.selinux : Restore SELinux labels on filesystem tree] ***************************\n\nTASK &#91;rhel-system-roles.selinux : Restore SELinux labels on filesystem tree in check mode] *************\n\nTASK &#91;rhel-system-roles.selinux : Set an SELinux label on a port] **************************************\n\nTASK &#91;rhel-system-roles.selinux : Set linux user to SELinux user mapping] ******************************\n\nTASK &#91;rhel-system-roles.selinux : Get SELinux modules facts] *******************************************\nok: &#91;rhel8]\nok: &#91;rhel9]\nok: &#91;ansible-pctrl]\nok: &#91;rhel7]\n\nTASK &#91;rhel-system-roles.selinux : include_tasks] *******************************************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\n\nPLAY RECAP *********************************************************************************************\nansible-pctrl              : ok=8    changed=0    unreachable=0    failed=0    skipped=17   rescued=0    ignored=0   \nrhel7                      : ok=7    changed=0    unreachable=0    failed=0    skipped=18   rescued=0    ignored=0   \nrhel8                      : ok=8    changed=0    unreachable=0    failed=0    skipped=17   rescued=0    ignored=0   \nrhel9                      : ok=8    changed=0    unreachable=0    failed=0    skipped=17   rescued=0    ignored=0   \n\n&#91;root@ansible-ctrl ansible]#<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@ansible-ctrl ansible]# ansible -m command -a'getenforce' all\nrhel7 | CHANGED | rc=0 &gt;&gt;\nEnforcing\nrhel8 | CHANGED | rc=0 &gt;&gt;\nEnforcing\nansible-pctrl | CHANGED | rc=0 &gt;&gt;\nEnforcing\nrhel9 | CHANGED | rc=0 &gt;&gt;\nEnforcing<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Zusammenfassung<\/h2>\n\n\n\n<p>Mit einem sehr einfachen Beispiel habe ich gezeigt, wie die RHEL System Role SELinux genutzt werden kann, um sicherzustellen, dass SELinux auf allen Ziel-Hosts im Enforcing-Modus  l\u00e4uft.<\/p>\n\n\n\n<p>Dazu habe ich keine Zeile Ansible-Code selbst geschrieben. Den Quelltext f\u00fcr mein Playbook habe ich per Copy-Paste-and-Modify aus der mitgelieferten Dokumentation \u00fcbernommen. Anschlie\u00dfend habe ich die notwendige Variable definiert und das Playbook ausgef\u00fchrt. Fertig.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"quellen-links\">Quellen und weiterf\u00fchrende Links<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.bsi.bund.de\/SharedDocs\/Downloads\/DE\/BSI\/Grundschutz\/Kompendium\/IT_Grundschutz_Kompendium_Edition2022.pdf?__blob=publicationFile&amp;v=3\">BSI IT-Grundschutz-Kompendium 2022<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.my-it-brain.de\/wordpress\/einfuehrung-in-das-grundlegende-konzept-von-selinux\/\" data-type=\"post\" data-id=\"1647\">Einf\u00fchrung in das grundlegende Konzept von SELinux<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/linux-system-roles\/selinux\">Quelltext im Upstream-Projekt {en}<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/access.redhat.com\/articles\/3050101\">Red Hat Enterprise Linux (RHEL) System Roles {en}<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/playbooks_reuse_roles.html#role-directory-structure\">Ansible Documentation: Role Directory Structure {en}<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/access.redhat.com\/downloads\/\">Red Hat Software and Download Center {en}<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.redhat.com\/de\/about\/value-of-subscription\">Die Vorteile einer Red Hat Subskription<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.my-it-brain.de\/wordpress\/rhel-system-roles-timesync\/\">RHEL System Roles: timesync<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.my-it-brain.de\/wordpress\/rhel-system-roles-sshd\/\">RHEL System Roles: sshd<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.my-it-brain.de\/wordpress\/rhel-system-roles-firewall\/\">RHEL System Roles: firewall<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Dies ist Teil 2 meiner kleinen Serie zu den RHEL System Roles. Ich beschreibe hierin, wie die Ansible-Rolle selinux genutzt werden kann, um Einstellungen f\u00fcr SELinux auf mehreren\/allen Hosts in der eigenen Infrastruktur zu konfigurieren. Die Anforderung dies zu tun, l\u00e4sst sich bspw. aus den IT-Grundschutzbausteinen SYS.1.3.A10, SYS.1.3.A16, SYS.2.3.A8 und SYS.2.3.A17 des BSI [2] ableiten.<span class=\"continue-reading\"> <a href=\"https:\/\/www.my-it-brain.de\/wordpress\/rhel-system-roles-selinux\/\">[Weiterlesen&#8230;]<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_metis_text_type":"","_metis_text_length":0,"_post_count":0,"footnotes":""},"categories":[532],"tags":[410,754,443],"class_list":["post-3346","post","type-post","status-publish","format-standard","hentry","category-ansible","tag-ansible","tag-rhel-system-roles","tag-selinux"],"_links":{"self":[{"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/posts\/3346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/comments?post=3346"}],"version-history":[{"count":6,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/posts\/3346\/revisions"}],"predecessor-version":[{"id":3460,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/posts\/3346\/revisions\/3460"}],"wp:attachment":[{"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/media?parent=3346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/categories?post=3346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/tags?post=3346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}