Blame SOURCES/scap-security-guide-0.1.61-pwquality-PR_8185.patch

07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/ansible/shared.yml
07cb6b
new file mode 100644
07cb6b
index 00000000000..b44c91cbf4a
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/ansible/shared.yml
07cb6b
@@ -0,0 +1,150 @@
07cb6b
+# platform = Red Hat Virtualization 4,multi_platform_fedora,multi_platform_rhel
07cb6b
+# reboot = false
07cb6b
+# strategy = configure
07cb6b
+# complexity = low
07cb6b
+# disruption = medium
07cb6b
+
07cb6b
+- name: Check for existing pam_pwquality.so entry
07cb6b
+  ansible.builtin.lineinfile:
07cb6b
+    path: "/etc/pam.d/password-auth"
07cb6b
+    create: no
07cb6b
+    regexp: '^password.*pam_pwquality.so.*'
07cb6b
+    state: absent
07cb6b
+  check_mode: true
07cb6b
+  changed_when: false
07cb6b
+  register: result_pam_pwquality_present
07cb6b
+
07cb6b
+- name: Check if system relies on authselect
07cb6b
+  ansible.builtin.stat:
07cb6b
+    path: /usr/bin/authselect
07cb6b
+  register: result_authselect_present
07cb6b
+
07cb6b
+- name: "Remediation where authselect tool is present"
07cb6b
+  block:
07cb6b
+    - name: Check the integrity of the current authselect profile
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect check
07cb6b
+      register: result_authselect_check_cmd
07cb6b
+      changed_when: false
07cb6b
+      ignore_errors: true
07cb6b
+
07cb6b
+    - name: Informative message based on the authselect integrity check result
07cb6b
+      ansible.builtin.assert:
07cb6b
+        that:
07cb6b
+          - result_authselect_check_cmd is success
07cb6b
+        fail_msg:
07cb6b
+        - authselect integrity check failed. Remediation aborted!
07cb6b
+        - This remediation could not be applied because the authselect profile is not intact.
07cb6b
+        - It is not recommended to manually edit the PAM files when authselect is available.
07cb6b
+        - In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended.
07cb6b
+        success_msg:
07cb6b
+        - authselect integrity check passed
07cb6b
+
07cb6b
+    - name: Get authselect current profile
07cb6b
+      ansible.builtin.shell:
07cb6b
+        cmd: authselect current -r | awk '{ print $1 }'
07cb6b
+      register: result_authselect_profile
07cb6b
+      changed_when: false
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+
07cb6b
+    - name: Define the current authselect profile as a local fact
07cb6b
+      ansible.builtin.set_fact:
07cb6b
+        authselect_current_profile: "{{ result_authselect_profile.stdout }}"
07cb6b
+        authselect_custom_profile: "{{ result_authselect_profile.stdout }}"
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - result_authselect_profile.stdout is match("custom/")
07cb6b
+
07cb6b
+    - name: Define the new authselect custom profile as a local fact
07cb6b
+      ansible.builtin.set_fact:
07cb6b
+        authselect_current_profile: "{{ result_authselect_profile.stdout }}"
07cb6b
+        authselect_custom_profile: "custom/hardening"
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - result_authselect_profile.stdout is not match("custom/")
07cb6b
+
07cb6b
+    - name: Get authselect current features to also enable them in the custom profile
07cb6b
+      ansible.builtin.shell:
07cb6b
+        cmd: authselect current | tail -n+3 | awk '{ print $2 }'
07cb6b
+      register: result_authselect_features
07cb6b
+      changed_when: false
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+
07cb6b
+    - name: Check if any custom profile with the same name was already created in the past
07cb6b
+      ansible.builtin.stat:
07cb6b
+        path: /etc/authselect/{{ authselect_custom_profile }}
07cb6b
+      register: result_authselect_custom_profile_present
07cb6b
+      changed_when: false
07cb6b
+      when:
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+
07cb6b
+    - name: Create a custom profile based on the current profile
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect create-profile hardening -b sssd
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+        - not result_authselect_custom_profile_present.stat.exists
07cb6b
+
07cb6b
+    - name: Ensure the desired configuration is present in the custom profile
07cb6b
+      ansible.builtin.lineinfile:
07cb6b
+        dest: "/etc/authselect/{{ authselect_custom_profile }}/password-auth"
07cb6b
+        insertbefore: ^password.*sufficient.*pam_unix.so.*
07cb6b
+        line: "password    requisite                                    pam_pwquality.so"
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - result_pam_pwquality_present.found == 0
07cb6b
+
07cb6b
+    - name: Ensure a backup of current authselect profile before selecting the custom profile
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect apply-changes -b --backup=before-pwquality-hardening.backup
07cb6b
+      register: result_authselect_backup
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+        - authselect_custom_profile is not match(authselect_current_profile)
07cb6b
+
07cb6b
+    - name: Ensure the custom profile is selected
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect select {{ authselect_custom_profile }} --force
07cb6b
+      register: result_pam_authselect_select_profile
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+        - authselect_custom_profile is not match(authselect_current_profile)
07cb6b
+
07cb6b
+    - name: Restore the authselect features in the custom profile
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect enable-feature {{ item }}
07cb6b
+      loop: "{{ result_authselect_features.stdout_lines }}"
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - result_authselect_features is not skipped
07cb6b
+        - result_pam_authselect_select_profile is not skipped
07cb6b
+
07cb6b
+    - name: Ensure the custom profile changes are applied
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect apply-changes -b --backup=after-pwquality-hardening.backup
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+  when:
07cb6b
+  - result_authselect_present.stat.exists
07cb6b
+
07cb6b
+# For systems without authselect
07cb6b
+- name: "Remediation where authselect tool is not present and PAM files are directly edited"
07cb6b
+  block:
07cb6b
+    - name: Ensure the desired configuration is present in the custom profile
07cb6b
+      ansible.builtin.lineinfile:
07cb6b
+        dest: "/etc/pam.d/password-auth"
07cb6b
+        insertbefore: ^password.*sufficient.*pam_unix.so.*
07cb6b
+        line: "password    requisite                                    pam_pwquality.so"
07cb6b
+      when:
07cb6b
+        - result_pam_pwquality_present.found == 0
07cb6b
+  when:
07cb6b
+    - not result_authselect_present.stat.exists
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/bash/shared.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/bash/shared.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..d2fca2a79ca
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/bash/shared.sh
07cb6b
@@ -0,0 +1,41 @@
07cb6b
+# platform = Red Hat Virtualization 4,multi_platform_fedora,multi_platform_rhel
07cb6b
+
07cb6b
+PAM_FILE="password-auth"
07cb6b
+
07cb6b
+if [ -f /usr/bin/authselect ]; then
07cb6b
+    if authselect check; then
07cb6b
+        CURRENT_PROFILE=$(authselect current -r | awk '{ print $1 }')
07cb6b
+        # Standard profiles delivered with authselect should not be modified.
07cb6b
+        # If not already in use, a custom profile is created preserving the enabled features.
07cb6b
+        if [[ ! $CURRENT_PROFILE == custom/* ]]; then
07cb6b
+            ENABLED_FEATURES=$(authselect current | tail -n+3 | awk '{ print $2 }')
07cb6b
+            authselect create-profile hardening -b $CURRENT_PROFILE
07cb6b
+            CURRENT_PROFILE="custom/hardening"
07cb6b
+            # Ensure a backup before changing the profile
07cb6b
+            authselect apply-changes -b --backup=before-pwquality-hardening.backup
07cb6b
+            authselect select $CURRENT_PROFILE
07cb6b
+            for feature in $ENABLED_FEATURES; do
07cb6b
+                authselect enable-feature $feature;
07cb6b
+            done
07cb6b
+        fi
07cb6b
+        # Include the desired configuration in the custom profile
07cb6b
+        CUSTOM_FILE="/etc/authselect/$CURRENT_PROFILE/$PAM_FILE"
07cb6b
+        # The line should be included on the top password section
07cb6b
+		if [ $(grep -c "^\s*password.*requisite.*pam_pwquality.so" $CUSTOM_FILE) -eq 0 ]; then
07cb6b
+  		  sed -i --follow-symlinks '0,/^password.*/s/^password.*/password    requisite                                    pam_pwquality.so\n&/' $CUSTOM_FILE
07cb6b
+		fi
07cb6b
+        authselect apply-changes -b --backup=after-pwquality-hardening.backup
07cb6b
+    else
07cb6b
+        echo "
07cb6b
+authselect integrity check failed. Remediation aborted!
07cb6b
+This remediation could not be applied because the authselect profile is not intact.
07cb6b
+It is not recommended to manually edit the PAM files when authselect is available.
07cb6b
+In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended."
07cb6b
+        false
07cb6b
+    fi
07cb6b
+else
07cb6b
+    FILE_PATH="/etc/pam.d/$PAM_FILE"
07cb6b
+    if [ $(grep -c "^\s*password.*requisite.*pam_pwquality.so" $FILE_PATH) -eq 0 ]; then
07cb6b
+        sed -i --follow-symlinks '0,/^password.*/s/^password.*/password    requisite                                    pam_pwquality.so\n&/' $FILE_PATH
07cb6b
+    fi
07cb6b
+fi
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/oval/shared.xml b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/oval/shared.xml
07cb6b
new file mode 100644
07cb6b
index 00000000000..84f32456beb
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/oval/shared.xml
07cb6b
@@ -0,0 +1,21 @@
07cb6b
+<def-group>
07cb6b
+  <definition class="compliance" id="{{{ rule_id }}}" version="1">
07cb6b
+    {{{ oval_metadata("The PAM module pam_pwquality is used in password-auth") }}}
07cb6b
+    <criteria comment="Condition for pam_pwquality in password-auth is satisfied">
07cb6b
+      
07cb6b
+                 test_ref="test_accounts_password_pam_pwquality_password_auth"/>
07cb6b
+      </criteria>
07cb6b
+  </definition>
07cb6b
+
07cb6b
+  <ind:textfilecontent54_object id="object_accounts_password_pam_pwquality_password_auth" version="1">
07cb6b
+    <ind:filepath>/etc/pam.d/password-auth</ind:filepath>
07cb6b
+    <ind:pattern operation="pattern match">^password[\s]*requisite[\s]*pam_pwquality\.so</ind:pattern>
07cb6b
+    <ind:instance datatype="int" operation="equals">1</ind:instance>
07cb6b
+  </ind:textfilecontent54_object>
07cb6b
+
07cb6b
+  
07cb6b
+                              id="test_accounts_password_pam_pwquality_password_auth"
07cb6b
+                              comment="check the configuration of /etc/pam.d/password-auth">
07cb6b
+    <ind:object object_ref="object_accounts_password_pam_pwquality_password_auth"/>
07cb6b
+  </ind:textfilecontent54_test>
07cb6b
+</def-group>
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/rule.yml b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/rule.yml
07cb6b
new file mode 100644
07cb6b
index 00000000000..6c7bb1ad7a0
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/rule.yml
07cb6b
@@ -0,0 +1,35 @@
07cb6b
+documentation_complete: true
07cb6b
+
07cb6b
+prodtype: fedora,rhel7,rhel8,rhel9,rhv4
07cb6b
+
07cb6b
+title: 'Ensure PAM password complexity module is enabled in password-auth'
07cb6b
+
07cb6b
+description: |-
07cb6b
+    To enable PAM password complexity in password-auth file:
07cb6b
+    Edit the <tt>password</tt> section in
07cb6b
+    <tt>/etc/pam.d/password-auth</tt> to show
07cb6b
+    <tt>password    requisite                                    pam_pwquality.so</tt>.
07cb6b
+
07cb6b
+rationale: |-
07cb6b
+    Enabling PAM password complexity permits to enforce strong passwords and consequently
07cb6b
+    makes the system less prone to dictionary attacks.
07cb6b
+
07cb6b
+severity: medium
07cb6b
+
07cb6b
+identifiers:
07cb6b
+    cce@rhel7: CCE-85876-1
07cb6b
+    cce@rhel8: CCE-85877-9
07cb6b
+    cce@rhel9: CCE-85878-7
07cb6b
+
07cb6b
+references:
07cb6b
+    stigid@rhel8: RHEL-08-020100
07cb6b
+
07cb6b
+ocil_clause: 'pam_pwquality.so is not enabled in password-auth'
07cb6b
+
07cb6b
+ocil: |-
07cb6b
+    To check if pam_pwhistory.so is enabled in password-auth, run the following command:
07cb6b
+    
$ grep pam_pwquality /etc/pam.d/password-auth
07cb6b
+    The output should be similar to the following:
07cb6b
+    
password    requisite                                    pam_pwquality.so
07cb6b
+
07cb6b
+platform: pam
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_commented_entry.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_commented_entry.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..3d696c36b76
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_commented_entry.fail.sh
07cb6b
@@ -0,0 +1,11 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = authselect
07cb6b
+# platform = Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9,multi_platform_fedora
07cb6b
+
07cb6b
+authselect create-profile hardening -b sssd
07cb6b
+CUSTOM_PROFILE="custom/hardening"
07cb6b
+authselect select $CUSTOM_PROFILE --force
07cb6b
+
07cb6b
+CUSTOM_SYSTEM_AUTH="/etc/authselect/$CUSTOM_PROFILE/password-auth"
07cb6b
+sed -i --follow-symlinks -e '/^password\s*requisite\s*pam_pwquality\.so/ s/^#*/#/g' $CUSTOM_SYSTEM_AUTH
07cb6b
+authselect apply-changes -b
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_correct_entry.pass.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_correct_entry.pass.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..0435899262b
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_correct_entry.pass.sh
07cb6b
@@ -0,0 +1,13 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = authselect
07cb6b
+# platform = Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9,multi_platform_fedora
07cb6b
+
07cb6b
+authselect create-profile hardening -b sssd
07cb6b
+CUSTOM_PROFILE="custom/hardening"
07cb6b
+authselect select $CUSTOM_PROFILE --force
07cb6b
+
07cb6b
+CUSTOM_SYSTEM_AUTH="/etc/authselect/$CUSTOM_PROFILE/password-auth"
07cb6b
+if [ $(grep -c "^\s*password.*requisite.*pam_pwquality.so" $CUSTOM_SYSTEM_AUTH) -eq 0 ]; then
07cb6b
+    sed -i --follow-symlinks '0,/^password.*/s/^password.*/password     requisite   pam_pwquality.so\n&/' $CUSTOM_SYSTEM_AUTH
07cb6b
+fi
07cb6b
+authselect apply-changes -b
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_missing_entry.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_missing_entry.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..472616a51f6
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_missing_entry.fail.sh
07cb6b
@@ -0,0 +1,11 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = authselect
07cb6b
+# platform = Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9,multi_platform_fedora
07cb6b
+
07cb6b
+authselect create-profile hardening -b sssd
07cb6b
+CUSTOM_PROFILE="custom/hardening"
07cb6b
+authselect select $CUSTOM_PROFILE --force
07cb6b
+
07cb6b
+CUSTOM_SYSTEM_AUTH="/etc/authselect/$CUSTOM_PROFILE/password-auth"
07cb6b
+sed -i --follow-symlinks '/^password\s*requisite\s*pam_pwquality\.so/d' $CUSTOM_SYSTEM_AUTH
07cb6b
+authselect apply-changes -b
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_modified_pam.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_modified_pam.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..59f9d6f77c4
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/authselect_modified_pam.fail.sh
07cb6b
@@ -0,0 +1,9 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = authselect
07cb6b
+# platform = Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9,multi_platform_fedora
07cb6b
+# remediation = none
07cb6b
+
07cb6b
+SYSTEM_AUTH_FILE="/etc/pam.d/password-auth"
07cb6b
+
07cb6b
+# This modification will break the integrity checks done by authselect.
07cb6b
+sed -i --follow-symlinks -e '/^password\s*requisite\s*pam_pwquality\.so/ s/^#*/#/g' $SYSTEM_AUTH_FILE
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/correct_entry.pass.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/correct_entry.pass.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..71f87b19045
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/correct_entry.pass.sh
07cb6b
@@ -0,0 +1,8 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = pam
07cb6b
+# platform = Red Hat Enterprise Linux 7,Red Hat Virtualization 4,multi_platform_fedora
07cb6b
+
07cb6b
+config_file=/etc/pam.d/password-auth
07cb6b
+if [ $(grep -c "^\s*password.*requisite.*pam_pwquality.so" $config_file) -eq 0 ]; then
07cb6b
+    sed -i --follow-symlinks '0,/^password.*/s/^password.*/password		requisite	pam_pwquality.so\n&/' $config_file
07cb6b
+fi
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/missing_entry.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/missing_entry.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..95b73b24d26
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_password_auth/tests/missing_entry.fail.sh
07cb6b
@@ -0,0 +1,7 @@
07cb6b
+#!/bin/bash
07cb6b
+# platform = Red Hat Enterprise Linux 7,Red Hat Virtualization 4,multi_platform_fedora
07cb6b
+# packages = pam
07cb6b
+
07cb6b
+config_file=/etc/pam.d/password-auth
07cb6b
+
07cb6b
+sed -i --follow-symlinks '/^password\s*requisite\s*pam_pwquality\.so/d' $config_file
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/ansible/shared.yml b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/ansible/shared.yml
07cb6b
new file mode 100644
07cb6b
index 00000000000..13cd20458ed
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/ansible/shared.yml
07cb6b
@@ -0,0 +1,150 @@
07cb6b
+# platform = Red Hat Virtualization 4,multi_platform_fedora,multi_platform_rhel
07cb6b
+# reboot = false
07cb6b
+# strategy = configure
07cb6b
+# complexity = low
07cb6b
+# disruption = medium
07cb6b
+
07cb6b
+- name: Check for existing pam_pwquality.so entry
07cb6b
+  ansible.builtin.lineinfile:
07cb6b
+    path: "/etc/pam.d/system-auth"
07cb6b
+    create: no
07cb6b
+    regexp: '^password.*pam_pwquality.so.*'
07cb6b
+    state: absent
07cb6b
+  check_mode: true
07cb6b
+  changed_when: false
07cb6b
+  register: result_pam_pwquality_present
07cb6b
+
07cb6b
+- name: Check if system relies on authselect
07cb6b
+  ansible.builtin.stat:
07cb6b
+    path: /usr/bin/authselect
07cb6b
+  register: result_authselect_present
07cb6b
+
07cb6b
+- name: "Remediation where authselect tool is present"
07cb6b
+  block:
07cb6b
+    - name: Check the integrity of the current authselect profile
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect check
07cb6b
+      register: result_authselect_check_cmd
07cb6b
+      changed_when: false
07cb6b
+      ignore_errors: true
07cb6b
+
07cb6b
+    - name: Informative message based on the authselect integrity check result
07cb6b
+      ansible.builtin.assert:
07cb6b
+        that:
07cb6b
+          - result_authselect_check_cmd is success
07cb6b
+        fail_msg:
07cb6b
+        - authselect integrity check failed. Remediation aborted!
07cb6b
+        - This remediation could not be applied because the authselect profile is not intact.
07cb6b
+        - It is not recommended to manually edit the PAM files when authselect is available.
07cb6b
+        - In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended.
07cb6b
+        success_msg:
07cb6b
+        - authselect integrity check passed
07cb6b
+
07cb6b
+    - name: Get authselect current profile
07cb6b
+      ansible.builtin.shell:
07cb6b
+        cmd: authselect current -r | awk '{ print $1 }'
07cb6b
+      register: result_authselect_profile
07cb6b
+      changed_when: false
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+
07cb6b
+    - name: Define the current authselect profile as a local fact
07cb6b
+      ansible.builtin.set_fact:
07cb6b
+        authselect_current_profile: "{{ result_authselect_profile.stdout }}"
07cb6b
+        authselect_custom_profile: "{{ result_authselect_profile.stdout }}"
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - result_authselect_profile.stdout is match("custom/")
07cb6b
+
07cb6b
+    - name: Define the new authselect custom profile as a local fact
07cb6b
+      ansible.builtin.set_fact:
07cb6b
+        authselect_current_profile: "{{ result_authselect_profile.stdout }}"
07cb6b
+        authselect_custom_profile: "custom/hardening"
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - result_authselect_profile.stdout is not match("custom/")
07cb6b
+
07cb6b
+    - name: Get authselect current features to also enable them in the custom profile
07cb6b
+      ansible.builtin.shell:
07cb6b
+        cmd: authselect current | tail -n+3 | awk '{ print $2 }'
07cb6b
+      register: result_authselect_features
07cb6b
+      changed_when: false
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+
07cb6b
+    - name: Check if any custom profile with the same name was already created in the past
07cb6b
+      ansible.builtin.stat:
07cb6b
+        path: /etc/authselect/{{ authselect_custom_profile }}
07cb6b
+      register: result_authselect_custom_profile_present
07cb6b
+      changed_when: false
07cb6b
+      when:
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+
07cb6b
+    - name: Create a custom profile based on the current profile
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect create-profile hardening -b sssd
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+        - not result_authselect_custom_profile_present.stat.exists
07cb6b
+
07cb6b
+    - name: Ensure the desired configuration is present in the custom profile
07cb6b
+      ansible.builtin.lineinfile:
07cb6b
+        dest: "/etc/authselect/{{ authselect_custom_profile }}/system-auth"
07cb6b
+        insertbefore: ^password.*sufficient.*pam_unix.so.*
07cb6b
+        line: "password    requisite                                    pam_pwquality.so"
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - result_pam_pwquality_present.found == 0
07cb6b
+
07cb6b
+    - name: Ensure a backup of current authselect profile before selecting the custom profile
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect apply-changes -b --backup=before-pwquality-hardening.backup
07cb6b
+      register: result_authselect_backup
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+        - authselect_custom_profile is not match(authselect_current_profile)
07cb6b
+
07cb6b
+    - name: Ensure the custom profile is selected
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect select {{ authselect_custom_profile }} --force
07cb6b
+      register: result_pam_authselect_select_profile
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - authselect_current_profile is not match("custom/")
07cb6b
+        - authselect_custom_profile is not match(authselect_current_profile)
07cb6b
+
07cb6b
+    - name: Restore the authselect features in the custom profile
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect enable-feature {{ item }}
07cb6b
+      loop: "{{ result_authselect_features.stdout_lines }}"
07cb6b
+      when:
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+        - result_authselect_features is not skipped
07cb6b
+        - result_pam_authselect_select_profile is not skipped
07cb6b
+
07cb6b
+    - name: Ensure the custom profile changes are applied
07cb6b
+      ansible.builtin.command:
07cb6b
+        cmd: authselect apply-changes -b --backup=after-pwquality-hardening.backup
07cb6b
+      when:
07cb6b
+        - result_authselect_check_cmd is success
07cb6b
+        - result_authselect_profile is not skipped
07cb6b
+  when:
07cb6b
+  - result_authselect_present.stat.exists
07cb6b
+
07cb6b
+# For systems without authselect
07cb6b
+- name: "Remediation where authselect tool is not present and PAM files are directly edited"
07cb6b
+  block:
07cb6b
+    - name: Ensure the desired configuration is present in the custom profile
07cb6b
+      ansible.builtin.lineinfile:
07cb6b
+        dest: "/etc/pam.d/system-auth"
07cb6b
+        insertbefore: ^password.*sufficient.*pam_unix.so.*
07cb6b
+        line: "password    requisite                                    pam_pwquality.so"
07cb6b
+      when:
07cb6b
+        - result_pam_pwquality_present.found == 0
07cb6b
+  when:
07cb6b
+    - not result_authselect_present.stat.exists
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/bash/shared.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/bash/shared.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..9a7972a3f93
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/bash/shared.sh
07cb6b
@@ -0,0 +1,41 @@
07cb6b
+# platform = Red Hat Virtualization 4,multi_platform_fedora,multi_platform_rhel
07cb6b
+
07cb6b
+PAM_FILE="system-auth"
07cb6b
+
07cb6b
+if [ -f /usr/bin/authselect ]; then
07cb6b
+    if authselect check; then
07cb6b
+        CURRENT_PROFILE=$(authselect current -r | awk '{ print $1 }')
07cb6b
+        # Standard profiles delivered with authselect should not be modified.
07cb6b
+        # If not already in use, a custom profile is created preserving the enabled features.
07cb6b
+        if [[ ! $CURRENT_PROFILE == custom/* ]]; then
07cb6b
+            ENABLED_FEATURES=$(authselect current | tail -n+3 | awk '{ print $2 }')
07cb6b
+            authselect create-profile hardening -b $CURRENT_PROFILE
07cb6b
+            CURRENT_PROFILE="custom/hardening"
07cb6b
+            # Ensure a backup before changing the profile
07cb6b
+            authselect apply-changes -b --backup=before-pwquality-hardening.backup
07cb6b
+            authselect select $CURRENT_PROFILE
07cb6b
+            for feature in $ENABLED_FEATURES; do
07cb6b
+                authselect enable-feature $feature;
07cb6b
+            done
07cb6b
+        fi
07cb6b
+        # Include the desired configuration in the custom profile
07cb6b
+        CUSTOM_FILE="/etc/authselect/$CURRENT_PROFILE/$PAM_FILE"
07cb6b
+        # The line should be included on the top password section
07cb6b
+		if [ $(grep -c "^\s*password.*requisite.*pam_pwquality.so" $CUSTOM_FILE) -eq 0 ]; then
07cb6b
+  		  sed -i --follow-symlinks '0,/^password.*/s/^password.*/password    requisite                                    pam_pwquality.so\n&/' $CUSTOM_FILE
07cb6b
+		fi
07cb6b
+        authselect apply-changes -b --backup=after-pwquality-hardening.backup
07cb6b
+    else
07cb6b
+        echo "
07cb6b
+authselect integrity check failed. Remediation aborted!
07cb6b
+This remediation could not be applied because the authselect profile is not intact.
07cb6b
+It is not recommended to manually edit the PAM files when authselect is available.
07cb6b
+In cases where the default authselect profile does not cover a specific demand, a custom authselect profile is recommended."
07cb6b
+        false
07cb6b
+    fi
07cb6b
+else
07cb6b
+    FILE_PATH="/etc/pam.d/$PAM_FILE"
07cb6b
+    if [ $(grep -c "^\s*password.*requisite.*pam_pwquality.so" $FILE_PATH) -eq 0 ]; then
07cb6b
+        sed -i --follow-symlinks '0,/^password.*/s/^password.*/password    requisite                                    pam_pwquality.so\n&/' $FILE_PATH
07cb6b
+    fi
07cb6b
+fi
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/oval/shared.xml b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/oval/shared.xml
07cb6b
new file mode 100644
07cb6b
index 00000000000..f8d241f1ff2
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/oval/shared.xml
07cb6b
@@ -0,0 +1,21 @@
07cb6b
+<def-group>
07cb6b
+  <definition class="compliance" id="{{{ rule_id }}}" version="1">
07cb6b
+    {{{ oval_metadata("The PAM module pam_pwquality is used in system-auth") }}}
07cb6b
+    <criteria comment="Condition for pam_pwquality in system-auth is satisfied">
07cb6b
+      
07cb6b
+                 test_ref="test_accounts_password_pam_pwquality_system_auth"/>
07cb6b
+      </criteria>
07cb6b
+  </definition>
07cb6b
+
07cb6b
+  <ind:textfilecontent54_object id="object_accounts_password_pam_pwquality_system_auth" version="1">
07cb6b
+    <ind:filepath>/etc/pam.d/system-auth</ind:filepath>
07cb6b
+    <ind:pattern operation="pattern match">^password[\s]*requisite[\s]*pam_pwquality\.so</ind:pattern>
07cb6b
+    <ind:instance datatype="int" operation="equals">1</ind:instance>
07cb6b
+  </ind:textfilecontent54_object>
07cb6b
+
07cb6b
+  
07cb6b
+                              id="test_accounts_password_pam_pwquality_system_auth"
07cb6b
+                              comment="check the configuration of /etc/pam.d/system-auth">
07cb6b
+    <ind:object object_ref="object_accounts_password_pam_pwquality_system_auth"/>
07cb6b
+  </ind:textfilecontent54_test>
07cb6b
+</def-group>
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/rule.yml b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/rule.yml
07cb6b
new file mode 100644
07cb6b
index 00000000000..ea42ff9b07a
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/rule.yml
07cb6b
@@ -0,0 +1,35 @@
07cb6b
+documentation_complete: true
07cb6b
+
07cb6b
+prodtype: fedora,rhel7,rhel8,rhel9,rhv4
07cb6b
+
07cb6b
+title: 'Ensure PAM password complexity module is enabled in system-auth'
07cb6b
+
07cb6b
+description: |-
07cb6b
+    To enable PAM password complexity in system-auth file:
07cb6b
+    Edit the <tt>password</tt> section in
07cb6b
+    <tt>/etc/pam.d/system-auth</tt> to show
07cb6b
+    <tt>password    requisite                                    pam_pwquality.so</tt>.
07cb6b
+
07cb6b
+rationale: |-
07cb6b
+    Enabling PAM password complexity permits to enforce strong passwords and consequently
07cb6b
+    makes the system less prone to dictionary attacks.
07cb6b
+
07cb6b
+severity: medium
07cb6b
+
07cb6b
+identifiers:
07cb6b
+    cce@rhel7: CCE-85874-6
07cb6b
+    cce@rhel8: CCE-85872-0
07cb6b
+    cce@rhel9: CCE-85873-8
07cb6b
+
07cb6b
+references:
07cb6b
+    stigid@rhel8: RHEL-08-020101
07cb6b
+
07cb6b
+ocil_clause: 'pam_pwquality.so is not enabled in system-auth'
07cb6b
+
07cb6b
+ocil: |-
07cb6b
+    To check if pam_pwhistory.so is enabled in system-auth, run the following command:
07cb6b
+    
$ grep pam_pwquality /etc/pam.d/system-auth
07cb6b
+    The output should be similar to the following:
07cb6b
+    
password    requisite                                    pam_pwquality.so
07cb6b
+
07cb6b
+platform: pam
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_commented_entry.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_commented_entry.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..849f16d0f93
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_commented_entry.fail.sh
07cb6b
@@ -0,0 +1,11 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = authselect
07cb6b
+# platform = Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9,multi_platform_fedora
07cb6b
+
07cb6b
+authselect create-profile hardening -b sssd
07cb6b
+CUSTOM_PROFILE="custom/hardening"
07cb6b
+authselect select $CUSTOM_PROFILE --force
07cb6b
+
07cb6b
+CUSTOM_SYSTEM_AUTH="/etc/authselect/$CUSTOM_PROFILE/system-auth"
07cb6b
+sed -i --follow-symlinks -e '/^password\s*requisite\s*pam_pwquality\.so/ s/^#*/#/g' $CUSTOM_SYSTEM_AUTH
07cb6b
+authselect apply-changes -b
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_correct_entry.pass.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_correct_entry.pass.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..6a98c244980
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_correct_entry.pass.sh
07cb6b
@@ -0,0 +1,13 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = authselect
07cb6b
+# platform = Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9,multi_platform_fedora
07cb6b
+
07cb6b
+authselect create-profile hardening -b sssd
07cb6b
+CUSTOM_PROFILE="custom/hardening"
07cb6b
+authselect select $CUSTOM_PROFILE --force
07cb6b
+
07cb6b
+CUSTOM_SYSTEM_AUTH="/etc/authselect/$CUSTOM_PROFILE/system-auth"
07cb6b
+if [ $(grep -c "^\s*password.*requisite.*pam_pwquality.so" $CUSTOM_SYSTEM_AUTH) -eq 0 ]; then
07cb6b
+    sed -i --follow-symlinks '0,/^password.*/s/^password.*/password     requisite   pam_pwquality.so\n&/' $CUSTOM_SYSTEM_AUTH
07cb6b
+fi
07cb6b
+authselect apply-changes -b
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_missing_entry.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_missing_entry.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..6786f6c13d7
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_missing_entry.fail.sh
07cb6b
@@ -0,0 +1,11 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = authselect
07cb6b
+# platform = Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9,multi_platform_fedora
07cb6b
+
07cb6b
+authselect create-profile hardening -b sssd
07cb6b
+CUSTOM_PROFILE="custom/hardening"
07cb6b
+authselect select $CUSTOM_PROFILE --force
07cb6b
+
07cb6b
+CUSTOM_SYSTEM_AUTH="/etc/authselect/$CUSTOM_PROFILE/system-auth"
07cb6b
+sed -i --follow-symlinks '/^password\s*requisite\s*pam_pwquality\.so/d' $CUSTOM_SYSTEM_AUTH
07cb6b
+authselect apply-changes -b
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_modified_pam.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_modified_pam.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..b3d9e5884f5
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/authselect_modified_pam.fail.sh
07cb6b
@@ -0,0 +1,9 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = authselect
07cb6b
+# platform = Red Hat Enterprise Linux 8,Red Hat Enterprise Linux 9,multi_platform_fedora
07cb6b
+# remediation = none
07cb6b
+
07cb6b
+SYSTEM_AUTH_FILE="/etc/pam.d/system-auth"
07cb6b
+
07cb6b
+# This modification will break the integrity checks done by authselect.
07cb6b
+sed -i --follow-symlinks -e '/^password\s*requisite\s*pam_pwquality\.so/ s/^#*/#/g' $SYSTEM_AUTH_FILE
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/correct_entry.pass.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/correct_entry.pass.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..71f87b19045
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/correct_entry.pass.sh
07cb6b
@@ -0,0 +1,8 @@
07cb6b
+#!/bin/bash
07cb6b
+# packages = pam
07cb6b
+# platform = Red Hat Enterprise Linux 7,Red Hat Virtualization 4,multi_platform_fedora
07cb6b
+
07cb6b
+config_file=/etc/pam.d/password-auth
07cb6b
+if [ $(grep -c "^\s*password.*requisite.*pam_pwquality.so" $config_file) -eq 0 ]; then
07cb6b
+    sed -i --follow-symlinks '0,/^password.*/s/^password.*/password		requisite	pam_pwquality.so\n&/' $config_file
07cb6b
+fi
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/missing_entry.fail.sh b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/missing_entry.fail.sh
07cb6b
new file mode 100644
07cb6b
index 00000000000..3c8f6f79fe9
07cb6b
--- /dev/null
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_pwquality_system_auth/tests/missing_entry.fail.sh
07cb6b
@@ -0,0 +1,7 @@
07cb6b
+#!/bin/bash
07cb6b
+# platform = Red Hat Enterprise Linux 7,Red Hat Virtualization 4,multi_platform_fedora
07cb6b
+# packages = pam
07cb6b
+
07cb6b
+config_file=/etc/pam.d/system-auth
07cb6b
+
07cb6b
+sed -i --follow-symlinks '/^password\s*requisite\s*pam_pwquality\.so/d' $config_file
07cb6b
diff --git a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_retry/rule.yml b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_retry/rule.yml
07cb6b
index eeb55a6ff5c..6b2219a3eab 100644
07cb6b
--- a/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_retry/rule.yml
07cb6b
+++ b/linux_os/guide/system/accounts/accounts-pam/password_quality/password_quality_pwquality/accounts_password_pam_retry/rule.yml
07cb6b
@@ -6,13 +6,16 @@ title: 'Ensure PAM Enforces Password Requirements - Authentication Retry Prompts
07cb6b
 
07cb6b
 description: |-
07cb6b
     To configure the number of retry prompts that are permitted per-session:
07cb6b
+    {{% if product in ['rhel8', 'rhel9'] %}}
07cb6b
+    Edit the <tt>/etc/security/pwquality.conf</tt> to include
07cb6b
+    {{% else %}}
07cb6b
     Edit the <tt>pam_pwquality.so</tt> statement in
07cb6b
     {{% if 'ubuntu' not in product %}}
07cb6b
-    <tt>/etc/pam.d/system-auth</tt> {{% if product in ['rhel8', 'rhel9'] %}} and
07cb6b
-    <tt>/etc/pam.d/password-auth</tt> {{% endif %}} to show
07cb6b
+    <tt>/etc/pam.d/system-auth</tt> to show
07cb6b
     {{% else %}}
07cb6b
     <tt>/etc/pam.d/common-password</tt> to show
07cb6b
     {{% endif %}}
07cb6b
+    {{% endif %}}
07cb6b
     <tt>retry={{{xccdf_value("var_password_pam_retry") }}}</tt>, or a lower value if site
07cb6b
     policy is more restrictive. The DoD requirement is a maximum of 3 prompts
07cb6b
     per session.
07cb6b
@@ -48,17 +51,21 @@ references:
07cb6b
     stigid@ol7: OL07-00-010119
07cb6b
     stigid@ol8: OL08-00-020100
07cb6b
     stigid@rhel7: RHEL-07-010119
07cb6b
-    stigid@rhel8: RHEL-08-020100
07cb6b
+    stigid@rhel8: RHEL-08-020104
07cb6b
     stigid@ubuntu2004: UBTU-20-010057
07cb6b
 
07cb6b
 ocil_clause: 'it is not the required value'
07cb6b
 
07cb6b
 ocil: |-
07cb6b
     To check how many retry attempts are permitted on a per-session basis, run the following command:
07cb6b
+    {{% if product in ['rhel8', 'rhel9'] %}}
07cb6b
+    
$ grep retry /etc/security/pwquality.conf
07cb6b
+    {{% else %}}
07cb6b
     {{% if 'ubuntu' in product %}}
07cb6b
     
$ grep pam_pwquality /etc/pam.d/common-password
07cb6b
     {{% else %}}
07cb6b
-    
$ grep pam_pwquality /etc/pam.d/system-auth {{% if product in ['rhel8', 'rhel9'] %}}/etc/pam.d/password-auth{{% endif %}}
07cb6b
+    
$ grep pam_pwquality /etc/pam.d/system-auth
07cb6b
+    {{% endif %}}
07cb6b
     {{% endif %}}
07cb6b
     The <tt>retry</tt> parameter will indicate how many attempts are permitted.
07cb6b
     The DoD required value is less than or equal to 3.
07cb6b
diff --git a/products/rhel8/profiles/stig.profile b/products/rhel8/profiles/stig.profile
07cb6b
index d92bc72971c..62fc512f05e 100644
07cb6b
--- a/products/rhel8/profiles/stig.profile
07cb6b
+++ b/products/rhel8/profiles/stig.profile
07cb6b
@@ -523,6 +523,20 @@ selections:
07cb6b
     - sssd_enable_certmap
07cb6b
 
07cb6b
     # RHEL-08-020100
07cb6b
+    - accounts_password_pam_pwquality_password_auth
07cb6b
+
07cb6b
+    # RHEL-08-020101
07cb6b
+    - accounts_password_pam_pwquality_system_auth
07cb6b
+
07cb6b
+    # RHEL-08-020102
07cb6b
+    # This is only required for RHEL8 systems below version 8.4 where the
07cb6b
+    # retry parameter was not yet available on /etc/security/pwquality.conf.
07cb6b
+
07cb6b
+    # RHEL-08-020103
07cb6b
+    # This is only required for RHEL8 systems below version 8.4 where the
07cb6b
+    # retry parameter was not yet available on /etc/security/pwquality.conf.
07cb6b
+
07cb6b
+    # RHEL-08-020104
07cb6b
     - accounts_password_pam_retry
07cb6b
 
07cb6b
     # RHEL-08-020110
07cb6b
diff --git a/products/rhel9/profiles/stig.profile b/products/rhel9/profiles/stig.profile
07cb6b
index 42c6d0e9aca..ad08a6d3410 100644
07cb6b
--- a/products/rhel9/profiles/stig.profile
07cb6b
+++ b/products/rhel9/profiles/stig.profile
07cb6b
@@ -524,6 +524,20 @@ selections:
07cb6b
     - sssd_enable_certmap
07cb6b
 
07cb6b
     # RHEL-08-020100
07cb6b
+    - accounts_password_pam_pwquality_password_auth
07cb6b
+
07cb6b
+    # RHEL-08-020101
07cb6b
+    - accounts_password_pam_pwquality_system_auth
07cb6b
+
07cb6b
+    # RHEL-08-020102
07cb6b
+    # This is only required for RHEL8 systems below version 8.4 where the
07cb6b
+    # retry parameter was not yet available on /etc/security/pwquality.conf.
07cb6b
+
07cb6b
+    # RHEL-08-020103
07cb6b
+    # This is only required for RHEL8 systems below version 8.4 where the
07cb6b
+    # retry parameter was not yet available on /etc/security/pwquality.conf.
07cb6b
+
07cb6b
+    # RHEL-08-020104
07cb6b
     - accounts_password_pam_retry
07cb6b
 
07cb6b
     # RHEL-08-020110
07cb6b
diff --git a/tests/data/profile_stability/rhel8/stig.profile b/tests/data/profile_stability/rhel8/stig.profile
07cb6b
index e4fee44f9f9..33e82401c3d 100644
07cb6b
--- a/tests/data/profile_stability/rhel8/stig.profile
07cb6b
+++ b/tests/data/profile_stability/rhel8/stig.profile
07cb6b
@@ -53,6 +53,8 @@ selections:
07cb6b
 - accounts_password_pam_ocredit
07cb6b
 - accounts_password_pam_pwhistory_remember_password_auth
07cb6b
 - accounts_password_pam_pwhistory_remember_system_auth
07cb6b
+- accounts_password_pam_pwquality_password_auth
07cb6b
+- accounts_password_pam_pwquality_system_auth
07cb6b
 - accounts_password_pam_retry
07cb6b
 - accounts_password_pam_ucredit
07cb6b
 - accounts_password_pam_unix_rounds_password_auth
07cb6b
diff --git a/tests/data/profile_stability/rhel8/stig_gui.profile b/tests/data/profile_stability/rhel8/stig_gui.profile
07cb6b
index 83d04775e3a..5beeb4f28af 100644
07cb6b
--- a/tests/data/profile_stability/rhel8/stig_gui.profile
07cb6b
+++ b/tests/data/profile_stability/rhel8/stig_gui.profile
07cb6b
@@ -64,6 +64,8 @@ selections:
07cb6b
 - accounts_password_pam_ocredit
07cb6b
 - accounts_password_pam_pwhistory_remember_password_auth
07cb6b
 - accounts_password_pam_pwhistory_remember_system_auth
07cb6b
+- accounts_password_pam_pwquality_password_auth
07cb6b
+- accounts_password_pam_pwquality_system_auth
07cb6b
 - accounts_password_pam_retry
07cb6b
 - accounts_password_pam_ucredit
07cb6b
 - accounts_password_pam_unix_rounds_password_auth