Skip to content

sysctl_kernel_core_pattern_empty_string: align with template#14448

Merged
jan-cerny merged 1 commit intoComplianceAsCode:masterfrom
vojtapolasek:template_sysctl_kernel_core_atern_empty_string
Feb 24, 2026
Merged

sysctl_kernel_core_pattern_empty_string: align with template#14448
jan-cerny merged 1 commit intoComplianceAsCode:masterfrom
vojtapolasek:template_sysctl_kernel_core_atern_empty_string

Conversation

@vojtapolasek
Copy link
Collaborator

@vojtapolasek vojtapolasek commented Feb 24, 2026

Description:

  • Align the custom Bash, Ansible, and OVAL implementations of sysctl_kernel_core_pattern_empty_string with the patterns used by the sysctl template (as seen in the sibling rule sysctl_kernel_core_pattern). The rule cannot use the template directly because the sysctl template does not support empty string values without significant reengineering.

  • Bash: Add bootc/container guard (bash_not_bootc_build) around sysctl -w call, add /usr/local/lib/sysctl.d/ to the comment-out loop, add --follow-symlinks to sed, add systemd-sysctl symlink skip, write to /etc/sysctl.d/kernel_core_pattern.conf instead of /etc/sysctl.conf, use bash_replace_or_append macro with CCE identifiers.

  • Ansible: Add set_fact for sysctl_paths including /usr/local/lib/sysctl.d/, add task to comment out entries from /etc/sysctl.conf, write to /etc/sysctl.d/kernel_core_pattern.conf instead of /etc/sysctl.conf.

  • OVAL: Rewrite static check to use the template's OR-based structure (user files correct OR user files missing AND package-managed files correct), add /usr/local/lib/sysctl.d/ and /usr/lib/sysctl.d/ directory checks, drop custom "defined_in_one_file" and symlink handling checks.

Rationale:

  • The custom Bash remediation called sysctl -w directly without the bash_not_bootc_build() guard, causing remediation failures in container/bootc build environments. Aligning the implementation with the template also brings consistency in directory coverage and config file handling.

  • Fixes sysctl_kernel_core_pattern_empty_string fails on RHEL9.8 #14373

Review Hints:

  • Affected products: rhel9, rhel10. Build with: ./build_product --datastream-only rhel10

  • Automatus tests all pass (7 scenarios × 2 remediation types = 14/14 on rhel10):

    ./tests/automatus.py rule --libvirt qemu:///system rhel10 --datastream build/ssg-rhel10-ds.xml sysctl_kernel_core_pattern_empty_string
    ./tests/automatus.py rule --libvirt qemu:///system rhel10 --datastream build/ssg-rhel10-ds.xml --remediate-using ansible sysctl_kernel_core_pattern_empty_string
    
  • The rendered OVAL closely mirrors the template-generated OVAL for sysctl_kernel_core_pattern, except it uses [[:blank:]] instead of [\s] in regex patterns (to avoid a cross-newline matching issue) and checks for an empty string value instead of |/bin/false.

  • Review all changes together — they form a single cohesive update.

…ule similar to the templated one

Ansible, BAsh, OVAL

Template not used, because empty string is tricky to implement in the current sysctl template and I decided that reengineering the whole template is not worth the result.
@github-actions
Copy link

This datastream diff is auto generated by the check Compare DS/Generate Diff

Click here to see the full diff
New content has different text for rule 'xccdf_org.ssgproject.content_rule_selinux_not_disabled'.
--- xccdf_org.ssgproject.content_rule_selinux_not_disabled
+++ xccdf_org.ssgproject.content_rule_selinux_not_disabled
@@ -9,18 +9,15 @@
 SELINUX=enforcing
 OR
 SELINUX=permissive
-If SELinux is currently disabled or not configured, ensure that all files have correct SELinux
-labels by running:
+Ensure that all files have correct SELinux labels by running:
 fixfiles onboot
 Then reboot the system.
 
 [warning]:
-The automated remediation checks the SELinux configuration in /etc/selinux/config.
-If SELinux is already set to "enforcing" or "permissive", the current state is preserved
-and no changes are made. If SELinux is "disabled" or not configured, the remediation will
-adopt a conservative approach and set it to "permissive" in order to avoid any system
-disruption and give the administrator the opportunity to assess the impact and necessary
-efforts before setting it to "enforcing", which is strongly recommended.
+In case the SELinux is "disabled", the automated remediation will adopt a more
+conservative approach and set it to "permissive" in order to avoid any system disruption
+and give the administrator the opportunity to assess the impact and necessary efforts
+before setting it to "enforcing", which is strongly recommended.
 
 [reference]:
 1.3.1.4

bash remediation for rule 'xccdf_org.ssgproject.content_rule_selinux_not_disabled' differs.
--- xccdf_org.ssgproject.content_rule_selinux_not_disabled
+++ xccdf_org.ssgproject.content_rule_selinux_not_disabled
@@ -1,17 +1,7 @@
 # Remediation is applicable only in certain platforms
 if rpm --quiet -q kernel-core; then
 
-# Check current SELinux state in config file
-selinux_current_state=""
-if [ -f "/etc/selinux/config" ]; then
-    selinux_current_state=$(grep -oP '^\s*SELINUX=\K(enforcing|permissive|disabled)' /etc/selinux/config || true)
-fi
-
-# Only remediate if SELinux is disabled or not configured
-# If already set to enforcing or permissive, it's compliant - preserve the current state
-if [ "$selinux_current_state" != "enforcing" ] && [ "$selinux_current_state" != "permissive" ]; then
-    # SELinux is disabled or not configured, set to permissive as a conservative approach
-    if [ -e "/etc/selinux/config" ] ; then
+if [ -e "/etc/selinux/config" ] ; then
     
     LC_ALL=C sed -i "/^SELINUX=/Id" "/etc/selinux/config"
 else
@@ -25,8 +15,8 @@
 printf '%s\n' "SELINUX=permissive" >> "/etc/selinux/config"
 # Clean up after ourselves.
 rm "/etc/selinux/config.bak"
-    fixfiles onboot
-fi
+
+fixfiles onboot
 
 else
     >&2 echo 'Remediation is not applicable, nothing was done'

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_selinux_not_disabled' differs.
--- xccdf_org.ssgproject.content_rule_selinux_not_disabled
+++ xccdf_org.ssgproject.content_rule_selinux_not_disabled
@@ -10,13 +10,12 @@
   - restrict_strategy
   - selinux_not_disabled
 
-- name: Ensure SELinux is Not Disabled - Check current SELinux configuration
+- name: Ensure SELinux is Not Disabled - Check current SELinux state
   ansible.builtin.command:
-    cmd: grep -oP '^\s*SELINUX=\K(enforcing|permissive|disabled)' /etc/selinux/config
-  register: selinux_config_state
+    cmd: getenforce
+  register: current_selinux_state
   check_mode: false
   changed_when: false
-  failed_when: false
   when: '"kernel-core" in ansible_facts.packages'
   tags:
   - CCE-86151-8
@@ -27,49 +26,35 @@
   - restrict_strategy
   - selinux_not_disabled
 
-- name: Ensure SELinux is Not Disabled - Set SELinux state to permissive if disabled
-    or not configured
+- name: Ensure SELinux is Not Disabled
   block:
 
-  - name: Ensure SELinux is Not Disabled
-    block:
+  - name: Check for duplicate values
+    ansible.builtin.lineinfile:
+      path: /etc/selinux/config
+      create: true
+      regexp: (?i)^SELINUX=
+      state: absent
+    check_mode: true
+    changed_when: false
+    register: dupes
 
-    - name: Check for duplicate values
-      ansible.builtin.lineinfile:
-        path: /etc/selinux/config
-        create: true
-        regexp: (?i)^SELINUX=
-        state: absent
-      check_mode: true
-      changed_when: false
-      register: dupes
+  - name: Deduplicate values from /etc/selinux/config
+    ansible.builtin.lineinfile:
+      path: /etc/selinux/config
+      create: true
+      regexp: (?i)^SELINUX=
+      state: absent
+    when: dupes.found is defined and dupes.found > 1
 
-    - name: Deduplicate values from /etc/selinux/config
-      ansible.builtin.lineinfile:
-        path: /etc/selinux/config
-        create: true
-        regexp: (?i)^SELINUX=
-        state: absent
-      when: dupes.found is defined and dupes.found > 1
-
-    - name: Insert correct line to /etc/selinux/config
-      ansible.builtin.lineinfile:
-        path: /etc/selinux/config
-        create: true
-        regexp: (?i)^SELINUX=
-        line: SELINUX=permissive
-        state: present
-
-  - name: Ensure SELinux is Not Disabled - Mark system to relabel SELinux on next
-      boot
-    ansible.builtin.file:
-      path: /.autorelabel
-      state: touch
-      access_time: preserve
-      modification_time: preserve
-  when:
-  - '"kernel-core" in ansible_facts.packages'
-  - selinux_config_state.stdout not in ['enforcing', 'permissive']
+  - name: Insert correct line to /etc/selinux/config
+    ansible.builtin.lineinfile:
+      path: /etc/selinux/config
+      create: true
+      regexp: (?i)^SELINUX=
+      line: SELINUX=permissive
+      state: present
+  when: '"kernel-core" in ansible_facts.packages'
   tags:
   - CCE-86151-8
   - high_severity
@@ -78,3 +63,21 @@
   - reboot_required
   - restrict_strategy
   - selinux_not_disabled
+
+- name: Ensure SELinux is Not Disabled - Mark system to relabel SELinux on next boot
+  ansible.builtin.file:
+    path: /.autorelabel
+    state: touch
+    access_time: preserve
+    modification_time: preserve
+  when:
+  - '"kernel-core" in ansible_facts.packages'
+  - current_selinux_state.stdout | lower != "permissive"
+  tags:
+  - CCE-86151-8
+  - high_severity
+  - low_complexity
+  - low_disruption
+  - reboot_required
+  - restrict_strategy
+  - selinux_not_disabled

@jan-cerny jan-cerny self-assigned this Feb 24, 2026
@jan-cerny jan-cerny added this to the 0.1.81 milestone Feb 24, 2026
Copy link
Collaborator

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

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

I have run a custom productization pipeline on RHEL 9.8 that executed the tests listed in #14373 with this PR and they all pass.

Image

Also the automatus's test pass on RHEL 9.

jcerny@fedora:~/work/git/scap-security-guide (pr/14448)$ python3 tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 sysctl_kernel_core_pattern_empty_string
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-2026-02-24-1409/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_sysctl_kernel_core_pattern_empty_string
INFO - Script correct_value.pass.sh using profile (all) OK
INFO - Script correct_value_with_spaces.pass.sh using profile (all) OK
INFO - Script wrong_value.fail.sh using profile (all) OK
INFO - Script wrong_value_d_directory.fail.sh using profile (all) OK
INFO - Script wrong_value_runtime.fail.sh using profile (all) OK
INFO - Script wrong_value_three_entries.fail.sh using profile (all) OK
INFO - Script wrong_value_two_entries.fail.sh using profile (all) OK
jcerny@fedora:~/work/git/scap-security-guide (pr/14448)$ python3 tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 --remediate-using ansible sysctl_kernel_core_pattern_empty_string
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-2026-02-24-1411/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_sysctl_kernel_core_pattern_empty_string
INFO - Script correct_value.pass.sh using profile (all) OK
INFO - Script correct_value_with_spaces.pass.sh using profile (all) OK
INFO - Script wrong_value.fail.sh using profile (all) OK
INFO - Script wrong_value_d_directory.fail.sh using profile (all) OK
INFO - Script wrong_value_runtime.fail.sh using profile (all) OK
INFO - Script wrong_value_three_entries.fail.sh using profile (all) OK
INFO - Script wrong_value_two_entries.fail.sh using profile (all) OK

<ind:textfilecontent54_object id="object_static_usr_lib_sysctld_sysctl_kernel_core_pattern_empty_string" version="1">
<ind:path>/usr/lib/sysctl.d</ind:path>
<ind:filename operation="pattern match">^.*\.conf$</ind:filename>
<ind:pattern operation="pattern match">^[[:blank:]]*kernel.core_pattern[[:blank:]]*=[[:blank:]]*(.*)$</ind:pattern>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor suggestion: The regular expression repeats multiple times in the OVAL. It would be better to extract the regular expression to a Jinja variable so that it would be defined only once and therefore easier to change in the future.

@jan-cerny jan-cerny merged commit abd58fb into ComplianceAsCode:master Feb 24, 2026
60 of 64 checks passed
@ggbecker ggbecker mentioned this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sysctl_kernel_core_pattern_empty_string fails on RHEL9.8

2 participants