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

Issue when using set -e with grep commands #11712

Merged
merged 4 commits into from
Mar 20, 2024

Conversation

2000rosser
Copy link

Description:

Changed two crypto policy remediation scripts to use the grep command in the if statement

Rationale:

grep -q will exit with code 0 if any match is found and returns 1 otherwise. This causes the script to exit if set -e is set. Having the grep command within the if statement fixes this issue.

@openshift-ci openshift-ci bot added the needs-ok-to-test Used by openshift-ci bot. label Mar 14, 2024
Copy link

openshift-ci bot commented Mar 14, 2024

Hi @2000rosser. Thanks for your PR.

I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

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

github-actions bot commented Mar 14, 2024

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_harden_sshd_ciphers_opensshserver_conf_crypto_policy' differs.
--- xccdf_org.ssgproject.content_rule_harden_sshd_ciphers_opensshserver_conf_crypto_policy
+++ xccdf_org.ssgproject.content_rule_harden_sshd_ciphers_opensshserver_conf_crypto_policy
@@ -11,9 +11,7 @@
 # Ensure CRYPTO_POLICY is not commented out
 sed -i 's/#CRYPTO_POLICY=/CRYPTO_POLICY=/' ${CONF_FILE}
 
-grep -q "'${correct_value}'" ${CONF_FILE}
-
-if [[ $? -ne 0 ]]; then
+if ! grep -q "$correct_value" "$CONF_FILE"; then
     # We need to get the existing value, using PCRE to maintain same regex
     existing_value=$(grep -Po '(-oCiphers=\S+)' ${CONF_FILE})
 

bash remediation for rule 'xccdf_org.ssgproject.content_rule_harden_sshd_macs_opensshserver_conf_crypto_policy' differs.
--- xccdf_org.ssgproject.content_rule_harden_sshd_macs_opensshserver_conf_crypto_policy
+++ xccdf_org.ssgproject.content_rule_harden_sshd_macs_opensshserver_conf_crypto_policy
@@ -11,9 +11,7 @@
 # Ensure CRYPTO_POLICY is not commented out
 sed -i 's/#CRYPTO_POLICY=/CRYPTO_POLICY=/' ${CONF_FILE}
 
-grep -q "'${correct_value}'" ${CONF_FILE}
-
-if [[ $? -ne 0 ]]; then
+if ! grep -q "$correct_value" "$CONF_FILE"; then
     # We need to get the existing value, using PCRE to maintain same regex
     existing_value=$(grep -Po '(-oMACs=\S+)' ${CONF_FILE})
 

@marcusburghardt marcusburghardt self-assigned this Mar 15, 2024
@marcusburghardt marcusburghardt added the Bash Bash remediation update. label Mar 15, 2024
Copy link

github-actions bot commented Mar 15, 2024

🤖 A k8s content image for this PR is available at:
ghcr.io/complianceascode/k8scontent:11712
This image was built from commit: f5cb12c

Click here to see how to deploy it

If you alread have Compliance Operator deployed:
utils/build_ds_container.py -i ghcr.io/complianceascode/k8scontent:11712

Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and:
CONTENT_IMAGE=ghcr.io/complianceascode/k8scontent:11712 make deploy-local

@marcusburghardt
Copy link
Member

These rules are not part of SLE15 profiles, so the Automatus SLE15 / Run Tests (pull_request) can be waived.

Regarding the Automatus Fedora / Run Tests (pull_request) test, it is happening because the content of /etc/crypto-policies/back-ends/opensshserver.config file is different on latest Fedora and RHEL9 when compared to RHEL8.
All checks, remediation and test scenarios in these rules are aligned, so it is expected they fail in latest Fedora. We can waive this test as well.

@2000rosser
Copy link
Author

In that case I'll revert the previous commit as it doesnt seem to have made any difference.

Copy link

codeclimate bot commented Mar 19, 2024

Code Climate has analyzed commit f5cb12c 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 59.3% (-0.5% change).

View more on Code Climate.

@marcusburghardt marcusburghardt added this to the 0.1.73 milestone Mar 20, 2024
Copy link
Member

@marcusburghardt marcusburghardt left a comment

Choose a reason for hiding this comment

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

LGTM. Tests also finished successfully in local VMs. Thanks for the contribution.

@marcusburghardt marcusburghardt merged commit c4b2797 into ComplianceAsCode:master Mar 20, 2024
36 of 39 checks passed
@2000rosser 2000rosser deleted the set-e-issue branch March 20, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bash Bash remediation update. needs-ok-to-test Used by openshift-ci bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants