Fix chronyd_or_ntpd_set_maxpoll bash remediation when /etc/chrony.d is missing#14638
Conversation
…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
|
This datastream diff is auto generated by the check Click here to see the full diffbash 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
left a comment
There was a problem hiding this comment.
Overall the fix looks good to me but can you please create a test scenario covering this situation?
Test scenarios added in e5bbfcc |
|
@ggbecker: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
jan-cerny
left a comment
There was a problem hiding this comment.
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
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:
Ansible remediation:
Rationale: