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

Update bash remediation to fix bug into account_disable_inactivity* #12134

Merged
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 @@ -16,13 +16,17 @@ fi
{{{ bash_ensure_pam_module_line("$PAM_FILE_PATH",
'auth',
'sufficient',
'pam_unix.so') }}}
'pam_unix.so',
'^\s*auth.*required.*pam_lastlog\.so.*') }}}
# Ensure pam_unix.so is configured after pam_lastlog.so
if ! grep -Pz \
"auth\s*required\s*pam_lastlog\.so[^#]*inactive=35[\s\S]*\n\s*auth\s*sufficient\s*pam_unix\.so"\
"$PAM_FILE_PATH" ; then
PAM_LASTLOG_LINE="$(grep -oP '^\s*auth.*pam_lastlog\.so.*' $PAM_FILE_PATH)"
sed -i "0,/^\s*auth.*pam_unix\.so.*/i$PAM_LASTLOG_LINE" "$PAM_FILE_PATH"
readarray -t pam_lastlog_lines <<< $(grep -oP '^\s*auth.*pam_lastlog\.so[^#]*inactive=35.*' $PAM_FILE_PATH)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the shellcheck warns about this, see the CI results

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The scenario is the test wrong_order.fail.sh, in that test we have as initial file

# Generated by authselect on Tue Jul 30 19:05:11 2024
# Do not modify this file manually.

auth        required                                     pam_env.so
auth        required                                     pam_faildelay.so delay=2000000
auth        sufficient                                   pam_unix.so nullok
auth required pam_lastlog.so inactive=35
auth        required                                     pam_deny.so

account     required                                     pam_unix.so

password    requisite                                    pam_pwquality.so
password    sufficient                                   pam_unix.so sha512 shadow nullok use_authtok
password    required                                     pam_deny.so

session     optional                                     pam_keyinit.so revoke
session     required                                     pam_limits.so
-session    optional                                     pam_systemd.so
session     [success=1 default=ignore]                   pam_succeed_if.so service in crond quiet use_uid
session     required                                     pam_unix.so

and after the bash remediation we have

# Generated by authselect on Tue Jul 30 19:09:20 2024
# Do not modify this file manually.

auth required pam_lastlog.so inactive=35
auth        required                                     pam_env.so
auth required pam_lastlog.so inactive=35
auth        required                                     pam_faildelay.so delay=2000000
auth required pam_lastlog.so inactive=35
auth required pam_lastlog.so inactive=35
auth        sufficient                                   pam_unix.so nullok
auth required pam_lastlog.so inactive=35
auth        required                                     pam_deny.so

account     required                                     pam_unix.so

password    requisite                                    pam_pwquality.so
password    sufficient                                   pam_unix.so sha512 shadow nullok use_authtok
password    required                                     pam_deny.so

The automatus tool mark that test as correct because the condition pass but not as expected.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK makes sense

So just please fix the shellcheck issues

sed -i "/^\s*auth.*pam_lastlog\.so[^#]*inactive=35.*/d" "$PAM_FILE_PATH"
for line in "${pam_lastlog_lines[@]}"; do
sed -i "/^\s*auth.*pam_unix\.so.*/i$line" "$PAM_FILE_PATH"
done
fi
if [ -f /usr/bin/authselect ]; then
authselect apply-changes -b --backup=after-hardening-pam_lastlog.so-inactive.backup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ fi
{{{ bash_ensure_pam_module_line("$PAM_FILE_PATH",
'auth',
'sufficient',
'pam_unix.so') }}}
'pam_unix.so',
'^\s*auth.*required.*pam_lastlog\.so.*') }}}
# Ensure pam_unix.so is configured after pam_lastlog.so
if ! grep -Pz \
"auth\s*required\s*pam_lastlog\.so[^#]*inactive=35[\s\S]*\n\s*auth\s*sufficient\s*pam_unix\.so"\
"$PAM_FILE_PATH" ; then
PAM_LASTLOG_LINE="$(grep -oP '^\s*auth.*pam_lastlog\.so.*' $PAM_FILE_PATH)"
sed -i "0,/^\s*auth.*pam_unix\.so.*/i$PAM_LASTLOG_LINE" "$PAM_FILE_PATH"
readarray -t pam_lastlog_lines <<< $(grep -oP '^\s*auth.*pam_lastlog\.so[^#]*inactive=35.*' $PAM_FILE_PATH)
sed -i "/^\s*auth.*pam_lastlog\.so[^#]*inactive=35.*/d" "$PAM_FILE_PATH"
for line in "${pam_lastlog_lines[@]}"; do
sed -i "/^\s*auth.*pam_unix\.so.*/i$line" "$PAM_FILE_PATH"
done
fi
if [ -f /usr/bin/authselect ]; then
authselect apply-changes -b --backup=after-hardening-pam_lastlog.so-inactive.backup
Expand Down
Loading