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 accounts_user_dot_user/group_ownership to only remediate regular files #13178

Merged
merged 1 commit into from
Mar 17, 2025

Conversation

mpurg
Copy link
Contributor

@mpurg mpurg commented Mar 14, 2025

Description:

  • Fix accounts_user_dot_user_ownership and accounts_user_dot_group_ownership to only remediate regular files

Rationale:

  • Prevents a possible symlink attack where a malicious user creates a symlink in their home directory pointing to sensitive system files

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

openshift-ci bot commented Mar 14, 2025

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

Copy link

github-actions bot commented Mar 14, 2025

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_user_dot_group_ownership' differs.
--- xccdf_org.ssgproject.content_rule_accounts_user_dot_group_ownership
+++ xccdf_org.ssgproject.content_rule_accounts_user_dot_group_ownership
@@ -1,2 +1,2 @@
 
-awk -F: '{if ($4 >= 1000 && $4 != 65534) print $4":"$6}' /etc/passwd | while IFS=: read -r gid home; do find "$home" -maxdepth 1 -name "\.[^.]*" -exec chgrp -f $gid "{}" \;; done
+awk -F: '{if ($4 >= 1000 && $4 != 65534) print $4":"$6}' /etc/passwd | while IFS=: read -r gid home; do find -P "$home" -maxdepth 1 -type f -name "\.[^.]*" -exec chgrp -f --no-dereference -- $gid "{}" \;; done

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_user_dot_group_ownership' differs.
--- xccdf_org.ssgproject.content_rule_accounts_user_dot_group_ownership
+++ xccdf_org.ssgproject.content_rule_accounts_user_dot_group_ownership
@@ -2,8 +2,8 @@
     files
   ansible.builtin.shell:
     cmd: 'awk -F: ''{if ($4 >= 1000 && $4 != 65534) print $4":"$6}'' /etc/passwd |
-      while IFS=: read -r gid home; do find "$home" -maxdepth 1 -name "\.[^.]*" -exec
-      chgrp -f $gid "{}" \;; done'
+      while IFS=: read -r gid home; do find -P "$home" -maxdepth 1 -type f -name "\.[^.]*"
+      -exec chgrp -f --no-dereference -- $gid "{}" \;; done'
   tags:
   - CCE-86314-2
   - accounts_user_dot_group_ownership

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_user_dot_user_ownership' differs.
--- xccdf_org.ssgproject.content_rule_accounts_user_dot_user_ownership
+++ xccdf_org.ssgproject.content_rule_accounts_user_dot_user_ownership
@@ -1,2 +1,2 @@
 
-awk -F: '{if ($3 >= 1000 && $3 != 65534) print $3":"$6}' /etc/passwd | while IFS=: read -r uid home; do find "$home" -maxdepth 1 -name "\.[^.]*" -exec chown -f $uid "{}" \;; done
+awk -F: '{if ($3 >= 1000 && $3 != 65534) print $3":"$6}' /etc/passwd | while IFS=: read -r uid home; do find -P "$home" -maxdepth 1 -type f -name "\.[^.]*" -exec chown -f --no-dereference -- $uid "{}" \;; done

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_user_dot_user_ownership' differs.
--- xccdf_org.ssgproject.content_rule_accounts_user_dot_user_ownership
+++ xccdf_org.ssgproject.content_rule_accounts_user_dot_user_ownership
@@ -2,8 +2,8 @@
     files
   ansible.builtin.shell:
     cmd: 'awk -F: ''{if ($3 >= 1000 && $3 != 65534) print $3":"$6}'' /etc/passwd |
-      while IFS=: read -r uid home; do find "$home" -maxdepth 1 -name "\.[^.]*" -exec
-      chown -f $uid "{}" \;; done'
+      while IFS=: read -r uid home; do find -P "$home" -maxdepth 1 -type f -name "\.[^.]*"
+      -exec chown -f --no-dereference -- $uid "{}" \;; done'
   tags:
   - CCE-86316-7
   - accounts_user_dot_user_ownership

Copy link

Change in Ansible shell module found.

Please consider using more suitable Ansible module than shell if possible.

@mpurg mpurg marked this pull request as draft March 14, 2025 14:14
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label Mar 14, 2025
@mpurg mpurg force-pushed the fix_chown_symlink branch from 145bed5 to ec7d08c Compare March 14, 2025 15:04
Copy link

Change in Ansible shell module found.

Please consider using more suitable Ansible module than shell if possible.

Copy link

codeclimate bot commented Mar 14, 2025

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

View more on Code Climate.

@mpurg mpurg changed the title Disable symlink dereference in accounts_user_dot_user/group_ownership Fix accounts_user_dot_user/group_ownership to only remediate regular files Mar 14, 2025
@mpurg mpurg marked this pull request as ready for review March 14, 2025 17:30
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Mar 14, 2025
@dodys dodys self-assigned this Mar 17, 2025
@dodys dodys added this to the 0.1.77 milestone Mar 17, 2025
@dodys dodys added Ansible Ansible remediation update. Bash Bash remediation update. labels Mar 17, 2025
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
Copy link
Contributor

dodys commented Mar 17, 2025

@ComplianceAsCode/red-hatters
@ComplianceAsCode/suse-maintainers
@ComplianceAsCode/oracle-maintainers
FYI

@dodys dodys merged commit 2c36889 into ComplianceAsCode:master Mar 17, 2025
100 of 102 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ansible Ansible remediation update. 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