Skip to content

Commit

Permalink
Update require_emergency_target_auth and require_singleuser_auth
Browse files Browse the repository at this point in the history
To better support drop in config files for RHEL and Fedora.
  • Loading branch information
Mab879 committed Oct 18, 2024
1 parent a07b4dd commit 94babc3
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# complexity = low
# disruption = low

{{% if 'sle' in product or 'rhel' in product %}}
{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}}
- name: Require emergency mode password
ansible.builtin.blockinfile:
create: yes
Expand All @@ -18,7 +18,7 @@
create: yes
dest: /usr/lib/systemd/system/emergency.service
regexp: "^#?ExecStart="
{{% if product in ["fedora", "ol8", "ol9", "rhel8", "rhel9"] -%}}
{{% if product in ["ol8", "ol9"] -%}}
line: "ExecStart=-/usr/lib/systemd/systemd-sulogin-shell emergency"
{{%- else -%}}
line: 'ExecStart=-/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# platform = multi_platform_all

{{% if 'sle' in product or 'rhel' in product %}}
{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}}
service_dropin_cfg_dir="/etc/systemd/system/emergency.service.d"
service_dropin_file="${service_dropin_cfg_dir}/10-oscap.conf"
{{% else %}}
service_file="/usr/lib/systemd/system/emergency.service"
{{% endif %}}

{{% if product in ["fedora", "ol8", "ol9", "rhel8", "rhel9", "sle12", "sle15"] -%}}
{{% if product in ["fedora", "ol8", "ol9", "sle12", "sle15"] or 'rhel' in product -%}}
sulogin="/usr/lib/systemd/systemd-sulogin-shell emergency"
{{%- else -%}}
sulogin='/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"'
{{%- endif %}}

{{% if 'sle' in product or 'rhel' in product %}}
{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}}
mkdir -p "${service_dropin_cfg_dir}"
echo "[Service]" >> "${service_dropin_file}"
echo "ExecStart=-$sulogin" >> "${service_dropin_file}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<definition class="compliance" id="require_emergency_target_auth" version="1">
{{{ oval_metadata("The requirement for a password to boot into emergency mode
should be configured correctly.") }}}
{{% if 'sle' in product or 'rhel' in product %}}
{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}}
<criteria operator="OR">
{{% endif %}}
<criteria operator="AND">
Expand All @@ -11,20 +11,19 @@
<criterion test_ref="test_require_emergency_service_emergency_target" />
<criterion test_ref="test_no_custom_emergency_target" negate="true"/>
<criterion test_ref="test_no_custom_emergency_service" negate="true"/>
<criterion test_ref="test_{{{ rule_id }}}_drop_in_config_exist" negate="true"/>
</criteria>
{{% if 'sle' in product or 'rhel' in product %}}
<criteria operator="OR">
<criterion comment="Check /usr/lib/* configuration"
test_ref="test_require_emergency_service" />
{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}}
<criteria operator="ONE">
<criterion comment="Check drop-in configuration"
test_ref="test_require_emergency_service_dropin" />
test_ref="test_require_emergency_service_drop_in" />
</criteria>
</criteria>
{{% endif %}}
</definition>
<ind:textfilecontent54_test check="all" check_existence="all_exist"
comment="Tests that
{{% if product in ["fedora", "ol8", "ol9", "rhel8", "rhel9", "sle12", "sle15"] -%}}
{{% if product in ["fedora", "ol8", "ol9", "sle12", "sle15"] or 'rhel' in product -%}}
/usr/lib/systemd/systemd-sulogin-shell
{{%- else -%}}
/sbin/sulogin
Expand All @@ -36,24 +35,24 @@
</ind:textfilecontent54_test>
<ind:textfilecontent54_object id="obj_require_emergency_service" version="1">
<ind:filepath>/usr/lib/systemd/system/emergency.service</ind:filepath>
{{%- if product in ["fedora", "ol8", "ol9", "kylinserver10", "openeuler2203", "rhel8", "rhel9", "sle12", "sle15"] -%}}
{{%- if product in ["fedora", "ol8", "ol9", "kylinserver10", "openeuler2203", "sle12", "sle15"] or 'rhel' in product -%}}
<ind:pattern operation="pattern match">^ExecStart=\-/usr/lib/systemd/systemd-sulogin-shell[\s]+emergency</ind:pattern>
{{%- else -%}}
<ind:pattern operation="pattern match">^ExecStart=\-/bin/sh[\s]+-c[\s]+\"(/usr)?/sbin/sulogin;[\s]+/usr/bin/systemctl[\s]+--fail[\s]+--no-block[\s]+default\"</ind:pattern>
{{%- endif -%}}
<ind:instance datatype="int">1</ind:instance>
</ind:textfilecontent54_object>

{{% if 'sle' in product or 'rhel' in product %}}
{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}}
<ind:textfilecontent54_test check="all" check_existence="all_exist"
comment="Tests that
/usr/lib/systemd/systemd-sulogin-shell
was not removed from the default systemd emergency.service to ensure that a
password must be entered to access single user mode"
id="test_require_emergency_service_dropin" version="1">
<ind:object object_ref="obj_require_emergency_service_dropin" />
id="test_require_emergency_service_drop_in" version="1">
<ind:object object_ref="obj_require_emergency_service_drop_in" />
</ind:textfilecontent54_test>
<ind:textfilecontent54_object id="obj_require_emergency_service_dropin" version="1">
<ind:textfilecontent54_object id="obj_require_emergency_service_drop_in" version="1">
<ind:path>/etc/systemd/system/emergency.service.d</ind:path>
<ind:filename operation="pattern match">^.*\.conf$</ind:filename>
<ind:pattern operation="pattern match">^ExecStart=\-/usr/lib/systemd/systemd-sulogin-shell[\s]+emergency</ind:pattern>
Expand Down Expand Up @@ -95,4 +94,20 @@
<unix:path operation="equals">/etc/systemd/system</unix:path>
<unix:filename operation="pattern match">^emergency.target$</unix:filename>
</unix:file_object>

<unix:file_test id="test_{{{ rule_id }}}_drop_in_config_exist"
comment="Look for drop in config files for emergency.service"
version="1"
check="all"
check_existence="at_least_one_exists">
<unix:object object_ref="object_{{{ rule_id }}}_drop_in_config_exist" />
</unix:file_test>

<unix:file_object id="object_{{{ rule_id }}}_drop_in_config_exist"
comment="Look for drop in config files for emergency.service"
version="1">
<unix:path operation="equals">/etc/systemd/system/emergency.service.d</unix:path>
<unix:filename operation="pattern match">^.*\.conf$</unix:filename>
</unix:file_object>

</def-group>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# platform = multi_platform_fedora,multi_platform_rhel,multi_platform_sle
rm -f /etc/systemd/system/emergency.service
mkdir -p /etc/systemd/system/emergency.service.d/
cat << EOF > /etc/systemd/system/emergency.service.d/10-automatus.conf
cat << EOF > /etc/systemd/system/emergency.service.d/10-oscap.conf
[Service]
ExecStart=-/usr/lib/systemd/systemd-sulogin-shell emergency
ExecStart=/bin/bash
EOF
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
# complexity = low
# disruption = low

{{% if 'rhel' not in product %}}
{{% if 'rhel' not in product and product != 'fedora' %}}
- name: Require single user mode password
lineinfile:
create: yes
dest: /usr/lib/systemd/system/rescue.service
regexp: "^#?ExecStart="
{{% if product in ["fedora", "ol8", "ol9", "sle12", "sle15"] -%}}
{{% if product in ["ol8", "ol9", "sle12", "sle15"]-%}}
line: "ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue"
{{%- else -%}}
line: 'ExecStart=-/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"'
{{%- endif %}}
{{% else %}}
- name: "{{{ rule_title }}} - Require single user mode password"
- name: "{{{ rule_title }}} - Require emergency user mode password"
community.general.ini_file:
path: "/etc/systemd/system/rescue.service.d/10-oscap.conf"
section: "Service"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# platform = multi_platform_all

{{% if product in ["fedora", "ol8", "ol9", "sle12", "sle15",] or 'rhel' in product -%}}
{{% set sulogin="/usr/lib/systemd/systemd-sulogin-shell rescue" %}}
{{% set sulogin="-/usr/lib/systemd/systemd-sulogin-shell rescue" %}}
{{%- else -%}}
{{% set sulogin='/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"' %}}
{{% set sulogin='-/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"' %}}
{{%- endif %}}

{{{ bash_ensure_ini_config("/etc/systemd/system/rescue.service.d/10-oscap.conf", "Service", "ExecStart", sulogin) }}}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ind:object object_ref="obj_require_rescue_service" />
</ind:textfilecontent54_test>
<ind:textfilecontent54_object id="obj_require_rescue_service" version="1">
{{%- if 'rhel' in product -%}}
{{%- if 'rhel' in product or product == 'fedora' -%}}
<ind:path>/etc/systemd/system/rescue.service.d</ind:path>
<ind:filename operation="pattern match">^.*\.conf$</ind:filename>
{{%- else -%}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ocil: |-
To check if authentication is required for single-user mode, run the following command:
<pre>$ grep sulogin /usr/lib/systemd/system/rescue.service</pre>
The output should be similar to the following, and the line must begin with
{{% if product in ["fedora", "ol8", "ol9", "rhel8", "rhel9", "rhcos4"] -%}}
{{% if product in ["fedora", "ol8", "ol9", "rhcos4"] or 'rhel' in product -%}}
ExecStart and /usr/lib/systemd/systemd-sulogin-shell.
<pre>ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue</pre>
{{%- else -%}}
Expand Down Expand Up @@ -84,7 +84,7 @@ fixtext: |-
Configure {{{ full_name }}} to require authentication in single user mode.
Add or update the following line in "/usr/lib/systemd/system/rescue.service":
{{% if product in ["fedora", "ol8", "ol9", "rhel8", "rhel9", "sle12", "sle15"] -%}}
{{% if product in ["fedora", "ol8", "ol9", "sle12", "sle15"] or 'rhel' in product -%}}
ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue
{{%- else -%}}
ExecStart=-/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# platform = multi_platform_fedora,multi_platform_rhel

rm -rf /etc/systemd/system/rescue.service.d
mkdir -p /etc/systemd/system/rescue.service.d
cat << EOF > /etc/systemd/system/rescue.service.d/10-automatus.conf
[Service]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# platform = Oracle Linux 8,Oracle Linux 9,multi_platform_fedora,multi_platform_rhel
# platform = Oracle Linux 8,Oracle Linux 9

service_file="/usr/lib/systemd/system/rescue.service"
sulogin="/usr/lib/systemd/systemd-sulogin-shell"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
# platform = multi_platform_fedora,multi_platform_rhel

rm -rf /etc/systemd/system/rescue.service.d
mkdir -p /etc/systemd/system/rescue.service.d
cat << EOF > /etc/systemd/system/rescue.service.d/10-automatus.conf
[Service]
ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue
ExecStart=/bin/bash
EOF

0 comments on commit 94babc3

Please sign in to comment.