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

accounts_umask_etc_bashrc: extend handled cases of umask #11822

Merged

Conversation

vojtapolasek
Copy link
Collaborator

Description:

  • extend regex in OVAL, Bash and Ansible to capture also cases of umask definition which are preceded by some other alphanumeric strings

Rationale:

Review Hints:

  • Review hints here. Replace this text. Don't use the italics format!

  • Use this optional section to give any relevant information which could help the reviewer to more quickly and assertively understand and test the changes.

  • Good examples are useful commands, if it is better to review all commits together or in a suggested sequence, any relevant discussion in other PRs or issues, etc.

@vojtapolasek vojtapolasek added Update Rule Issues or pull requests related to Rules updates. STIG STIG Benchmark related. labels Apr 16, 2024
@vojtapolasek vojtapolasek added this to the 0.1.73 milestone Apr 16, 2024
Copy link

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 Apr 16, 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_umask_etc_bashrc' differs.
--- xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc
+++ xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc
@@ -8,8 +8,8 @@
 
 
 
-grep -q "^\s*umask" /etc/bashrc && \
-  sed -i -E -e "s/^(\s*umask).*/\1 $var_accounts_user_umask/g" /etc/bashrc
+grep -q "^[^#]*\bumask" /etc/bashrc && \
+  sed -i -E -e "s/^([^#]*\bumask).*/\1 $var_accounts_user_umask/g" /etc/bashrc
 if ! [ $? -eq 0 ]; then
     echo "umask $var_accounts_user_umask" >> /etc/bashrc
 fi

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc' differs.
--- xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc
+++ xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc
@@ -21,7 +21,7 @@
 - name: Check if umask in /etc/bashrc is already set
   ansible.builtin.lineinfile:
     path: /etc/bashrc
-    regexp: ^(\s*)umask\s+.*
+    regexp: ^[^#]*\bumask\s+
     state: absent
   check_mode: true
   changed_when: false
@@ -42,7 +42,7 @@
 - name: Replace user umask in /etc/bashrc
   ansible.builtin.replace:
     path: /etc/bashrc
-    regexp: ^(\s*)umask(\s+).*
+    regexp: ^([^#]*\b)umask(\s*)
     replace: \g<1>umask\g<2>{{ var_accounts_user_umask }}
   when:
   - '"bash" in ansible_facts.packages'

Copy link

github-actions bot commented Apr 16, 2024

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

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

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

@@ -4,5 +4,5 @@
sed -i '/umask/d' /etc/bashrc
echo "umask 000" >> /etc/bashrc
echo "umask 000" >> /etc/bashrc
echo "umask 000" >> /etc/bashrc
echo " [ `umask` -eq 0 ] && umask 022" >> /etc/bashrc
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 problem in #11700 is that DISA content reports a fail because the regex in DISA check matches a line that doesn't have an effect on configuration because it's inside an irrelevant block of code whereas our content doesn't find it and behaves correct, why we are changing our OVAL? Shouldn't they change their OVAL instead?

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 don't think that the code block is irrelevant. It is true that the code block is executed for non login shells, at the other hand, there is no explicit mention of login shells in STIG: https://stigaview.com/products/rhel9/v1r2/RHEL-09-412055/
Why do you think the command you mention is actually irrelevant to the STIG? @jan-cerny

Copy link

codeclimate bot commented Apr 17, 2024

Code Climate has analyzed commit ad4277c 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.2% (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.

The problem with this rule is that we can't write a proper check using OVAL. We use regex matching but the code of /etc/bashrc is a bash script in which can be many constructions that we can't understand using regular expressions. For example, the umask setting can be wrapped by a condition that is evaluated as false.

This change improves the check for the specific situation, however, it can cause some false results in other situations.

The reason I merge it is that we improve the alignment of our checks with DISA STIG.

I have run tests locally against a RHEL 9 VM and they pass.

jcerny@fedora:~/work/git/scap-security-guide (pr/11822)$ python3 tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 accounts_umask_etc_bashrc
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-04-17-1759/test_suite.log
WARNING - Script stig_correct.pass.sh is not applicable on given platform
INFO - xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc
INFO - Script missing.fail.sh using profile (all) OK
WARNING - Rule xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc isn't part of profile xccdf_org.ssgproject.content_profile_ospp requested by script ospp_cis_correct.pass.sh.
INFO - Script super_compliant.pass.sh using profile (all) OK
INFO - Script wrong.fail.sh using profile (all) OK
INFO - Script wrong_multiple.fail.sh using profile (all) OK
INFO - Script wrong_and_not_at_the_begining_of_line.fail.sh using profile (all) OK
jcerny@fedora:~/work/git/scap-security-guide (pr/11822)$ python3 tests/automatus.py rule --libvirt qemu:///system ssgts_rhel9 --remediate-using ansible accounts_umask_etc_bashrc
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-04-17-1804/test_suite.log
WARNING - Script stig_correct.pass.sh is not applicable on given platform
INFO - xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc
INFO - Script missing.fail.sh using profile (all) OK
WARNING - Rule xccdf_org.ssgproject.content_rule_accounts_umask_etc_bashrc isn't part of profile xccdf_org.ssgproject.content_profile_ospp requested by script ospp_cis_correct.pass.sh.
INFO - Script super_compliant.pass.sh using profile (all) OK
INFO - Script wrong.fail.sh using profile (all) OK
INFO - Script wrong_multiple.fail.sh using profile (all) OK
INFO - Script wrong_and_not_at_the_begining_of_line.fail.sh using profile (all) OK

@jan-cerny jan-cerny merged commit f35e3a3 into ComplianceAsCode:master Apr 17, 2024
45 checks passed
@jan-cerny jan-cerny self-assigned this Apr 17, 2024
marcusburghardt added a commit to marcusburghardt/contest that referenced this pull request Apr 26, 2024
comps pushed a commit to RHSecurityCompliance/contest that referenced this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STIG STIG Benchmark related. Update Rule Issues or pull requests related to Rules updates.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

accounts_umask_etc_bashrc is misaligned with DISA
2 participants