Blame SOURCES/scap-security-guide-0.1.53-update_stig_RHEL_07_040000-PR_6063.patch

fe0dde
From 8e7f586ff2c52a7a30cf55973ba8a15303dcdff1 Mon Sep 17 00:00:00 2001
fe0dde
From: Gabriel Becker <ggasparb@redhat.com>
fe0dde
Date: Tue, 8 Sep 2020 19:17:27 +0200
fe0dde
Subject: [PATCH 1/2] Fix ansible remediation of
fe0dde
 accounts_max_concurrent_login_sessions.
fe0dde
fe0dde
Add test scenarios.
fe0dde
---
fe0dde
 .../ansible/shared.yml                        | 27 +++++++++++++++++--
fe0dde
 .../tests/correct_value.pass.sh               |  2 ++
fe0dde
 .../tests/correct_value_2.pass.sh             |  2 ++
fe0dde
 .../tests/line_not_there.fail.sh              |  2 ++
fe0dde
 .../tests/wrong_value_1000.fail.sh            |  2 ++
fe0dde
 .../tests/wrong_value_1000_limits_d.fail.sh   |  3 +++
fe0dde
 6 files changed, 36 insertions(+), 2 deletions(-)
fe0dde
 create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/correct_value.pass.sh
fe0dde
 create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/correct_value_2.pass.sh
fe0dde
 create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/line_not_there.fail.sh
fe0dde
 create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/wrong_value_1000.fail.sh
fe0dde
 create mode 100644 linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/wrong_value_1000_limits_d.fail.sh
fe0dde
fe0dde
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/ansible/shared.yml
fe0dde
index ed3d15331a..f901edee4d 100644
fe0dde
--- a/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/ansible/shared.yml
fe0dde
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/ansible/shared.yml
fe0dde
@@ -3,7 +3,29 @@
fe0dde
 # strategy = restrict
fe0dde
 # complexity = low
fe0dde
 # disruption = low
fe0dde
-- (xccdf-var var_accounts_max_concurrent_login_sessions)
fe0dde
+
fe0dde
+{{{ ansible_instantiate_variables("var_accounts_max_concurrent_login_sessions") }}}
fe0dde
+
fe0dde
+- name: Find /etc/security/limits.d files contains maxlogins configuration
fe0dde
+  shell: "grep -q '^[^#]*\\<maxlogins\\>' /etc/security/limits.d/*.conf"
fe0dde
+  register: maxlogins
fe0dde
+  failed_when: False
fe0dde
+
fe0dde
+- name: Find /etc/security/limits.d files contains maxlogins configuration 2
fe0dde
+  find:
fe0dde
+    paths:
fe0dde
+      - /etc/security/limits.d
fe0dde
+  register: configuration_files
fe0dde
+  when: maxlogins.rc == 0
fe0dde
+
fe0dde
+- name: "Limit the Number of Concurrent Login Sessions Allowed Per User limits.d"
fe0dde
+  replace:
fe0dde
+    dest: "{{ item.path }}"
fe0dde
+    regexp: "^#?\\*.*maxlogins.*"
fe0dde
+    replace: "*          hard    maxlogins     {{ var_accounts_max_concurrent_login_sessions }}"
fe0dde
+  with_items:
fe0dde
+    - "{{ configuration_files.files }}"
fe0dde
+  when: maxlogins.rc == 0
fe0dde
 
fe0dde
 - name: "Limit the Number of Concurrent Login Sessions Allowed Per User"
fe0dde
   lineinfile:
fe0dde
@@ -11,5 +33,6 @@
fe0dde
     dest: /etc/security/limits.conf
fe0dde
     insertbefore: "^# End of file"
fe0dde
     regexp: "^#?\\*.*maxlogins"
fe0dde
-    line: "*           hard    maxlogins     {{ var_accounts_max_concurrent_login_sessions }}"
fe0dde
+    line: "*          hard    maxlogins     {{ var_accounts_max_concurrent_login_sessions }}"
fe0dde
     create: yes
fe0dde
+  when: maxlogins.rc != 0 # no files found on /etc/security/limits.d
fe0dde
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/correct_value.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/correct_value.pass.sh
fe0dde
new file mode 100644
fe0dde
index 0000000000..0edb1e2873
fe0dde
--- /dev/null
fe0dde
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/correct_value.pass.sh
fe0dde
@@ -0,0 +1,2 @@
fe0dde
+#!/bin/bash
fe0dde
+echo "* hard maxlogins 1" >> /etc/security/limits.conf
fe0dde
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/correct_value_2.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/correct_value_2.pass.sh
fe0dde
new file mode 100644
fe0dde
index 0000000000..a58f18abf1
fe0dde
--- /dev/null
fe0dde
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/correct_value_2.pass.sh
fe0dde
@@ -0,0 +1,2 @@
fe0dde
+#!/bin/bash
fe0dde
+echo "* hard maxlogins 1" >> /etc/security/limits.d/limits.conf
fe0dde
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/line_not_there.fail.sh b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/line_not_there.fail.sh
fe0dde
new file mode 100644
fe0dde
index 0000000000..05a7907cf5
fe0dde
--- /dev/null
fe0dde
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/line_not_there.fail.sh
fe0dde
@@ -0,0 +1,2 @@
fe0dde
+#!/bin/bash
fe0dde
+
fe0dde
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/wrong_value_1000.fail.sh b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/wrong_value_1000.fail.sh
fe0dde
new file mode 100644
fe0dde
index 0000000000..bbf7622d87
fe0dde
--- /dev/null
fe0dde
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/wrong_value_1000.fail.sh
fe0dde
@@ -0,0 +1,2 @@
fe0dde
+#!/bin/bash
fe0dde
+echo "* hard maxlogins 1000" >> /etc/security/limits.conf
fe0dde
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/wrong_value_1000_limits_d.fail.sh b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/wrong_value_1000_limits_d.fail.sh
fe0dde
new file mode 100644
fe0dde
index 0000000000..49ed331a3e
fe0dde
--- /dev/null
fe0dde
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/tests/wrong_value_1000_limits_d.fail.sh
fe0dde
@@ -0,0 +1,3 @@
fe0dde
+#!/bin/bash
fe0dde
+mkdir -p /etc/security/limits.d/
fe0dde
+echo "* hard maxlogins 1000" >> /etc/security/limits.d/limits.conf
fe0dde
fe0dde
From c84d31d789675ac2373bc1dec5cb218f15a06ec0 Mon Sep 17 00:00:00 2001
fe0dde
From: Gabriel Becker <ggasparb@redhat.com>
fe0dde
Date: Wed, 9 Sep 2020 14:05:53 +0200
fe0dde
Subject: [PATCH 2/2] Use ansible find module in
fe0dde
 accounts_max_concurrent_login_sessions.
fe0dde
fe0dde
---
fe0dde
 .../ansible/shared.yml                        | 22 +++++++------------
fe0dde
 1 file changed, 8 insertions(+), 14 deletions(-)
fe0dde
fe0dde
diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/ansible/shared.yml
fe0dde
index f901edee4d..9d50a9d20c 100644
fe0dde
--- a/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/ansible/shared.yml
fe0dde
+++ b/linux_os/guide/system/accounts/accounts-session/accounts_max_concurrent_login_sessions/ansible/shared.yml
fe0dde
@@ -6,26 +6,20 @@
fe0dde
 
fe0dde
 {{{ ansible_instantiate_variables("var_accounts_max_concurrent_login_sessions") }}}
fe0dde
 
fe0dde
-- name: Find /etc/security/limits.d files contains maxlogins configuration
fe0dde
-  shell: "grep -q '^[^#]*\\<maxlogins\\>' /etc/security/limits.d/*.conf"
fe0dde
-  register: maxlogins
fe0dde
-  failed_when: False
fe0dde
-
fe0dde
-- name: Find /etc/security/limits.d files contains maxlogins configuration 2
fe0dde
+- name: Find /etc/security/limits.d files containing maxlogins configuration
fe0dde
   find:
fe0dde
-    paths:
fe0dde
-      - /etc/security/limits.d
fe0dde
-  register: configuration_files
fe0dde
-  when: maxlogins.rc == 0
fe0dde
+    paths: "/etc/security/limits.d"
fe0dde
+    contains: '^[\s]*\*[\s]+(?:(?:hard)|(?:-))[\s]+maxlogins'
fe0dde
+    patterns: "*.conf"
fe0dde
+  register: maxlogins
fe0dde
 
fe0dde
-- name: "Limit the Number of Concurrent Login Sessions Allowed Per User limits.d"
fe0dde
+- name: "Limit the Number of Concurrent Login Sessions Allowed Per User in files from limits.d"
fe0dde
   replace:
fe0dde
     dest: "{{ item.path }}"
fe0dde
     regexp: "^#?\\*.*maxlogins.*"
fe0dde
     replace: "*          hard    maxlogins     {{ var_accounts_max_concurrent_login_sessions }}"
fe0dde
   with_items:
fe0dde
-    - "{{ configuration_files.files }}"
fe0dde
-  when: maxlogins.rc == 0
fe0dde
+    - "{{ maxlogins.files }}"
fe0dde
 
fe0dde
 - name: "Limit the Number of Concurrent Login Sessions Allowed Per User"
fe0dde
   lineinfile:
fe0dde
@@ -35,4 +29,4 @@
fe0dde
     regexp: "^#?\\*.*maxlogins"
fe0dde
     line: "*          hard    maxlogins     {{ var_accounts_max_concurrent_login_sessions }}"
fe0dde
     create: yes
fe0dde
-  when: maxlogins.rc != 0 # no files found on /etc/security/limits.d
fe0dde
+  when: maxlogins.matched == 0 # no files found on /etc/security/limits.d matching maxlogins