Skip to content

Conversation

@comps
Copy link
Collaborator

@comps comps commented May 22, 2025

This is #13479 backported to stabilization-v0.1.77.

comps added 3 commits May 22, 2025 11:48
Signed-off-by: Jiri Jaburek <comps@nomail.dom>
Signed-off-by: Jiri Jaburek <comps@nomail.dom>
The original code was really buggy:

- it relied on a *running* ntpd process to signify whether ntpd
  or chronyd is used (presumably)

- it was a copy/paste from (likely) some maxpoll code, inheriting its
  comment and 'grep -v' check, likely breaking the config on repeated
  remediation

So I simply rewrote it to just detect the presence of files or the
chrony.d directory, and if found, to do the modification.

I also avoid re-reading all the files via bash line iteration and just
let 'sed' do all the work.

Signed-off-by: Jiri Jaburek <comps@nomail.dom>
@github-actions
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_chrony_set_nts' differs.
--- xccdf_org.ssgproject.content_rule_chrony_set_nts
+++ xccdf_org.ssgproject.content_rule_chrony_set_nts
@@ -1,23 +1,22 @@
 # Remediation is applicable only in certain platforms
 if rpm --quiet -q kernel || rpm --quiet -q kernel-uek && { rpm --quiet -q chrony; }; then
 
-pof="/usr/sbin/pidof"
+config_files=(/etc/ntp.conf)
+config_files+=("/etc/chrony.conf")
 
+chrony_d_path=/etc/chrony.d/
+if [[ -d $chrony_d_path ]]; then
+    while IFS= read -r filename; do
+        config_files+=("$filename")
+    done < <(find "$chrony_d_path" -type f -name '*.conf')
+fi
 
-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')
-    CONFIG_FILES+=(/etc/chrony.conf)
-}
-
-# get list of ntp files
-
-for config_file in "${CONFIG_FILES[@]}" ; do
-    # Add maxpoll to server, pool or peer entries without maxpoll
-    grep "^\(server\|pool\|peer\)" "$config_file" | grep -v maxpoll | while read -r line ; do
-        sed -i "s/$line/& nts/" "$config_file"
-    done
+for config_file in "${config_files[@]}"; do
+    [[ -e $config_file ]] || continue
+    # if the line doesn't start with 'server/pool/peer ', just print it
+    # if the line does contain ' nts' already, skip it
+    # else append ' nts' to it
+    sed "/^\(server\|pool\|peer\) /! b; / nts/ b; s/$/ nts/" -i "$config_file"
 done
 
 else

@vojtapolasek
Copy link
Collaborator

/packit retest-failed

Copy link
Collaborator

@vojtapolasek vojtapolasek left a comment

Choose a reason for hiding this comment

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

LGTM.
Automatus tests fail because the rule is included in RHEL 10 only and Automatus does not run on this distro.
Centos-stream 9 testing farm test is currently broken because of problems with repo mirrors.

@vojtapolasek vojtapolasek merged commit 746d002 into ComplianceAsCode:stabilization-v0.1.77 May 22, 2025
107 of 116 checks passed
@comps comps deleted the centos_stream_10_stab branch January 28, 2026 11:46
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.

2 participants