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

Fix display_login_attempts #12603

Merged
merged 1 commit into from
Nov 13, 2024
Merged

Conversation

jan-cerny
Copy link
Collaborator

Due to the change in Bash Jinja macros introduced by #12600 the regular expressions in Bash remediation in rule display_login_attempts have been broken. The escaping of the control parameter is now done inside bash_ensure_pam_module_option and therefore the bash remediation should pass the control parameter without escaping.

Due to the change in Bash Jinja macros introduced by
ComplianceAsCode#12600 the regular
expressions in Bash remediation in rule `display_login_attempts` have
been broken. The escaping of the `control` parameter is now done inside
`bash_ensure_pam_module_option` and therefore the bash remediation
should pass the `control` parameter without escaping.
@jan-cerny jan-cerny added the Bash Bash remediation update. label Nov 13, 2024
@jan-cerny jan-cerny added this to the 0.1.76 milestone Nov 13, 2024
Copy link

Start a new ephemeral environment with changes proposed in this pull request:

rhel8 (from CTF) Environment (using Fedora as testing environment)
Open in Gitpod

Fedora Testing Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

Copy link

This datastream diff is auto generated by the check Compare DS/Generate Diff

Click here to see the full diff
bash remediation for rule 'xccdf_org.ssgproject.content_rule_display_login_attempts' differs.
--- xccdf_org.ssgproject.content_rule_display_login_attempts
+++ xccdf_org.ssgproject.content_rule_display_login_attempts
@@ -79,23 +79,23 @@
             fi
             
 
-                if ! grep -qP "^\s*session\s+\\[default=1\\]\s+pam_lastlog.so\s*.*" "$PAM_FILE_PATH"; then
+                if ! grep -qP "^\s*session\s+\[default=1\]\s+pam_lastlog.so\s*.*" "$PAM_FILE_PATH"; then
                     # Line matching group + control + module was not found. Check group + module.
                     if [ "$(grep -cP '^\s*session\s+.*\s+pam_lastlog.so\s*' "$PAM_FILE_PATH")" -eq 1 ]; then
                         # The control is updated only if one single line matches.
-                        sed -i -E --follow-symlinks "s/^(\s*session\s+).*(\bpam_lastlog.so.*)/\1\[default=1\] \2/" "$PAM_FILE_PATH"
+                        sed -i -E --follow-symlinks "s/^(\s*session\s+).*(\bpam_lastlog.so.*)/\1[default=1] \2/" "$PAM_FILE_PATH"
                     else
                         LAST_MATCH_LINE=$(grep -nP "^\s*session\s+.*pam_succeed_if\.so.*" "$PAM_FILE_PATH" | tail -n 1 | cut -d: -f 1)
                         if [ ! -z $LAST_MATCH_LINE ]; then
-                            sed -i --follow-symlinks $LAST_MATCH_LINE" a session     \[default=1\]    pam_lastlog.so" "$PAM_FILE_PATH"
+                            sed -i --follow-symlinks $LAST_MATCH_LINE" a session     [default=1]    pam_lastlog.so" "$PAM_FILE_PATH"
                         else
-                            echo "session    \[default=1\]    pam_lastlog.so" >> "$PAM_FILE_PATH"
+                            echo "session    [default=1]    pam_lastlog.so" >> "$PAM_FILE_PATH"
                         fi
                     fi
                 fi
                 # Check the option
-                if ! grep -qP "^\s*session\s+\\[default=1\\]\s+pam_lastlog.so\s*.*\sshowfailed\b" "$PAM_FILE_PATH"; then
-                    sed -i -E --follow-symlinks "/\s*session\s+\\[default=1\\]\s+pam_lastlog.so.*/ s/$/ showfailed/" "$PAM_FILE_PATH"
+                if ! grep -qP "^\s*session\s+\[default=1\]\s+pam_lastlog.so\s*.*\sshowfailed\b" "$PAM_FILE_PATH"; then
+                    sed -i -E --follow-symlinks "/\s*session\s+\[default=1\]\s+pam_lastlog.so.*/ s/$/ showfailed/" "$PAM_FILE_PATH"
                 fi
             if [ -f /usr/bin/authselect ]; then
                 
@@ -138,8 +138,8 @@
                 authselect apply-changes -b
             fi
             
-        if grep -qP "^\s*session\s+\[default=1\]\s+pam_lastlog.so\s.*\bsilent\b" "$PAM_FILE_PATH"; then
-            sed -i -E --follow-symlinks "s/(.*session.*\[default=1\].*pam_lastlog.so.*)\ssilent=?[[:alnum:]]*(.*)/\1\2/g" "$PAM_FILE_PATH"
+        if grep -qP "^\s*session\s+[default=1]\s+pam_lastlog.so\s.*\bsilent\b" "$PAM_FILE_PATH"; then
+            sed -i -E --follow-symlinks "s/(.*session.*[default=1].*pam_lastlog.so.*)\ssilent=?[[:alnum:]]*(.*)/\1\2/g" "$PAM_FILE_PATH"
         fi
             if [ -f /usr/bin/authselect ]; then
                 
@@ -185,23 +185,23 @@
             fi
             
 
-                if ! grep -qP "^\s*session\s+\\[default=1\\]\s+pam_lastlog.so\s*.*" "$PAM_FILE_PATH"; then
+                if ! grep -qP "^\s*session\s+\[default=1\]\s+pam_lastlog.so\s*.*" "$PAM_FILE_PATH"; then
                     # Line matching group + control + module was not found. Check group + module.
                     if [ "$(grep -cP '^\s*session\s+.*\s+pam_lastlog.so\s*' "$PAM_FILE_PATH")" -eq 1 ]; then
                         # The control is updated only if one single line matches.
-                        sed -i -E --follow-symlinks "s/^(\s*session\s+).*(\bpam_lastlog.so.*)/\1\[default=1\] \2/" "$PAM_FILE_PATH"
+                        sed -i -E --follow-symlinks "s/^(\s*session\s+).*(\bpam_lastlog.so.*)/\1[default=1] \2/" "$PAM_FILE_PATH"
                     else
                         LAST_MATCH_LINE=$(grep -nP "^\s*session\s+.*pam_succeed_if\.so.*" "$PAM_FILE_PATH" | tail -n 1 | cut -d: -f 1)
                         if [ ! -z $LAST_MATCH_LINE ]; then
-                            sed -i --follow-symlinks $LAST_MATCH_LINE" a session     \[default=1\]    pam_lastlog.so" "$PAM_FILE_PATH"
+                            sed -i --follow-symlinks $LAST_MATCH_LINE" a session     [default=1]    pam_lastlog.so" "$PAM_FILE_PATH"
                         else
-                            echo "session    \[default=1\]    pam_lastlog.so" >> "$PAM_FILE_PATH"
+                            echo "session    [default=1]    pam_lastlog.so" >> "$PAM_FILE_PATH"
                         fi
                     fi
                 fi
                 # Check the option
-                if ! grep -qP "^\s*session\s+\\[default=1\\]\s+pam_lastlog.so\s*.*\sshowfailed\b" "$PAM_FILE_PATH"; then
-                    sed -i -E --follow-symlinks "/\s*session\s+\\[default=1\\]\s+pam_lastlog.so.*/ s/$/ showfailed/" "$PAM_FILE_PATH"
+                if ! grep -qP "^\s*session\s+\[default=1\]\s+pam_lastlog.so\s*.*\sshowfailed\b" "$PAM_FILE_PATH"; then
+                    sed -i -E --follow-symlinks "/\s*session\s+\[default=1\]\s+pam_lastlog.so.*/ s/$/ showfailed/" "$PAM_FILE_PATH"
                 fi
             if [ -f /usr/bin/authselect ]; then
                 
@@ -244,8 +244,8 @@
                 authselect apply-changes -b
             fi
             
-        if grep -qP "^\s*session\s+\[default=1\]\s+pam_lastlog.so\s.*\bsilent\b" "$PAM_FILE_PATH"; then
-            sed -i -E --follow-symlinks "s/(.*session.*\[default=1\].*pam_lastlog.so.*)\ssilent=?[[:alnum:]]*(.*)/\1\2/g" "$PAM_FILE_PATH"
+        if grep -qP "^\s*session\s+[default=1]\s+pam_lastlog.so\s.*\bsilent\b" "$PAM_FILE_PATH"; then
+            sed -i -E --follow-symlinks "s/(.*session.*[default=1].*pam_lastlog.so.*)\ssilent=?[[:alnum:]]*(.*)/\1\2/g" "$PAM_FILE_PATH"
         fi
             if [ -f /usr/bin/authselect ]; then
                 

Copy link

codeclimate bot commented Nov 13, 2024

Code Climate has analyzed commit 7f4ef13 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 60.9% (0.0% change).

View more on Code Climate.

@Mab879 Mab879 self-assigned this Nov 13, 2024
@Mab879 Mab879 merged commit 5d0bbe0 into ComplianceAsCode:master Nov 13, 2024
103 of 105 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bash Bash remediation update.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants