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

Improve bash_ensure_pam_module_line macro #9252

Merged

Conversation

marcusburghardt
Copy link
Member

Description:

This macro was previously updated to align to the Ansible equivalent in cases where multiple matches were found, in order to only include a line after the last match. However, in cases where the informed regex have no match, many lines would be included. This patch ensures the same behavior of the Ansible equivalent when there is no match.

Rationale:

Makes the macro more robust and better aligned to the equivalent in Ansible.

This macro was previously updated to align to the Ansible equivalent in
cases where multiple matches were found, in order to only include a line
after the last match. However, in cases where the informed regex have no
match, many lines would be included. This patch ensures the same
behavior of the Ansible equivalent when there is no match.
@marcusburghardt marcusburghardt added bugfix Fixes to reported bugs. Bash Bash remediation update. labels Jul 28, 2022
@marcusburghardt marcusburghardt added this to the 0.1.64 milestone Jul 28, 2022
@github-actions
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

@github-actions
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_accounts_password_pam_pwhistory_remember_password_auth' differs:
--- old datastream
+++ new datastream
@@ -43,7 +43,11 @@
 sed -i -E --follow-symlinks 's/^(\s*password\s+).*(\bpam_pwhistory.so.*)/\1'"$var_password_pam_remember_control_flag"' \2/' "$PAM_FILE_PATH"
 else
 LAST_MATCH_LINE=$(grep -nP "^password.*requisite.*pam_pwquality.so" "$PAM_FILE_PATH" | tail -n 1 | cut -d: -f 1)
- sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"$var_password_pam_remember_control_flag"' pam_pwhistory.so' "$PAM_FILE_PATH"
+ if [ ! -z $LAST_MATCH_LINE ]; then
+ sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"$var_password_pam_remember_control_flag"' pam_pwhistory.so' "$PAM_FILE_PATH"
+ else
+ echo 'password '"$var_password_pam_remember_control_flag"' pam_pwhistory.so' >> "$PAM_FILE_PATH"
+ fi
 fi
 fi
 # Check the option

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_password_pam_pwhistory_remember_system_auth' differs:
--- old datastream
+++ new datastream
@@ -43,7 +43,11 @@
 sed -i -E --follow-symlinks 's/^(\s*password\s+).*(\bpam_pwhistory.so.*)/\1'"$var_password_pam_remember_control_flag"' \2/' "$PAM_FILE_PATH"
 else
 LAST_MATCH_LINE=$(grep -nP "^password.*requisite.*pam_pwquality.so" "$PAM_FILE_PATH" | tail -n 1 | cut -d: -f 1)
- sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"$var_password_pam_remember_control_flag"' pam_pwhistory.so' "$PAM_FILE_PATH"
+ if [ ! -z $LAST_MATCH_LINE ]; then
+ sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"$var_password_pam_remember_control_flag"' pam_pwhistory.so' "$PAM_FILE_PATH"
+ else
+ echo 'password '"$var_password_pam_remember_control_flag"' pam_pwhistory.so' >> "$PAM_FILE_PATH"
+ fi
 fi
 fi
 # Check the option

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_password_pam_unix_remember' differs:
--- old datastream
+++ new datastream
@@ -43,7 +43,11 @@
 sed -i -E --follow-symlinks 's/^(\s*password\s+).*(\bpam_pwhistory.so.*)/\1'"requisite"' \2/' "$PAM_FILE_PATH"
 else
 LAST_MATCH_LINE=$(grep -nP "^password.*requisite.*pam_pwquality.so" "$PAM_FILE_PATH" | tail -n 1 | cut -d: -f 1)
- sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"requisite"' pam_pwhistory.so' "$PAM_FILE_PATH"
+ if [ ! -z $LAST_MATCH_LINE ]; then
+ sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"requisite"' pam_pwhistory.so' "$PAM_FILE_PATH"
+ else
+ echo 'password '"requisite"' pam_pwhistory.so' >> "$PAM_FILE_PATH"
+ fi
 fi
 fi
 # Check the option
@@ -98,7 +102,11 @@
 sed -i -E --follow-symlinks 's/^(\s*password\s+).*(\bpam_pwhistory.so.*)/\1'"requisite"' \2/' "$PAM_FILE_PATH"
 else
 LAST_MATCH_LINE=$(grep -nP "^password.*requisite.*pam_pwquality.so" "$PAM_FILE_PATH" | tail -n 1 | cut -d: -f 1)
- sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"requisite"' pam_pwhistory.so' "$PAM_FILE_PATH"
+ if [ ! -z $LAST_MATCH_LINE ]; then
+ sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"requisite"' pam_pwhistory.so' "$PAM_FILE_PATH"
+ else
+ echo 'password '"requisite"' pam_pwhistory.so' >> "$PAM_FILE_PATH"
+ fi
 fi
 fi
 # Check the option

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_password_pam_pwquality_password_auth' differs:
--- old datastream
+++ new datastream
@@ -39,7 +39,11 @@
 sed -i -E --follow-symlinks 's/^(\s*password\s+).*(\bpam_pwquality.so.*)/\1'"requisite"' \2/' "$PAM_FILE_PATH"
 else
 LAST_MATCH_LINE=$(grep -nP "^account.*required.*pam_permit.so" "$PAM_FILE_PATH" | tail -n 1 | cut -d: -f 1)
- sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"requisite"' pam_pwquality.so' "$PAM_FILE_PATH"
+ if [ ! -z $LAST_MATCH_LINE ]; then
+ sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"requisite"' pam_pwquality.so' "$PAM_FILE_PATH"
+ else
+ echo 'password '"requisite"' pam_pwquality.so' >> "$PAM_FILE_PATH"
+ fi
 fi
 fi
 if [ -f /usr/bin/authselect ]; then

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_password_pam_pwquality_system_auth' differs:
--- old datastream
+++ new datastream
@@ -39,7 +39,11 @@
 sed -i -E --follow-symlinks 's/^(\s*password\s+).*(\bpam_pwquality.so.*)/\1'"requisite"' \2/' "$PAM_FILE_PATH"
 else
 LAST_MATCH_LINE=$(grep -nP "^account.*required.*pam_permit.so" "$PAM_FILE_PATH" | tail -n 1 | cut -d: -f 1)
- sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"requisite"' pam_pwquality.so' "$PAM_FILE_PATH"
+ if [ ! -z $LAST_MATCH_LINE ]; then
+ sed -i --follow-symlinks $LAST_MATCH_LINE' a password '"requisite"' pam_pwquality.so' "$PAM_FILE_PATH"
+ else
+ echo 'password '"requisite"' pam_pwquality.so' >> "$PAM_FILE_PATH"
+ fi
 fi
 fi
 if [ -f /usr/bin/authselect ]; then

@codeclimate
Copy link

codeclimate bot commented Jul 28, 2022

Code Climate has analyzed commit b3d5df8 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 42.7% (0.0% change).

View more on Code Climate.

@marcusburghardt
Copy link
Member Author

/retest

@openshift-ci
Copy link

openshift-ci bot commented Jul 28, 2022

@marcusburghardt: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-rhcos4-moderate b3d5df8 link true /test e2e-aws-rhcos4-moderate
ci/prow/e2e-aws-rhcos4-high b3d5df8 link true /test e2e-aws-rhcos4-high

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@jan-cerny jan-cerny self-assigned this Jul 29, 2022
@jan-cerny jan-cerny merged commit 6c9fcf1 into ComplianceAsCode:master Jul 29, 2022
@marcusburghardt marcusburghardt deleted the ensure_pam_module_line branch July 29, 2022 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bash Bash remediation update. bugfix Fixes to reported bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants