-
Notifications
You must be signed in to change notification settings - Fork 685
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
accounts_umask_etc_bashrc: extend handled cases of umask #11822
Conversation
This datastream diff is auto generated by the check Click here to see the full diffbash 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' |
🤖 A k8s content image for this PR is available at: Click here to see how to deploy itIf you alread have Compliance Operator deployed: Otherwise deploy the content and operator together by checking out ComplianceAsCode/compliance-operator and: |
.../accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/tests/wrong_multiple.fail.sh
Outdated
Show resolved
Hide resolved
.../guide/system/accounts/accounts-session/user_umask/accounts_umask_etc_bashrc/oval/shared.xml
Outdated
Show resolved
Hide resolved
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
…umask which are not at the begining of line
9b0e026
to
ad4277c
Compare
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. |
There was a problem hiding this 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
Description:
Rationale:
sometimes the umask definition might be for example part of a one line conditional. This modification covers these cases as well.
Fixes accounts_umask_etc_bashrc is misaligned with DISA #11700
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.