-
Notifications
You must be signed in to change notification settings - Fork 765
New rule accounts_password_pam_modules_in_authselect_profile #14279
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| # platform = multi_platform_rhel | ||
| # reboot = false | ||
| # strategy = restrict | ||
| # complexity = low | ||
| # disruption = low | ||
|
|
||
| {{{ ansible_check_authselect_integrity(rule_title) }}} | ||
|
|
||
| {{{ ansible_ensure_authselect_custom_profile(rule_title) }}} | ||
|
|
||
| - name: '{{{ rule_title }}} - Get authselect current profile' | ||
| ansible.builtin.command: head -1 /etc/authselect/authselect.conf | ||
| register: result_authselect_profile_name | ||
| changed_when: false | ||
| when: | ||
| - result_authselect_check_cmd is success | ||
|
|
||
| - name: '{{{ rule_title }}} - Determine PAM profile path' | ||
| ansible.builtin.set_fact: | ||
| pam_profile_path: >- | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably avoid manually editing of PAM profiles. Please check if you can replace some of the tasks that edit
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that's possible. The authselect enable-feature and authselect disable-feature commands modify the currently selected profile, they don't modify the files in /etc/authselect/custom/. |
||
| {%- if result_authselect_profile_name.stdout is match('^custom/') -%} | ||
| /etc/authselect/{{ result_authselect_profile_name.stdout }} | ||
| {%- else -%} | ||
| /usr/share/authselect/default/{{ result_authselect_profile_name.stdout }} | ||
| {%- endif %} | ||
| when: | ||
| - result_authselect_check_cmd is success | ||
| - result_authselect_profile_name is not skipped | ||
|
|
||
| - name: '{{{ rule_title }}} - Ensure PAM modules are present in system-auth and password-auth' | ||
| block: | ||
| - name: '{{{ rule_title }}} - Check if {{ item }} file exists' | ||
| ansible.builtin.stat: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| register: pam_file_stat | ||
| loop: | ||
| - system-auth | ||
| - password-auth | ||
| when: | ||
| - pam_profile_path is defined | ||
|
|
||
| - name: '{{{ rule_title }}} - Set list of PAM files to process' | ||
| ansible.builtin.set_fact: | ||
| pam_files_to_process: "{{ pam_file_stat.results | default([]) | selectattr('stat.exists', 'equalto', true) | map(attribute='item') | list }}" | ||
|
|
||
| - name: '{{{ rule_title }}} - Check if pam_faillock.so exists in auth section of {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*auth\s+\S+\s+pam_faillock\.so\s+preauth | ||
| state: absent | ||
| check_mode: true | ||
| changed_when: false | ||
| register: pam_faillock_auth_check_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
|
|
||
| - name: '{{{ rule_title }}} - Add pam_faillock.so preauth entry in auth section of {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*auth\s+\S+\s+pam_faillock\.so\s+preauth | ||
| insertbefore: "^auth" | ||
| line: "auth required pam_faillock.so preauth" | ||
| state: present | ||
| register: pam_faillock_auth_add_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
| - "pam_faillock_auth_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(1) == 0" | ||
|
|
||
| - name: '{{{ rule_title }}} - Check if pam_faillock.so exists in account section of {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*account\s+\S+\s+pam_faillock\.so | ||
| state: absent | ||
| check_mode: true | ||
| changed_when: false | ||
| register: pam_faillock_account_check_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
|
|
||
| - name: '{{{ rule_title }}} - Add pam_faillock.so entry in account section of {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*account\s+\S+\s+pam_faillock\.so | ||
| insertafter: "^account" | ||
| line: "account required pam_faillock.so" | ||
| state: present | ||
| register: pam_faillock_account_add_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
| - "pam_faillock_account_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(1) == 0" | ||
|
|
||
| - name: '{{{ rule_title }}} - Check if pam_pwquality.so exists in {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*password\s+\S+\s+pam_pwquality\.so | ||
| state: absent | ||
| check_mode: true | ||
| changed_when: false | ||
| register: pam_pwquality_check_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
|
|
||
| - name: '{{{ rule_title }}} - Add pam_pwquality.so entry in password section of {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*password\s+\S+\s+pam_pwquality\.so | ||
| insertbefore: "^password" | ||
| line: "password requisite pam_pwquality.so" | ||
| state: present | ||
| register: pam_pwquality_add_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
| - "pam_pwquality_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(1) == 0" | ||
|
|
||
| - name: '{{{ rule_title }}} - Check if pam_pwhistory.so exists in {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*password\s+\S+\s+pam_pwhistory\.so | ||
| state: absent | ||
| check_mode: true | ||
| changed_when: false | ||
| register: pam_pwhistory_check_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
|
|
||
| - name: '{{{ rule_title }}} - Add pam_pwhistory.so entry after pam_pwquality in {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*password\s+\S+\s+pam_pwhistory\.so | ||
| insertafter: "^.*pam_pwquality\\.so.*" | ||
| line: "password requisite pam_pwhistory.so" | ||
| state: present | ||
| register: pam_pwhistory_add_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
| - "pam_pwhistory_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(1) == 0" | ||
| - "pam_pwquality_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(0) > 0" | ||
|
|
||
| - name: '{{{ rule_title }}} - Add pam_pwhistory.so entry at beginning of password section in {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*password\s+\S+\s+pam_pwhistory\.so | ||
| insertbefore: "^password" | ||
| line: "password requisite pam_pwhistory.so" | ||
| state: present | ||
| register: pam_pwhistory_add_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
| - "pam_pwhistory_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(1) == 0" | ||
| - "pam_pwquality_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(1) == 0" | ||
|
|
||
| - name: '{{{ rule_title }}} - Check if pam_unix.so exists in password section of {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*password\s+\S+\s+pam_unix\.so | ||
| state: absent | ||
| check_mode: true | ||
| changed_when: false | ||
| register: pam_unix_check_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
|
|
||
| - name: '{{{ rule_title }}} - Add pam_unix.so entry after pam_pwhistory in {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*password\s+\S+\s+pam_unix\.so | ||
| insertafter: "^.*pam_pwhistory\\.so.*" | ||
| line: "password sufficient pam_unix.so" | ||
| state: present | ||
| register: pam_unix_add_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
| - "pam_unix_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(1) == 0" | ||
| - "pam_pwhistory_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(0) > 0" | ||
|
|
||
| - name: '{{{ rule_title }}} - Add pam_unix.so entry at end of password section in {{ item }}' | ||
| ansible.builtin.lineinfile: | ||
| path: "{{ pam_profile_path }}/{{ item }}" | ||
| regexp: ^\s*password\s+\S+\s+pam_unix\.so | ||
| insertafter: "^password.*" | ||
| line: "password sufficient pam_unix.so" | ||
| state: present | ||
| register: pam_unix_add_result | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
| - "pam_unix_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(1) == 0" | ||
| - "pam_pwhistory_check_result.results | selectattr('item', 'equalto', item) | map(attribute='found') | first | default(1) == 0" | ||
|
|
||
| - name: '{{{ rule_title }}} - Store results for {{ item }}' | ||
| ansible.builtin.set_fact: | ||
| "pam_changes_{{ item | replace('-', '_') }}": >- | ||
| {{ ((pam_faillock_auth_add_result.results | selectattr('item', 'equalto', item) | map(attribute='changed') | first | default(false)) or | ||
| (pam_faillock_account_add_result.results | selectattr('item', 'equalto', item) | map(attribute='changed') | first | default(false)) or | ||
| (pam_pwquality_add_result.results | selectattr('item', 'equalto', item) | map(attribute='changed') | first | default(false)) or | ||
| (pam_pwhistory_add_result.results | selectattr('item', 'equalto', item) | map(attribute='changed') | first | default(false)) or | ||
| (pam_unix_add_result.results | selectattr('item', 'equalto', item) | map(attribute='changed') | first | default(false))) }} | ||
| loop: "{{ pam_files_to_process | default([]) }}" | ||
| when: | ||
| - item is defined | ||
| - pam_profile_path is defined | ||
|
|
||
| when: | ||
| - result_authselect_check_cmd is success | ||
| - pam_profile_path is defined | ||
|
|
||
| {{{ ansible_apply_authselect_changes(rule_title=rule_title) }}} | ||
| when: | ||
| - result_authselect_check_cmd is success | ||
| - >- | ||
| (pam_changes_system_auth is defined and pam_changes_system_auth) | ||
| or (pam_changes_password_auth is defined and pam_changes_password_auth) | ||
Uh oh!
There was an error while loading. Please reload this page.