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

Make the behavior of chronyd_sync_clock rule more consistent #12039

Merged
merged 1 commit into from
May 31, 2024

Conversation

alanmcanonical
Copy link
Contributor

Description:

  • Use key_value_pair_in_file template to make sure the chronyd_sync_clock behavior is consistent.

Rationale:

  • Previous template lineinfile usage will append the configuration even when there is an existing line.

@openshift-ci openshift-ci bot added the needs-ok-to-test Used by openshift-ci bot. label May 30, 2024
Copy link

openshift-ci bot commented May 30, 2024

Hi @alanmcanonical. 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

Start a new ephemeral environment with changes proposed in this pull request:

ubuntu2004 (from CTF) Environment (using Fedora as testing environment)
Open in Gitpod

Fedora Testing Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

Copy link

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

Click here to see the full diff
OVAL for rule 'xccdf_org.ssgproject.content_rule_chronyd_sync_clock' differs.
--- oval:ssg-chronyd_sync_clock:def:1
+++ oval:ssg-chronyd_sync_clock:def:1
@@ -1,2 +1,4 @@
 criteria AND
+criteria OR
 criterion oval:ssg-test_chronyd_sync_clock:tst:1
+criterion oval:ssg-test_chronyd_sync_clock_config_file_exists:tst:1

bash remediation for rule 'xccdf_org.ssgproject.content_rule_chronyd_sync_clock' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_sync_clock
+++ xccdf_org.ssgproject.content_rule_chronyd_sync_clock
@@ -3,7 +3,7 @@
 
 if [ -e "/etc/chrony/chrony.conf" ] ; then
     
-    LC_ALL=C sed -i "/^\s*makestep 1 \-1/Id" "/etc/chrony/chrony.conf"
+    LC_ALL=C sed -i "/^\s*makestep /Id" "/etc/chrony/chrony.conf"
 else
     touch "/etc/chrony/chrony.conf"
 fi

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_chronyd_sync_clock' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_sync_clock
+++ xccdf_org.ssgproject.content_rule_chronyd_sync_clock
@@ -1,15 +1,37 @@
 - name: Synchronize internal information system clocks
-  lineinfile:
-    path: /etc/chrony/chrony.conf
-    create: true
-    line: makestep 1 -1
-    state: present
+  block:
+
+  - name: Check for duplicate values
+    lineinfile:
+      path: /etc/chrony/chrony.conf
+      create: true
+      regexp: '^\s*makestep '
+      state: absent
+    check_mode: true
+    changed_when: false
+    register: dupes
+
+  - name: Deduplicate values from /etc/chrony/chrony.conf
+    lineinfile:
+      path: /etc/chrony/chrony.conf
+      create: true
+      regexp: '^\s*makestep '
+      state: absent
+    when: dupes.found is defined and dupes.found > 1
+
+  - name: Insert correct line to /etc/chrony/chrony.conf
+    lineinfile:
+      path: /etc/chrony/chrony.conf
+      create: true
+      regexp: '^\s*makestep '
+      line: makestep 1 -1
+      state: present
   when: ansible_virtualization_type not in ["docker", "lxc", "openvz", "podman", "container"]
   tags:
   - DISA-STIG-UBTU-20-010436
   - chronyd_sync_clock
+  - configure_strategy
   - low_complexity
   - low_disruption
   - medium_severity
   - no_reboot_needed
-  - restrict_strategy

Copy link

github-actions bot commented May 30, 2024

🤖 A k8s content image for this PR is available at:
ghcr.io/complianceascode/k8scontent:12039
This image was built from commit: fd8c3e9

Click here to see how to deploy it

If you alread have Compliance Operator deployed:
utils/build_ds_container.py -i ghcr.io/complianceascode/k8scontent:12039

Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and:
CONTENT_IMAGE=ghcr.io/complianceascode/k8scontent:12039 make deploy-local

@dodys dodys requested a review from a team May 30, 2024 15:00
@dodys dodys self-assigned this May 30, 2024
Previous template lineinfile usage will append the configuration even when there is an existing line. Use key_value_pair_in_file to make sure its behavior.
Copy link

codeclimate bot commented May 31, 2024

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

View more on Code Climate.

@@ -2,7 +2,7 @@
# packages = chrony

{{% if product == 'ubuntu2204' -%}}
echo "makestep 1 1" >> {{{ chrony_conf_path }}}
echo "makestep 1 1" > {{{ chrony_conf_path }}}
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason for not being an append?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the latest doc, If multiple occurrences of key have conflicting values, the check will evaluate to fail.

Copy link
Contributor

@dodys dodys left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@dodys dodys merged commit faf1888 into ComplianceAsCode:master May 31, 2024
103 of 108 checks passed
@jan-cerny jan-cerny added this to the 0.1.74 milestone Jun 28, 2024
@Mab879 Mab879 added the Update Profile Issues or pull requests related to Profiles updates. label Aug 8, 2024
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. Update Profile Issues or pull requests related to Profiles updates.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants