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

Add root user to interactive users #11729

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

jan-cerny
Copy link
Collaborator

The rule file_permission_user_init_files now checks only dot files of users with UID greater than or equal 1000. But according to RHEL 9 STIG and CIS benchmarks it should check also the root user's dot files. This commit extends the rule to account also for the root user and adds a simple test scenario covering this situation.

Fixes #11699

@jan-cerny jan-cerny added bugfix Fixes to reported bugs. Ansible Ansible remediation update. OVAL OVAL update. Related to the systems assessments. Bash Bash remediation update. STIG STIG Benchmark related. labels Mar 19, 2024
@jan-cerny jan-cerny added this to the 0.1.73 milestone Mar 19, 2024
Copy link

github-actions bot commented Mar 19, 2024

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

rhel9 (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 Mar 19, 2024

This datastream diff is auto generated by the check Compare DS/Generate Diff

Click here to see the full diff
New content has different text for rule 'xccdf_org.ssgproject.content_rule_file_permission_user_init_files'.
--- xccdf_org.ssgproject.content_rule_file_permission_user_init_files
+++ xccdf_org.ssgproject.content_rule_file_permission_user_init_files
@@ -16,12 +16,6 @@
 [reference]:
 R50
 
-[reference]:
-RHEL-09-232045
-
-[reference]:
-SV-257889r925654_rule
-
 [rationale]:
 Local initialization files are used to configure the user's shell environment
 upon logon. Malicious modification of these files could compromise accounts upon

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_file_permission_user_init_files' differs.
--- xccdf_org.ssgproject.content_rule_file_permission_user_init_files
+++ xccdf_org.ssgproject.content_rule_file_permission_user_init_files
@@ -10,7 +10,6 @@
     database: passwd
   tags:
   - CCE-83637-9
-  - DISA-STIG-RHEL-09-232045
   - file_permission_user_init_files
   - low_complexity
   - low_disruption
@@ -33,7 +32,6 @@
   register: found_init_files
   tags:
   - CCE-83637-9
-  - DISA-STIG-RHEL-09-232045
   - file_permission_user_init_files
   - low_complexity
   - low_disruption
@@ -50,7 +48,6 @@
     {''skip_missing'': True}) }}'
   tags:
   - CCE-83637-9
-  - DISA-STIG-RHEL-09-232045
   - file_permission_user_init_files
   - low_complexity
   - low_disruption

Copy link

github-actions bot commented Mar 19, 2024

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

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

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

@Mab879 Mab879 self-assigned this Mar 19, 2024
@Mab879
Copy link
Member

Mab879 commented Mar 20, 2024

Tests pass locally

$ ./automatus.py rule --datastream ../build/ssg-rhel9-ds.xml --libvirt qemu:///system automatus_rhel9_4 file_permission_user_init_files
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/mburket/Developer/ComplianceAsCode/content/tests/logs/rule-custom-2024-03-19-1855/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_file_permission_user_init_files
INFO - Script all_permissions.fail.sh using profile (all) OK
INFO - Script correct_permissions.pass.sh using profile (all) OK
INFO - Script different_home_correct_permissions.pass.sh using profile (all) OK
INFO - Script different_home_wrong_permissions.fail.sh using profile (all) OK
INFO - Script lenient_permissions.fail.sh using profile (all) OK
INFO - Script stricter_permissions.pass.sh using profile (all) OK
INFO - Script lenient_permissions_root.fail.sh using profile (all) OK
$ ./automatus.py rule --datastream ../build/ssg-rhel9-ds.xml --libvirt qemu:///system automatus_rhel9_4 file_permission_user_init_files
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/mburket/Developer/ComplianceAsCode/content/tests/logs/rule-custom-2024-03-19-1855/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_file_permission_user_init_files
INFO - Script all_permissions.fail.sh using profile (all) OK
INFO - Script correct_permissions.pass.sh using profile (all) OK
INFO - Script different_home_correct_permissions.pass.sh using profile (all) OK
INFO - Script different_home_wrong_permissions.fail.sh using profile (all) OK
INFO - Script lenient_permissions.fail.sh using profile (all) OK
INFO - Script stricter_permissions.pass.sh using profile (all) OK
INFO - Script lenient_permissions_root.fail.sh using profile (all) OK

</set>
</unix:password_object>

<unix:password_object id="{{{ object_id }}}_root" version="1">
Copy link
Member

Choose a reason for hiding this comment

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

There are more rules using this macro. We should ensure the remediation on them are aligned to the OVAL assessment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes already working on it

Copy link
Member

@Mab879 Mab879 left a comment

Choose a reason for hiding this comment

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

The scan has option for root, but the remediation doesn't. Is that expected.

readarray -t interactive_users < <(awk -F: '$3>={{{ uid_min }}} {print $1}' /etc/passwd)
readarray -t interactive_users_home < <(awk -F: '$3>={{{ uid_min }}} {print $6}' /etc/passwd)
readarray -t interactive_users_shell < <(awk -F: '$3>={{{ uid_min }}} {print $7}' /etc/passwd)
readarray -t interactive_users < <(awk -F: '$3==0 || $3>={{{ uid_min }}} {print $1}' /etc/passwd)
Copy link
Member

Choose a reason for hiding this comment

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

This always checks root do we want that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think yes - I think that is the point of the issue that the root's files were not evaluated and were not remediatied.

Copy link
Member

@Mab879 Mab879 left a comment

Choose a reason for hiding this comment

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

The testing farm failure for RHEL 7 looks valid, please take look.

@jan-cerny
Copy link
Collaborator Author

The rule passes after first remediation and passes after second remediation but suddenly it fails in the final scan. I suspect something happens during the third reboot. I will try to identify the cause.

@jan-cerny
Copy link
Collaborator Author

The problem is that it conflicts with the rule rpm_verify_permissions. The root's dot files are owned by the rootfiles RPM package and they're shipped with different permissions. The first remediation changes the permissions in the code for rule file_permission_user_init_files, but that makes the rule rpm_verify_permissions fail and this fail is fixed during the second remediation and that makes the rule file_permission_user_init_files fail.

@jan-cerny
Copy link
Collaborator Author

We're trying to fix a RHEL 9 STIG misalignement. But the conflict with rpm_verify_permissions happens on RHEL 7. The reason is that RHEL 9 STIG doesn't contain rpm_verify_permissions. So we can solve this situation this way: We won't change rule file_permission_user_init_files. We will create a new rule that will be similar but will check the root files. We will replace the file_permission_user_init_files in RHEL 9 STIG with the new rule. We will select the new rule only in RHEL 9 STIG. This way, we won't break other products. What do you think?

@Mab879
Copy link
Member

Mab879 commented Mar 22, 2024

We're trying to fix a RHEL 9 STIG misalignement. But the conflict with rpm_verify_permissions happens on RHEL 7. The reason is that RHEL 9 STIG doesn't contain rpm_verify_permissions. So we can solve this situation this way: We won't change rule file_permission_user_init_files. We will create a new rule that will be similar but will check the root files. We will replace the file_permission_user_init_files in RHEL 9 STIG with the new rule. We will select the new rule only in RHEL 9 STIG. This way, we won't break other products. What do you think?

That seems like a fine solution.

@jan-cerny
Copy link
Collaborator Author

OK I will proceed with my proposal

The rule file_permission_user_init_files now checks only dot files of
users with UID greater than or equal 1000. But according to RHEL 9 STIG
and CIS benchmarks it should check also the root user's dot files.

This commit creates a new rule file_permission_user_init_files_root
which is almost the same as file_permission_user_init_files, but the
new rule accounts also for the root user and his init files.

We also change the OVAL jinja macro. This change will include the root
user to the user list only if needed. We will use the root in the rule
file_permission_user_init_file. But we will not use the root in
accounts_user_interactive_home_directory_defined where we keep the old
behavior.

The commit also adds a simple test scenario covering this situation.

Fixes: ComplianceAsCode#11699
Copy link

codeclimate bot commented Mar 26, 2024

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

View more on Code Climate.

Copy link
Member

@Mab879 Mab879 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

@Mab879 Mab879 merged commit ad141d4 into ComplianceAsCode:master Mar 26, 2024
43 of 44 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. bugfix Fixes to reported bugs. OVAL OVAL update. Related to the systems assessments. STIG STIG Benchmark related.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

file_permission_user_init_files is misaligned with DISA
3 participants