Skip to content

Commit

Permalink
Merge pull request #6049 from ggbecker/update-stig-RHEL-07-010340
Browse files Browse the repository at this point in the history
Add bash and ansible remediation for sudo_remove_nopasswd and sudo_remove_no_authenticate
  • Loading branch information
redhatrises committed Sep 10, 2020
2 parents c7a58e4 + e6ebab4 commit 4d8701f
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# platform = multi_platform_all
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low

{{{ ansible_sudo_remove_config("!authenticate", "!authenticate") }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# platform = multi_platform_all
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low

{{{ bash_sudo_remove_config("!authenticate", "!authenticate") }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_stig

rm -f /etc/sudoers
echo "Defaults authenticate" > /etc/sudoers
chmod 440 /etc/sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_stig

echo "Defaults !authenticate" >> /etc/sudoers
chmod 440 /etc/sudoers

mkdir /etc/sudoers.d/
echo "Defaults !authenticate" >> /etc/sudoers.d/sudoers
chmod 440 /etc/sudoers.d/sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# platform = multi_platform_all
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low

{{{ ansible_sudo_remove_config("NOPASSWD", "NOPASSWD[\s]*\:") }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# platform = multi_platform_all
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low

{{{ bash_sudo_remove_config("NOPASSWD", "NOPASSWD[\s]*\:") }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_stig

rm -f /etc/sudoers
echo "%wheel ALL=(ALL) ALL" > /etc/sudoers
chmod 440 /etc/sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_stig

echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
chmod 440 /etc/sudoers

mkdir /etc/sudoers.d/
echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/sudoers
chmod 440 /etc/sudoers.d/sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# platform = multi_platform_all
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low

{{{ ansible_sudo_remove_config("NOPASSWD", "NOPASSWD[\s]*\:") }}}

{{{ ansible_sudo_remove_config("!authenticate", "!authenticate") }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# platform = multi_platform_all
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low

{{{ bash_sudo_remove_config("NOPASSWD", "NOPASSWD[\s]*\:") }}}

{{{ bash_sudo_remove_config("!authenticate", "!authenticate") }}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_e8

rm -f /etc/sudoers
echo "%wheel ALL=(ALL) ALL" > /etc/sudoers
echo "Defaults authenticate" > /etc/sudoers
chmod 440 /etc/sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_e8

echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "Defaults !authenticate" >> /etc/sudoers
chmod 440 /etc/sudoers

mkdir /etc/sudoers.d/
echo "%wheel ALL=(ALL) !authenticate ALL" >> /etc/sudoers.d/sudoers
echo "Defaults !authenticate" >> /etc/sudoers.d/sudoers
chmod 440 /etc/sudoers.d/sudoers
19 changes: 19 additions & 0 deletions shared/macros-ansible.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,22 @@ See official documentation: https://jinja.palletsprojects.com/en/2.11.x/template
create: yes
mode: 0644
{{%- endmacro %}}

{{%- macro ansible_sudo_remove_config(parameter, pattern) -%}}

- name: Find /etc/sudoers.d/ files
find:
paths:
- /etc/sudoers.d/
register: sudoers

- name: "Remove lines containing {{{ parameter }}} from sudoers files"
replace:
regexp: '(^(?!#).*[\s]+\{{{ pattern }}}.*$)'
replace: '# \g<1>'
path: "{{ item.path }}"
validate: /usr/sbin/visudo -cf %s
with_items:
- { path: /etc/sudoers }
- "{{ sudoers.files }}"
{{%- endmacro -%}}
14 changes: 14 additions & 0 deletions shared/macros-bash.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,17 @@ else
fi
fi
{{%- endmacro %}}

{{%- macro bash_sudo_remove_config(parameter, pattern) -%}}
for f in $( ls /etc/sudoers /etc/sudoers.d/* 2> /dev/null ) ; do
matching_list=$(grep -P '^(?!#).*[\s]+\{{{ pattern }}}.*$' $f | uniq )
if ! test -z "$matching_list"; then
while IFS= read -r entry; do
# comment out "{{{ parameter }}}" matches to preserve user data
sed -i "s/^${entry}$/# &/g" $f
done <<< "$matching_list"

/usr/sbin/visudo -cf $f &> /dev/null || echo "Fail to validate $f with visudo"
fi
done
{{%- endmacro -%}}

0 comments on commit 4d8701f

Please sign in to comment.