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

[Ubuntu2404] Fix remediation of rule accounts_user_dot_group_ownership #13027

Conversation

alanmcanonical
Copy link
Contributor

Description:

  • Use find instead globbing inside awk
  • Change occurrence of uid into gid

Rationale:

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

openshift-ci bot commented Feb 11, 2025

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.

@alanmcanonical
Copy link
Contributor Author

@dodys Please have a look.

Copy link

github-actions bot commented Feb 11, 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 ($3 >= 1000 && $3 != 65534) system("chgrp -f " $4" "$6"/.[^\.]?*") }' /etc/passwd
+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

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
@@ -1,8 +1,9 @@
 - name: Ensure interactive local users are the group-owners of their respective initialization
     files
-  ansible.builtin.command:
-    cmd: awk -F':' '{ if ($3 >= 1000 && $3 != 65534) system("chgrp -f " $4" "$6"/.[^\.]?*")
-      }' /etc/passwd
+  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'
   tags:
   - CCE-86314-2
   - accounts_user_dot_group_ownership

Copy link

Change in Ansible shell module found.

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

@@ -4,4 +4,4 @@
# complexity = low
# disruption = low

awk -F':' '{ if ($3 >= {{{ uid_min }}} && $3 != {{{ nobody_uid }}}) system("chgrp -f " $4" "$6"/.[^\.]?*") }' /etc/passwd
awk -F':' '{ if ($4 >= {{{ gid_min }}} && $4 != {{{ nobody_gid }}}) system("find "$6" -maxdepth 1 -name \.[^.]?* -exec chgrp -f "$4" {} \;") }' /etc/passwd
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason for the ? in the regex? I think it should be \.[^.]*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right.

@dodys dodys self-assigned this Feb 12, 2025
@dodys dodys added the Ubuntu Ubuntu product related. label Feb 12, 2025
@dodys dodys added this to the 0.1.77 milestone Feb 12, 2025
@dodys dodys added the CIS CIS Benchmark related. label Feb 12, 2025
Copy link

Change in Ansible shell module found.

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

1 similar comment
Copy link

Change in Ansible shell module found.

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

@alanmcanonical alanmcanonical force-pushed the fix_accounts_user_dot_group_ownership branch from f95548e to 99d2959 Compare February 12, 2025 18:15
Copy link

Change in Ansible shell module found.

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

Copy link

codeclimate bot commented Feb 12, 2025

Code Climate has analyzed commit 99d2959 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.

@dodys
Copy link
Contributor

dodys commented Feb 13, 2025

@Mab879 @vojtapolasek could youalso take a look on this PR as it will also affect you, specifically the ansible

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 a22ce4a into ComplianceAsCode:master Feb 14, 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
CIS CIS Benchmark related. 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