{"id":3367,"date":"2023-03-27T07:00:00","date_gmt":"2023-03-27T06:00:00","guid":{"rendered":"https:\/\/www.my-it-brain.de\/wordpress\/?p=3367"},"modified":"2023-04-10T22:02:31","modified_gmt":"2023-04-10T20:02:31","slug":"rhel-system-roles-firewall","status":"publish","type":"post","link":"https:\/\/www.my-it-brain.de\/wordpress\/rhel-system-roles-firewall\/","title":{"rendered":"RHEL System Roles: firewall"},"content":{"rendered":"\n<p>In Teil 5 meiner losen Reihe \u00fcber die <a href=\"https:\/\/access.redhat.com\/articles\/3050101\">RHEL System Roles<\/a> stelle ich die Rolle <em>firewall<\/em> vor. Diese dient der Konfiguration des Regelwerks f\u00fcr <a href=\"https:\/\/firewalld.org\/\">firewalld<\/a>. M\u00f6chte man bestimmte Regels\u00e4tze f\u00fcr alle bzw. eine Gruppe von Servern konfigurieren, erleichtert der Einsatz dieser Rolle die Arbeit und reduziert den administrativen Aufwand.<\/p>\n\n\n\n<p>Im Folgenden stelle ich meinen Anwendungsfall vor. Anschlie\u00dfend beschreibe ich, wie ich diesen mithilfe der RHEL System Role l\u00f6se.<\/p>\n\n\n\n<p>W\u00e4hrend mir dieser Artikel zur Dokumentation dient, soll er euch den Einsatz von RHEL Roles verdeutlichen.<\/p>\n\n\n\n<p><strong>Warnung:<\/strong> Die Firewall-Konfiguration eines Hosts \u00fcber das Netzwerk birgt die Gefahr, sich selbst auszusperren. Wenn dies passiert, ben\u00f6tigt man h\u00f6chstwahrscheinlich physischen Zugriff auf den verkonfigurierten Host.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Anwendungsfall<\/h2>\n\n\n\n<p>Ich m\u00f6chte sicherstellen, dass auf allen RHEL-Systemen in meiner Labor-Umgebung das Paket <code>firewalld<\/code> installiert ist, der Service aktiviert ist und l\u00e4uft. Dar\u00fcber hinaus m\u00f6chte ich sicherstellen, dass ausschlie\u00dflich der SSH-Zugriff in der lokalen Hostfirewall freigegeben ist und alle \u00fcbrigen Regeln entfernt werden.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Die Rolle<\/h2>\n\n\n\n<p>Durch die Installation des Pakets <code>rhel-system-roles<\/code> existiert diese Rolle bereits auf meinem System und muss nur noch konfiguriert werden. Die Rolle selbst findet man im Pfad <code>\/usr\/share\/ansible\/roles\/rhel-system-roles.firewall\/<\/code> und die Dokumentation in <code>\/usr\/share\/doc\/rhel-system-roles\/firewall\/README.md<\/code>. Aus letzterer stammt auch folgendes Beispiel:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\n- name: Erase existing config and enable ssh service\n  hosts: myhost\n\n  vars:\n    firewall:\n      - previous: replaced\n      - service: 'ssh'\n        state: 'enabled'\n  roles:\n    - rhel-system-roles.firewall<\/code><\/pre>\n\n\n\n<p>Dieses Beispiel kann ich direkt in das folgende Playbook \u00fcbernehmen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Das Playbook<\/h2>\n\n\n\n<p>Das Playbook ist kompakt und \u00fcbersichtlich:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\n- name: Ensure firewalld is started with SSH-acess only\n  hosts: all\n\n  vars:\n    firewall:\n      - previous: replaced\n      - service: 'ssh'\n        state: 'enabled'\n  roles:\n    - rhel-system-roles.firewall<\/code><\/pre>\n\n\n\n<p>Der folgende Playbook-Lauf in meiner Labor-Umgebung zeigt, dass sich die RHEL System Role auch um die Installation, Aktivierung und den Start des Dienstes <em>firewalld<\/em> k\u00fcmmert, wenn dies erforderlich ist.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@ansible-ctrl ansible]# ansible-playbook firewall_config.yml \n\nPLAY &#91;Ensure firewalld is started with SSH-acess only] ************************************\n\nTASK &#91;Gathering Facts] ********************************************************************\nok: &#91;rhel7]\nok: &#91;ansible-pctrl]\nok: &#91;rhel9]\nok: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : include_tasks] *****************************************\nincluded: \/usr\/share\/ansible\/roles\/rhel-system-roles.firewall\/tasks\/firewalld.yml for ansible-pctrl, rhel7, rhel8, rhel9\n\nTASK &#91;rhel-system-roles.firewall : Ensure ansible_facts used by role] *********************\nok: &#91;rhel7]\nok: &#91;rhel9]\nok: &#91;ansible-pctrl]\nok: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : Install firewalld] *************************************\nok: &#91;ansible-pctrl]\nchanged: &#91;rhel9]\nchanged: &#91;rhel8]\nchanged: &#91;rhel7]\n\nTASK &#91;rhel-system-roles.firewall : Install python-firewall] *******************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel8]\nskipping: &#91;rhel9]\nok: &#91;rhel7]\n\nTASK &#91;rhel-system-roles.firewall : Install python3-firewall] ******************************\nskipping: &#91;rhel7]\nok: &#91;rhel9]\nok: &#91;ansible-pctrl]\nok: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : Enable and start firewalld service] ********************\nok: &#91;ansible-pctrl]\nchanged: &#91;rhel7]\nchanged: &#91;rhel9]\nchanged: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : Check if previous replaced is defined] *****************\nok: &#91;rhel7]\nok: &#91;ansible-pctrl]\nok: &#91;rhel9]\nok: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : Get config files, checksums before and remove] *********\nok: &#91;rhel9]\nok: &#91;rhel7]\nok: &#91;rhel8]\nok: &#91;ansible-pctrl]\n\nTASK &#91;rhel-system-roles.firewall : Configure firewall] ************************************\nok: &#91;rhel7] =&gt; (item={'service': 'ssh', 'state': 'enabled'})\nok: &#91;rhel9] =&gt; (item={'service': 'ssh', 'state': 'enabled'})\nok: &#91;rhel8] =&gt; (item={'service': 'ssh', 'state': 'enabled'})\nok: &#91;ansible-pctrl] =&gt; (item={'service': 'ssh', 'state': 'enabled'})\n\nTASK &#91;rhel-system-roles.firewall : gather firewall config information] ********************\nskipping: &#91;ansible-pctrl] =&gt; (item={'service': 'ssh', 'state': 'enabled'}) \nskipping: &#91;rhel9] =&gt; (item={'service': 'ssh', 'state': 'enabled'}) \nskipping: &#91;rhel7] =&gt; (item={'service': 'ssh', 'state': 'enabled'}) \nskipping: &#91;rhel8] =&gt; (item={'service': 'ssh', 'state': 'enabled'}) \n\nTASK &#91;rhel-system-roles.firewall : update firewalld_config fact] **************************\nskipping: &#91;rhel7]\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel9]\nskipping: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : gather firewall config if no arguments] ****************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel9]\nskipping: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : update firewalld_config fact] **************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel7]\nskipping: &#91;rhel9]\nskipping: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : Get config files, checksums after] *********************\nok: &#91;rhel7]\nok: &#91;rhel9]\nok: &#91;ansible-pctrl]\nok: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : Calculate what has changed] ****************************\nchanged: &#91;ansible-pctrl]\nchanged: &#91;rhel7]\nchanged: &#91;rhel9]\nchanged: &#91;rhel8]\n\nTASK &#91;rhel-system-roles.firewall : Show diffs] ********************************************\nskipping: &#91;ansible-pctrl]\nskipping: &#91;rhel8]\nskipping: &#91;rhel7]\nskipping: &#91;rhel9]\n\nPLAY RECAP ********************************************************************************\nansible-pctrl              : ok=11   changed=1    unreachable=0    failed=0    skipped=6    rescued=0    ignored=0   \nrhel7                      : ok=11   changed=3    unreachable=0    failed=0    skipped=6    rescued=0    ignored=0   \nrhel8                      : ok=11   changed=3    unreachable=0    failed=0    skipped=6    rescued=0    ignored=0   \nrhel9                      : ok=11   changed=3    unreachable=0    failed=0    skipped=6    rescued=0    ignored=0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Fazit<\/h2>\n\n\n\n<p>Ich beginne, mich an dieser Stelle zu wiederholen. Auch diesmal war es m\u00f6glich, mithilfe einer RHEL System Role einen einfachen Anwendungsfall schnell und unkompliziert zu l\u00f6sen, ohne selbst eine Ansible-Rolle schreiben zu m\u00fcssen. Ein einfaches Copy-Past-and-Modify gen\u00fcgte.<\/p>\n\n\n\n<p>In meinen Augen ist es Red Hat gelungen, den System-Administratoren mit den RHEL System Roles etwas Arbeit abzunehmen und sie beim Einsatz von Ansible zu unterst\u00fctzen.<\/p>\n\n\n\n<p>Lasst euch \u00fcberraschen, welche Rolle ich mir als n\u00e4chstes herauspicke.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Quellen und weiterf\u00fchrende Links<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\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-selinux\/\">RHEL System Roles: selinux<\/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<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In Teil 5 meiner losen Reihe \u00fcber die RHEL System Roles stelle ich die Rolle firewall vor. Diese dient der Konfiguration des Regelwerks f\u00fcr firewalld. M\u00f6chte man bestimmte Regels\u00e4tze f\u00fcr alle bzw. eine Gruppe von Servern konfigurieren, erleichtert der Einsatz dieser Rolle die Arbeit und reduziert den administrativen Aufwand. Im Folgenden stelle ich meinen Anwendungsfall<span class=\"continue-reading\"> <a href=\"https:\/\/www.my-it-brain.de\/wordpress\/rhel-system-roles-firewall\/\">[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":[588,754],"class_list":["post-3367","post","type-post","status-publish","format-standard","hentry","category-ansible","tag-firewalld","tag-rhel-system-roles"],"_links":{"self":[{"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/posts\/3367","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=3367"}],"version-history":[{"count":7,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/posts\/3367\/revisions"}],"predecessor-version":[{"id":3463,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/posts\/3367\/revisions\/3463"}],"wp:attachment":[{"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/media?parent=3367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/categories?post=3367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.my-it-brain.de\/wordpress\/wp-json\/wp\/v2\/tags?post=3367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}