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

Update Account Home Folder Rules #12465

Merged
merged 5 commits into from
Oct 11, 2024

Conversation

Mab879
Copy link
Member

@Mab879 Mab879 commented Oct 3, 2024

Description:

The following now skip users with home folders defined as /.

  • Macros
    • bash_restrict_permissions_home_directories
    • ansible_restrict_permissions_home_directories
  • Rules
    • accounts_users_home_files_groupownership
    • accounts_users_home_files_ownership

Rationale:

Ensuring the scripts complete successfully with a user doesn't a proper home folder defined.

@Mab879 Mab879 added the bugfix Fixes to reported bugs. label Oct 3, 2024
@Mab879 Mab879 added this to the 0.1.75 milestone Oct 3, 2024
Copy link

github-actions bot commented Oct 3, 2024

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 Oct 3, 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_accounts_users_home_files_groupownership' differs.
--- xccdf_org.ssgproject.content_rule_accounts_users_home_files_groupownership
+++ xccdf_org.ssgproject.content_rule_accounts_users_home_files_groupownership
@@ -1,5 +1,5 @@
 
-for user in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534) print $1 }' /etc/passwd); do
+for user in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534 && $6 != "/") print $1 }' /etc/passwd); do
     home_dir=$(getent passwd $user | cut -d: -f6)
     group=$(getent passwd $user | cut -d: -f4)
     # Only update the group-ownership when necessary. This will avoid changing the inode timestamp

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_users_home_files_groupownership' differs.
--- xccdf_org.ssgproject.content_rule_accounts_users_home_files_groupownership
+++ xccdf_org.ssgproject.content_rule_accounts_users_home_files_groupownership
@@ -34,6 +34,7 @@
   when:
   - item.value[1]|int >= 1000
   - item.value[1]|int != 65534
+  - item.value[4] != "/"
   tags:
   - CCE-86534-5
   - DISA-STIG-RHEL-08-010741

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_users_home_files_ownership' differs.
--- xccdf_org.ssgproject.content_rule_accounts_users_home_files_ownership
+++ xccdf_org.ssgproject.content_rule_accounts_users_home_files_ownership
@@ -1,5 +1,5 @@
 
-for user in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534) print $1 }' /etc/passwd); do
+for user in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534 && $6 != "/") print $1 }' /etc/passwd); do
     home_dir=$(getent passwd $user | cut -d: -f6)
     # Only update the ownership when necessary. This will avoid changing the inode timestamp
     # when the owner is already defined as expected, therefore not impacting in possible integrity

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_users_home_files_ownership' differs.
--- xccdf_org.ssgproject.content_rule_accounts_users_home_files_ownership
+++ xccdf_org.ssgproject.content_rule_accounts_users_home_files_ownership
@@ -32,6 +32,7 @@
   when:
   - item.value[1]|int >= 1000
   - item.value[1]|int != 65534
+  - item.value[4] != "/"
   tags:
   - CCE-87040-2
   - accounts_users_home_files_ownership

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_users_home_files_permissions' differs.
--- xccdf_org.ssgproject.content_rule_accounts_users_home_files_permissions
+++ xccdf_org.ssgproject.content_rule_accounts_users_home_files_permissions
@@ -1,5 +1,5 @@
 
-for home_dir in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534) print $6 }' /etc/passwd); do
+for home_dir in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534 && $6 != "/") print $6 }' /etc/passwd); do
     # Only update the permissions when necessary. This will avoid changing the inode timestamp when
     # the permission is already defined as expected, therefore not impacting in possible integrity
     # check systems that also check inodes timestamps.

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_users_home_files_permissions' differs.
--- xccdf_org.ssgproject.content_rule_accounts_users_home_files_permissions
+++ xccdf_org.ssgproject.content_rule_accounts_users_home_files_permissions
@@ -33,6 +33,7 @@
   when:
   - item.value[1]|int >= 1000
   - item.value[1]|int != 65534
+  - item.value[4] != "/"
   tags:
   - CCE-85888-6
   - DISA-STIG-RHEL-08-010731

bash remediation for rule 'xccdf_org.ssgproject.content_rule_file_permissions_home_directories' differs.
--- xccdf_org.ssgproject.content_rule_file_permissions_home_directories
+++ xccdf_org.ssgproject.content_rule_file_permissions_home_directories
@@ -1,5 +1,5 @@
 
-for home_dir in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534) print $6 }' /etc/passwd); do
+for home_dir in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534 && $6 != "/") print $6 }' /etc/passwd); do
     # Only update the permissions when necessary. This will avoid changing the inode timestamp when
     # the permission is already defined as expected, therefore not impacting in possible integrity
     # check systems that also check inodes timestamps.

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_file_permissions_home_directories' differs.
--- xccdf_org.ssgproject.content_rule_file_permissions_home_directories
+++ xccdf_org.ssgproject.content_rule_file_permissions_home_directories
@@ -33,6 +33,7 @@
   when:
   - item.value[1]|int >= 1000
   - item.value[1]|int != 65534
+  - item.value[4] != "/"
   tags:
   - CCE-84038-9
   - DISA-STIG-RHEL-08-010730

bash remediation for rule 'xccdf_org.ssgproject.content_rule_file_permissions_home_dirs' differs.
--- xccdf_org.ssgproject.content_rule_file_permissions_home_dirs
+++ xccdf_org.ssgproject.content_rule_file_permissions_home_dirs
@@ -1,5 +1,5 @@
 
-for home_dir in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534) print $6 }' /etc/passwd); do
+for home_dir in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534 && $6 != "/") print $6 }' /etc/passwd); do
     # Only update the permissions when necessary. This will avoid changing the inode timestamp when
     # the permission is already defined as expected, therefore not impacting in possible integrity
     # check systems that also check inodes timestamps.

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_file_permissions_home_dirs' differs.
--- xccdf_org.ssgproject.content_rule_file_permissions_home_dirs
+++ xccdf_org.ssgproject.content_rule_file_permissions_home_dirs
@@ -37,6 +37,7 @@
   when:
   - item.value[1]|int >= 1000
   - item.value[1]|int != 65534
+  - item.value[4] != "/"
   tags:
   - CCE-84274-0
   - NIST-800-53-AC-6(1)

Copy link

github-actions bot commented Oct 3, 2024

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

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

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

Copy link
Collaborator

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

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

Can we have a test scenario covering the / situation?

@jan-cerny jan-cerny self-assigned this Oct 4, 2024
@Mab879
Copy link
Member Author

Mab879 commented Oct 8, 2024

Can we have a test scenario covering the / situation?

I'm working on this, it's taking a bit of time to ensure I don't break other rules in the process.

Make sure that script doesn't run on users that don't have
proper home folder defined. This commit makes the script
skip home folders defined as "/".
Make sure that script doesn't run on users that don't have
proper home folder defined. This commit makes the script
skip home folders defined as "/".
Make sure that script doesn't run on users that don't have
proper home folder defined. This commit makes the script
skip home folders defined as "/".
To show the rule will fail and will stay failing as remedating
this situation doesn't make sense as change the permissions on /
isn't a great idea.
@Mab879 Mab879 force-pushed the fix_home_folder_remedations branch from 7c6304c to a7f140d Compare October 10, 2024 18:19
@Mab879
Copy link
Member Author

Mab879 commented Oct 10, 2024

I have added a test scenario. Since there really isn't way to fix the finding other assigning the user a proper home folder, I have disabled the remediation.

Copy link

codeclimate bot commented Oct 10, 2024

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

View more on Code Climate.

Copy link
Collaborator

@jan-cerny jan-cerny left a comment

Choose a reason for hiding this comment

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

jcerny@fedora:~/work/git/scap-security-guide (pr/12465)$ python3 tests/automatus.py  rule --libvirt qemu:///system ssgts_rhel9 accounts_users_home_files_ownership
Setting console output to log level INFO
INFO - The base image option has not been specified, choosing libvirt-based test environment.
INFO - Logging into /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2024-10-11-1412/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_accounts_users_home_files_ownership
INFO - Script expected_owner.pass.sh using profile (all) OK
INFO - Script home_dirs_all_absent.pass.sh using profile (all) OK
INFO - Script home_dirs_one_absent.pass.sh using profile (all) OK
INFO - Script unexpected_owner_system_id.fail.sh using profile (all) OK
INFO - Script unexpected_owner_unknown_id.fail.sh using profile (all) OK
INFO - Script warning_home_dirs_swapped_owner.pass.sh using profile (all) OK
INFO - Script interactive_users_absent.pass.sh using profile (all) OK
INFO - Script interactive_user_nologin_ignored.pass.sh using profile (all) OK
INFO - Script root_fs_home.fail.sh using profile (all) OK
jcerny@fedora:~/work/git/scap-security-guide (pr/12465)$ python3 tests/automatus.py  rule --libvirt qemu:///system ssgts_rhel9 --remediate-using ansible accounts_users_home_files_ownership
Setting console output to log level INFO
INFO - The base image option has not been specified, choosing libvirt-based test environment.
INFO - Logging into /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2024-10-11-1416/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_accounts_users_home_files_ownership
INFO - Script expected_owner.pass.sh using profile (all) OK
INFO - Script home_dirs_all_absent.pass.sh using profile (all) OK
INFO - Script home_dirs_one_absent.pass.sh using profile (all) OK
INFO - Script unexpected_owner_system_id.fail.sh using profile (all) OK
INFO - Script unexpected_owner_unknown_id.fail.sh using profile (all) OK
INFO - Script warning_home_dirs_swapped_owner.pass.sh using profile (all) OK
INFO - Script interactive_users_absent.pass.sh using profile (all) OK
INFO - Script interactive_user_nologin_ignored.pass.sh using profile (all) OK
INFO - Script root_fs_home.fail.sh using profile (all) OK
jcerny@fedora:~/work/git/scap-security-guide (pr/12465)$ python3 tests/automatus.py  rule --libvirt qemu:///system ssgts_rhel9 accounts_users_home_files_groupownership
Setting console output to log level INFO
INFO - The base image option has not been specified, choosing libvirt-based test environment.
INFO - Logging into /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2024-10-11-1418/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_accounts_users_home_files_groupownership
INFO - Script expected_groupowner.pass.sh using profile (all) OK
INFO - Script home_dirs_all_absent.pass.sh using profile (all) OK
INFO - Script home_dirs_one_absent.pass.sh using profile (all) OK
INFO - Script unexpected_groupowner_system_gid.fail.sh using profile (all) OK
INFO - Script unexpected_groupowner_unknown_gid.fail.sh using profile (all) OK
INFO - Script warning_home_dirs_swapped_groupowner.pass.sh using profile (all) OK
INFO - Script interactive_users_absent.pass.sh using profile (all) OK
INFO - Script interactive_user_nologin_ignored.pass.sh using profile (all) OK
INFO - Script root_fs_home.fail.sh using profile (all) OK
jcerny@fedora:~/work/git/scap-security-guide (pr/12465)$ python3 tests/automatus.py  rule --libvirt qemu:///system ssgts_rhel9 --remediate-using ansible accounts_users_home_files_groupownership
Setting console output to log level INFO
INFO - The base image option has not been specified, choosing libvirt-based test environment.
INFO - Logging into /home/jcerny/work/git/scap-security-guide/logs/rule-custom-2024-10-11-1421/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_accounts_users_home_files_groupownership
INFO - Script expected_groupowner.pass.sh using profile (all) OK
INFO - Script home_dirs_all_absent.pass.sh using profile (all) OK
INFO - Script home_dirs_one_absent.pass.sh using profile (all) OK
INFO - Script unexpected_groupowner_system_gid.fail.sh using profile (all) OK
INFO - Script unexpected_groupowner_unknown_gid.fail.sh using profile (all) OK
INFO - Script warning_home_dirs_swapped_groupowner.pass.sh using profile (all) OK
INFO - Script interactive_users_absent.pass.sh using profile (all) OK
INFO - Script interactive_user_nologin_ignored.pass.sh using profile (all) OK
INFO - Script root_fs_home.fail.sh using profile (all) OK

@jan-cerny jan-cerny merged commit babc829 into ComplianceAsCode:master Oct 11, 2024
97 of 100 checks passed
@Mab879 Mab879 deleted the fix_home_folder_remedations branch October 11, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes to reported bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants