ComplianceAsCode / content

Security automation content in SCAP, Bash, Ansible, and other formats
https://complianceascode.readthedocs.io/en/latest/
Other
2.22k stars 698 forks source link

Update chronyd rules for bootable containers #12582

Closed matusmarhefka closed 2 weeks ago

matusmarhefka commented 2 weeks ago

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.

github-actions[bot] commented 2 weeks ago

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

github-actions[bot] commented 2 weeks ago

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

Click here to see the full diff ```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 commented 2 weeks ago

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

codeclimate[bot] commented 2 weeks ago

Code Climate has analyzed commit 40262a8f 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.