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

Fix umask bash and Ansible #11108

Merged
merged 4 commits into from
Sep 13, 2023

Conversation

Xeicker
Copy link
Contributor

@Xeicker Xeicker commented Sep 11, 2023

Description:

  • Updated sed regexes in rules accounts_umask_etc_profile & accounts_umask_interactive_users

Rationale:

  • In accounts_umask_etc_profile the sed command would modify also commented lines
  • In accounts_umask_interactive_users the umask ocurrences that have leading spaces were being ignored

Review Hints:

  • For accounts_umask_interactive_users I added a automatus test
  • For accounts_umask_etc_profile I tested in this way:
    Whith existing regex:
$ cat file.txt 
# umask 777 This shouldn't be touched
# umask 000
umask 022
   umask 026 # This shouldn't be touched either
$ file=file.txt;var_accounts_user_umask=077; grep -qE '^[^#]*umask' "$file" && sed -i "s/umask.*/umask $var_accounts_user_umask/g" "$file"
$ cat file.txt 
# umask 077
# umask 077
umask 077
   umask 077

Whith new regex:

cat file.txt 
# umask 777 This shouldn't be touched
# umask 000
umask 022
   umask 026 # This shouldn't be touched either
$ file=file.txt;var_accounts_user_umask=077; grep -qE '^[^#]*umask' "$file" && sed -i -E "s/^(\s*umask\s*)[0-7]+/\1$var_accounts_user_umask/g" "$file"
$ # umask 777 This shouldn't be touched
# umask 000
umask 077
   umask 077 # This shouldn't be touched either

The sed regex doesn't find correctly blanck spaces at the beginning
of the configuration line

Signed-off-by: Edgar Aguilar <edgar.aguilar@oracle.com>
This ensures bash handles correctly spaces at the beginning of the line

Signed-off-by: Edgar Aguilar <edgar.aguilar@oracle.com>
The existing one is toot intrusive and could modify commented lines

Signed-off-by: Edgar Aguilar <edgar.aguilar@oracle.com>
@openshift-ci
Copy link

openshift-ci bot commented Sep 11, 2023

Hi @Xeicker. Thanks for your PR.

I'm waiting for a ComplianceAsCode member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added the needs-ok-to-test Used by openshift-ci bot. label Sep 11, 2023
@github-actions
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

@github-actions
Copy link

github-actions bot commented Sep 11, 2023

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_profile' differs.
--- xccdf_org.ssgproject.content_rule_accounts_umask_etc_profile
+++ xccdf_org.ssgproject.content_rule_accounts_umask_etc_profile
@@ -5,7 +5,7 @@
 readarray -t profile_files < <(find /etc/profile.d/ -type f -name '*.sh' -or -name 'sh.local')
 
 for file in "${profile_files[@]}" /etc/profile; do
-  grep -qE '^[^#]*umask' "$file" && sed -i "s/umask.*/umask $var_accounts_user_umask/g" "$file"
+  grep -qE '^[^#]*umask' "$file" && sed -i -E "s/^(\s*umask\s*)[0-7]+/\1$var_accounts_user_umask/g" "$file"
 done
 
 if ! grep -qrE '^[^#]*umask' /etc/profile*; then

bash remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_umask_interactive_users' differs.
--- xccdf_org.ssgproject.content_rule_accounts_umask_interactive_users
+++ xccdf_org.ssgproject.content_rule_accounts_umask_interactive_users
@@ -2,7 +2,7 @@
 while IFS= read -r dir; do
     while IFS= read -r -d '' file; do
         if [ "$(basename $file)" != ".bash_history" ]; then
-            sed -i 's/^\([\s]*umask\s*\)/#\1/g' "$file"
+            sed -i 's/^\(\s*umask\s*\)/#\1/g' "$file"
         fi
     done <   <(find $dir -maxdepth 1 -type f -name ".*" -print0)
 done <   <(awk -F':' '{ if ($3 >= 1000 && $3 != 65534) print $6}' /etc/passwd)

ansible remediation for rule 'xccdf_org.ssgproject.content_rule_accounts_umask_interactive_users' differs.
--- xccdf_org.ssgproject.content_rule_accounts_umask_interactive_users
+++ xccdf_org.ssgproject.content_rule_accounts_umask_interactive_users
@@ -5,7 +5,7 @@
       for dir in $(awk -F':' '{ if ($3 >= 1000 && $3 != 65534) print $6}' /etc/passwd); do
         for file in $(find $dir -maxdepth 1 -type f -name ".*"); do
           if [ "$(basename $file)" != ".bash_history" ]; then
-            sed -i 's/^\([\s]*umask\s*\)/#\1/g' $file
+            sed -i 's/^\(\s*umask\s*\)/#\1/g' $file
           fi
         done
       done

@Mab879 Mab879 added the Bash Bash remediation update. label Sep 11, 2023
@Mab879 Mab879 added this to the 0.1.70 milestone Sep 11, 2023
@Mab879 Mab879 self-assigned this Sep 11, 2023
Ansible uses a bash command, and the sed regex doesn't find correctly
blanck spaces at the beginning of the configuration line

Signed-off-by: Edgar Aguilar <edgar.aguilar@oracle.com>
@codeclimate
Copy link

codeclimate bot commented Sep 12, 2023

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

View more on Code Climate.

Copy link
Member

@marcusburghardt marcusburghardt left a comment

Choose a reason for hiding this comment

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

Thanks

@marcusburghardt marcusburghardt self-assigned this Sep 13, 2023
@marcusburghardt marcusburghardt merged commit aa6f2f0 into ComplianceAsCode:master Sep 13, 2023
36 of 37 checks passed
@marcusburghardt marcusburghardt changed the title Fix umask bash Fix umask bash and Ansible Sep 13, 2023
@Mab879 Mab879 removed their assignment Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bash Bash remediation update. needs-ok-to-test Used by openshift-ci bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants