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

Avoid tmpfiles override #12218

Merged

Conversation

alanmcanonical
Copy link
Contributor

Description:

  • Rename the systemd.conf to avoid override /usr/lib/tmpfiles.d/systemd.conf

  • Remove existing line

Rationale:

  • Avoid overriding systemd tmpfile configurations

Copy link

openshift-ci bot commented Jul 24, 2024

Hi @alanmcanonical. 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-sigs/prow repository.

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

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

ubuntu2204 (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 Jul 24, 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_dir_groupowner_system_journal' differs.
--- xccdf_org.ssgproject.content_rule_dir_groupowner_system_journal
+++ xccdf_org.ssgproject.content_rule_dir_groupowner_system_journal
@@ -1,18 +1,20 @@
 # Remediation is applicable only in certain platforms
 if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
 
-TMPFILES_CONF="/etc/tmpfiles.d/systemd.conf"
+TMPFILES_CONF="/usr/lib/tmpfiles.d/systemd.conf"
 
-if grep -qP "^.[+]*\s+\/var\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/var\/log\/journal\s\+[^ $]\+\s\+[^ $]\+\s\+\)\([^ $]\+\)/Z\2systemd-journal/" "$TMPFILES_CONF"
-else
-    echo "Z /var/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /var/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/var\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/var\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /var/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
-if grep -qP "^.[+]*\s+\/run\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/run\/log\/journal\s\+[^ $]\+\s\+[^ $]\+\s\+\)\([^ $]\+\)/Z\2systemd-journal/" "$TMPFILES_CONF"
-else
-    echo "Z /run/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /run/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/run\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/run\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /run/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
 systemd-tmpfiles --create

bash remediation for rule 'xccdf_org.ssgproject.content_rule_dir_owner_system_journal' differs.
--- xccdf_org.ssgproject.content_rule_dir_owner_system_journal
+++ xccdf_org.ssgproject.content_rule_dir_owner_system_journal
@@ -1,18 +1,20 @@
 # Remediation is applicable only in certain platforms
 if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
 
-TMPFILES_CONF="/etc/tmpfiles.d/systemd.conf"
+TMPFILES_CONF="/usr/lib/tmpfiles.d/systemd.conf"
 
-if grep -qP "^.[+]*\s+\/var\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/var\/log\/journal\s\+[^ $]\+\s\+\)\([^ $]\+\)/Z\2root/" "$TMPFILES_CONF"
-else
-    echo "Z /var/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /var/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/var\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/var\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /var/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
-if grep -qP "^.[+]*\s+\/run\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/run\/log\/journal\s\+[^ $]\+\s\+\)\([^ $]\+\)/Z\2root/" "$TMPFILES_CONF"
-else
-    echo "Z /run/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /run/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/run\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/run\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /run/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
 systemd-tmpfiles --create

bash remediation for rule 'xccdf_org.ssgproject.content_rule_dir_permissions_system_journal' differs.
--- xccdf_org.ssgproject.content_rule_dir_permissions_system_journal
+++ xccdf_org.ssgproject.content_rule_dir_permissions_system_journal
@@ -1,18 +1,20 @@
 # Remediation is applicable only in certain platforms
 if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
 
-TMPFILES_CONF="/etc/tmpfiles.d/systemd.conf"
+TMPFILES_CONF="/usr/lib/tmpfiles.d/systemd.conf"
 
-if grep -qP "^.[+]*\s+\/var\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/var\/log\/journal\s\+\)\([^ $]*\)/Z\2~2750/" "$TMPFILES_CONF"
-else
-    echo "Z /var/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /var/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/var\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/var\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /var/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
-if grep -qP "^.[+]*\s+\/run\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/run\/log\/journal\s\+\)\([^ $]*\)/Z\2~2750/" "$TMPFILES_CONF"
-else
-    echo "Z /run/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /run/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/run\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/run\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /run/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
 systemd-tmpfiles --create

bash remediation for rule 'xccdf_org.ssgproject.content_rule_file_groupowner_system_journal' differs.
--- xccdf_org.ssgproject.content_rule_file_groupowner_system_journal
+++ xccdf_org.ssgproject.content_rule_file_groupowner_system_journal
@@ -1,18 +1,20 @@
 # Remediation is applicable only in certain platforms
 if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
 
-TMPFILES_CONF="/etc/tmpfiles.d/systemd.conf"
+TMPFILES_CONF="/usr/lib/tmpfiles.d/systemd.conf"
 
-if grep -qP "^.[+]*\s+\/var\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/var\/log\/journal\s\+[^ $]\+\s\+[^ $]\+\s\+\)\([^ $]\+\)/Z\2systemd-journal/" "$TMPFILES_CONF"
-else
-    echo "Z /var/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /var/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/var\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/var\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /var/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
-if grep -qP "^.[+]*\s+\/run\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/run\/log\/journal\s\+[^ $]\+\s\+[^ $]\+\s\+\)\([^ $]\+\)/Z\2systemd-journal/" "$TMPFILES_CONF"
-else
-    echo "Z /run/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /run/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/run\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/run\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /run/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
 systemd-tmpfiles --create

bash remediation for rule 'xccdf_org.ssgproject.content_rule_file_owner_system_journal' differs.
--- xccdf_org.ssgproject.content_rule_file_owner_system_journal
+++ xccdf_org.ssgproject.content_rule_file_owner_system_journal
@@ -1,18 +1,20 @@
 # Remediation is applicable only in certain platforms
 if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
 
-TMPFILES_CONF="/etc/tmpfiles.d/systemd.conf"
+TMPFILES_CONF="/usr/lib/tmpfiles.d/systemd.conf"
 
-if grep -qP "^.[+]*\s+\/var\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/var\/log\/journal\s\+[^ $]\+\s\+\)\([^ $]\+\)/Z\2root/" "$TMPFILES_CONF"
-else
-    echo "Z /var/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /var/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/var\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/var\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /var/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
-if grep -qP "^.[+]*\s+\/run\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/run\/log\/journal\s\+[^ $]\+\s\+\)\([^ $]\+\)/Z\2root/" "$TMPFILES_CONF"
-else
-    echo "Z /run/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /run/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/run\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/run\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /run/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
 systemd-tmpfiles --create

bash remediation for rule 'xccdf_org.ssgproject.content_rule_file_permissions_system_journal' differs.
--- xccdf_org.ssgproject.content_rule_file_permissions_system_journal
+++ xccdf_org.ssgproject.content_rule_file_permissions_system_journal
@@ -1,18 +1,20 @@
 # Remediation is applicable only in certain platforms
 if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
 
-TMPFILES_CONF="/etc/tmpfiles.d/systemd.conf"
+TMPFILES_CONF="/usr/lib/tmpfiles.d/systemd.conf"
 
-if grep -qP "^.[+]*\s+\/var\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/var\/log\/journal\s\+\)\([^ $]*\)/Z\2~2750/" "$TMPFILES_CONF"
-else
-    echo "Z /var/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /var/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/var\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/var\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /var/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
-if grep -qP "^.[+]*\s+\/run\/log\/journal\s+" "$TMPFILES_CONF"; then
-    sed -i --follow-symlinks "s/\(^.[+]*\)\(\s\+\/run\/log\/journal\s\+\)\([^ $]*\)/Z\2~2750/" "$TMPFILES_CONF"
-else
-    echo "Z /run/log/journal ~2750 root systemd-journal - -" >> "$TMPFILES_CONF"
+if ! grep -q 'Z /run/log/journal ~2750 root systemd-journal - -' "$TMPFILES_CONF"; then
+    if grep -qP "^[zZ][+]*\s+\/run\/log\/journal" "$TMPFILES_CONF"; then
+        sed -i --follow-symlinks "s/\(^[zZ][+]*\)\(\s\+\/run\/log\/journal.*\)/# \1\2/" "$TMPFILES_CONF"
+    fi
+    echo "Z /run/log/journal ~2750 root systemd-journal - -" >>"$TMPFILES_CONF"
 fi
 
 systemd-tmpfiles --create

Copy link

github-actions bot commented Jul 24, 2024

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

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

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

@jan-cerny jan-cerny self-assigned this Jul 24, 2024
@alanmcanonical alanmcanonical force-pushed the avoid-tmpfiles-override branch from 9cf5e3b to e7c7850 Compare July 24, 2024 17:49
@alanmcanonical alanmcanonical marked this pull request as draft July 24, 2024 17:53
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label Jul 24, 2024
@alanmcanonical alanmcanonical force-pushed the avoid-tmpfiles-override branch from e7c7850 to aa658d7 Compare July 24, 2024 20:54
Align with STIG
Avoid override the whole configuration
@alanmcanonical alanmcanonical force-pushed the avoid-tmpfiles-override branch from aa658d7 to 84a9e52 Compare July 27, 2024 09:59
Copy link

codeclimate bot commented Jul 27, 2024

Code Climate has analyzed commit 84a9e52 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.

@marcusburghardt marcusburghardt added the Ubuntu Ubuntu product related. label Jul 31, 2024
@alanmcanonical alanmcanonical marked this pull request as ready for review August 12, 2024 14:41
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Aug 12, 2024
@jan-cerny jan-cerny added this to the 0.1.75 milestone Aug 13, 2024
@jan-cerny jan-cerny added the Bash Bash remediation update. label Aug 13, 2024
@jan-cerny jan-cerny merged commit bce290c into ComplianceAsCode:master Aug 13, 2024
86 of 90 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. needs-ok-to-test Used by openshift-ci bot. Ubuntu Ubuntu product related.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants