Skip to content

Commit

Permalink
Merge pull request #11315 from Mab879/fix_tests_for_sudo_require_auth…
Browse files Browse the repository at this point in the history
…entication

Fix tests for sudo_require_authentication
  • Loading branch information
vojtapolasek committed Dec 1, 2023
2 parents 3c3b708 + 722e6d6 commit 6494d8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ echo "Defaults !authenticate" >> /etc/sudoers
chmod 440 /etc/sudoers

mkdir -p /etc/sudoers.d
echo "%wheel ALL=(ALL) !authenticate ALL" >> /etc/sudoers.d/sudoers
echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/sudoers
echo "Defaults !authenticate" >> /etc/sudoers.d/sudoers
chmod 440 /etc/sudoers.d/sudoers
12 changes: 10 additions & 2 deletions shared/macros/10-ansible.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -721,17 +721,25 @@ The following macro remediates Audit syscall rule in :code:`/etc/audit/audit.rul
mode: 0644
{{%- endmacro %}}

{{#
This macro comments out a given line of the sudoers and then validates it before saving.

:param parameter: The parameter to remove
:type parameter: str
:param pattern: The pattern to remove
:type pattern: str

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

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

- name: "Remove lines containing {{{ parameter }}} from sudoers files"
replace:
ansible.builtin.replace:
regexp: '(^(?!#).*[\s]+{{{ pattern }}}.*$)'
replace: '# \g<1>'
path: "{{ item.path }}"
Expand Down

0 comments on commit 6494d8f

Please sign in to comment.