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

Fixes related to SLE 12/15 for the rules set_min/max_life_existing #10173

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
register: user_names

- name: Change the maximum time period between password changes
{{% if product not in ["rhel7", "ol7"] %}}
{{% if product in ["rhel7", "ol7","sle12","sle15"] %}}
{{% if product in ["rhel7", "ol7"] %}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can avoid nesting conditions and have an if-elif instead.

ansible.builtin.command:
cmd: chage -M {{ var_accounts_maximum_age_login_defs }} {{ item }}
{{% else %}}
ansible.builtin.command:
cmd: passwd -q -x {{ var_accounts_maximum_age_login_defs }} {{ item }}
{{% endif %}}
{{% else %}}
ansible.builtin.user:
user: '{{ item }}'
password_expire_max: '{{ var_accounts_maximum_age_login_defs }}'
{{% else %}}
ansible.builtin.command:
cmd: chage -M {{ var_accounts_maximum_age_login_defs }} {{ item }}
{{% endif %}}
with_items: '{{ user_names.stdout_lines }}'
when: user_names.stdout_lines | length > 0
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

{{{ bash_instantiate_variables("var_accounts_maximum_age_login_defs") }}}

{{% if product not in ["sle12", "sle15"] %}}
{{% call iterate_over_command_output("i", "awk -v var=\"$var_accounts_maximum_age_login_defs\" -F: '(/^[^:]+:[^!*]/ && ($5 > var || $5 == \"\")) {print $1}' /etc/shadow") -%}}
chage -M $var_accounts_maximum_age_login_defs $i
{{%- endcall %}}
{{% else %}}
usrs_max_pass_age=( $(awk -F: '$5 > $var_accounts_maximum_age_login_defs || $5 == "" {print $1}' /etc/shadow) )
for i in ${usrs_max_pass_age[@]};
do
passwd -q -x $((var_accounts_maximum_age_login_defs)) $i
done
{{% endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ ocil: |-

fixtext: |-
Configure non-compliant accounts to enforce a 60-day maximum password lifetime restriction.

passwd -x {{{ xccdf_value("var_accounts_maximum_age_login_defs") }}} [user]
{{% if product not in ["sle12", "sle15"] %}}
passwd -q -x {{{ xccdf_value("var_accounts_maximum_age_login_defs") }}} [user]
{{% else %}}
usrs_max_pass_age=( $(awk -F: '$5 > $var_accounts_maximum_age_login_defs || $5 == "" {print $1}' /etc/shadow) )
for i in ${usrs_max_pass_age[@]};
do
passwd -q -x $((var_accounts_maximum_age_login_defs)) $i
done
{{% endif %}}

srg_requirement: |-
{{{ full_name }}} user account passwords must have a 60-day maximum password lifetime restriction.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
# complexity = low
# disruption = low

{{{ ansible_instantiate_variables("var_accounts_minimum_age_login_defs") }}}

- name: Collect users with not correct minimum time period between password changes
command: >
awk -F: '(/^[^:]+:[^!*]/ && ($4 < 1 || $4 == "")) {print $1}' /etc/shadow
awk -F':' '(/^[^:]+:[^!*]/ && ($4 < {{ var_accounts_minimum_age_login_defs }} || $4 == "")) {print $1}' /etc/shadow
register: user_names

- name: Change the minimum time period between password changes
{{% if product not in ["sle12", "sle15"] %}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the opposite condition instead of using a negative condition.

command: >
chage -m 1 {{ item }}
{{% else %}}
command: >
passwd -q -n {{ var_accounts_minimum_age_login_defs }} {{ item }}
{{% endif %}}
with_items: "{{ user_names.stdout_lines }}"
when: user_names.stdout_lines | length > 0
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

{{{ bash_instantiate_variables("var_accounts_minimum_age_login_defs") }}}

{{% if product not in ["sle12", "sle15"] %}}
{{% call iterate_over_command_output("i", "awk -v var=\"$var_accounts_minimum_age_login_defs\" -F: '(/^[^:]+:[^!*]/ && ($4 < var || $4 == \"\")) {print $1}' /etc/shadow") -%}}
chage -m $var_accounts_minimum_age_login_defs $i
{{%- endcall %}}
{{% else %}}
usrs_min_pass_age=( $(awk -F: '$4 < $var_accounts_minimum_age_login_defs || $4 == "" {print $1}' /etc/shadow) )
for i in ${usrs_min_pass_age[@]};
do
passwd -q -n $((var_accounts_minimum_age_login_defs)) $i
done
{{% endif %}}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ ocil: |-

fixtext: |-
Configure non-compliant accounts to enforce a 24 hours/1 day minimum password lifetime:

{{% if product not in ["sle12", "sle15"] %}}
$ sudo chage -m {{{ xccdf_value("var_accounts_minimum_age_login_defs") }}} [user]
{{% else %}}
usrs_min_pass_age=( $(awk -F: '$4 < $var_accounts_minimum_age_login_defs || $4 == "" {print $1}' /etc/shadow) )
for i in ${usrs_min_pass_age[@]};
do
passwd -q -n $((var_accounts_minimum_age_login_defs)) $i
done
{{% endif %}}

srg_requirement: |-
{{{ full_name }}} passwords must have a 24 hours/1 day minimum password lifetime restriction in /etc/shadow.