Blame SOURCES/scap-security-guide-0.1.61-chrony_maxpoll-PR_8187.patch

12e95e
From bbafe0a7b4b9eb50bc622d9f9f3c0074fca932f9 Mon Sep 17 00:00:00 2001
12e95e
From: Watson Sato <wsato@redhat.com>
12e95e
Date: Wed, 9 Feb 2022 16:17:52 +0100
12e95e
Subject: [PATCH 1/2] Pass the rule when no time server nor pool is set
12e95e
12e95e
If no time server or pool is configured, there is no entry to add
12e95e
maxpoll option to, so the rule should evaluate to pass.
12e95e
---
12e95e
 .../oval/shared.xml                           | 50 +++++++++++++++----
12e95e
 .../ntp/chronyd_or_ntpd_set_maxpoll/rule.yml  |  2 +
12e95e
 .../tests/chrony_no_pool_nor_servers.pass.sh  | 12 +++++
12e95e
 3 files changed, 54 insertions(+), 10 deletions(-)
12e95e
 create mode 100644 linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/tests/chrony_no_pool_nor_servers.pass.sh
12e95e
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/oval/shared.xml b/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/oval/shared.xml
12e95e
index 780c2e2d0ba..76f810123f3 100644
12e95e
--- a/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/oval/shared.xml
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/oval/shared.xml
12e95e
@@ -3,17 +3,25 @@
12e95e
     {{{ oval_metadata("Configure the maxpoll setting in /etc/ntp.conf or chrony.conf
12e95e
       to continuously poll the time source servers.") }}}
12e95e
     <criteria operator="OR">
12e95e
-      <criteria operator="AND">
12e95e
-        
12e95e
-        test_ref="test_ntp_set_maxpoll" />
12e95e
-        
12e95e
-        test_ref="test_ntp_all_server_has_maxpoll"/>
12e95e
+      <criteria operator="OR">
12e95e
+        
12e95e
+          test_ref="test_ntp_no_server"/>
12e95e
+        <criteria operator="AND">
12e95e
+          
12e95e
+          test_ref="test_ntp_set_maxpoll" />
12e95e
+          
12e95e
+          test_ref="test_ntp_all_server_has_maxpoll"/>
12e95e
+        </criteria>
12e95e
       </criteria>
12e95e
-      <criteria operator="AND">
12e95e
-        
12e95e
-        test_ref="test_chrony_set_maxpoll" />
12e95e
-        
12e95e
-        test_ref="test_chrony_all_server_has_maxpoll"/>
12e95e
+      <criteria operator="OR">
12e95e
+        
12e95e
+          test_ref="test_chrony_no_server_nor_pool"/>
12e95e
+        <criteria operator="AND">
12e95e
+          
12e95e
+          test_ref="test_chrony_set_maxpoll" />
12e95e
+          
12e95e
+          test_ref="test_chrony_all_server_has_maxpoll"/>
12e95e
+        </criteria>
12e95e
       </criteria>
12e95e
     </criteria>
12e95e
   </definition>
12e95e
@@ -77,4 +85,26 @@
12e95e
     <ind:subexpression operation="pattern match" datatype="string">maxpoll \d+</ind:subexpression>
12e95e
   </ind:textfilecontent54_state>
12e95e
 
12e95e
+  
12e95e
+  comment="check if no server entries have server or pool set in /etc/chrony.conf"
12e95e
+  id="test_chrony_no_server_nor_pool" version="1">
12e95e
+    <ind:object object_ref="obj_chrony_no_server_nor_pool" />
12e95e
+  </ind:textfilecontent54_test>
12e95e
+  <ind:textfilecontent54_object id="obj_chrony_no_server_nor_pool" version="1">
12e95e
+    <ind:filepath operation="pattern match">^/etc/chrony\.(conf|d/.+\.conf)$</ind:filepath>
12e95e
+    <ind:pattern operation="pattern match">^(?:server|pool).*</ind:pattern>
12e95e
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
12e95e
+  </ind:textfilecontent54_object>
12e95e
+
12e95e
+  
12e95e
+  comment="check if all server entries have maxpoll set in /etc/ntp.conf"
12e95e
+  id="test_ntp_no_server" version="1">
12e95e
+    <ind:object object_ref="obj_ntp_no_server_nor_pool" />
12e95e
+  </ind:textfilecontent54_test>
12e95e
+  <ind:textfilecontent54_object id="obj_ntp_no_server_nor_pool" version="1">
12e95e
+    <ind:filepath>/etc/ntp.conf</ind:filepath>
12e95e
+    <ind:pattern operation="pattern match">^server.*</ind:pattern>
12e95e
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
12e95e
+  </ind:textfilecontent54_object>
12e95e
+
12e95e
 </def-group>
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/rule.yml b/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/rule.yml
12e95e
index 20e7467a7b5..c115ad3c115 100644
12e95e
--- a/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/rule.yml
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/rule.yml
12e95e
@@ -13,6 +13,8 @@ description: |-
12e95e
     
maxpoll {{{ xccdf_value("var_time_service_set_maxpoll") }}}
12e95e
     to 
server
directives. If using chrony any
pool
directives
12e95e
     should be configured too.
12e95e
+    If no <tt>server</tt> or <tt>pool</tt> directives are configured, the rule evaluates
12e95e
+    to pass.
12e95e
     {{% if product == "rhcos4" %}}
12e95e
     

12e95e
     Note that if the remediation shipping with this content is being used, the
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/tests/chrony_no_pool_nor_servers.pass.sh b/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/tests/chrony_no_pool_nor_servers.pass.sh
12e95e
new file mode 100644
12e95e
index 00000000000..bbae20fc696
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/tests/chrony_no_pool_nor_servers.pass.sh
12e95e
@@ -0,0 +1,12 @@
12e95e
+#!/bin/bash
12e95e
+# packages = chrony
12e95e
+#
12e95e
+# profiles = xccdf_org.ssgproject.content_profile_stig
12e95e
+
12e95e
+yum remove -y ntp
12e95e
+
12e95e
+# Remove all pool and server options
12e95e
+sed -i "/^pool.*/d" /etc/chrony.conf
12e95e
+sed -i "/^server.*/d" /etc/chrony.conf
12e95e
+
12e95e
+systemctl enable chronyd.service
12e95e
12e95e
From 60ef6eb2cce9e53ea256738ff2583b332155a318 Mon Sep 17 00:00:00 2001
12e95e
From: Watson Sato <wsato@redhat.com>
12e95e
Date: Fri, 11 Feb 2022 12:14:30 +0100
12e95e
Subject: [PATCH 2/2] Add rule ensuring Chrony only uses server directive
12e95e
12e95e
This new rule only asserts that Chrony has at least one time source configured,
12e95e
and that it is done with the  'server' directive.
12e95e
No remediation is provided for rule, that is left for other specialized
12e95e
rules.
12e95e
---
12e95e
 .../chronyd_server_directive/oval/shared.xml  | 33 +++++++++++++++++++
12e95e
 .../ntp/chronyd_server_directive/rule.yml     | 32 ++++++++++++++++++
12e95e
 .../tests/file_empty.fail.sh                  |  6 ++++
12e95e
 .../tests/file_missing.fail.sh                |  6 ++++
12e95e
 .../tests/line_missing.fail.sh                |  7 ++++
12e95e
 .../tests/multiple_servers.pass.sh            |  8 +++++
12e95e
 .../tests/only_pool.fail.sh                   |  9 +++++
12e95e
 .../tests/only_server.pass.sh                 |  6 ++++
12e95e
 products/rhel8/profiles/stig.profile          |  1 +
12e95e
 products/rhel9/profiles/stig.profile          |  1 +
12e95e
 shared/references/cce-redhat-avail.txt        |  2 --
12e95e
 .../data/profile_stability/rhel8/stig.profile |  1 +
12e95e
 .../profile_stability/rhel8/stig_gui.profile  |  1 +
12e95e
 13 files changed, 111 insertions(+), 2 deletions(-)
12e95e
 create mode 100644 linux_os/guide/services/ntp/chronyd_server_directive/oval/shared.xml
12e95e
 create mode 100644 linux_os/guide/services/ntp/chronyd_server_directive/rule.yml
12e95e
 create mode 100644 linux_os/guide/services/ntp/chronyd_server_directive/tests/file_empty.fail.sh
12e95e
 create mode 100644 linux_os/guide/services/ntp/chronyd_server_directive/tests/file_missing.fail.sh
12e95e
 create mode 100644 linux_os/guide/services/ntp/chronyd_server_directive/tests/line_missing.fail.sh
12e95e
 create mode 100644 linux_os/guide/services/ntp/chronyd_server_directive/tests/multiple_servers.pass.sh
12e95e
 create mode 100644 linux_os/guide/services/ntp/chronyd_server_directive/tests/only_pool.fail.sh
12e95e
 create mode 100644 linux_os/guide/services/ntp/chronyd_server_directive/tests/only_server.pass.sh
12e95e
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_server_directive/oval/shared.xml b/linux_os/guide/services/ntp/chronyd_server_directive/oval/shared.xml
12e95e
new file mode 100644
12e95e
index 00000000000..2244e608047
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_server_directive/oval/shared.xml
12e95e
@@ -0,0 +1,33 @@
12e95e
+<def-group>
12e95e
+  <definition class="compliance" id="{{{ rule_id }}}" version="1">
12e95e
+    {{{ oval_metadata("Ensure Chrony has time sources configured with server directive") }}}
12e95e
+    <criteria comment="chrony.conf only has server directive">
12e95e
+      <criterion test_ref="test_chronyd_server_directive_with_server" />
12e95e
+      <criterion test_ref="test_chronyd_server_directive_no_pool" />
12e95e
+    </criteria>
12e95e
+  </definition>
12e95e
+
12e95e
+  
12e95e
+  comment="Ensure at least one time source is set with server directive" id="test_chronyd_server_directive_with_server"
12e95e
+  version="1">
12e95e
+    <ind:object object_ref="object_chronyd_server_directive" />
12e95e
+  </ind:textfilecontent54_test>
12e95e
+  
12e95e
+  id="object_chronyd_server_directive" version="1">
12e95e
+    <ind:filepath operation="pattern match">^/etc/chrony\.(conf|d/.+\.conf)$</ind:filepath>
12e95e
+    <ind:pattern operation="pattern match">^[\s]*server.*$</ind:pattern>
12e95e
+    <ind:instance datatype="int">1</ind:instance>
12e95e
+  </ind:textfilecontent54_object>
12e95e
+
12e95e
+  
12e95e
+  comment="Ensure no time source is set with pool directive" id="test_chronyd_server_directive_no_pool"
12e95e
+  version="1">
12e95e
+    <ind:object object_ref="object_chronyd_no_pool_directive" />
12e95e
+  </ind:textfilecontent54_test>
12e95e
+  
12e95e
+  id="object_chronyd_no_pool_directive" version="1">
12e95e
+    <ind:filepath operation="pattern match">^/etc/chrony\.(conf|d/.+\.conf)$</ind:filepath>
12e95e
+    <ind:pattern operation="pattern match">^[\s]+pool.*$</ind:pattern>
12e95e
+    <ind:instance datatype="int">1</ind:instance>
12e95e
+  </ind:textfilecontent54_object>
12e95e
+</def-group>
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_server_directive/rule.yml b/linux_os/guide/services/ntp/chronyd_server_directive/rule.yml
12e95e
new file mode 100644
12e95e
index 00000000000..6dc24f1be85
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_server_directive/rule.yml
12e95e
@@ -0,0 +1,32 @@
12e95e
+documentation_complete: true
12e95e
+
12e95e
+title: 'Ensure Chrony is only configured with the server directive'
12e95e
+
12e95e
+description: |-
12e95e
+    Check that Chrony only has time sources configured with the <tt>server</tt> directive.
12e95e
+
12e95e
+rationale: |-
12e95e
+    Depending on the infrastruture being used the <tt>pool</tt> directive may not be supported.
12e95e
+
12e95e
+severity: medium
12e95e
+
12e95e
+platform: chrony
12e95e
+
12e95e
+warnings:
12e95e
+  - general: This rule doesn't come with a remediation, the time source needs to be added by the adminstrator.
12e95e
+
12e95e
+identifiers:
12e95e
+    cce@rhel8: CCE-86077-5
12e95e
+    cce@rhel9: CCE-87077-4
12e95e
+
12e95e
+references:
12e95e
+    disa: CCI-001891
12e95e
+    srg: SRG-OS-000355-GPOS-00143,SRG-OS-000356-GPOS-00144,SRG-OS-000359-GPOS-00146
12e95e
+    stigid@rhel8: RHEL-08-030740
12e95e
+
12e95e
+ocil_clause: 'a remote time server is not configured or configured with pool directive'
12e95e
+
12e95e
+ocil: |-
12e95e
+    Run the following command and verify that time sources are only configure with <tt>server</tt> directive:
12e95e
+    
# grep -E "^(server|pool)" /etc/chrony.conf
12e95e
+    A line with the appropriate server should be returned, any line returned starting with <tt>pool</tt> is a finding.
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_server_directive/tests/file_empty.fail.sh b/linux_os/guide/services/ntp/chronyd_server_directive/tests/file_empty.fail.sh
12e95e
new file mode 100644
12e95e
index 00000000000..d1ba0755198
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_server_directive/tests/file_empty.fail.sh
12e95e
@@ -0,0 +1,6 @@
12e95e
+#!/bin/bash
12e95e
+# packages = chrony
12e95e
+# platform = multi_platform_fedora,multi_platform_rhel
12e95e
+# remediation = none
12e95e
+
12e95e
+echo "" > /etc/chrony.conf
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_server_directive/tests/file_missing.fail.sh b/linux_os/guide/services/ntp/chronyd_server_directive/tests/file_missing.fail.sh
12e95e
new file mode 100644
12e95e
index 00000000000..12a50ebc3d2
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_server_directive/tests/file_missing.fail.sh
12e95e
@@ -0,0 +1,6 @@
12e95e
+#!/bin/bash
12e95e
+# packages = chrony
12e95e
+# platform = multi_platform_fedora,multi_platform_rhel
12e95e
+# remediation = none
12e95e
+
12e95e
+rm -f /etc/chrony.conf
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_server_directive/tests/line_missing.fail.sh b/linux_os/guide/services/ntp/chronyd_server_directive/tests/line_missing.fail.sh
12e95e
new file mode 100644
12e95e
index 00000000000..bffa8b62b1b
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_server_directive/tests/line_missing.fail.sh
12e95e
@@ -0,0 +1,7 @@
12e95e
+#!/bin/bash
12e95e
+# packages = chrony
12e95e
+# platform = multi_platform_fedora,multi_platform_rhel
12e95e
+# remediation = none
12e95e
+
12e95e
+echo "some line" > /etc/chrony.conf
12e95e
+echo "another line" >> /etc/chrony.conf
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_server_directive/tests/multiple_servers.pass.sh b/linux_os/guide/services/ntp/chronyd_server_directive/tests/multiple_servers.pass.sh
12e95e
new file mode 100644
12e95e
index 00000000000..5527f389316
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_server_directive/tests/multiple_servers.pass.sh
12e95e
@@ -0,0 +1,8 @@
12e95e
+#!/bin/bash
12e95e
+# packages = chrony
12e95e
+# platform = multi_platform_fedora,multi_platform_rhel
12e95e
+# remediation = none
12e95e
+
12e95e
+sed -i "^pool.*" /etc/chrony.conf
12e95e
+echo "server 0.pool.ntp.org" > /etc/chrony.conf
12e95e
+echo "server 1.pool.ntp.org" >> /etc/chrony.conf
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_server_directive/tests/only_pool.fail.sh b/linux_os/guide/services/ntp/chronyd_server_directive/tests/only_pool.fail.sh
12e95e
new file mode 100644
12e95e
index 00000000000..616fe8844fc
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_server_directive/tests/only_pool.fail.sh
12e95e
@@ -0,0 +1,9 @@
12e95e
+#!/bin/bash
12e95e
+# packages = chrony
12e95e
+# platform = multi_platform_fedora,multi_platform_rhel
12e95e
+# remediation = none
12e95e
+
12e95e
+sed -i "^server.*" /etc/chrony.conf
12e95e
+if ! grep "^pool.*" /etc/chrony.conf; then
12e95e
+    echo "pool 0.pool.ntp.org" > /etc/chrony.conf
12e95e
+fi
12e95e
diff --git a/linux_os/guide/services/ntp/chronyd_server_directive/tests/only_server.pass.sh b/linux_os/guide/services/ntp/chronyd_server_directive/tests/only_server.pass.sh
12e95e
new file mode 100644
12e95e
index 00000000000..21a70dc4900
12e95e
--- /dev/null
12e95e
+++ b/linux_os/guide/services/ntp/chronyd_server_directive/tests/only_server.pass.sh
12e95e
@@ -0,0 +1,6 @@
12e95e
+#!/bin/bash
12e95e
+# packages = chrony
12e95e
+# platform = multi_platform_fedora,multi_platform_rhel
12e95e
+
12e95e
+sed -i "^pool.*" /etc/chrony.conf
12e95e
+echo "server 0.pool.ntp.org" > /etc/chrony.conf
12e95e
diff --git a/products/rhel8/profiles/stig.profile b/products/rhel8/profiles/stig.profile
12e95e
index 36f606ee461..2bd1fb54316 100644
12e95e
--- a/products/rhel8/profiles/stig.profile
12e95e
+++ b/products/rhel8/profiles/stig.profile
12e95e
@@ -909,6 +909,7 @@ selections:
12e95e
     # RHEL-08-030740
12e95e
     # remediation fails because default configuration file contains pool instead of server keyword
12e95e
     - chronyd_or_ntpd_set_maxpoll
12e95e
+    - chronyd_server_directive
12e95e
 
12e95e
     # RHEL-08-030741
12e95e
     - chronyd_client_only
12e95e
diff --git a/products/rhel9/profiles/stig.profile b/products/rhel9/profiles/stig.profile
12e95e
index 374932cfd32..0d4d7b0ff97 100644
12e95e
--- a/products/rhel9/profiles/stig.profile
12e95e
+++ b/products/rhel9/profiles/stig.profile
12e95e
@@ -909,6 +909,7 @@ selections:
12e95e
     # RHEL-08-030740
12e95e
     # remediation fails because default configuration file contains pool instead of server keyword
12e95e
     - chronyd_or_ntpd_set_maxpoll
12e95e
+    - chronyd_server_directive
12e95e
 
12e95e
     # RHEL-08-030741
12e95e
     - chronyd_client_only
12e95e
diff --git a/shared/references/cce-redhat-avail.txt b/shared/references/cce-redhat-avail.txt
12e95e
index 8c59c5d3201..0081fe1938f 100644
12e95e
--- a/shared/references/cce-redhat-avail.txt
12e95e
+++ b/shared/references/cce-redhat-avail.txt
12e95e
@@ -152,7 +152,6 @@ CCE-86073-4
12e95e
 CCE-86074-2
12e95e
 CCE-86075-9
12e95e
 CCE-86076-7
12e95e
-CCE-86077-5
12e95e
 CCE-86078-3
12e95e
 CCE-86079-1
12e95e
 CCE-86080-9
12e95e
@@ -1079,7 +1078,6 @@ CCE-87073-3
12e95e
 CCE-87074-1
12e95e
 CCE-87075-8
12e95e
 CCE-87076-6
12e95e
-CCE-87077-4
12e95e
 CCE-87078-2
12e95e
 CCE-87079-0
12e95e
 CCE-87080-8
12e95e
diff --git a/tests/data/profile_stability/rhel8/stig.profile b/tests/data/profile_stability/rhel8/stig.profile
12e95e
index 5b06103d72e..7d44f8910d1 100644
12e95e
--- a/tests/data/profile_stability/rhel8/stig.profile
12e95e
+++ b/tests/data/profile_stability/rhel8/stig.profile
12e95e
@@ -160,6 +160,7 @@ selections:
12e95e
 - chronyd_client_only
12e95e
 - chronyd_no_chronyc_network
12e95e
 - chronyd_or_ntpd_set_maxpoll
12e95e
+- chronyd_server_directive
12e95e
 - clean_components_post_updating
12e95e
 - configure_bashrc_exec_tmux
12e95e
 - configure_bind_crypto_policy
12e95e
diff --git a/tests/data/profile_stability/rhel8/stig_gui.profile b/tests/data/profile_stability/rhel8/stig_gui.profile
12e95e
index 11e0ee9515a..91546d1d418 100644
12e95e
--- a/tests/data/profile_stability/rhel8/stig_gui.profile
12e95e
+++ b/tests/data/profile_stability/rhel8/stig_gui.profile
12e95e
@@ -171,6 +171,7 @@ selections:
12e95e
 - chronyd_client_only
12e95e
 - chronyd_no_chronyc_network
12e95e
 - chronyd_or_ntpd_set_maxpoll
12e95e
+- chronyd_server_directive
12e95e
 - clean_components_post_updating
12e95e
 - configure_bashrc_exec_tmux
12e95e
 - configure_bind_crypto_policy