test: verify unmanaged sudoers files survive
Guard against regressions that remove the login user’s sudo access. Verify that only a drop-in marked state: absent is removed. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
3 files changed
+22
-10
No files matched your search
+6
-6
@@ -3,9 +3,9 @@
|
|||||||
sudo_users_sudoers: []
|
sudo_users_sudoers: []
|
||||||
# - commands:
|
# - commands:
|
||||||
# - ALL
|
# - ALL
|
||||||
# filename: "" # Optional: Default to user or group
|
# filename: "" # Optional: Default to user or group
|
||||||
# group: "" # Group or User, not booth!
|
# group: "" # Group or User, not booth!
|
||||||
# nopassword: true
|
# nopassword: true #
|
||||||
# runas: "" # Optional
|
# runas: "" # Optional
|
||||||
# state: present # Optional: present or absent. Default to present
|
# state: present # Optional: absent removes this drop-in; defaults to present
|
||||||
# user: "markus": # Group or User, not booth!
|
# user: "markus": # Group or User, not booth!
|
||||||
@@ -41,8 +41,7 @@
|
|||||||
- molecule-alice
|
- molecule-alice
|
||||||
- molecule-bob
|
- molecule-bob
|
||||||
|
|
||||||
# The removal path of the role can only be observed on a drop-in file that exists before the role runs.
|
- name: Create the drop-in directory for the seeded files
|
||||||
- name: Create the drop-in directory the seeded file lives in
|
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /etc/sudoers.d
|
path: /etc/sudoers.d
|
||||||
state: directory
|
state: directory
|
||||||
@@ -50,10 +49,13 @@
|
|||||||
group: root
|
group: root
|
||||||
mode: "0750"
|
mode: "0750"
|
||||||
|
|
||||||
- name: Seed the drop-in file that the converge removes again
|
- name: Seed the obsolete and unmanaged drop-in files
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
content: "molecule-alice ALL=NOPASSWD: /usr/bin/true\n"
|
content: "molecule-alice ALL=NOPASSWD: /usr/bin/true\n"
|
||||||
dest: /etc/sudoers.d/molecule-obsolete
|
dest: '/etc/sudoers.d/{{ item }}'
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0440"
|
mode: "0440"
|
||||||
|
loop:
|
||||||
|
- molecule-obsolete
|
||||||
|
- molecule-unmanaged
|
||||||
@@ -26,6 +26,16 @@
|
|||||||
- not _directory.results[1].stat.exists
|
- not _directory.results[1].stat.exists
|
||||||
fail_msg: "/etc/sudoers.d is not owned by the role or the file molecule-obsolete was not removed"
|
fail_msg: "/etc/sudoers.d is not owned by the role or the file molecule-obsolete was not removed"
|
||||||
|
|
||||||
|
- name: Read the unmanaged drop-in file
|
||||||
|
ansible.builtin.slurp:
|
||||||
|
src: /etc/sudoers.d/molecule-unmanaged
|
||||||
|
register: _unmanaged_rule
|
||||||
|
|
||||||
|
- name: Assert that the unmanaged drop-in file was preserved unchanged
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that: >-
|
||||||
|
(_unmanaged_rule.content | b64decode) == 'molecule-alice ALL=NOPASSWD: /usr/bin/true\n'
|
||||||
|
|
||||||
- name: Stat the drop-in files of the declared rules
|
- name: Stat the drop-in files of the declared rules
|
||||||
ansible.builtin.stat:
|
ansible.builtin.stat:
|
||||||
path: "/etc/sudoers.d/{{ item.key }}"
|
path: "/etc/sudoers.d/{{ item.key }}"
|
||||||
|
|||||||
Reference in new issue
Block a user