Skip to content
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 regex to support RainerScript in rsyslog_cron_logging #13172

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mrkanon
Copy link
Contributor

@mrkanon mrkanon commented Mar 12, 2025

Description:

  • Upgraded regex remediations to fully support RainerScript syntax in multiline format
  • Enhanced OVAL regex to support multiline detection
  • Adjusted remediations to include OL-specific conditional
  • Added new tests to check RainerScript multiline

Rationale:

The current regex only checks for the legacy configuration and does not include support for RainerScript. Additionally, the OVAL file contains a condition for OL products that redirects all facility logs to /var/log/messages. This scenario is not currently supported by the remediation scripts.
The RainerScript accepts multi-line configurations, we need to ensure the correct behavior of the rule.

@openshift-ci openshift-ci bot added the needs-ok-to-test Used by openshift-ci bot. label Mar 12, 2025
Copy link

openshift-ci bot commented Mar 12, 2025

Hi @mrkanon. Thanks for your PR.

I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

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

Click here to see the full diff
bash remediation for rule 'xccdf_org.ssgproject.content_rule_rsyslog_cron_logging' differs.
--- xccdf_org.ssgproject.content_rule_rsyslog_cron_logging
+++ xccdf_org.ssgproject.content_rule_rsyslog_cron_logging
@@ -1,7 +1,8 @@
 # Remediation is applicable only in certain platforms
 if rpm --quiet -q kernel && rpm --quiet -q rsyslog; then
 
-if ! grep -s "^\s*cron\.\*\s*/var/log/cron$" /etc/rsyslog.conf /etc/rsyslog.d/*.conf; then
+if ! grep -Pzo '(?m)^\s*cron\.\*\s*(/var/log/cron|action\(\s*.*(?i:\btype\b)="omfile"\s*.*(?i:\bfile\b)="/var/log/cron"\s*\))\s*$' /etc/rsyslog.conf /etc/rsyslog.d/*.conf; then
+
 	mkdir -p /etc/rsyslog.d
 	echo "cron.*	/var/log/cron" >> /etc/rsyslog.d/cron.conf
 fi

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_rsyslog_cron_logging' differs.
--- xccdf_org.ssgproject.content_rule_rsyslog_cron_logging
+++ xccdf_org.ssgproject.content_rule_rsyslog_cron_logging
@@ -13,8 +13,8 @@
   - rsyslog_cron_logging
 
 - name: Ensure cron Is Logging To Rsyslog - Search if cron configuration exists
-  ansible.builtin.command: grep -s "^\s*cron\.\*\s*/var/log/cron$" /etc/rsyslog.conf
-    /etc/rsyslog.d/*.conf
+  ansible.builtin.command: grep -Pzo '(?m)^\s*cron\.\*\s*(/var/log/cron|action\(\s*.*(?i:\btype\b)="omfile"\s*.*(?i:\bfile\b)="/var/log/cron"\s*\))\s*$'
+    /etc/rsyslog.conf /etc/rsyslog.d/*.conf
   register: cron_log_config_exists
   failed_when: false
   when:

Copy link

Change in Ansible shell module found.

Please consider using more suitable Ansible module than shell if possible.

Copy link

codeclimate bot commented Mar 12, 2025

Code Climate has analyzed commit c0a72c1 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 62.0% (0.0% change).

View more on Code Climate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ok-to-test Used by openshift-ci bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant