Skip to content

Commit

Permalink
Merge pull request #12726 from alanmcanonical/ubt24_5324
Browse files Browse the repository at this point in the history
Ubuntu 24.04: Implement 5.3.2.4 Ensure pam_pwhistory module is enabled
  • Loading branch information
dodys authored Dec 19, 2024
2 parents 7708eb8 + 3b8cf2d commit 797df15
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/pam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ rules:
- accounts_password_pam_minclass
- accounts_password_pam_minlen
- accounts_password_pam_ocredit
- accounts_password_pam_pwhistory_enabled
- accounts_password_pam_pwhistory_remember
- accounts_password_pam_pwhistory_remember_password_auth
- accounts_password_pam_pwhistory_remember_system_auth
Expand Down
5 changes: 3 additions & 2 deletions controls/cis_ubuntu2404.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1880,8 +1880,9 @@ controls:
levels:
- l1_server
- l1_workstation
status: planned
notes: TODO. Rule does not seem to be implemented, nor does it map to any rules in ubuntu2204 profile.
rules:
- accounts_password_pam_pwhistory_enabled
status: automated

- id: 5.3.3.1.1
title: Ensure password failed attempts lockout is configured (Automated)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# platform = multi_platform_ubuntu

{{{ bash_pam_pwhistory_enable('cac_pwhistory','requisite') }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<def-group>
<definition class="compliance" id="{{{ rule_id }}}" version="2">
{{{ oval_metadata("The passwords to remember should be set correctly.") }}}
<criteria operator="AND" comment="Check if pam_pwhistory.so is properly enabled">
<!--
pam_pwhistory.so parameters can be defined directly in pam files or, in newer versions,
in /etc/security/pwhistory.conf. The last is the recommended option when available. Also,
is the option used by auselect tool. However, regardless the approach, a minimal
declaration is common in pam files. -->
<criterion test_ref="test_accounts_password_pam_pwhistory_remember_common_password"
comment="pam_pwhistory.so is properly defined in password section of common-password"/>
</criteria>
</definition>

<!-- is pam_pwhistory.so enabled? -->
<ind:textfilecontent54_test id="test_accounts_password_pam_pwhistory_remember_common_password" check="all"
check_existence="at_least_one_exists" version="1" comment="Check pam_pwhistory.so presence in /etc/pam.d/common-password">
<ind:object object_ref="object_accounts_password_pam_pwhistory_remember_common_password"/>
</ind:textfilecontent54_test>

<ind:textfilecontent54_object id="object_accounts_password_pam_pwhistory_remember_common_password"
version="1">
<ind:filepath>/etc/pam.d/common-password</ind:filepath>
<ind:pattern operation="pattern match">^[\s]*password[\s]+((?:\[success=\d+\s+default=ignore\])|(?:requisite)|(?:required))[\s]+pam_pwhistory\.so[\s]+.*$</ind:pattern>
<ind:instance datatype="int">1</ind:instance>
</ind:textfilecontent54_object>
</def-group>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
documentation_complete: true


title: 'Verify pam_pwhistory module is activated'

description: |-
The <tt>pam_pwhistory.so</tt> module is part of the Pluggable Authentication Modules (PAM)
framework designed to increase password security. It works by storing a history of previously
used passwords for each user, ensuring users cannot alternate between the same passwords too frequently.
<br /><br />
This module is incompatible with Kerberos. Furthermore, its usage with <tt>NIS</tt> or <tt>LDAP</tt> is
generally impractical, as other machines can not access local password histories.
rationale: |-
Enforcing strong passwords increases the difficulty and resources required
for password compromise.
severity: medium

platform: package[pam]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# platform = multi_platform_ubuntu

config_file=/usr/share/pam-configs/tmp_pwhistory
cat << EOF > "$config_file"
Name: pwhistory password history checking
Default: yes
Priority: 1024
Password-Type: Primary
Password: requisite # pam_pwhistory.so remember=24 enforce_for_root try_first_pass use_authtok
EOF

DEBIAN_FRONTEND=noninteractive pam-auth-update

rm "$config_file"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# platform = multi_platform_ubuntu

config_file=/usr/share/pam-configs/tmp_pwhistory
cat << EOF > "$config_file"
Name: pwhistory password history checking
Default: yes
Priority: 1024
Password-Type: Primary
Password: requisite pam_pwhistory.so remember=24 enforce_for_root try_first_pass use_authtok
EOF

DEBIAN_FRONTEND=noninteractive pam-auth-update

rm "$config_file"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# platform = multi_platform_ubuntu

rm /usr/share/pam-configs/*pwhistory

DEBIAN_FRONTEND=noninteractive pam-auth-update
17 changes: 17 additions & 0 deletions shared/macros/10-bash.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,24 @@ if [ -f /usr/bin/authselect ]; then
{{{ bash_ensure_pam_module_line("$PAM_FILE_PATH", 'password', control, 'pam_pwhistory.so', after_match) | indent(8) }}}
fi
else
{{% if 'ubuntu' in product %}}
conf_name={{{ pam_file }}}
conf_path="/usr/share/pam-configs"

if [ ! -f "$conf_path"/"$conf_name" ]; then
cat << EOF > "$conf_path"/"$conf_name"
Name: pwhistory password history checking
Default: yes
Priority: 1024
Password-Type: Primary
Password: {{{ control }}} pam_pwhistory.so remember=24 enforce_for_root try_first_pass use_authtok
EOF
fi

DEBIAN_FRONTEND=noninteractive pam-auth-update
{{% else %}}
{{{ bash_ensure_pam_module_line(pam_file, 'password', control, 'pam_pwhistory.so', after_match) | indent(4) }}}
{{% endif %}}
fi
{{%- endmacro -%}}

Expand Down

0 comments on commit 797df15

Please sign in to comment.