Skip to content

Fix chronyd_or_ntpd_set_maxpoll bash remediation when /etc/chrony.d is missing#14638

Merged
jan-cerny merged 2 commits intoComplianceAsCode:masterfrom
ggbecker:fix-chrony-d-remediation
Apr 13, 2026
Merged

Fix chronyd_or_ntpd_set_maxpoll bash remediation when /etc/chrony.d is missing#14638
jan-cerny merged 2 commits intoComplianceAsCode:masterfrom
ggbecker:fix-chrony-d-remediation

Conversation

@ggbecker
Copy link
Copy Markdown
Member

Description:

Both bash and Ansible remediation scripts failed when /etc/chrony.d directory
doesn't exist, which happens on systems using chrony-dhcp (e.g., ppc64le
systems in Testing Farm).

Bash remediation:

  • Add directory existence check before running find
  • Remove product-specific branching and unify code path
  • Initialize empty array if directory is missing

Ansible remediation:

  • Add stat task to check directory existence before find
  • Only run find when directory exists and is a directory
  • Use 'default([])' for safe variable handling
  • Check variable is defined before accessing .matched

Rationale:

…sing

Both bash and Ansible remediation scripts failed when /etc/chrony.d directory
doesn't exist, which happens on systems using chrony-dhcp (e.g., ppc64le
systems in Testing Farm).

Bash remediation:
- Add directory existence check before running find
- Remove product-specific branching and unify code path
- Initialize empty array if directory is missing

Ansible remediation:
- Add stat task to check directory existence before find
- Only run find when directory exists and is a directory
- Use 'default([])' for safe variable handling
- Check variable is defined before accessing .matched

Fixes ComplianceAsCode#14541
@ggbecker ggbecker added this to the 0.1.81 milestone Apr 10, 2026
@ggbecker ggbecker added Ansible Ansible remediation update. Bash Bash remediation update. labels Apr 10, 2026
@github-actions
Copy link
Copy Markdown

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_chronyd_or_ntpd_set_maxpoll' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_set_maxpoll
+++ xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_set_maxpoll
@@ -12,9 +12,11 @@
 CONFIG_FILES="/etc/ntp.conf"
 $pof ntpd || {
     CHRONY_D_PATH=/etc/chrony.d/
-    
-    mapfile -t CONFIG_FILES < <(find ${CHRONY_D_PATH}.* -type f -name '*.conf')
-    
+    if [ -d "${CHRONY_D_PATH}" ]; then
+        mapfile -t CONFIG_FILES < <(find ${CHRONY_D_PATH} -type f -name '*.conf')
+    else
+        CONFIG_FILES=()
+    fi
     CONFIG_FILES+=(/etc/chrony.conf)
 }
 

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_set_maxpoll' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_set_maxpoll
+++ xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_set_maxpoll
@@ -122,6 +122,24 @@
   - '"kernel-core" in ansible_facts.packages'
   - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
   - chrony_conf_exist_result.stat.exists
+  tags:
+  - NIST-800-53-AU-12(1)
+  - NIST-800-53-AU-8(1)(b)
+  - NIST-800-53-CM-6(a)
+  - chronyd_or_ntpd_set_maxpoll
+  - low_complexity
+  - low_disruption
+  - medium_severity
+  - no_reboot_needed
+  - restrict_strategy
+
+- name: Configure Time Service Maxpoll Interval - Check That /etc/chrony.d/ Exist
+  ansible.builtin.stat:
+    path: /etc/chrony.d/
+  register: chrony_d_path_exists
+  when:
+  - '"kernel-core" in ansible_facts.packages'
+  - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
   tags:
   - NIST-800-53-AU-12(1)
   - NIST-800-53-AU-8(1)(b)
@@ -142,6 +160,7 @@
   when:
   - '"kernel-core" in ansible_facts.packages'
   - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
+  - chrony_d_path_exists.stat.exists and chrony_d_path_exists.stat.isdir
   tags:
   - NIST-800-53-AU-12(1)
   - NIST-800-53-AU-8(1)(b)
@@ -158,11 +177,11 @@
     path: '{{ item.path }}'
     regexp: ^((?:server|pool|peer).*maxpoll)[ ]+[0-9,-]+(.*)$
     replace: \1 {{ var_time_service_set_maxpoll }}\2
-  loop: '{{ chrony_d_conf_files.files }}'
-  when:
-  - '"kernel-core" in ansible_facts.packages'
-  - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
-  - chrony_d_conf_files.matched
+  loop: '{{ chrony_d_conf_files.files | default([]) }}'
+  when:
+  - '"kernel-core" in ansible_facts.packages'
+  - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
+  - chrony_d_conf_files is defined and chrony_d_conf_files.matched
   tags:
   - NIST-800-53-AU-12(1)
   - NIST-800-53-AU-8(1)(b)
@@ -179,18 +198,18 @@
     path: '{{ item.path }}'
     regexp: (^(?:server|pool|peer)\s+((?!maxpoll).)*)$
     replace: \1 maxpoll {{ var_time_service_set_maxpoll }}\n
-  loop: '{{ chrony_d_conf_files.files }}'
-  when:
-  - '"kernel-core" in ansible_facts.packages'
-  - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
-  - chrony_d_conf_files.matched
-  tags:
-  - NIST-800-53-AU-12(1)
-  - NIST-800-53-AU-8(1)(b)
-  - NIST-800-53-CM-6(a)
-  - chronyd_or_ntpd_set_maxpoll
-  - low_complexity
-  - low_disruption
-  - medium_severity
-  - no_reboot_needed
-  - restrict_strategy
+  loop: '{{ chrony_d_conf_files.files | default([]) }}'
+  when:
+  - '"kernel-core" in ansible_facts.packages'
+  - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
+  - chrony_d_conf_files is defined and chrony_d_conf_files.matched
+  tags:
+  - NIST-800-53-AU-12(1)
+  - NIST-800-53-AU-8(1)(b)
+  - NIST-800-53-CM-6(a)
+  - chronyd_or_ntpd_set_maxpoll
+  - low_complexity
+  - low_disruption
+  - medium_severity
+  - no_reboot_needed
+  - restrict_strategy

@jan-cerny jan-cerny self-assigned this Apr 13, 2026
Copy link
Copy Markdown
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.

Overall the fix looks good to me but can you please create a test scenario covering this situation?

@ggbecker
Copy link
Copy Markdown
Member Author

Overall the fix looks good to me but can you please create a test scenario covering this situation?

Test scenarios added in e5bbfcc

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 13, 2026

@ggbecker: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-openshift-platform-compliance e5bbfcc link true /test e2e-aws-openshift-platform-compliance

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

Copy link
Copy Markdown
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 the automatus tests locally and they all pass.

jcerny@fedora:~/work/git/scap-security-guide (pr/14638)$ python3 tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9  chronyd_or_ntpd_set_maxpoll
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-04-13-1556/test_suite.log
WARNING - Script 'chrony_nothing_done.fail.sh' is not applicable on 'rhel9' target because its platform is 'Oracle Linux 7'
WARNING - Script 'ntp.pass.sh' is not applicable on 'rhel9' target because its platform is 'Oracle Linux 7'
WARNING - Script 'ntp_multiple_misconfigured.fail.sh' is not applicable on 'rhel9' target because its platform is 'Oracle Linux 7'
WARNING - Script 'ntp_wrong_maxpoll.fail.sh' is not applicable on 'rhel9' target because its platform is 'Oracle Linux 7'
INFO - xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_set_maxpoll
INFO - Script chrony.pass.sh using profile (all) OK
INFO - Script chrony_d_one_pool_misconfigured.fail.sh using profile (all) OK
INFO - Script chrony_d_one_server_misconfigured.fail.sh using profile (all) OK
INFO - Script chrony_no_pool_nor_servers.fail.sh using profile (all) OK
INFO - Script chrony_one_pool_configured.pass.sh using profile (all) OK
INFO - Script chrony_one_pool_misconfigured.fail.sh using profile (all) OK
INFO - Script chrony_one_pool_missing_parameter.fail.sh using profile (all) OK
INFO - Script chrony_one_server_misconfigured.fail.sh using profile (all) OK
INFO - Script chrony_d_missing_main_conf_configured.pass.sh using profile (all) OK
INFO - Script chrony_d_missing_main_conf_misconfigured.fail.sh using profile (all) OK
jcerny@fedora:~/work/git/scap-security-guide (pr/14638)$ python3 tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 --remediate-using ansible  chronyd_or_ntpd_set_maxpoll
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-04-13-1601/test_suite.log
WARNING - Script 'chrony_nothing_done.fail.sh' is not applicable on 'rhel9' target because its platform is 'Oracle Linux 7'
WARNING - Script 'ntp.pass.sh' is not applicable on 'rhel9' target because its platform is 'Oracle Linux 7'
WARNING - Script 'ntp_multiple_misconfigured.fail.sh' is not applicable on 'rhel9' target because its platform is 'Oracle Linux 7'
WARNING - Script 'ntp_wrong_maxpoll.fail.sh' is not applicable on 'rhel9' target because its platform is 'Oracle Linux 7'
INFO - xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_set_maxpoll
INFO - Script chrony.pass.sh using profile (all) OK
INFO - Script chrony_d_one_pool_misconfigured.fail.sh using profile (all) OK
INFO - Script chrony_d_one_server_misconfigured.fail.sh using profile (all) OK
INFO - Script chrony_no_pool_nor_servers.fail.sh using profile (all) OK
INFO - Script chrony_one_pool_configured.pass.sh using profile (all) OK
INFO - Script chrony_one_pool_misconfigured.fail.sh using profile (all) OK
INFO - Script chrony_one_pool_missing_parameter.fail.sh using profile (all) OK
INFO - Script chrony_one_server_misconfigured.fail.sh using profile (all) OK
INFO - Script chrony_d_missing_main_conf_configured.pass.sh using profile (all) OK

@jan-cerny jan-cerny merged commit fc1e897 into ComplianceAsCode:master Apr 13, 2026
61 of 65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ansible Ansible remediation update. Bash Bash remediation update.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rule chronyd_or_ntpd_set_maxpoll fails to remediate

2 participants