diff --git a/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/ansible/shared.yml index a3490a60d13..fe2d974f672 100644 --- a/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/ansible/shared.yml +++ b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/ansible/shared.yml @@ -4,7 +4,7 @@ # complexity = low # disruption = low -{{% if 'sle' in product %}} +{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}} - name: Require emergency mode password ansible.builtin.blockinfile: create: yes @@ -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"' diff --git a/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/bash/shared.sh b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/bash/shared.sh index 2a65ef992e5..22847e2df8e 100644 --- a/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/bash/shared.sh +++ b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/bash/shared.sh @@ -1,19 +1,19 @@ # platform = multi_platform_all -{{% if 'sle' 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 %}} +{{% 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}" diff --git a/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/oval/shared.xml b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/oval/shared.xml index 6a0e0f10d09..f16fe60c0b2 100644 --- a/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/oval/shared.xml +++ b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/oval/shared.xml @@ -2,7 +2,7 @@ {{{ oval_metadata("The requirement for a password to boot into emergency mode should be configured correctly.") }}} -{{% if 'sle' in product %}} +{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}} {{% endif %}} @@ -11,20 +11,19 @@ + -{{% if 'sle' in product %}} - - +{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}} + + test_ref="test_require_emergency_service_drop_in" /> {{% endif %}} /usr/lib/systemd/system/emergency.service - {{%- 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 -%}} ^ExecStart=\-/usr/lib/systemd/systemd-sulogin-shell[\s]+emergency {{%- else -%}} ^ExecStart=\-/bin/sh[\s]+-c[\s]+\"(/usr)?/sbin/sulogin;[\s]+/usr/bin/systemctl[\s]+--fail[\s]+--no-block[\s]+default\" @@ -44,16 +43,16 @@ 1 -{{% if 'sle' in product %}} +{{% if 'sle' in product or 'rhel' in product or product == 'fedora' %}} - + id="test_require_emergency_service_drop_in" version="1"> + - + /etc/systemd/system/emergency.service.d ^.*\.conf$ ^ExecStart=\-/usr/lib/systemd/systemd-sulogin-shell[\s]+emergency @@ -95,4 +94,20 @@ /etc/systemd/system ^emergency.target$ + + + + + + + /etc/systemd/system/emergency.service.d + ^.*\.conf$ + + diff --git a/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/tests/correct_value_dropin.pass.sh b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/tests/correct_value_dropin.pass.sh new file mode 100644 index 00000000000..73d2f3ad045 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/tests/correct_value_dropin.pass.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# 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 +[Service] +ExecStart=-/usr/lib/systemd/systemd-sulogin-shell emergency +EOF diff --git a/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/tests/wrong_value_dropin.fail.sh b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/tests/wrong_value_dropin.fail.sh new file mode 100644 index 00000000000..4545cf49f2c --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-physical/require_emergency_target_auth/tests/wrong_value_dropin.fail.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# 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-oscap.conf +[Service] +ExecStart=/bin/bash +EOF diff --git a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/ansible/shared.yml index 94e34a0f82d..8f202eb31dd 100644 --- a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/ansible/shared.yml +++ b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/ansible/shared.yml @@ -4,13 +4,22 @@ # complexity = low # disruption = low +{{% 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", "rhel8", "rhel9", "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 emergency user mode password" + community.general.ini_file: + path: "/etc/systemd/system/rescue.service.d/10-oscap.conf" + section: "Service" + option: "ExecStart" + value: "-/usr/lib/systemd/systemd-sulogin-shell rescue" +{{% endif %}} diff --git a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/bash/shared.sh b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/bash/shared.sh index 1d43e2d51dc..39b5667dba9 100644 --- a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/bash/shared.sh +++ b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/bash/shared.sh @@ -1,15 +1,9 @@ # platform = multi_platform_all -service_file="/usr/lib/systemd/system/rescue.service" - {{% if product in ["fedora", "ol8", "ol9", "sle12", "sle15",] or 'rhel' in product -%}} -sulogin="/usr/lib/systemd/systemd-sulogin-shell rescue" +{{% set sulogin="-/usr/lib/systemd/systemd-sulogin-shell rescue" %}} {{%- else -%}} -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 %}} -if grep "^ExecStart=.*" "$service_file" ; then - sed -i "s%^ExecStart=.*%ExecStart=-$sulogin%" "$service_file" -else - echo "ExecStart=-$sulogin" >> "$service_file" -fi +{{{ bash_ensure_ini_config("/etc/systemd/system/rescue.service.d/10-oscap.conf", "Service", "ExecStart", sulogin) }}} diff --git a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/oval/shared.xml b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/oval/shared.xml index 62fd1a76a25..ba3c7adddb1 100644 --- a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/oval/shared.xml +++ b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/oval/shared.xml @@ -5,7 +5,7 @@ - {{%- if product not in ["ol8", "rhel8"] -%}} + {{%- if product not in ["ol8"] and 'rhel' not in product and "fedora" != product-%}} @@ -14,7 +14,7 @@ + {{%- if 'rhel' in product or product == 'fedora' -%}} + /etc/systemd/system/rescue.service.d + ^.*\.conf$ + {{%- else -%}} /usr/lib/systemd/system/rescue.service - {{%- if product in ["fedora", "ol8", "ol9", "rhel8", "rhel9", "rhcos4", "sle12", "sle15"] -%}} - ^ExecStart=\-.*/usr/lib/systemd/systemd-sulogin-shell[ ]+rescue + {{%- endif -%}} + {{%- if product in ["fedora", "ol8", "ol9", "rhcos4", "sle12", "sle15"] or 'rhel' in product -%}} + ^ExecStart\s?=\s?\-.*/usr/lib/systemd/systemd-sulogin-shell[ ]+rescue {{%- else -%}} - ^ExecStart=\-/bin/sh[\s]+-c[\s]+\"(/usr)?/sbin/sulogin;[\s]+/usr/bin/systemctl[\s]+--fail[\s]+--no-block[\s]+default\" + ^ExecStart\s?=\s?\-/bin/sh[\s]+-c[\s]+\"(/usr)?/sbin/sulogin;[\s]+/usr/bin/systemctl[\s]+--fail[\s]+--no-block[\s]+default\" {{%- endif -%}} 1 - {{%- if product not in ["ol8", "rhel8"] -%}} + {{%- if product not in ["ol8"] and 'rhel' not in product -%}} diff --git a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/rule.yml b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/rule.yml index ac4b5a7337d..90c48074eb1 100644 --- a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/rule.yml +++ b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/rule.yml @@ -54,7 +54,7 @@ ocil: |- To check if authentication is required for single-user mode, run the following command:
$ grep sulogin /usr/lib/systemd/system/rescue.service
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.
ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue
{{%- else -%}} @@ -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" diff --git a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/correct_dropin.pass.sh b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/correct_dropin.pass.sh new file mode 100644 index 00000000000..3cf97a45713 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/correct_dropin.pass.sh @@ -0,0 +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 +EOF diff --git a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/correct_value.pass.sh b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/correct_value.pass.sh index fd13fbd1c80..5154e96a6b7 100644 --- a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/correct_value.pass.sh +++ b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/correct_value.pass.sh @@ -1,5 +1,5 @@ #!/bin/bash -# platform = Oracle Linux 8,Oracle Linux 9,Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9,multi_platform_fedora +# platform = Oracle Linux 8,Oracle Linux 9 service_file="/usr/lib/systemd/system/rescue.service" sulogin="/usr/lib/systemd/systemd-sulogin-shell" diff --git a/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/wrong_dropin.fail.sh b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/wrong_dropin.fail.sh new file mode 100644 index 00000000000..0bb3ce9ff16 --- /dev/null +++ b/linux_os/guide/system/accounts/accounts-physical/require_singleuser_auth/tests/wrong_dropin.fail.sh @@ -0,0 +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=/bin/bash +EOF