-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update select rules for RHEL not to modify systemd units in /usr #12486
Update select rules for RHEL not to modify systemd units in /usr #12486
Conversation
This datastream diff is auto generated by the check Click here to see the full diffOVAL for rule 'xccdf_org.ssgproject.content_rule_require_emergency_target_auth' differs.
--- oval:ssg-require_emergency_target_auth:def:1
+++ oval:ssg-require_emergency_target_auth:def:1
@@ -1,5 +1,9 @@
+criteria OR
criteria AND
criterion oval:ssg-test_require_emergency_service:tst:1
criterion oval:ssg-test_require_emergency_service_emergency_target:tst:1
criterion oval:ssg-test_no_custom_emergency_target:tst:1
criterion oval:ssg-test_no_custom_emergency_service:tst:1
+criterion oval:ssg-test_require_emergency_target_auth_drop_in_config_exist:tst:1
+criteria ONE
+criterion oval:ssg-test_require_emergency_service_drop_in:tst:1
bash remediation for rule 'xccdf_org.ssgproject.content_rule_require_emergency_target_auth' differs.
--- xccdf_org.ssgproject.content_rule_require_emergency_target_auth
+++ xccdf_org.ssgproject.content_rule_require_emergency_target_auth
@@ -1,17 +1,16 @@
# Remediation is applicable only in certain platforms
if rpm --quiet -q kernel; then
-service_file="/usr/lib/systemd/system/emergency.service"
+service_dropin_cfg_dir="/etc/systemd/system/emergency.service.d"
+service_dropin_file="${service_dropin_cfg_dir}/10-oscap.conf"
sulogin="/usr/lib/systemd/systemd-sulogin-shell emergency"
-if grep "^ExecStart=.*" "$service_file" ; then
- sed -i "s%^ExecStart=.*%ExecStart=-$sulogin%" "$service_file"
-else
- echo "ExecStart=-$sulogin" >> "$service_file"
-fi
+mkdir -p "${service_dropin_cfg_dir}"
+echo "[Service]" >> "${service_dropin_file}"
+echo "ExecStart=-$sulogin" >> "${service_dropin_file}"
else
>&2 echo 'Remediation is not applicable, nothing was done'
ansible remediation for rule 'xccdf_org.ssgproject.content_rule_require_emergency_target_auth' differs.
--- xccdf_org.ssgproject.content_rule_require_emergency_target_auth
+++ xccdf_org.ssgproject.content_rule_require_emergency_target_auth
@@ -17,11 +17,12 @@
- restrict_strategy
- name: Require emergency mode password
- lineinfile:
+ ansible.builtin.blockinfile:
create: true
- dest: /usr/lib/systemd/system/emergency.service
- regexp: ^#?ExecStart=
- line: ExecStart=-/usr/lib/systemd/systemd-sulogin-shell emergency
+ dest: /etc/systemd/system/emergency.service.d/10-oscap.conf
+ block: |-
+ [Service]
+ ExecStart=-/usr/lib/systemd/systemd-sulogin-shell emergency
when: '"kernel" in ansible_facts.packages'
tags:
- CCE-82186-8
bash remediation for rule 'xccdf_org.ssgproject.content_rule_require_singleuser_auth' differs.
--- xccdf_org.ssgproject.content_rule_require_singleuser_auth
+++ xccdf_org.ssgproject.content_rule_require_singleuser_auth
@@ -1,14 +1,37 @@
# Remediation is applicable only in certain platforms
if rpm --quiet -q kernel; then
-service_file="/usr/lib/systemd/system/rescue.service"
+found=false
-sulogin="/usr/lib/systemd/systemd-sulogin-shell rescue"
+# set value in all files if they contain section or key
+for f in $(echo -n "/etc/systemd/system/rescue.service.d/10-oscap.conf"); do
+ if [ ! -e "$f" ]; then
+ continue
+ fi
-if grep "^ExecStart=.*" "$service_file" ; then
- sed -i "s%^ExecStart=.*%ExecStart=-$sulogin%" "$service_file"
-else
- echo "ExecStart=-$sulogin" >> "$service_file"
+ # find key in section and change value
+ if grep -qzosP "[[:space:]]*\[Service\]([^\n\[]*\n+)+?[[:space:]]*ExecStart" "$f"; then
+
+ sed -i "s/ExecStart[^(\n)]*/ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue/" "$f"
+
+ found=true
+
+ # find section and add key = value to it
+ elif grep -qs "[[:space:]]*\[Service\]" "$f"; then
+
+ sed -i "/[[:space:]]*\[Service\]/a ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue" "$f"
+
+ found=true
+ fi
+done
+
+# if section not in any file, append section with key = value to FIRST file in files parameter
+if ! $found ; then
+ file=$(echo "/etc/systemd/system/rescue.service.d/10-oscap.conf" | cut -f1 -d ' ')
+ mkdir -p "$(dirname "$file")"
+
+ echo -e "[Service]\nExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue" >> "$file"
+
fi
else
ansible remediation for rule 'xccdf_org.ssgproject.content_rule_require_singleuser_auth' differs.
--- xccdf_org.ssgproject.content_rule_require_singleuser_auth
+++ xccdf_org.ssgproject.content_rule_require_singleuser_auth
@@ -16,12 +16,13 @@
- require_singleuser_auth
- restrict_strategy
-- name: Require single user mode password
- lineinfile:
- create: true
- dest: /usr/lib/systemd/system/rescue.service
- regexp: ^#?ExecStart=
- line: ExecStart=-/usr/lib/systemd/systemd-sulogin-shell rescue
+- name: Require Authentication for Single User Mode - 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
when: '"kernel" in ansible_facts.packages'
tags:
- CCE-80855-0 |
🤖 A k8s content image for this PR is available at: Click here to see how to deploy itIf you alread have Compliance Operator deployed: Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and: |
b560bc1
to
55277d3
Compare
- 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 ["fedora", "ol8", "ol9", "sle12", "sle15"] -%}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ocil and fixtext in the rule.yml should be updated the same way.
@@ -4,7 +4,7 @@ | |||
# complexity = low | |||
# disruption = low | |||
|
|||
{{% if 'sle' in product %}} | |||
{{% if 'sle' in product or 'rhel' in product %}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition on line 21 should be updated
@@ -4,7 +4,7 @@ | |||
# complexity = low | |||
# disruption = low | |||
|
|||
{{% if 'sle' in product %}} | |||
{{% if 'sle' in product or 'rhel' in product %}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should add a test scenario that covers the situation when the .d
directory is used.
<criterion test_ref="test_require_rescue_service_runlevel1" /> | ||
<criterion test_ref="test_no_custom_runlevel1_target" negate="true"/> | ||
<criterion test_ref="test_no_custom_rescue_service" negate="true"/> | ||
<criterion test_ref="test_no_custom_rescue_service" negate="true"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unwanted whitespace change
@@ -5,16 +5,16 @@ | |||
<criteria operator="AND"> | |||
<criterion comment="Conditions are satisfied" | |||
test_ref="test_require_rescue_service" /> | |||
{{%- if product not in ["ol8", "rhel8"] -%}} | |||
{{%- if product not in ["ol8"] and 'rhel' not in product -%}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got errors from Automatus:
jcerny@fedora:~/work/git/scap-security-guide (pr/12486)$ python3 tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 require_singleuser_auth
Setting console output to log level INFO
INFO - The base image option has not been specified, choosing libvirt-based test environment.
INFO - Logging into /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2024-10-14-1548/test_suite.log
WARNING - Script rhel7_correct_value.pass.sh is not applicable on given platform
INFO - xccdf_org.ssgproject.content_rule_require_singleuser_auth
INFO - Script wrong_value.fail.sh using profile (all) OK
ERROR - Rule evaluation resulted in error, instead of expected fixed during remediation stage
ERROR - The remediation failed for rule 'xccdf_org.ssgproject.content_rule_require_singleuser_auth'.
ERROR - Script correct_value.pass.sh using profile (all) found issue:
ERROR - Rule evaluation resulted in fail, instead of expected pass during initial stage
ERROR - The initial scan failed for rule 'xccdf_org.ssgproject.content_rule_require_singleuser_auth'.
jcerny@fedora:~/work/git/scap-security-guide (pr/12486)$ python3 tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 --remediate-using ansible require_singleuser_auth
Setting console output to log level INFO
INFO - The base image option has not been specified, choosing libvirt-based test environment.
INFO - Logging into /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2024-10-14-1550/test_suite.log
WARNING - Script rhel7_correct_value.pass.sh is not applicable on given platform
INFO - xccdf_org.ssgproject.content_rule_require_singleuser_auth
INFO - Script wrong_value.fail.sh using profile (all) OK
ERROR - Rule evaluation resulted in fail, instead of expected pass during final stage
ERROR - The check after remediation failed for rule 'xccdf_org.ssgproject.content_rule_require_singleuser_auth'.
ERROR - Script correct_value.pass.sh using profile (all) found issue:
ERROR - Rule evaluation resulted in fail, instead of expected pass during initial stage
ERROR - The initial scan failed for rule 'xccdf_org.ssgproject.content_rule_require_singleuser_auth'.
Can you take a look?
Don't modify /usr files they are controled by the operating system.
Don't modify /usr files they are controled by the operating system.
94babc3
to
7da7181
Compare
To better support drop in config files for RHEL and Fedora.
7da7181
to
269dfd8
Compare
Allow spaces for ini file Fix for Fedora
Code Climate has analyzed commit 903b851 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 60.9% (0.0% change). View more on Code Climate. |
@mildas We can use the FQCN for |
@Mab879 Test doesn't accept |
This looks fine now:
|
Description:
require_singleuser_auth
to use drop in filesrequire_emergency_target_auth
to use drop in filesRationale:
Help with RPM verify pass.