forked from ansible-lockdown/RHEL9-CIS
interactive users ilogic improvements thanks to @polski-g
Signed-off-by: Mark Bolwell <mark.bollyuk@gmail.com>
This commit is contained in:
parent
daf5a3f462
commit
f83e5a69a2
5 changed files with 20 additions and 19 deletions
|
|
@ -23,18 +23,16 @@
|
||||||
- name: "PRELIM | AUDIT | Interactive Users"
|
- name: "PRELIM | AUDIT | Interactive Users"
|
||||||
tags: always
|
tags: always
|
||||||
ansible.builtin.shell: >
|
ansible.builtin.shell: >
|
||||||
grep -E -v '^(root|halt|sync|shutdown)' /etc/passwd | awk -F: '(!index($7, "sbin/nologin") && $7 != "/bin/nologin" && $7 != "/bin/false" && $7 != "/dev/null") { print $1 }'
|
grep -E -v '^(root|halt|sync|shutdown)' /etc/passwd | awk -F: '(!index($7, "sbin/nologin") && $7 != "/bin/nologin" && $7 != "/bin/false" && $7 != "/dev/null") { print $1":"$3":"$6 }'
|
||||||
changed_when: false
|
changed_when: false
|
||||||
check_mode: false
|
check_mode: false
|
||||||
register: prelim_interactive_usernames
|
register: prelim_interactive_users_raw
|
||||||
|
|
||||||
- name: "PRELIM | AUDIT | Interactive User accounts home directories"
|
- name: "PRELIM | AUDIT | Interactive Users (reformat)"
|
||||||
tags: always
|
tags: always
|
||||||
ansible.builtin.shell: >
|
ansible.builtin.set_fact:
|
||||||
grep -E -v '^(root|halt|sync|shutdown)' /etc/passwd | awk -F: '(!index($7, "sbin/nologin") && $7 != "/bin/nologin" && $7 != "/bin/false") { print $6 }'
|
prelim_interactive_usernames: "{{ prelim_interactive_users | default([]) + [dict([('username', item.split(':')[0]), ('uid', item.split(':')[1]), ('home', item.split(':')[2])])] }}"
|
||||||
changed_when: false
|
loop: "{{ prelim_interactive_users_raw.stdout_lines }}"
|
||||||
check_mode: false
|
|
||||||
register: prelim_interactive_users_home
|
|
||||||
|
|
||||||
- name: "PRELIM | AUDIT | Interactive UIDs"
|
- name: "PRELIM | AUDIT | Interactive UIDs"
|
||||||
tags: always
|
tags: always
|
||||||
|
|
@ -205,7 +203,7 @@
|
||||||
tags:
|
tags:
|
||||||
- always
|
- always
|
||||||
block:
|
block:
|
||||||
- name: "PRELIM | AUDIT | Discover is wirelss adapter on system"
|
- name: "PRELIM | AUDIT | Discover is wireless adapter on system"
|
||||||
ansible.builtin.command: find /sys/class/net/*/ -type d -name wireless
|
ansible.builtin.command: find /sys/class/net/*/ -type d -name wireless
|
||||||
register: discover_wireless_adapters
|
register: discover_wireless_adapters
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
- name: "5.4.1.1 | PATCH | Ensure password expiration is 365 days or less | Set existing users PASS_MAX_DAYS"
|
- name: "5.4.1.1 | PATCH | Ensure password expiration is 365 days or less | Set existing users PASS_MAX_DAYS"
|
||||||
when:
|
when:
|
||||||
- discovered_max_days.stdout_lines | length > 0
|
- discovered_max_days.stdout_lines | length > 0
|
||||||
- item in prelim_interactive_usernames.stdout
|
- item in prelim_interactive_usernames | map(attribute='username') | list
|
||||||
- rhel9cis_force_user_maxdays
|
- rhel9cis_force_user_maxdays
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
|
|
@ -60,7 +60,7 @@
|
||||||
- name: "5.4.1.2 | PATCH | Ensure minimum password days is configured | Set existing users PASS_MIN_DAYS"
|
- name: "5.4.1.2 | PATCH | Ensure minimum password days is configured | Set existing users PASS_MIN_DAYS"
|
||||||
when:
|
when:
|
||||||
- discovered_min_days.stdout_lines | length > 0
|
- discovered_min_days.stdout_lines | length > 0
|
||||||
- item in prelim_interactive_usernames.stdout
|
- item in prelim_interactive_usernames | map(attribute='username') | list
|
||||||
- rhel9cis_force_user_mindays
|
- rhel9cis_force_user_mindays
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
|
|
@ -91,7 +91,7 @@
|
||||||
- name: "5.4.1.3 | PATCH | Ensure password expiration warning days is configured | Set existing users WARN_DAYS"
|
- name: "5.4.1.3 | PATCH | Ensure password expiration warning days is configured | Set existing users WARN_DAYS"
|
||||||
when:
|
when:
|
||||||
- discovered_warn_days.stdout_lines | length > 0
|
- discovered_warn_days.stdout_lines | length > 0
|
||||||
- item in prelim_interactive_usernames.stdout
|
- item in prelim_interactive_usernames | map(attribute='username') | list
|
||||||
- rhel9cis_force_user_warnage
|
- rhel9cis_force_user_warnage
|
||||||
ansible.builtin.command: "chage --warndays {{ rhel9cis_pass['warn_age'] }} {{ item }}"
|
ansible.builtin.command: "chage --warndays {{ rhel9cis_pass['warn_age'] }} {{ item }}"
|
||||||
changed_when: true
|
changed_when: true
|
||||||
|
|
@ -140,7 +140,7 @@
|
||||||
register: discovered_passwdlck_user_list
|
register: discovered_passwdlck_user_list
|
||||||
|
|
||||||
- name: "5.4.1.5 | PATCH | Ensure inactive password lock is 30 days or less | Apply Inactive setting to existing accounts"
|
- name: "5.4.1.5 | PATCH | Ensure inactive password lock is 30 days or less | Apply Inactive setting to existing accounts"
|
||||||
when: item in prelim_interactive_usernames.stdout
|
when: item in prelim_interactive_usernames | map(attribute='username') | list
|
||||||
ansible.builtin.command: chage --inactive {{ rhel9cis_inactivelock.lock_days }} "{{ item }}"
|
ansible.builtin.command: chage --inactive {{ rhel9cis_inactivelock.lock_days }} "{{ item }}"
|
||||||
changed_when: true
|
changed_when: true
|
||||||
loop: "{{ discovered_passwdlck_user_list.stdout_lines }}"
|
loop: "{{ discovered_passwdlck_user_list.stdout_lines }}"
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@
|
||||||
- name: "5.4.2.7 | PATCH | Ensure system accounts do not have a valid login shell"
|
- name: "5.4.2.7 | PATCH | Ensure system accounts do not have a valid login shell"
|
||||||
when:
|
when:
|
||||||
- rhel9cis_rule_5_4_2_7
|
- rhel9cis_rule_5_4_2_7
|
||||||
- "item.id not in prelim_interactive_usernames.stdout"
|
- "item.id not in prelim_interactive_usernames | map(attribute='username')"
|
||||||
- item.id not in rhel9cis_system_users_shell
|
- item.id not in rhel9cis_system_users_shell
|
||||||
- "'root' not in item.id"
|
- "'root' not in item.id"
|
||||||
- rhel9cis_disruption_high
|
- rhel9cis_disruption_high
|
||||||
|
|
@ -220,7 +220,7 @@
|
||||||
when:
|
when:
|
||||||
- rhel9cis_rule_5_4_2_8
|
- rhel9cis_rule_5_4_2_8
|
||||||
- rhel9cis_disruption_high
|
- rhel9cis_disruption_high
|
||||||
- "item.id not in prelim_interactive_usernames.stdout"
|
- "item.id not in prelim_interactive_usernames | map(attribute='username')"
|
||||||
- "'root' not in item.id"
|
- "'root' not in item.id"
|
||||||
tags:
|
tags:
|
||||||
- level1-server
|
- level1-server
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,7 @@
|
||||||
etype: group
|
etype: group
|
||||||
permissions: rx
|
permissions: rx
|
||||||
state: present
|
state: present
|
||||||
loop: "{{ prelim_interactive_users_home.stdout_lines }}"
|
loop: "{{ prelim_interactive_users | map(attribute='home') | list }}"
|
||||||
|
|
||||||
- name: "7.2.8 | PATCH | Ensure local interactive user home directories are configured | Set other ACL"
|
- name: "7.2.8 | PATCH | Ensure local interactive user home directories are configured | Set other ACL"
|
||||||
when: not system_is_container
|
when: not system_is_container
|
||||||
|
|
@ -266,7 +266,7 @@
|
||||||
etype: other
|
etype: other
|
||||||
permissions: 0
|
permissions: 0
|
||||||
state: present
|
state: present
|
||||||
loop: "{{ prelim_interactive_users_home.stdout_lines }}"
|
loop: "{{ prelim_interactive_users | map(attribute='home') | list }}"
|
||||||
|
|
||||||
- name: "7.2.9 | PATCH | Ensure local interactive user dot files access is configured"
|
- name: "7.2.9 | PATCH | Ensure local interactive user dot files access is configured"
|
||||||
when:
|
when:
|
||||||
|
|
@ -315,6 +315,6 @@
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: '{{ item }}'
|
path: '{{ item }}'
|
||||||
mode: 'go-w'
|
mode: 'go-w'
|
||||||
owner: "{{ rhel9cis_passwd | selectattr('dir', 'in', prelim_interactive_users_home.stdout_lines) | selectattr('dir', 'in', item) | map(attribute='uid') | last }}"
|
owner: "{{ rhel9cis_passwd | selectattr('dir', 'in', prelim_interactive_users_raw.stdout_lines) | selectattr('dir', 'in', item) | map(attribute='uid') | last }}"
|
||||||
group: "{{ rhel9cis_passwd | selectattr('dir', 'in', prelim_interactive_users_home.stdout_lines) | selectattr('dir', 'in', item) | map(attribute='gid') | last }}"
|
group: "{{ rhel9cis_passwd | selectattr('dir', 'in', prelim_interactive_users_raw.stdout_lines) | selectattr('dir', 'in', item) | map(attribute='gid') | last }}"
|
||||||
with_items: "{{ discovered_homedir_hidden_files.stdout_lines }}"
|
with_items: "{{ discovered_homedir_hidden_files.stdout_lines }}"
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ rhel9cis_allowed_crypto_policies_modules:
|
||||||
warn_control_list: ""
|
warn_control_list: ""
|
||||||
warn_count: 0
|
warn_count: 0
|
||||||
|
|
||||||
|
# list of dicts of interactive users, filled in during prelim.yml
|
||||||
|
prelim_interactive_users: []
|
||||||
|
|
||||||
# Default empty values for 1.4.2
|
# Default empty values for 1.4.2
|
||||||
efi_mount_opts_addition: ''
|
efi_mount_opts_addition: ''
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue