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 config paths and regex for auditd_audispd_configure_remote_server #11857

Merged
merged 3 commits into from
Apr 30, 2024

Conversation

mpurg
Copy link
Contributor

@mpurg mpurg commented Apr 19, 2024

Description:

  • Defined config paths and packages for audisp on Ubuntu
  • Changed OVAL and remediation for auditd_audispd_configure_remote_server to allow case-insensitive keywords
  • Added tests for auditd_audispd_configure_remote_server for Ubuntu

Rationale:

  • Fixed broken config paths/packages
  • Better alignment with STIG rule UBTU-22-653020

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

openshift-ci bot commented Apr 19, 2024

Hi @mpurg. 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

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_auditd_audispd_configure_remote_server' differs.
--- xccdf_org.ssgproject.content_rule_auditd_audispd_configure_remote_server
+++ xccdf_org.ssgproject.content_rule_auditd_audispd_configure_remote_server
@@ -8,27 +8,21 @@
 
 
 
-# Strip any search characters in the key arg so that the key can be replaced without
-# adding any search characters to the config file.
-stripped_key=$(sed 's/[\^=\$,;+]*//g' <<< "^remote_server")
+if [ -e "$AUDITCONFIG" ] ; then
+    
+    LC_ALL=C sed -i "/^\s*remote_server\s*=\s*/Id" "$AUDITCONFIG"
+else
+    printf '%s\n' "Path '$AUDITCONFIG' wasn't found on this system. Refusing to continue." >&2
+    return 1
+fi
+# make sure file has newline at the end
+sed -i -e '$a\' "$AUDITCONFIG"
 
-# shellcheck disable=SC2059
-printf -v formatted_output "%s = %s" "$stripped_key" "$var_audispd_remote_server"
-
-# If the key exists, change it. Otherwise, add it to the config_file.
-# We search for the key string followed by a word boundary (matched by \>),
-# so if we search for 'setting', 'setting2' won't match.
-if LC_ALL=C grep -q -m 1 -i -e "^remote_server\\>" "$AUDITCONFIG"; then
-    escaped_formatted_output=$(sed -e 's|/|\\/|g' <<< "$formatted_output")
-    LC_ALL=C sed -i --follow-symlinks "s/^remote_server\\>.*/$escaped_formatted_output/gi" "$AUDITCONFIG"
-else
-    if [[ -s "$AUDITCONFIG" ]] && [[ -n "$(tail -c 1 -- "$AUDITCONFIG" || true)" ]]; then
-        LC_ALL=C sed -i --follow-symlinks '$a'\\ "$AUDITCONFIG"
-    fi
-    cce="CCE-80925-1"
-    printf '# Per %s: Set %s in %s\n' "${cce}" "${formatted_output}" "$AUDITCONFIG" >> "$AUDITCONFIG"
-    printf '%s\n' "$formatted_output" >> "$AUDITCONFIG"
-fi
+cp "$AUDITCONFIG" "$AUDITCONFIG.bak"
+# Insert at the end of the file
+printf '%s\n' "remote_server = $var_audispd_remote_server" >> "$AUDITCONFIG"
+# Clean up after ourselves.
+rm "$AUDITCONFIG.bak"
 
 else
     >&2 echo 'Remediation is not applicable, nothing was done'

Copy link

github-actions bot commented Apr 19, 2024

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

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:11857

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

@marcusburghardt marcusburghardt added Ubuntu Ubuntu product related. STIG STIG Benchmark related. labels Apr 22, 2024
@dodys dodys self-assigned this Apr 26, 2024
@dodys dodys requested a review from a team April 26, 2024 11:20
@dodys dodys added ok-to-test Used by openshift-ci bot. and removed needs-ok-to-test Used by openshift-ci bot. labels Apr 26, 2024
@dodys
Copy link
Contributor

dodys commented Apr 30, 2024

@mpurg there are some test failures, could you please investigate?

@mpurg mpurg requested a review from a team as a code owner April 30, 2024 10:32
@mpurg
Copy link
Contributor Author

mpurg commented Apr 30, 2024

@dodys , should work now. I updated tests/data/product_stability/ubuntu2004.yml.

Copy link

codeclimate bot commented Apr 30, 2024

Code Climate has analyzed commit 5ec6469 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.4% (0.0% change).

View more on Code Climate.

Copy link
Contributor

@dodys dodys left a comment

Choose a reason for hiding this comment

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

lgtm, thanks

@dodys dodys merged commit 5259e14 into ComplianceAsCode:master Apr 30, 2024
109 of 113 checks passed
@Mab879 Mab879 added this to the 0.1.74 milestone Apr 30, 2024
@Mab879 Mab879 added OVAL OVAL update. Related to the systems assessments. Bash Bash remediation update. labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bash Bash remediation update. ok-to-test Used by openshift-ci bot. OVAL OVAL update. Related to the systems assessments. STIG STIG Benchmark related. Ubuntu Ubuntu product related.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants