-
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
Open
jan-cerny
wants to merge
6
commits into
ComplianceAsCode:master
Choose a base branch
from
jan-cerny:authselect_template
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+602
−31
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c05874b
New rule accounts_password_pam_modules_in_authselect_profile
jan-cerny 65e40da
Improve Ansible Tasks idempotency
jan-cerny daa236d
Stop modifying the default authselect profile
jan-cerny 4144003
Remove unused variable
jan-cerny 0013a83
Remove empty lines
jan-cerny c9728f1
Add Fedora to test scenarios
jan-cerny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 235 additions & 0 deletions
235
...ounts/accounts-pam/accounts_password_pam_modules_in_authselect_profile/ansible/shared.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
Arden97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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: >- | ||
Arden97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {%- 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) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fedora?