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 chronyd rules for bootable containers #12582

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

matusmarhefka
Copy link
Member

@matusmarhefka matusmarhefka commented Nov 6, 2024

The rules used service_chronyd_enabled or service_ntpd_enabled
in their OVALs to not only check the services configuration but to
also check if the services are enabled.

This approach is unnecessary and it won't work in the bootable
container build environment where systemd services don't run.

Therefore, we update OVALs of these rules and remove the mentioned
service enabled checks and we rather use CPE platforms to make the
rules applicable only in cases when chrony or ntp packages are
installed. This shouldn't be a big change as if chrony or ntp
packages are installed their service config files should exist and
in case chronyd or ntpd services are enabled later they will
already run with the expected configuration.

@matusmarhefka matusmarhefka added the Image Mode Bootable containers and Image Mode RHEL label Nov 6, 2024
@matusmarhefka matusmarhefka added this to the 0.1.76 milestone Nov 6, 2024
@jan-cerny jan-cerny self-assigned this Nov 6, 2024
Copy link

github-actions bot commented Nov 6, 2024

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

rhel8 (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

github-actions bot commented Nov 6, 2024

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_client_only' differs.
--- oval:ssg-chronyd_client_only:def:1
+++ oval:ssg-chronyd_client_only:def:1
@@ -1,3 +1,2 @@
 criteria AND
-extend_definition oval:ssg-service_chronyd_enabled:def:1
 criterion oval:ssg-test_chronyd_client_only:tst:1

bash remediation for rule 'xccdf_org.ssgproject.content_rule_chronyd_client_only' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_client_only
+++ xccdf_org.ssgproject.content_rule_chronyd_client_only
@@ -1,5 +1,5 @@
 # Remediation is applicable only in certain platforms
-if rpm --quiet -q kernel; then
+if rpm --quiet -q kernel && { rpm --quiet -q chrony; }; then
 
 # Strip any search characters in the key arg so that the key can be replaced without
 # adding any search characters to the config file.

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_chronyd_client_only' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_client_only
+++ xccdf_org.ssgproject.content_rule_chronyd_client_only
@@ -41,7 +41,9 @@
       regexp: (?i)^\s*port\s+
       line: port 0
       state: present
-  when: '"kernel" in ansible_facts.packages'
+  when:
+  - '"kernel" in ansible_facts.packages'
+  - '"chrony" in ansible_facts.packages'
   tags:
   - CCE-82988-7
   - DISA-STIG-RHEL-08-030741

Platform has been changed for rule 'xccdf_org.ssgproject.content_rule_chronyd_client_only'
--- xccdf_org.ssgproject.content_rule_chronyd_client_only
+++ xccdf_org.ssgproject.content_rule_chronyd_client_only
@@ -1 +1 @@
-
+oval:ssg-package_chrony:def:1

OVAL for rule 'xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network' differs.
--- oval:ssg-chronyd_no_chronyc_network:def:1
+++ oval:ssg-chronyd_no_chronyc_network:def:1
@@ -1,3 +1,2 @@
 criteria AND
-extend_definition oval:ssg-service_chronyd_enabled:def:1
 criterion oval:ssg-test_chronyd_no_chronyc_network:tst:1

bash remediation for rule 'xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network
+++ xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network
@@ -1,5 +1,5 @@
 # Remediation is applicable only in certain platforms
-if rpm --quiet -q kernel; then
+if rpm --quiet -q kernel && { rpm --quiet -q chrony; }; then
 
 # Strip any search characters in the key arg so that the key can be replaced without
 # adding any search characters to the config file.

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network
+++ xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network
@@ -40,7 +40,9 @@
       regexp: (?i)^\s*cmdport\s+
       line: cmdport 0
       state: present
-  when: '"kernel" in ansible_facts.packages'
+  when:
+  - '"kernel" in ansible_facts.packages'
+  - '"chrony" in ansible_facts.packages'
   tags:
   - CCE-82840-0
   - DISA-STIG-RHEL-08-030742

Platform has been changed for rule 'xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network'
--- xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network
+++ xccdf_org.ssgproject.content_rule_chronyd_no_chronyc_network
@@ -1 +1 @@
-
+oval:ssg-package_chrony:def:1

OVAL for rule 'xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers' differs.
--- oval:ssg-chronyd_or_ntpd_specify_multiple_servers:def:1
+++ oval:ssg-chronyd_or_ntpd_specify_multiple_servers:def:1
@@ -1,7 +1,3 @@
 criteria OR
-criteria AND
-extend_definition oval:ssg-service_chronyd_enabled:def:1
 extend_definition oval:ssg-chronyd_specify_multiple_servers:def:1
-criteria AND
-extend_definition oval:ssg-service_ntpd_enabled:def:1
 extend_definition oval:ssg-ntpd_specify_multiple_servers:def:1

bash remediation for rule 'xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers
+++ xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers
@@ -1,5 +1,5 @@
 # Remediation is applicable only in certain platforms
-if rpm --quiet -q kernel; then
+if rpm --quiet -q kernel && { ( rpm --quiet -q chrony || rpm --quiet -q ntp ); }; then
 
 var_multiple_time_servers=''
 

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers' differs.
--- xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers
+++ xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers
@@ -25,7 +25,9 @@
     path: /etc
     patterns: chrony.conf
   register: chrony_server_config
-  when: '"kernel" in ansible_facts.packages'
+  when:
+  - '"kernel" in ansible_facts.packages'
+  - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
   tags:
   - CCE-80764-4
   - NIST-800-53-AU-12(1)
@@ -49,6 +51,7 @@
   loop: '{{ var_multiple_time_servers.split(",") }}'
   when:
   - '"kernel" in ansible_facts.packages'
+  - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
   - chrony_server_config.matched == 1
   tags:
   - CCE-80764-4
@@ -69,7 +72,9 @@
     path: /etc
     patterns: ntp.conf
   register: ntp_server_config
-  when: '"kernel" in ansible_facts.packages'
+  when:
+  - '"kernel" in ansible_facts.packages'
+  - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
   tags:
   - CCE-80764-4
   - NIST-800-53-AU-12(1)
@@ -93,6 +98,7 @@
   loop: '{{ var_multiple_time_servers.split(",") }}'
   when:
   - '"kernel" in ansible_facts.packages'
+  - ( "chrony" in ansible_facts.packages or "ntp" in ansible_facts.packages )
   - ntp_server_config.matched == 1
   tags:
   - CCE-80764-4

Platform has been changed for rule 'xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers'
--- xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers
+++ xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_multiple_servers
@@ -1 +1,2 @@
-
+oval:ssg-package_chrony:def:1
+oval:ssg-package_ntp:def:1

OVAL for rule 'xccdf_org.ssgproject.content_rule_chronyd_or_ntpd_specify_remote_server' differs.
--- oval:ssg-chronyd_or_ntpd_specify_remote_server:def:1
+++ oval:ssg-chronyd_or_ntpd_specify_remote_server:def:1
@@ -1,7 +1,3 @@
 criteria OR
-criteria AND
-extend_definition oval:ssg-service_chronyd_enabled:def:1
 extend_definition oval:ssg-chronyd_specify_remote_server:def:1
-criteria AND
-extend_definition oval:ssg-service_ntpd_enabled:def:1
 extend_definition oval:ssg-ntpd_specify_remote_server:def:1

@jan-cerny
Copy link
Collaborator

I think that these checks for packages and services should be replaced by assigning a CPE platform to the rule.

Copy link
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 STIG build and run and the chronyd rules are passing now. But, please fix the CI fails.

The rules used `service_chronyd_enabled` or `service_ntpd_enabled`
in their OVALs to not only check the services configuration but to
also check if the services are enabled.

This approach is unnecessary and it won't work in the bootable
container build environment where systemd services don't run.

Therefore, we update OVALs of these rules and remove the mentioned
service enabled checks and we rather use CPE platforms to make the
rules applicable only in cases when `chrony` or `ntp` packages are
installed. This shouldn't be a big change as if `chrony` or `ntp`
packages are installed their service config files should exist and
in case `chronyd` or `ntpd` services are enabled later they will
already run with the expected configuration.
Copy link

codeclimate bot commented Nov 7, 2024

Code Climate has analyzed commit 40262a8 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 60.9% (0.0% change).

View more on Code Climate.

@jan-cerny jan-cerny merged commit cf82959 into ComplianceAsCode:master Nov 7, 2024
100 of 105 checks passed
@matusmarhefka matusmarhefka deleted the bootc_chronyd branch November 7, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Image Mode Bootable containers and Image Mode RHEL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants