Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low

- name: Ensure firewalld default zone is drop
ansible.builtin.lineinfile:
path: /etc/firewalld/firewalld.conf
regexp: '^DefaultZone='
line: 'DefaultZone=drop'
create: yes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this file doesn't exist is firewalld installed?

Also it seems this might be a symlink on some systems.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low

{{{ bash_replace_or_append('/etc/firewalld/firewalld.conf', '^DefaultZone=', 'drop', '%s=%s') }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<def-group>
<definition class="compliance" id="{{{ rule_id }}}" version="1">
{{{ oval_metadata("Firewalld Must Employ a Deny-all, Allow-by-exception Policy") }}}
<criteria operator="AND">
<criterion comment="firewalld default zone has target DROP"
test_ref="test_firewalld_default_zone_target_drop" />
</criteria>
</definition>

<ind:textfilecontent54_object id="object_firewalld_default_zone" version="1">
<ind:filepath>/etc/firewalld/firewalld.conf</ind:filepath>
<ind:pattern operation="pattern match">^DefaultZone=(.*)$</ind:pattern>
<ind:instance datatype="int">1</ind:instance>
</ind:textfilecontent54_object>

<local_variable id="var_firewalld_default_zone" datatype="string" version="1" comment="Default zone name">
<object_component object_ref="object_firewalld_default_zone" item_field="subexpression" />
</local_variable>

<local_variable id="var_firewalld_default_zone_xml_filename" datatype="string" version="1" comment="Default zone xml file name">
<concat>
<variable_component var_ref="var_firewalld_default_zone" />
<literal_component>.xml</literal_component>
</concat>
</local_variable>

<ind:xmlfilecontent_test id="test_firewalld_default_zone_target_drop" version="1" check="all" check_existence="at_least_one_exists" comment="Ensure default zone has target DROP">
<ind:object object_ref="object_firewalld_default_zone_target_drop_etc" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is invalid OVAL. You need split this into test two tests.

<ind:object object_ref="object_firewalld_default_zone_target_drop_usr" />
</ind:xmlfilecontent_test>

<ind:xmlfilecontent_object id="object_firewalld_default_zone_target_drop_etc" version="1">
<ind:path>/etc/firewalld/zones</ind:path>
<ind:filename var_ref="var_firewalld_default_zone_xml_filename" var_check="all"/>
<ind:xpath>/zone[@target='DROP']</ind:xpath>
</ind:xmlfilecontent_object>

<ind:xmlfilecontent_object id="object_firewalld_default_zone_target_drop_usr" version="1">
<ind:path>/usr/lib/firewalld/zones</ind:path>
<ind:filename var_ref="var_firewalld_default_zone_xml_filename" var_check="all"/>
<ind:xpath>/zone[@target='DROP']</ind:xpath>
</ind:xmlfilecontent_object>

</def-group>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# packages = firewalld
# platform = multi_platform_all

if grep -q "^DefaultZone=" /etc/firewalld/firewalld.conf; then
sed -i 's/^DefaultZone=.*/DefaultZone=drop/' /etc/firewalld/firewalld.conf
else
echo "DefaultZone=drop" >> /etc/firewalld/firewalld.conf
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# packages = firewalld
# platform = multi_platform_all

if grep -q "^DefaultZone=" /etc/firewalld/firewalld.conf; then
sed -i 's/^DefaultZone=.*/DefaultZone=public/' /etc/firewalld/firewalld.conf
else
echo "DefaultZone=public" >> /etc/firewalld/firewalld.conf
fi
Loading