Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restructure PAM handling and update for currently supported Linux distributions #392

Merged
merged 32 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a55a4d2
remove pam_tally2
schurzi Feb 8, 2021
b210df1
re-add debian tally config
schurzi Feb 8, 2021
ebbf685
add rhel faillock config
schurzi Feb 8, 2021
3ad4fba
add guard for tally debian unstable
schurzi Feb 8, 2021
94b9bfc
add files for faillock
schurzi Feb 10, 2021
157f4fc
add tasks for faillock on debian
schurzi Feb 10, 2021
7282187
Merge branch 'master' into tally
schurzi Feb 10, 2021
fc7fb4f
make compatible to authconfig
schurzi Feb 13, 2021
19482c3
force create symlink
schurzi Feb 13, 2021
aa166f4
split debian and rhel pam config
schurzi Feb 14, 2021
04654d0
correct typo
schurzi Feb 14, 2021
532917d
remove rhel6 support from pam
schurzi Feb 14, 2021
30f0839
add support for rhel8 and sssd
schurzi Feb 14, 2021
7f1765c
consolidate auth for rhel
schurzi Feb 14, 2021
b9e3309
fix problems with auth
schurzi Feb 14, 2021
26c73ed
fix debian faillock config
schurzi Feb 14, 2021
28c6bf5
put force on the right task
schurzi Feb 14, 2021
08aad6e
add documentation
schurzi Feb 14, 2021
ec36bf5
document parameter
schurzi Feb 14, 2021
4a5fa70
default faillock to yes
schurzi Feb 16, 2021
dba5371
sssd is disabled on Amazonlinus
schurzi Feb 16, 2021
23071a1
add testcases for PAM
schurzi Feb 22, 2021
9b6f313
move pam tests up
schurzi Feb 22, 2021
26d84b5
use custom /tmp dir
schurzi Feb 22, 2021
3334000
set locale for test
schurzi Feb 22, 2021
6d2c92d
correct locale
schurzi Feb 22, 2021
335df54
correct version
schurzi Feb 22, 2021
10841ce
case sensitive
schurzi Feb 22, 2021
75fc31b
remove cracklib
schurzi Feb 22, 2021
5f97dff
Merge branch 'master' into tally
schurzi Mar 11, 2021
ec9d7d2
cleanup and typos
schurzi Mar 15, 2021
b2dd73d
remove unneeded tasks
schurzi Mar 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions molecule/os_hardening/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
os_security_kernel_enable_core_dump: true
os_security_suid_sgid_remove_from_unknown: true
os_auth_pam_passwdqc_enable: false
os_auth_lockout_time: 15
os_desktop_enable: true
os_env_extra_user_paths: ['/home']
os_auth_allow_homeless: true
Expand Down
4 changes: 4 additions & 0 deletions molecule/os_hardening/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
name: procps
when: ansible_facts.os_family == 'Debian'

- name: include PAM tests
include: verify_pam.yml
when: ansible_facts.distribution in ['Debian', 'Ubuntu'] or ansible_facts.os_family == 'RedHat'

- name: download cinc-auditor
get_url:
url: https://omnitruck.cinc.sh/install.sh
Expand Down
59 changes: 59 additions & 0 deletions molecule/os_hardening/verify_pam.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
- name: download pam-tester
get_url:
url: https://github.com/schurzi/pam-tester/releases/download/latest/pam-tester
dest: /bin/pam-tester
mode: 0555

- name: set password for test
set_fact:
test_pw: "myTest!pw"

- name: set locale for test
set_fact:
locale: "en_US.UTF-8"
when:
- ansible_facts.os_family == 'RedHat'
- ansible_facts.distribution_major_version < '8'

- name: create testuser
user:
name: testuser
password: "{{ test_pw | password_hash('sha512') }}"

- name: check successfull login with correct password
shell:
cmd: "pam-tester --user testuser --password {{ test_pw }}"
environment:
TMPDIR: /var/tmp
LC_ALL: "{{ locale | default('C.UTF-8') }}"
LANG: "{{ locale | default('C.UTF-8') }}"

- name: check unsuccessfull login with incorrect password
shell:
cmd: "pam-tester --user testuser --password {{ test_pw }}fail --expectfail"
environment:
TMPDIR: /var/tmp
LC_ALL: "{{ locale | default('C.UTF-8') }}"
LANG: "{{ locale | default('C.UTF-8') }}"
with_sequence: count=6

- name: check unsuccessfull login, with correct password (lockout)
shell:
cmd: "pam-tester --user testuser --password {{ test_pw }} --expectfail"
environment:
TMPDIR: /var/tmp
LC_ALL: "{{ locale | default('C.UTF-8') }}"
LANG: "{{ locale | default('C.UTF-8') }}"

- name: wait for account to unlock
pause:
seconds: 20

- name: check successfull login
shell:
cmd: "pam-tester --user testuser --password {{ test_pw }}"
environment:
TMPDIR: /var/tmp
LC_ALL: "{{ locale | default('C.UTF-8') }}"
LANG: "{{ locale | default('C.UTF-8') }}"
10 changes: 10 additions & 0 deletions roles/os_hardening/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ We know that this is the case on Raspberry Pi.
- `os_auth_pam_passwdqc_options`
- Default: `min=disabled,disabled,16,12,8`
- Description: set to any option line (as a string) that you want to pass to passwdqc.
- `os_auth_pam_sssd_enable`
- Default: `false` (on RHEL8/CentOS8/Fedora `true`)
- Description: activate PAM auth support for sssd
- `os_security_users_allow`
- Default: `[]`
- Description: list of things, that a user is allowed to do. May contain `change_user`.
Expand Down Expand Up @@ -249,6 +252,13 @@ For more information, please see this [upstream documentation](https://www.kerne

## More information

We use specific PAM configuration for every linux distribution. This is a very diverse area, since every vendor seems to push their own system for managing PAM. We used following guides and sources for our configuration.

- on Debian/Ubuntu we use [pam-config-framework](https://wiki.ubuntu.com/PAMConfigFrameworkSpec)
- RHEL8 and compatible use information from [authselect](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_authentication_and_authorization_in_rhel/configuring-user-authentication-using-authselect_configuring-authentication-and-authorization-in-rhel), but our setup disables the configuration from authselect
- RHEL 6/7 and compatible use [authconfig](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system-level_authentication_guide/authconfig-install), but our setup disables the configuration from authconfig
- for RHEL 6/7 we also use information from [Desktop Security](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/chap-hardening_your_system_with_tools_and_services#sec-Desktop_Security)

This role is mostly based on guides by:

- [Arch Linux wiki, Sysctl hardening](https://wiki.archlinux.org/index.php/Sysctl)
Expand Down
118 changes: 8 additions & 110 deletions roles/os_hardening/tasks/pam.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
- name: update pam on Debian systems
command: 'pam-auth-update --package'
when: ansible_facts.distribution in ['Debian', 'Ubuntu']
changed_when: false
environment:
DEBIAN_FRONTEND: noninteractive
- name: Gather package facts
package_facts:
manager: auto
when:
- ansible_facts.os_family != 'Suse'
- ansible_facts.os_family != 'Archlinux'

# the reason for this is so a user cannot connect to a server,
# that isn't connected to an LDAP server anymore.
Expand All @@ -17,115 +17,13 @@
when:
- ansible_facts.os_family != 'Archlinux'

- name: remove pam_cracklib, because it does not play nice with passwdqc
apt:
name: '{{ os_packages_pam_cracklib }}'
state: 'absent'
when:
- ansible_facts.distribution in ['Debian', 'Ubuntu']
- os_auth_pam_passwdqc_enable

- name: install the package for strong password checking
apt:
name: '{{ os_packages_pam_passwdqc }}'
state: 'present'
update_cache: 'yes'
- import_tasks: pam_debian.yml
when:
- ansible_facts.distribution in ['Debian', 'Ubuntu']
- os_auth_pam_passwdqc_enable

- name: configure passwdqc
template:
src: 'usr/share/pam-configs/pam_passwdqd.j2'
dest: '{{ passwdqc_path }}'
mode: '0644'
owner: 'root'
group: 'root'
when:
- ansible_facts.distribution in ['Debian', 'Ubuntu']
- os_auth_pam_passwdqc_enable

- name: remove passwdqc
apt:
name: '{{ os_packages_pam_passwdqc }}'
state: 'absent'
when:
- ansible_facts.distribution in ['Debian', 'Ubuntu']
- not os_auth_pam_passwdqc_enable

- name: install tally2
apt:
name: 'libpam-modules'
state: 'present'
when:
- ansible_facts.distribution in ['Debian', 'Ubuntu']
- not os_auth_pam_passwdqc_enable
- os_auth_retries > 0

- name: configure tally2
template:
src: 'usr/share/pam-configs/pam_tally2.j2'
dest: '{{ tally2_path }}'
mode: '0644'
owner: 'root'
group: 'root'
when:
- ansible_facts.distribution in ['Debian', 'Ubuntu']
- not os_auth_pam_passwdqc_enable
- os_auth_retries > 0

- name: delete tally2 when retries is 0
file:
path: '{{ tally2_path }}'
state: 'absent'
when:
- ansible_facts.distribution in ['Debian', 'Ubuntu']
- not os_auth_pam_passwdqc_enable
- os_auth_retries == 0

- name: remove pam_cracklib, because it does not play nice with passwdqc
yum:
name: '{{ os_packages_pam_cracklib }}'
state: 'absent'
when:
- ansible_facts.os_family == 'RedHat'
- ansible_facts.distribution_major_version|int is version('7', '<')
- ansible_facts.distribution != 'Amazon'
- os_auth_pam_passwdqc_enable

- name: install the package for strong password checking
yum:
name: '{{ os_packages_pam_passwdqc }}'
state: 'present'
when:
- ansible_facts.os_family == 'RedHat'
- ansible_facts.distribution_major_version|int is version('7', '<')
- ansible_facts.distribution != 'Amazon'
- os_auth_pam_passwdqc_enable

- name: remove passwdqc
yum:
name: '{{ os_packages_pam_passwdqc }}'
state: 'absent'
- import_tasks: pam_rhel.yml
when:
- ansible_facts.os_family == 'RedHat'
- not os_auth_pam_passwdqc_enable

- name: configure passwdqc and tally via central system-auth confic
template:
src: 'etc/pam.d/rhel_system_auth.j2'
dest: '/etc/pam.d/system-auth-ac'
mode: '0640'
owner: 'root'
group: 'root'
when: ansible_facts.os_family == 'RedHat'

- name: Gather package facts
package_facts:
manager: auto
when:
- ansible_facts.os_family != 'Suse'
- ansible_facts.os_family != 'Archlinux'

- name: NSA 2.3.3.5 Upgrade Password Hashing Algorithm to SHA-512
template:
Expand Down
120 changes: 120 additions & 0 deletions roles/os_hardening/tasks/pam_debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
- name: install the package for strong password checking
apt:
name: 'libpam-passwdqc'
state: 'present'
update_cache: 'yes'
when:
- os_auth_pam_passwdqc_enable

- name: configure passwdqc
template:
src: 'usr/share/pam-configs/pam_passwdqc.j2'
dest: '{{ passwdqc_path }}'
mode: '0644'
owner: 'root'
group: 'root'
when:
- os_auth_pam_passwdqc_enable

- name: install tally2
apt:
name: 'libpam-modules'
state: 'present'
when:
- os_auth_retries > 0

- name: manage tally on Debian stable
block:
- name: configure tally2
template:
src: 'usr/share/pam-configs/pam_tally2.j2'
dest: '{{ tally2_path }}'
mode: '0644'
owner: 'root'
group: 'root'
when:
- os_auth_retries > 0

- name: delete tally2 when retries is 0
file:
path: '{{ tally2_path }}'
state: 'absent'
when:
- os_auth_retries == 0
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '<')"

- name: manage tally/faillock on Debian unstable
block:
- name: delete tally2
file:
path: '{{ tally2_path }}'
state: 'absent'

- name: create tally directory
rndmh3ro marked this conversation as resolved.
Show resolved Hide resolved
file:
path: '/var/run/faillock'
state: 'directory'
mode: '0755'
owner: 'root'
group: 'root'

- name: configure faillock
template:
src: 'etc/security/faillock.conf.j2'
dest: '/etc/security/faillock.conf'
mode: '0644'
owner: 'root'
group: 'root'

- name: configure faillock pam
template:
src: 'usr/share/pam-configs/pam_faillock.j2'
dest: '/usr/share/pam-configs/faillock'
mode: '0644'
owner: 'root'
group: 'root'
when:
- os_auth_retries > 0

- name: configure faillock pam authfail
template:
src: 'usr/share/pam-configs/pam_faillock_authfail.j2'
dest: '/usr/share/pam-configs/faillock_authfail'
mode: '0644'
owner: 'root'
group: 'root'
when:
- os_auth_retries > 0

- name: delete faillock when retries is 0
file:
path: '/usr/share/pam-configs/faillock'
state: 'absent'
when:
- os_auth_retries == 0

- name: delete faillock authfail when retries is 0
file:
path: '/usr/share/pam-configs/faillock_authfail'
state: 'absent'
when:
- os_auth_retries == 0
when:
- "'libpam-modules' in ansible_facts.packages"
- "ansible_facts.packages['libpam-modules'][0].version is version('1.4.0', '>=')"

- name: update pam on Debian systems
command: 'pam-auth-update --package'
environment:
DEBIAN_FRONTEND: noninteractive
changed_when: false

- name: remove passwdqc
apt:
name: 'libpam-passwdqc'
state: 'absent'
when:
- not os_auth_pam_passwdqc_enable