Blame SOURCES/scap-security-guide-0.1.65-stig_rhel8_ClientAliveCountMax-PR_9784.patch

f6303c
From c4afa942edea4b26498dc223d4965fb722d919ed Mon Sep 17 00:00:00 2001
f6303c
From: Watson Sato <wsato@redhat.com>
f6303c
Date: Tue, 8 Nov 2022 13:53:14 +0100
f6303c
Subject: [PATCH 1/7] RHEL8 STIG v1R8 requires ClientAliveCountMax 1
f6303c
f6303c
Following update from V1R8, update the STIG profile to configure
f6303c
ClientAliveCountMax to 1.
f6303c
f6303c
This will timeout SSH connections when client alive messages are not
f6303c
received within ClientAliveInterval seconds.
f6303c
This serves the purpose of disconnecting sessions when the client has
f6303c
become unresponsive.
f6303c
---
f6303c
 .../guide/services/ssh/ssh_server/sshd_set_keepalive/rule.yml | 1 +
f6303c
 .../services/ssh/ssh_server/sshd_set_keepalive_0/rule.yml     | 1 -
f6303c
 products/rhel8/profiles/stig.profile                          | 4 ++--
f6303c
 3 files changed, 3 insertions(+), 3 deletions(-)
f6303c
f6303c
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/rule.yml b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/rule.yml
f6303c
index bc8ee914565..df0681f3f3a 100644
f6303c
--- a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/rule.yml
f6303c
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/rule.yml
f6303c
@@ -55,6 +55,7 @@ references:
f6303c
     pcidss: Req-8.1.8
f6303c
     srg: SRG-OS-000163-GPOS-00072,SRG-OS-000279-GPOS-00109
f6303c
     stigid@ol7: OL07-00-040340
f6303c
+    stigid@rhel8: RHEL-08-010200
f6303c
     stigid@sle12: SLES-12-030191
f6303c
     stigid@ubuntu2004: UBTU-20-010036
f6303c
     vmmsrg: SRG-OS-000480-VMM-002000
f6303c
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive_0/rule.yml b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive_0/rule.yml
f6303c
index 024cb687382..a02fa8f40db 100644
f6303c
--- a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive_0/rule.yml
f6303c
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive_0/rule.yml
f6303c
@@ -54,7 +54,6 @@ references:
f6303c
     stigid@ol7: OL07-00-040340
f6303c
     stigid@ol8: OL08-00-010200
f6303c
     stigid@rhel7: RHEL-07-040340
f6303c
-    stigid@rhel8: RHEL-08-010200
f6303c
     stigid@sle12: SLES-12-030191
f6303c
     stigid@sle15: SLES-15-010320
f6303c
     vmmsrg: SRG-OS-000480-VMM-002000
f6303c
diff --git a/products/rhel8/profiles/stig.profile b/products/rhel8/profiles/stig.profile
f6303c
index 96dfbf6b203..d184957f28c 100644
f6303c
--- a/products/rhel8/profiles/stig.profile
f6303c
+++ b/products/rhel8/profiles/stig.profile
f6303c
@@ -50,7 +50,7 @@ selections:
f6303c
     - var_password_pam_lcredit=1
f6303c
     - var_password_pam_retry=3
f6303c
     - var_password_pam_minlen=15
f6303c
-    # - var_sshd_set_keepalive=0
f6303c
+    - var_sshd_set_keepalive=1
f6303c
     - sshd_approved_macs=stig
f6303c
     - sshd_approved_ciphers=stig
f6303c
     - sshd_idle_timeout_value=10_minutes
f6303c
@@ -174,7 +174,7 @@ selections:
f6303c
     # they still need to be selected so it follows exactly what STIG
f6303c
     # states.
f6303c
     # RHEL-08-010200
f6303c
-    - sshd_set_keepalive_0
f6303c
+    - sshd_set_keepalive
f6303c
     # RHEL-08-010201
f6303c
     - sshd_set_idle_timeout
f6303c
 
f6303c
f6303c
From a9f13cdff06ce7de53420b0ca65b3a8110eae85a Mon Sep 17 00:00:00 2001
f6303c
From: Watson Sato <wsato@redhat.com>
f6303c
Date: Tue, 8 Nov 2022 14:06:42 +0100
f6303c
Subject: [PATCH 2/7] Change verbiage on keepalive rules
f6303c
f6303c
Stop using the 'idle', that implies an idle user; And
f6303c
start using unresponsive, which better describes the state of network.
f6303c
---
f6303c
 .../ssh/ssh_server/sshd_set_keepalive/rule.yml    | 15 ++++++++-------
f6303c
 .../ssh/ssh_server/sshd_set_keepalive_0/rule.yml  |  6 +++---
f6303c
 2 files changed, 11 insertions(+), 10 deletions(-)
f6303c
f6303c
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/rule.yml b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/rule.yml
f6303c
index df0681f3f3a..7a27c134f1e 100644
f6303c
--- a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/rule.yml
f6303c
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/rule.yml
f6303c
@@ -7,14 +7,15 @@ description: |-
f6303c
     during a SSH session and waits for a response from the SSH client.
f6303c
     The option <tt>ClientAliveInterval</tt> configures timeout after
f6303c
     each <tt>ClientAliveCountMax</tt> message. If the SSH server does not
f6303c
-    receive a response from the client, then the connection is considered idle
f6303c
+    receive a response from the client, then the connection is considered unresponsive
f6303c
     and terminated.
f6303c
     For SSH earlier than v8.2, a <tt>ClientAliveCountMax</tt> value of <tt>0</tt>
f6303c
-    causes an idle timeout precisely when the <tt>ClientAliveInterval</tt> is set.
f6303c
+    causes a timeout precisely when the <tt>ClientAliveInterval</tt> is set.
f6303c
     Starting with v8.2, a value of <tt>0</tt> disables the timeout functionality
f6303c
     completely. If the option is set to a number greater than <tt>0</tt>, then
f6303c
-    the idle session will be disconnected after
f6303c
-    <tt>ClientAliveInterval * ClientAliveCountMax</tt> seconds.
f6303c
+    the session will be disconnected after
f6303c
+    <tt>ClientAliveInterval * ClientAliveCountMax</tt> seconds without receiving
f6303c
+    a keep alive message.
f6303c
 
f6303c
 rationale: |-
f6303c
     This ensures a user login will be terminated as soon as the <tt>ClientAliveInterval</tt>
f6303c
@@ -70,8 +71,8 @@ ocil: |-
f6303c
     
$ sudo grep ClientAliveCountMax /etc/ssh/sshd_config
f6303c
     If properly configured, the output should be:
f6303c
     
ClientAliveCountMax {{{ xccdf_value("var_sshd_set_keepalive") }}}
f6303c
-    For SSH earlier than v8.2, a <tt>ClientAliveCountMax</tt> value of <tt>0</tt> causes an idle timeout precisely when
f6303c
+    For SSH earlier than v8.2, a <tt>ClientAliveCountMax</tt> value of <tt>0</tt> causes a timeout precisely when
f6303c
     the <tt>ClientAliveInterval</tt> is set.  Starting with v8.2, a value of <tt>0</tt> disables the timeout
f6303c
     functionality completely.
f6303c
-    If the option is set to a number greater than <tt>0</tt>, then the idle session will be disconnected after
f6303c
-    <tt>ClientAliveInterval * ClientAliveCountMax</tt> seconds.
f6303c
+    If the option is set to a number greater than <tt>0</tt>, then the session will be disconnected after
f6303c
+    <tt>ClientAliveInterval * ClientAliveCountMax</tt> seconds witout receiving a keep alive message.
f6303c
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive_0/rule.yml b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive_0/rule.yml
f6303c
index a02fa8f40db..55011ab66a7 100644
f6303c
--- a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive_0/rule.yml
f6303c
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive_0/rule.yml
f6303c
@@ -10,10 +10,10 @@ description: |-
f6303c
     during a SSH session and waits for a response from the SSH client.
f6303c
     The option <tt>ClientAliveInterval</tt> configures timeout after
f6303c
     each <tt>ClientAliveCountMax</tt> message. If the SSH server does not
f6303c
-    receive a response from the client, then the connection is considered idle
f6303c
+    receive a response from the client, then the connection is considered unresponsive
f6303c
     and terminated.
f6303c
 
f6303c
-    To ensure the SSH idle timeout occurs precisely when the
f6303c
+    To ensure the SSH timeout occurs precisely when the
f6303c
     <tt>ClientAliveInterval</tt> is set, set the <tt>ClientAliveCountMax</tt> to
f6303c
     value of <tt>0</tt> in
f6303c
     {{{ sshd_config_file() }}}
f6303c
@@ -73,7 +73,7 @@ ocil: |-
f6303c
     If properly configured, the output should be:
f6303c
     
ClientAliveCountMax 0
f6303c
 
f6303c
-    In this case, the SSH idle timeout occurs precisely when
f6303c
+    In this case, the SSH timeout occurs precisely when
f6303c
     the <tt>ClientAliveInterval</tt> is set.
f6303c
 
f6303c
 template:
f6303c
f6303c
From 587cec666b6379995e38a90bcd0ed86bbf4bd3e3 Mon Sep 17 00:00:00 2001
f6303c
From: Watson Sato <wsato@redhat.com>
f6303c
Date: Tue, 8 Nov 2022 14:27:50 +0100
f6303c
Subject: [PATCH 3/7] Add tests to check for configuration conflicts
f6303c
f6303c
---
f6303c
 .../sshd_set_keepalive/tests/param_conflict.fail.sh | 11 +++++++++++
f6303c
 .../tests/param_conflict_directory.fail.sh          | 13 +++++++++++++
f6303c
 2 files changed, 24 insertions(+)
f6303c
 create mode 100644 linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/tests/param_conflict.fail.sh
f6303c
 create mode 100644 linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/tests/param_conflict_directory.fail.sh
f6303c
f6303c
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/tests/param_conflict.fail.sh b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/tests/param_conflict.fail.sh
f6303c
new file mode 100644
f6303c
index 00000000000..54441cbb5b6
f6303c
--- /dev/null
f6303c
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/tests/param_conflict.fail.sh
f6303c
@@ -0,0 +1,11 @@
f6303c
+#!/bin/bash
f6303c
+
f6303c
+mkdir -p /etc/ssh/sshd_config.d
f6303c
+touch /etc/ssh/sshd_config.d/nothing
f6303c
+
f6303c
+if grep -q "^\s*ClientAliveCountMax" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* ; then
f6303c
+	sed -i "/^\s*ClientAliveCountMax.*/Id" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
f6303c
+fi
f6303c
+
f6303c
+echo "ClientAliveCountMax 0" >> /etc/ssh/sshd_config
f6303c
+echo "ClientAliveCountMax 1" >> /etc/ssh/sshd_config
f6303c
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/tests/param_conflict_directory.fail.sh b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/tests/param_conflict_directory.fail.sh
f6303c
new file mode 100644
f6303c
index 00000000000..aa6931cc243
f6303c
--- /dev/null
f6303c
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/tests/param_conflict_directory.fail.sh
f6303c
@@ -0,0 +1,13 @@
f6303c
+#!/bin/bash
f6303c
+
f6303c
+# platform = multi_platform_fedora,Red Hat Enterprise Linux 9
f6303c
+
f6303c
+mkdir -p /etc/ssh/sshd_config.d
f6303c
+touch /etc/ssh/sshd_config.d/nothing
f6303c
+
f6303c
+if grep -q "^\s*ClientAliveCountMax" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* ; then
f6303c
+	sed -i "/^\s*ClientAliveCountMax.*/Id" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
f6303c
+fi
f6303c
+
f6303c
+echo "ClientAliveCountMax 0" > /etc/ssh/sshd_config.d/good_config.conf
f6303c
+echo "ClientAliveCountMax 1" > /etc/ssh/sshd_config.d/bad_config.conf
f6303c
f6303c
From d07a7f33cc5dd486d5d56ce71b90118366b68091 Mon Sep 17 00:00:00 2001
f6303c
From: Watson Sato <wsato@redhat.com>
f6303c
Date: Tue, 8 Nov 2022 17:09:16 +0100
f6303c
Subject: [PATCH 4/7] Check all instances of ClientAliveCountMax
f6303c
f6303c
The rule was only checking the first occurence of ClientAliveCountMax,
f6303c
but we need to check that all and any occurrences of
f6303c
ClientAliveCountMax are compliant.
f6303c
---
f6303c
 .../services/ssh/ssh_server/sshd_set_keepalive/oval/shared.xml  | 2 +-
f6303c
 1 file changed, 1 insertion(+), 1 deletion(-)
f6303c
f6303c
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/oval/shared.xml b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/oval/shared.xml
f6303c
index 5e07d982821..404c36c8dbc 100644
f6303c
--- a/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/oval/shared.xml
f6303c
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_set_keepalive/oval/shared.xml
f6303c
@@ -49,7 +49,7 @@
f6303c
   <ind:textfilecontent54_object id="obj_sshd_clientalivecountmax" version="2">
f6303c
     <ind:filepath>/etc/ssh/sshd_config</ind:filepath>
f6303c
     <ind:pattern operation="pattern match">^[\s]*(?i)ClientAliveCountMax[\s]+([\d]+)[\s]*(?:#.*)?$</ind:pattern>
f6303c
-    <ind:instance datatype="int">1</ind:instance>
f6303c
+    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
f6303c
   </ind:textfilecontent54_object>
f6303c
   {{%- if sshd_distributed_config == "true" %}}
f6303c
   
f6303c
f6303c
From d15ebb0b563895fbc2ab85c631410ea60bd02d95 Mon Sep 17 00:00:00 2001
f6303c
From: Watson Sato <wsato@redhat.com>
f6303c
Date: Tue, 8 Nov 2022 17:40:26 +0100
f6303c
Subject: [PATCH 5/7] Add test to check for configuration conflicts
f6303c
f6303c
Add test for non distributed ssh config conflicts for
f6303c
ClientAliveInterval.
f6303c
---
f6303c
 .../tests/param_conflict.fail.sh                  | 15 +++++++++++++++
f6303c
 1 file changed, 15 insertions(+)
f6303c
 create mode 100644 linux_os/guide/services/ssh/ssh_server/sshd_set_idle_timeout/tests/param_conflict.fail.sh
f6303c
f6303c
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_set_idle_timeout/tests/param_conflict.fail.sh b/linux_os/guide/services/ssh/ssh_server/sshd_set_idle_timeout/tests/param_conflict.fail.sh
f6303c
new file mode 100644
f6303c
index 00000000000..1e14aa3da36
f6303c
--- /dev/null
f6303c
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_set_idle_timeout/tests/param_conflict.fail.sh
f6303c
@@ -0,0 +1,15 @@
f6303c
+#!/bin/bash
f6303c
+
f6303c
+mkdir -p /etc/ssh/sshd_config.d
f6303c
+touch /etc/ssh/sshd_config.d/nothing
f6303c
+
f6303c
+if grep -q "^\s*ClientAliveInterval" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* ; then
f6303c
+    sed -i "/^\s*ClientAliveInterval.*/Id" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
f6303c
+fi
f6303c
+if grep -q "^\s*ClientAliveCountMax" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* ; then
f6303c
+	sed -i "/^\s*ClientAliveCountMax.*/Id" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*
f6303c
+fi
f6303c
+
f6303c
+echo "ClientAliveInterval 6000" >> /etc/ssh/sshd_config
f6303c
+echo "ClientAliveInterval 200" >> /etc/ssh/sshd_config
f6303c
+echo "ClientAliveCountMax 0" >> /etc/ssh/sshd_config
f6303c
f6303c
From c19d5400bd3ded71aae9175f27361065c962069e Mon Sep 17 00:00:00 2001
f6303c
From: Watson Sato <wsato@redhat.com>
f6303c
Date: Tue, 8 Nov 2022 17:41:19 +0100
f6303c
Subject: [PATCH 6/7] Change verbiage on idle timeout rule
f6303c
f6303c
The config is not really about idle user timeout, the config is about
f6303c
unresponsive network timeout.
f6303c
---
f6303c
 .../ssh/ssh_server/sshd_set_idle_timeout/rule.yml    | 12 ++++++------
f6303c
 1 file changed, 6 insertions(+), 6 deletions(-)
f6303c
f6303c
diff --git a/linux_os/guide/services/ssh/ssh_server/sshd_set_idle_timeout/rule.yml b/linux_os/guide/services/ssh/ssh_server/sshd_set_idle_timeout/rule.yml
f6303c
index aa085894f61..c5606aac557 100644
f6303c
--- a/linux_os/guide/services/ssh/ssh_server/sshd_set_idle_timeout/rule.yml
f6303c
+++ b/linux_os/guide/services/ssh/ssh_server/sshd_set_idle_timeout/rule.yml
f6303c
@@ -1,12 +1,12 @@
f6303c
 documentation_complete: true
f6303c
 
f6303c
-title: 'Set SSH Idle Timeout Interval'
f6303c
+title: 'Set SSH Client Alive Interval'
f6303c
 
f6303c
 description: |-
f6303c
-    SSH allows administrators to set an idle timeout interval. After this interval
f6303c
-    has passed, the idle user will be automatically logged out.
f6303c
+    SSH allows administrators to set a network responsiveness timeout interval.
f6303c
+    After this interval has passed, the unresponsive client will be automatically logged out.
f6303c
     

f6303c
-    To set an idle timeout interval, edit the following line in <tt>/etc/ssh/sshd_config</tt> as
f6303c
+    To set this timeout interval, edit the following line in <tt>/etc/ssh/sshd_config</tt> as
f6303c
     follows:
f6303c
     
ClientAliveInterval {{{ xccdf_value("sshd_idle_timeout_value") }}}
f6303c
     

f6303c
@@ -15,7 +15,7 @@ description: |-
f6303c
     

f6303c
     If a shorter timeout has already been set for the login shell, that value will
f6303c
     preempt any SSH setting made in <tt>/etc/ssh/sshd_config</tt>. Keep in mind that
f6303c
-    some processes may stop SSH  from correctly detecting that the user is idle.
f6303c
+    some processes may stop SSH from correctly detecting that the user is idle.
f6303c
 
f6303c
 rationale: |-
f6303c
     Terminating an idle ssh session within a short time period reduces the window of
f6303c
@@ -81,7 +81,7 @@ ocil: |-
f6303c
 
f6303c
 warnings:
f6303c
     - dependency: |-
f6303c
-        SSH disconnecting idle clients will not have desired effect without also
f6303c
+        SSH disconnecting unresponsive clients will not have desired effect without also
f6303c
         configuring ClientAliveCountMax in the SSH service configuration.
f6303c
     - general: |-
f6303c
         Following conditions may prevent the SSH session to time out:
f6303c
f6303c
From 86b1a6147582c896e1bb49a0649493eeec37a8d4 Mon Sep 17 00:00:00 2001
f6303c
From: Watson Sato <wsato@redhat.com>
f6303c
Date: Wed, 9 Nov 2022 11:31:50 +0100
f6303c
Subject: [PATCH 7/7] Update profile stability test data
f6303c
f6303c
---
f6303c
 tests/data/profile_stability/rhel8/stig.profile     | 3 ++-
f6303c
 tests/data/profile_stability/rhel8/stig_gui.profile | 3 ++-
f6303c
 2 files changed, 4 insertions(+), 2 deletions(-)
f6303c
f6303c
diff --git a/tests/data/profile_stability/rhel8/stig.profile b/tests/data/profile_stability/rhel8/stig.profile
f6303c
index cadc3f5fc7a..51971451996 100644
f6303c
--- a/tests/data/profile_stability/rhel8/stig.profile
f6303c
+++ b/tests/data/profile_stability/rhel8/stig.profile
f6303c
@@ -371,7 +371,7 @@ selections:
f6303c
 - sshd_print_last_log
f6303c
 - sshd_rekey_limit
f6303c
 - sshd_set_idle_timeout
f6303c
-- sshd_set_keepalive_0
f6303c
+- sshd_set_keepalive
f6303c
 - sshd_use_strong_rng
f6303c
 - sshd_x11_use_localhost
f6303c
 - sssd_certificate_verification
f6303c
@@ -441,6 +441,7 @@ selections:
f6303c
 - var_password_pam_ucredit=1
f6303c
 - var_password_pam_lcredit=1
f6303c
 - var_password_pam_retry=3
f6303c
+- var_sshd_set_keepalive=1
f6303c
 - sshd_approved_macs=stig
f6303c
 - sshd_approved_ciphers=stig
f6303c
 - sshd_idle_timeout_value=10_minutes
f6303c
diff --git a/tests/data/profile_stability/rhel8/stig_gui.profile b/tests/data/profile_stability/rhel8/stig_gui.profile
f6303c
index bde4e18b068..fd150744167 100644
f6303c
--- a/tests/data/profile_stability/rhel8/stig_gui.profile
f6303c
+++ b/tests/data/profile_stability/rhel8/stig_gui.profile
f6303c
@@ -381,7 +381,7 @@ selections:
f6303c
 - sshd_print_last_log
f6303c
 - sshd_rekey_limit
f6303c
 - sshd_set_idle_timeout
f6303c
-- sshd_set_keepalive_0
f6303c
+- sshd_set_keepalive
f6303c
 - sshd_use_strong_rng
f6303c
 - sshd_x11_use_localhost
f6303c
 - sssd_certificate_verification
f6303c
@@ -449,6 +449,7 @@ selections:
f6303c
 - var_password_pam_ucredit=1
f6303c
 - var_password_pam_lcredit=1
f6303c
 - var_password_pam_retry=3
f6303c
+- var_sshd_set_keepalive=1
f6303c
 - sshd_approved_macs=stig
f6303c
 - sshd_approved_ciphers=stig
f6303c
 - sshd_idle_timeout_value=10_minutes