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 new rule for rootfiles package #13134

Merged
merged 8 commits into from
Mar 10, 2025

Conversation

Mab879
Copy link
Member

@Mab879 Mab879 commented Mar 3, 2025

Description:
Add rules to ensure that root's init files created by the rootfiles package are correctly configured.

Rationale:
Fixes #13100

@Mab879 Mab879 added RHEL Red Hat Enterprise Linux product related. New Rule Issues or pull requests related to new Rules. Update Profile Issues or pull requests related to Profiles updates. STIG STIG Benchmark related. labels Mar 3, 2025
@Mab879 Mab879 added this to the 0.1.77 milestone Mar 3, 2025
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Used by openshift-ci bot. label Mar 3, 2025
Copy link

openshift-ci bot commented Mar 3, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@Mab879 Mab879 marked this pull request as ready for review March 3, 2025 18:40
@Mab879 Mab879 requested a review from a team as a code owner March 3, 2025 18:40
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Used by openshift-ci bot. label Mar 3, 2025
Comment on lines 25 to 26
}}}$
</ind:pattern>
Copy link
Collaborator

Choose a reason for hiding this comment

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

All automatus tests fail. It's caused by the newline and spaces between the $ and </ind:pattern>.

<def-group>
<definition class="compliance" id="{{{ rule_id }}}" version="1">
{{{ oval_metadata("Ensure that tmpfiles for rootfiles is configured correctly.") }}}]
<criteria operator="AND" comment="Ensure that">
Copy link
Collaborator

Choose a reason for hiding this comment

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

the comment is incomplete

C /root/.bash_profile 644 root root - /usr/share/rootfiles/.bash_profile
C /root/.bashrc 644 root root - /usr/share/rootfiles/.bashrc
C /root/.cshrc 644 root root - /usr/share/rootfiles/.cshrc
C /root/.tcshrc 644 root root - /usr/share/rootfiles/.tcshrc
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the Bash remediation is applied, the result is the following:

[root@localhost ~]# cat /etc/tmpfiles.d/rootconf.conf
C /root/.bash_logout   644 root root - /usr/share/rootfiles/.bash_logout
C /root/.bash_profile  644 root root - /usr/share/rootfiles/.bash_profile
C /root/.bashrc        644 root root - /usr/share/rootfiles/.bashrc
C /root/.cshrc         644 root root - /usr/share/rootfiles/.cshrc
C /root/.tcshrc        644 root root - /usr/share/rootfiles/.tcshrc
C /root/.bash_logout 600 root root - /usr/share/rootfiles/.bash_logout
C /root/.bash_profile 600 root root - /usr/share/rootfiles/.bash_profile
C /root/.bashrc 600 root root - /usr/share/rootfiles/.bashrc
C /root/.cshrc 600 root root - /usr/share/rootfiles/.cshrc
C /root/.tcshrc 600 root root - /usr/share/rootfiles/.tcshrc

This isn't expected - the items should be replaced instead of added.

(Ansible remediation seems to work correctly).

Comment on lines 6 to 8
To set the mode of the root user initialization file <tt>/root/.bash_profile</tt>,
ensure the following line is is included in a file ending in <tt>.conf</tt> under
<tt>/etc/tmpfiles.d/</tt>.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This part of the description is about a single file and about a single line but then it adds multiple files and multiple lines. Please reword.

@@ -0,0 +1,33 @@
documentation_complete: true

title: "Ensure rootfiles tmpfile.d is configured correctly"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Capitals

@jan-cerny jan-cerny self-assigned this Mar 4, 2025
Mab879 added 2 commits March 5, 2025 12:51
* Ensure that only one configuration exists
* Adjust PR based on feedback
references:
disa: CCI-000366
srg: SRG-OS-000480-GPOS-00227

Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing OCIL, OCIL clause and fixtext. This makes the thin data stream for this rule invalid. (It's unfortunate that we don't test this).

# strategy = configure
# complexity = low
# disruption = low

Copy link
Collaborator

Choose a reason for hiding this comment

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

The test scenarios fail for me if Bash remediation is used:

jcerny@fedora:~/work/git/scap-security-guide (pr/13134)$ python3  tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 rootfiles_configured
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-2025-03-06-0845/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_rootfiles_configured
INFO - Script configured_wrong.fail.sh using profile (all) OK
ERROR - Rule evaluation resulted in error, instead of expected fixed during remediation stage 
ERROR - The remediation failed for rule 'xccdf_org.ssgproject.content_rule_rootfiles_configured'.
INFO - Script conflicting.fail.sh using profile (all) OK
ERROR - Rule evaluation resulted in error, instead of expected fixed during remediation stage 
ERROR - The remediation failed for rule 'xccdf_org.ssgproject.content_rule_rootfiles_configured'.
INFO - Script file_not_there.fail.sh using profile (all) OK
INFO - Script missing_some.fail.sh using profile (all) OK
INFO - Script valid.pass.sh using profile (all) OK

I can see this suspicious message in the results:

sed: no input files
sed: no input files
sed: no input files
sed: no input files
sed: no input files

Copy link

codeclimate bot commented Mar 6, 2025

Code Climate has analyzed commit 2dcb09a 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 62.1% (0.0% change).

View more on Code Climate.

@Mab879
Copy link
Member Author

Mab879 commented Mar 7, 2025

/packit build

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.

I have run automatus tests on RHEL 9.

jcerny@fedora:~/work/git/scap-security-guide (pr/13134)$ python3  tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 rootfiles_configured
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-2025-03-10-1306/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_rootfiles_configured
INFO - Script configured_wrong.fail.sh using profile (all) OK
INFO - Script conflicting.fail.sh using profile (all) OK
INFO - Script file_not_there.fail.sh using profile (all) OK
INFO - Script missing_some.fail.sh using profile (all) OK
INFO - Script valid.pass.sh using profile (all) OK
jcerny@fedora:~/work/git/scap-security-guide (pr/13134)$ python3  tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 --remediate-using ansible rootfiles_configured
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-2025-03-10-1309/test_suite.log
INFO - xccdf_org.ssgproject.content_rule_rootfiles_configured
INFO - Script configured_wrong.fail.sh using profile (all) OK
INFO - Script conflicting.fail.sh using profile (all) OK
INFO - Script file_not_there.fail.sh using profile (all) OK
INFO - Script missing_some.fail.sh using profile (all) OK
INFO - Script valid.pass.sh using profile (all) OK

@jan-cerny jan-cerny merged commit 398b847 into ComplianceAsCode:master Mar 10, 2025
106 of 111 checks passed
@Mab879 Mab879 deleted the fix_13100_2 branch March 10, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Rule Issues or pull requests related to new Rules. RHEL Red Hat Enterprise Linux product related. STIG STIG Benchmark related. Update Profile Issues or pull requests related to Profiles updates.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule file_permission_user_init_files_root fails to remediate
2 participants