Blame SOURCES/scap-security-guide-0.1.61-update_RHEL_08_020041-PR_8146.patch

07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/bash/shared.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/bash/shared.sh
07cb6b
index 737d725872d..08b62057bde 100644
07cb6b
--- a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/bash/shared.sh
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/bash/shared.sh
07cb6b
@@ -1,7 +1,11 @@
07cb6b
 # platform = multi_platform_all
07cb6b
+# reboot = true
07cb6b
+# strategy = enable
07cb6b
+# complexity = low
07cb6b
+# disruption = low
07cb6b
 
07cb6b
 if ! grep -x '  case "$name" in sshd|login) exec tmux ;; esac' /etc/bashrc; then
07cb6b
-    cat >> /etc/bashrc <<'EOF'
07cb6b
+    cat >> /etc/profile.d/tmux.sh <<'EOF'
07cb6b
 if [ "$PS1" ]; then
07cb6b
   parent=$(ps -o ppid= -p $$)
07cb6b
   name=$(ps -o comm= -p $parent)
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/oval/shared.xml b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/oval/shared.xml
07cb6b
index 00ac349e292..4cb2f9e0e04 100644
07cb6b
--- a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/oval/shared.xml
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/oval/shared.xml
07cb6b
@@ -4,21 +4,27 @@
07cb6b
     <criteria comment="Check exec tmux configured at the end of bashrc" operator="AND">
07cb6b
       
07cb6b
         test_ref="test_configure_bashrc_exec_tmux" />
07cb6b
+      <criterion comment="check tmux is running" test_ref="test_tmux_running"/>
07cb6b
     </criteria>
07cb6b
   </definition>
07cb6b
-  
07cb6b
+  
07cb6b
     comment="check tmux is configured to exec on the last line of /etc/bashrc"
07cb6b
     id="test_configure_bashrc_exec_tmux" version="1">
07cb6b
     <ind:object object_ref="obj_configure_bashrc_exec_tmux" />
07cb6b
-    <ind:state state_ref="state_configure_bashrc_exec_tmux" />
07cb6b
   </ind:textfilecontent54_test>
07cb6b
   <ind:textfilecontent54_object id="obj_configure_bashrc_exec_tmux" version="1">
07cb6b
     <ind:behaviors singleline="true" multiline="false" />
07cb6b
-    <ind:filepath>/etc/bashrc</ind:filepath>
07cb6b
-    <ind:pattern operation="pattern match">^(.*)$</ind:pattern>
07cb6b
-    <ind:instance datatype="int">1</ind:instance>
07cb6b
+    <ind:filepath operation="pattern match">^/etc/bashrc$|^/etc/profile\.d/.*$</ind:filepath>
07cb6b
+    <ind:pattern operation="pattern match">if \[ "\$PS1" \]; then\n\s+parent=\$\(ps -o ppid= -p \$\$\)\n\s+name=\$\(ps -o comm= -p \$parent\)\n\s+case "\$name" in sshd\|login\) exec tmux ;; esac\nfi</ind:pattern>
07cb6b
+    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
07cb6b
   </ind:textfilecontent54_object>
07cb6b
-  <ind:textfilecontent54_state id="state_configure_bashrc_exec_tmux" version="1">
07cb6b
-    <ind:subexpression datatype="string" operation="pattern match">if \[ "\$PS1" \]; then\n\s+parent=\$\(ps -o ppid= -p \$\$\)\n\s+name=\$\(ps -o comm= -p \$parent\)\n\s+case "\$name" in sshd\|login\) exec tmux ;; esac\nfi</ind:subexpression>
07cb6b
-  </ind:textfilecontent54_state>
07cb6b
+
07cb6b
+  <unix:process58_test check="all" id="test_tmux_running" comment="is tmux running" version="1">
07cb6b
+      <unix:object object_ref="obj_tmux_running"/>
07cb6b
+  </unix:process58_test>
07cb6b
+
07cb6b
+  <unix:process58_object id="obj_tmux_running" version="1">
07cb6b
+      <unix:command_line operation="pattern match">^tmux(?:|[\s]+.*)$</unix:command_line>
07cb6b
+      <unix:pid datatype="int" operation="greater than">0</unix:pid>
07cb6b
+  </unix:process58_object>
07cb6b
 </def-group>
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/rule.yml b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/rule.yml
07cb6b
index 3ba0f4a2d8f..7afc5fc5e6b 100644
07cb6b
--- a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/rule.yml
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/rule.yml
07cb6b
@@ -7,12 +7,20 @@ title: 'Support session locking with tmux'
07cb6b
 description: |-
07cb6b
     The <tt>tmux</tt> terminal multiplexer is used to implement
07cb6b
     automatic session locking. It should be started from
07cb6b
-    <tt>/etc/bashrc</tt>.
07cb6b
+    <tt>/etc/bashrc</tt> or drop-in files within <tt>/etc/profile.d/</tt>.
07cb6b
+    Additionally it must be ensured that the <tt>tmux</tt> process is running
07cb6b
+    and it can be verified with the following command:
07cb6b
+    
ps all | grep tmux | grep -v grep
07cb6b
 
07cb6b
 rationale: |-
07cb6b
     Unlike <tt>bash</tt> itself, the <tt>tmux</tt> terminal multiplexer
07cb6b
     provides a mechanism to lock sessions after period of inactivity.
07cb6b
 
07cb6b
+warnings:
07cb6b
+  - general: |-
07cb6b
+        The remediation does not start the tmux process, so it must be
07cb6b
+        manually started or have the system rebooted after applying the fix.
07cb6b
+
07cb6b
 severity: medium
07cb6b
 
07cb6b
 identifiers:
07cb6b
@@ -26,17 +34,21 @@ references:
07cb6b
     stigid@ol8: OL08-00-020041
07cb6b
     stigid@rhel8: RHEL-08-020041
07cb6b
 
07cb6b
-ocil_clause: 'exec tmux is not present at the end of bashrc'
07cb6b
+ocil_clause: 'exec tmux is not present at the end of bashrc or tmux process is not running'
07cb6b
 
07cb6b
 ocil: |-
07cb6b
     To verify that tmux is configured to execute,
07cb6b
     run the following command:
07cb6b
-    
$ grep -A1 -B3 "case ..name. in sshd|login) exec tmux ;; esac" /etc/bashrc
07cb6b
+    
$ grep -A1 -B3 "case ..name. in sshd|login) exec tmux ;; esac" /etc/bashrc /etc/profile.d/*
07cb6b
     The output should return the following:
07cb6b
     
if [ "$PS1" ]; then
07cb6b
       parent=$(ps -o ppid= -p $$)
07cb6b
       name=$(ps -o comm= -p $parent)
07cb6b
       case "$name" in sshd|login) exec tmux ;; esac
07cb6b
     fi
07cb6b
+    To verify that the tmux process is running,
07cb6b
+    run the following command:
07cb6b
+    
ps all | grep tmux | grep -v grep
07cb6b
+    If the command does not produce output, this is a finding.
07cb6b
 
07cb6b
 platform: machine
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value.pass.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value.pass.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..221c18665ef
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value.pass.sh
07cb6b
@@ -0,0 +1,12 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = tmux
07cb6b
+
07cb6b
+cat >> /etc/bashrc <<'EOF'
07cb6b
+if [ "$PS1" ]; then
07cb6b
+  parent=$(ps -o ppid= -p $$)
07cb6b
+  name=$(ps -o comm= -p $parent)
07cb6b
+  case "$name" in sshd|login) exec tmux ;; esac
07cb6b
+fi
07cb6b
+EOF
07cb6b
+
07cb6b
+tmux new-session -s root -d
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value_d_directory.pass.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value_d_directory.pass.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..1702bb17e79
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/correct_value_d_directory.pass.sh
07cb6b
@@ -0,0 +1,13 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = tmux
07cb6b
+
07cb6b
+
07cb6b
+cat >> /etc/profile.d/00-complianceascode.conf <<'EOF'
07cb6b
+if [ "$PS1" ]; then
07cb6b
+  parent=$(ps -o ppid= -p $$)
07cb6b
+  name=$(ps -o comm= -p $parent)
07cb6b
+  case "$name" in sshd|login) exec tmux ;; esac
07cb6b
+fi
07cb6b
+EOF
07cb6b
+
07cb6b
+tmux new-session -s root -d
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/duplicate_value_multiple_files.pass.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/duplicate_value_multiple_files.pass.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..16d4acfcb5a
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/duplicate_value_multiple_files.pass.sh
07cb6b
@@ -0,0 +1,20 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = tmux
07cb6b
+
07cb6b
+cat >> /etc/profile.d/00-complianceascode.conf <<'EOF'
07cb6b
+if [ "$PS1" ]; then
07cb6b
+  parent=$(ps -o ppid= -p $$)
07cb6b
+  name=$(ps -o comm= -p $parent)
07cb6b
+  case "$name" in sshd|login) exec tmux ;; esac
07cb6b
+fi
07cb6b
+EOF
07cb6b
+
07cb6b
+cat >> /etc/bashrc <<'EOF'
07cb6b
+if [ "$PS1" ]; then
07cb6b
+  parent=$(ps -o ppid= -p $$)
07cb6b
+  name=$(ps -o comm= -p $parent)
07cb6b
+  case "$name" in sshd|login) exec tmux ;; esac
07cb6b
+fi
07cb6b
+EOF
07cb6b
+
07cb6b
+tmux new-session -s root -d
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/tmux_not_running.fail.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/tmux_not_running.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..6cb9d83efc5
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/tmux_not_running.fail.sh
07cb6b
@@ -0,0 +1,13 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = tmux
07cb6b
+# remediation = none
07cb6b
+
07cb6b
+cat >> /etc/bashrc <<'EOF'
07cb6b
+if [ "$PS1" ]; then
07cb6b
+  parent=$(ps -o ppid= -p $$)
07cb6b
+  name=$(ps -o comm= -p $parent)
07cb6b
+  case "$name" in sshd|login) exec tmux ;; esac
07cb6b
+fi
07cb6b
+EOF
07cb6b
+
07cb6b
+killall tmux || true
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/wrong_value.fail.sh b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/wrong_value.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..f13a8b038e4
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-physical/screen_locking/console_screen_locking/configure_bashrc_exec_tmux/tests/wrong_value.fail.sh
07cb6b
@@ -0,0 +1,105 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = tmux
07cb6b
+
07cb6b
+cat > /etc/bashrc <<'EOF'
07cb6b
+# /etc/bashrc
07cb6b
+
07cb6b
+# System wide functions and aliases
07cb6b
+# Environment stuff goes in /etc/profile
07cb6b
+
07cb6b
+# It's NOT a good idea to change this file unless you know what you
07cb6b
+# are doing. It's much better to create a custom.sh shell script in
07cb6b
+# /etc/profile.d/ to make custom changes to your environment, as this
07cb6b
+# will prevent the need for merging in future updates.
07cb6b
+
07cb6b
+# Prevent doublesourcing
07cb6b
+if [ -z "$BASHRCSOURCED" ]; then
07cb6b
+  BASHRCSOURCED="Y"
07cb6b
+
07cb6b
+  # are we an interactive shell?
07cb6b
+  if [ "$PS1" ]; then
07cb6b
+    if [ -z "$PROMPT_COMMAND" ]; then
07cb6b
+      case $TERM in
07cb6b
+      xterm*|vte*)
07cb6b
+        if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
07cb6b
+            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
07cb6b
+        elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
07cb6b
+            PROMPT_COMMAND="__vte_prompt_command"
07cb6b
+        else
07cb6b
+            PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
07cb6b
+        fi
07cb6b
+        ;;
07cb6b
+      screen*)
07cb6b
+        if [ -e /etc/sysconfig/bash-prompt-screen ]; then
07cb6b
+            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
07cb6b
+        else
07cb6b
+            PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
07cb6b
+        fi
07cb6b
+        ;;
07cb6b
+      *)
07cb6b
+        [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
07cb6b
+        ;;
07cb6b
+      esac
07cb6b
+    fi
07cb6b
+    # Turn on parallel history
07cb6b
+    shopt -s histappend
07cb6b
+    history -a
07cb6b
+    # Turn on checkwinsize
07cb6b
+    shopt -s checkwinsize
07cb6b
+    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
07cb6b
+    # You might want to have e.g. tty in prompt (e.g. more virtual machines)
07cb6b
+    # and console windows
07cb6b
+    # If you want to do so, just add e.g.
07cb6b
+    # if [ "$PS1" ]; then
07cb6b
+    #   PS1="[\u@\h:\l \W]\\$ "
07cb6b
+    # fi
07cb6b
+    # to your custom modification shell script in /etc/profile.d/ directory
07cb6b
+  fi
07cb6b
+
07cb6b
+  if ! shopt -q login_shell ; then # We're not a login shell
07cb6b
+    # Need to redefine pathmunge, it gets undefined at the end of /etc/profile
07cb6b
+    pathmunge () {
07cb6b
+        case ":${PATH}:" in
07cb6b
+            *:"$1":*)
07cb6b
+                ;;
07cb6b
+            *)
07cb6b
+                if [ "$2" = "after" ] ; then
07cb6b
+                    PATH=$PATH:$1
07cb6b
+                else
07cb6b
+                    PATH=$1:$PATH
07cb6b
+                fi
07cb6b
+        esac
07cb6b
+    }
07cb6b
+
07cb6b
+    # By default, we want umask to get set. This sets it for non-login shell.
07cb6b
+    # Current threshold for system reserved uid/gids is 200
07cb6b
+    # You could check uidgid reservation validity in
07cb6b
+    # /usr/share/doc/setup-*/uidgid file
07cb6b
+    if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
07cb6b
+       umask 002
07cb6b
+    else
07cb6b
+       umask 022
07cb6b
+    fi
07cb6b
+
07cb6b
+    SHELL=/bin/bash
07cb6b
+    # Only display echos from profile.d scripts if we are no login shell
07cb6b
+    # and interactive - otherwise just process them to set envvars
07cb6b
+    for i in /etc/profile.d/*.sh; do
07cb6b
+        if [ -r "$i" ]; then
07cb6b
+            if [ "$PS1" ]; then
07cb6b
+                . "$i"
07cb6b
+            else
07cb6b
+                . "$i" >/dev/null
07cb6b
+            fi
07cb6b
+        fi
07cb6b
+    done
07cb6b
+
07cb6b
+    unset i
07cb6b
+    unset -f pathmunge
07cb6b
+  fi
07cb6b
+
07cb6b
+fi
07cb6b
+# vim:ts=4:sw=4
07cb6b
+EOF
07cb6b
+
07cb6b
+tmux new-session -s root -d